mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
re-enable builtin module caching
This commit is contained in:
parent
2b94eeed60
commit
e9bdf0e5de
5 changed files with 79 additions and 60 deletions
|
@ -5,16 +5,16 @@ use roc_load_internal::file::Threading;
|
||||||
use roc_module::symbol::ModuleId;
|
use roc_module::symbol::ModuleId;
|
||||||
|
|
||||||
const MODULES: &[(ModuleId, &str)] = &[
|
const MODULES: &[(ModuleId, &str)] = &[
|
||||||
// (ModuleId::BOOL, "Bool.roc"),
|
(ModuleId::BOOL, "Bool.roc"),
|
||||||
// (ModuleId::RESULT, "Result.roc"),
|
(ModuleId::RESULT, "Result.roc"),
|
||||||
// (ModuleId::NUM, "Num.roc"),
|
(ModuleId::NUM, "Num.roc"),
|
||||||
// (ModuleId::LIST, "List.roc"),
|
(ModuleId::LIST, "List.roc"),
|
||||||
// (ModuleId::STR, "Str.roc"),
|
(ModuleId::STR, "Str.roc"),
|
||||||
// (ModuleId::DICT, "Dict.roc"),
|
(ModuleId::DICT, "Dict.roc"),
|
||||||
// (ModuleId::SET, "Set.roc"),
|
(ModuleId::SET, "Set.roc"),
|
||||||
// (ModuleId::BOX, "Box.roc"),
|
(ModuleId::BOX, "Box.roc"),
|
||||||
// (ModuleId::ENCODE, "Encode.roc"),
|
(ModuleId::ENCODE, "Encode.roc"),
|
||||||
// (ModuleId::JSON, "Json.roc"),
|
(ModuleId::JSON, "Json.roc"),
|
||||||
];
|
];
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -180,14 +180,14 @@ pub fn load_and_typecheck_str<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// const BOOL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Bool.dat")) as &[_];
|
const BOOL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Bool.dat")) as &[_];
|
||||||
// const RESULT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Result.dat")) as &[_];
|
const RESULT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Result.dat")) as &[_];
|
||||||
// const LIST: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/List.dat")) as &[_];
|
const LIST: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/List.dat")) as &[_];
|
||||||
// const STR: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Str.dat")) as &[_];
|
const STR: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Str.dat")) as &[_];
|
||||||
// const DICT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Dict.dat")) as &[_];
|
const DICT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Dict.dat")) as &[_];
|
||||||
// const SET: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Set.dat")) as &[_];
|
const SET: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Set.dat")) as &[_];
|
||||||
// const BOX: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Box.dat")) as &[_];
|
const BOX: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Box.dat")) as &[_];
|
||||||
// const NUM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Num.dat")) as &[_];
|
const NUM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Num.dat")) as &[_];
|
||||||
|
|
||||||
fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) {
|
fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) {
|
||||||
let (subs, slice) = Subs::deserialize(bytes);
|
let (subs, slice) = Subs::deserialize(bytes);
|
||||||
|
@ -201,16 +201,16 @@ fn read_cached_subs() -> MutMap<ModuleId, (Subs, Vec<(Symbol, Variable)>)> {
|
||||||
// Wasm seems to re-order definitions between build time and runtime, but only in release mode.
|
// Wasm seems to re-order definitions between build time and runtime, but only in release mode.
|
||||||
// That is very strange, but we can solve it separately
|
// That is very strange, but we can solve it separately
|
||||||
if !cfg!(target_family = "wasm") {
|
if !cfg!(target_family = "wasm") {
|
||||||
// output.insert(ModuleId::BOOL, deserialize_help(BOOL));
|
output.insert(ModuleId::BOOL, deserialize_help(BOOL));
|
||||||
// output.insert(ModuleId::RESULT, deserialize_help(RESULT));
|
output.insert(ModuleId::RESULT, deserialize_help(RESULT));
|
||||||
// output.insert(ModuleId::NUM, deserialize_help(NUM));
|
output.insert(ModuleId::NUM, deserialize_help(NUM));
|
||||||
//
|
|
||||||
// output.insert(ModuleId::LIST, deserialize_help(LIST));
|
output.insert(ModuleId::LIST, deserialize_help(LIST));
|
||||||
// output.insert(ModuleId::STR, deserialize_help(STR));
|
output.insert(ModuleId::STR, deserialize_help(STR));
|
||||||
// output.insert(ModuleId::DICT, deserialize_help(DICT));
|
output.insert(ModuleId::DICT, deserialize_help(DICT));
|
||||||
//
|
|
||||||
// output.insert(ModuleId::SET, deserialize_help(SET));
|
output.insert(ModuleId::SET, deserialize_help(SET));
|
||||||
// output.insert(ModuleId::BOX, deserialize_help(BOX));
|
output.insert(ModuleId::BOX, deserialize_help(BOX));
|
||||||
}
|
}
|
||||||
|
|
||||||
output
|
output
|
||||||
|
|
|
@ -8,7 +8,7 @@ use roc_module::ident::{Lowercase, TagName, Uppercase};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter::{once, Iterator, Map};
|
use std::iter::{once, Iterator, Map};
|
||||||
use ven_ena::unify::{InPlace, /* Snapshot, UnificationTable, */ UnifyKey};
|
use ven_ena::unify::UnifyKey;
|
||||||
|
|
||||||
use crate::unification_table::{Snapshot, UnificationTable};
|
use crate::unification_table::{Snapshot, UnificationTable};
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ impl Subs {
|
||||||
written += header.len();
|
written += header.len();
|
||||||
writer.write_all(&header)?;
|
writer.write_all(&header)?;
|
||||||
|
|
||||||
written = Self::serialize_unification_table(&self.utable, writer, written)?;
|
written = self.utable.serialize(writer, written)?;
|
||||||
|
|
||||||
written = Self::serialize_slice(&self.variables, writer, written)?;
|
written = Self::serialize_slice(&self.variables, writer, written)?;
|
||||||
written = Self::serialize_tag_names(&self.tag_names, writer, written)?;
|
written = Self::serialize_tag_names(&self.tag_names, writer, written)?;
|
||||||
|
@ -144,14 +144,6 @@ impl Subs {
|
||||||
Ok(written)
|
Ok(written)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_unification_table(
|
|
||||||
utable: &UnificationTable,
|
|
||||||
writer: &mut impl std::io::Write,
|
|
||||||
mut written: usize,
|
|
||||||
) -> std::io::Result<usize> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Lowercase can be heap-allocated
|
/// Lowercase can be heap-allocated
|
||||||
fn serialize_field_names(
|
fn serialize_field_names(
|
||||||
lowercases: &[Lowercase],
|
lowercases: &[Lowercase],
|
||||||
|
@ -201,7 +193,7 @@ impl Subs {
|
||||||
Self::serialize_slice(&buf, writer, written)
|
Self::serialize_slice(&buf, writer, written)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_slice<T>(
|
pub(crate) fn serialize_slice<T>(
|
||||||
slice: &[T],
|
slice: &[T],
|
||||||
writer: &mut impl std::io::Write,
|
writer: &mut impl std::io::Write,
|
||||||
written: usize,
|
written: usize,
|
||||||
|
@ -225,8 +217,7 @@ impl Subs {
|
||||||
offset += header_slice.len();
|
offset += header_slice.len();
|
||||||
let header = SubsHeader::from_array(header_slice.try_into().unwrap());
|
let header = SubsHeader::from_array(header_slice.try_into().unwrap());
|
||||||
|
|
||||||
let (utable, offset) =
|
let (utable, offset) = UnificationTable::deserialize(bytes, header.utable as usize, offset);
|
||||||
Self::deserialize_unification_table(bytes, header.utable as usize, offset);
|
|
||||||
|
|
||||||
let (variables, offset) = Self::deserialize_slice(bytes, header.variables as usize, offset);
|
let (variables, offset) = Self::deserialize_slice(bytes, header.variables as usize, offset);
|
||||||
let (tag_names, offset) =
|
let (tag_names, offset) =
|
||||||
|
@ -255,14 +246,6 @@ impl Subs {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_unification_table(
|
|
||||||
bytes: &[u8],
|
|
||||||
length: usize,
|
|
||||||
offset: usize,
|
|
||||||
) -> (UnificationTable, usize) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn deserialize_field_names(
|
fn deserialize_field_names(
|
||||||
bytes: &[u8],
|
bytes: &[u8],
|
||||||
length: usize,
|
length: usize,
|
||||||
|
@ -309,7 +292,11 @@ impl Subs {
|
||||||
(tag_names, offset)
|
(tag_names, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_slice<T>(bytes: &[u8], length: usize, mut offset: usize) -> (&[T], usize) {
|
pub(crate) fn deserialize_slice<T>(
|
||||||
|
bytes: &[u8],
|
||||||
|
length: usize,
|
||||||
|
mut offset: usize,
|
||||||
|
) -> (&[T], usize) {
|
||||||
let alignment = std::mem::align_of::<T>();
|
let alignment = std::mem::align_of::<T>();
|
||||||
let size = std::mem::size_of::<T>();
|
let size = std::mem::size_of::<T>();
|
||||||
|
|
||||||
|
@ -1878,11 +1865,6 @@ impl Subs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn flex_var_descriptor() -> Descriptor {
|
|
||||||
Descriptor::from(unnamed_flex_var())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
const fn unnamed_flex_var() -> Content {
|
const fn unnamed_flex_var() -> Content {
|
||||||
Content::FlexVar(None)
|
Content::FlexVar(None)
|
||||||
|
|
|
@ -12,6 +12,7 @@ pub struct UnificationTable {
|
||||||
pub struct Snapshot(UnificationTable);
|
pub struct Snapshot(UnificationTable);
|
||||||
|
|
||||||
impl UnificationTable {
|
impl UnificationTable {
|
||||||
|
#[allow(unused)]
|
||||||
pub fn with_capacity(cap: usize) -> Self {
|
pub fn with_capacity(cap: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
contents: Vec::with_capacity(cap), // vec![Content::Error; cap],
|
contents: Vec::with_capacity(cap), // vec![Content::Error; cap],
|
||||||
|
@ -65,6 +66,7 @@ impl UnificationTable {
|
||||||
variable
|
variable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub fn set(
|
pub fn set(
|
||||||
&mut self,
|
&mut self,
|
||||||
key: Variable,
|
key: Variable,
|
||||||
|
@ -217,4 +219,40 @@ impl UnificationTable {
|
||||||
self.marks[index] = desc.mark;
|
self.marks[index] = desc.mark;
|
||||||
self.copies[index] = desc.copy;
|
self.copies[index] = desc.copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn serialize(
|
||||||
|
&self,
|
||||||
|
writer: &mut impl std::io::Write,
|
||||||
|
mut written: usize,
|
||||||
|
) -> std::io::Result<usize> {
|
||||||
|
use crate::subs::Subs;
|
||||||
|
|
||||||
|
written = Subs::serialize_slice(&self.contents, writer, written)?;
|
||||||
|
written = Subs::serialize_slice(&self.ranks, writer, written)?;
|
||||||
|
written = Subs::serialize_slice(&self.marks, writer, written)?;
|
||||||
|
written = Subs::serialize_slice(&self.copies, writer, written)?;
|
||||||
|
written = Subs::serialize_slice(&self.redirects, writer, written)?;
|
||||||
|
|
||||||
|
Ok(written)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn deserialize(bytes: &[u8], length: usize, offset: usize) -> (Self, usize) {
|
||||||
|
use crate::subs::Subs;
|
||||||
|
|
||||||
|
let (contents, offset) = Subs::deserialize_slice::<Content>(bytes, length, offset);
|
||||||
|
let (ranks, offset) = Subs::deserialize_slice::<Rank>(bytes, length, offset);
|
||||||
|
let (marks, offset) = Subs::deserialize_slice::<Mark>(bytes, length, offset);
|
||||||
|
let (copies, offset) = Subs::deserialize_slice::<OptVariable>(bytes, length, offset);
|
||||||
|
let (redirects, offset) = Subs::deserialize_slice::<OptVariable>(bytes, length, offset);
|
||||||
|
|
||||||
|
let this = Self {
|
||||||
|
contents: contents.to_vec(),
|
||||||
|
ranks: ranks.to_vec(),
|
||||||
|
marks: marks.to_vec(),
|
||||||
|
copies: copies.to_vec(),
|
||||||
|
redirects: redirects.to_vec(),
|
||||||
|
};
|
||||||
|
|
||||||
|
(this, offset)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -502,7 +502,7 @@ fn unify_two_aliases(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(other_args.all_variables().into_iter());
|
.zip(other_args.all_variables().into_iter());
|
||||||
|
|
||||||
let args_unification_snapshot = subs.snapshot();
|
let length_before = subs.len();
|
||||||
|
|
||||||
for (l, r) in it {
|
for (l, r) in it {
|
||||||
let l_var = subs[l];
|
let l_var = subs[l];
|
||||||
|
@ -514,10 +514,9 @@ fn unify_two_aliases(
|
||||||
outcome.union(merge(subs, ctx, *other_content));
|
outcome.union(merge(subs, ctx, *other_content));
|
||||||
}
|
}
|
||||||
|
|
||||||
let args_unification_had_changes = !subs
|
let length_after = subs.len();
|
||||||
.vars_since_snapshot(&args_unification_snapshot)
|
|
||||||
.is_empty();
|
let args_unification_had_changes = length_after != length_before;
|
||||||
subs.commit_snapshot(args_unification_snapshot);
|
|
||||||
|
|
||||||
if !args.is_empty() && args_unification_had_changes && outcome.mismatches.is_empty() {
|
if !args.is_empty() && args_unification_had_changes && outcome.mismatches.is_empty() {
|
||||||
// We need to unify the real vars because unification of type variables
|
// We need to unify the real vars because unification of type variables
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue