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;
|
||||
|
||||
const MODULES: &[(ModuleId, &str)] = &[
|
||||
// (ModuleId::BOOL, "Bool.roc"),
|
||||
// (ModuleId::RESULT, "Result.roc"),
|
||||
// (ModuleId::NUM, "Num.roc"),
|
||||
// (ModuleId::LIST, "List.roc"),
|
||||
// (ModuleId::STR, "Str.roc"),
|
||||
// (ModuleId::DICT, "Dict.roc"),
|
||||
// (ModuleId::SET, "Set.roc"),
|
||||
// (ModuleId::BOX, "Box.roc"),
|
||||
// (ModuleId::ENCODE, "Encode.roc"),
|
||||
// (ModuleId::JSON, "Json.roc"),
|
||||
(ModuleId::BOOL, "Bool.roc"),
|
||||
(ModuleId::RESULT, "Result.roc"),
|
||||
(ModuleId::NUM, "Num.roc"),
|
||||
(ModuleId::LIST, "List.roc"),
|
||||
(ModuleId::STR, "Str.roc"),
|
||||
(ModuleId::DICT, "Dict.roc"),
|
||||
(ModuleId::SET, "Set.roc"),
|
||||
(ModuleId::BOX, "Box.roc"),
|
||||
(ModuleId::ENCODE, "Encode.roc"),
|
||||
(ModuleId::JSON, "Json.roc"),
|
||||
];
|
||||
|
||||
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 RESULT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Result.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 DICT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Dict.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 NUM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Num.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 LIST: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/List.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 SET: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Set.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 &[_];
|
||||
|
||||
fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) {
|
||||
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.
|
||||
// That is very strange, but we can solve it separately
|
||||
if !cfg!(target_family = "wasm") {
|
||||
// output.insert(ModuleId::BOOL, deserialize_help(BOOL));
|
||||
// output.insert(ModuleId::RESULT, deserialize_help(RESULT));
|
||||
// output.insert(ModuleId::NUM, deserialize_help(NUM));
|
||||
//
|
||||
// output.insert(ModuleId::LIST, deserialize_help(LIST));
|
||||
// output.insert(ModuleId::STR, deserialize_help(STR));
|
||||
// output.insert(ModuleId::DICT, deserialize_help(DICT));
|
||||
//
|
||||
// output.insert(ModuleId::SET, deserialize_help(SET));
|
||||
// output.insert(ModuleId::BOX, deserialize_help(BOX));
|
||||
output.insert(ModuleId::BOOL, deserialize_help(BOOL));
|
||||
output.insert(ModuleId::RESULT, deserialize_help(RESULT));
|
||||
output.insert(ModuleId::NUM, deserialize_help(NUM));
|
||||
|
||||
output.insert(ModuleId::LIST, deserialize_help(LIST));
|
||||
output.insert(ModuleId::STR, deserialize_help(STR));
|
||||
output.insert(ModuleId::DICT, deserialize_help(DICT));
|
||||
|
||||
output.insert(ModuleId::SET, deserialize_help(SET));
|
||||
output.insert(ModuleId::BOX, deserialize_help(BOX));
|
||||
}
|
||||
|
||||
output
|
||||
|
|
|
@ -8,7 +8,7 @@ use roc_module::ident::{Lowercase, TagName, Uppercase};
|
|||
use roc_module::symbol::Symbol;
|
||||
use std::fmt;
|
||||
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};
|
||||
|
||||
|
@ -132,7 +132,7 @@ impl Subs {
|
|||
written += header.len();
|
||||
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_tag_names(&self.tag_names, writer, written)?;
|
||||
|
@ -144,14 +144,6 @@ impl Subs {
|
|||
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
|
||||
fn serialize_field_names(
|
||||
lowercases: &[Lowercase],
|
||||
|
@ -201,7 +193,7 @@ impl Subs {
|
|||
Self::serialize_slice(&buf, writer, written)
|
||||
}
|
||||
|
||||
fn serialize_slice<T>(
|
||||
pub(crate) fn serialize_slice<T>(
|
||||
slice: &[T],
|
||||
writer: &mut impl std::io::Write,
|
||||
written: usize,
|
||||
|
@ -225,8 +217,7 @@ impl Subs {
|
|||
offset += header_slice.len();
|
||||
let header = SubsHeader::from_array(header_slice.try_into().unwrap());
|
||||
|
||||
let (utable, offset) =
|
||||
Self::deserialize_unification_table(bytes, header.utable as usize, offset);
|
||||
let (utable, offset) = UnificationTable::deserialize(bytes, header.utable as usize, offset);
|
||||
|
||||
let (variables, offset) = Self::deserialize_slice(bytes, header.variables as usize, 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(
|
||||
bytes: &[u8],
|
||||
length: usize,
|
||||
|
@ -309,7 +292,11 @@ impl Subs {
|
|||
(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 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)]
|
||||
const fn unnamed_flex_var() -> Content {
|
||||
Content::FlexVar(None)
|
||||
|
|
|
@ -12,6 +12,7 @@ pub struct UnificationTable {
|
|||
pub struct Snapshot(UnificationTable);
|
||||
|
||||
impl UnificationTable {
|
||||
#[allow(unused)]
|
||||
pub fn with_capacity(cap: usize) -> Self {
|
||||
Self {
|
||||
contents: Vec::with_capacity(cap), // vec![Content::Error; cap],
|
||||
|
@ -65,6 +66,7 @@ impl UnificationTable {
|
|||
variable
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn set(
|
||||
&mut self,
|
||||
key: Variable,
|
||||
|
@ -217,4 +219,40 @@ impl UnificationTable {
|
|||
self.marks[index] = desc.mark;
|
||||
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()
|
||||
.zip(other_args.all_variables().into_iter());
|
||||
|
||||
let args_unification_snapshot = subs.snapshot();
|
||||
let length_before = subs.len();
|
||||
|
||||
for (l, r) in it {
|
||||
let l_var = subs[l];
|
||||
|
@ -514,10 +514,9 @@ fn unify_two_aliases(
|
|||
outcome.union(merge(subs, ctx, *other_content));
|
||||
}
|
||||
|
||||
let args_unification_had_changes = !subs
|
||||
.vars_since_snapshot(&args_unification_snapshot)
|
||||
.is_empty();
|
||||
subs.commit_snapshot(args_unification_snapshot);
|
||||
let length_after = subs.len();
|
||||
|
||||
let args_unification_had_changes = length_after != length_before;
|
||||
|
||||
if !args.is_empty() && args_unification_had_changes && outcome.mismatches.is_empty() {
|
||||
// We need to unify the real vars because unification of type variables
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue