mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
skeleton for caching stdlib subs
This commit is contained in:
parent
1716879f82
commit
afee877cf1
3 changed files with 83 additions and 18 deletions
53
compiler/load/build.rs
Normal file
53
compiler/load/build.rs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use bumpalo::Bump;
|
||||||
|
use roc_module::symbol::ModuleId;
|
||||||
|
|
||||||
|
const MODULES: &[(ModuleId, &str)] = &[
|
||||||
|
(ModuleId::BOOL, "Bool.roc"),
|
||||||
|
// (ModuleId::RESULT, "Result.roc"),
|
||||||
|
// (ModuleId::LIST, "List.roc"),
|
||||||
|
// (ModuleId::STR, "Str.roc"),
|
||||||
|
// (ModuleId::DICT, "Dict.roc"),
|
||||||
|
// (ModuleId::SET, "Set.roc"),
|
||||||
|
// (ModuleId::BOX, "Box.roc"),
|
||||||
|
// (ModuleId::NUM, "Num.roc"),
|
||||||
|
];
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
for (module_id, filename) in MODULES {
|
||||||
|
write_subs_for_module(*module_id, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_subs_for_module(module_id: ModuleId, filename: &str) {
|
||||||
|
// Tell Cargo that if the given file changes, to rerun this build script.
|
||||||
|
println!(
|
||||||
|
"cargo:rerun-if-changed=../builtins/standard_library/{}",
|
||||||
|
filename
|
||||||
|
);
|
||||||
|
|
||||||
|
let arena = Bump::new();
|
||||||
|
let src_dir = PathBuf::from(".");
|
||||||
|
let source = roc_builtins::standard_library::module_source(module_id);
|
||||||
|
let target_info = roc_target::TargetInfo::default_x86_64();
|
||||||
|
|
||||||
|
let res_module = roc_load_internal::file::load_and_typecheck_str(
|
||||||
|
&arena,
|
||||||
|
PathBuf::from(filename),
|
||||||
|
source,
|
||||||
|
&src_dir,
|
||||||
|
Default::default(),
|
||||||
|
target_info,
|
||||||
|
);
|
||||||
|
|
||||||
|
let module = res_module.unwrap();
|
||||||
|
let subs = module.solved.inner();
|
||||||
|
let exposed_vars_by_symbol: Vec<_> = module.exposed_to_host.into_iter().collect();
|
||||||
|
|
||||||
|
let mut output_path = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||||
|
output_path.extend(&[filename]);
|
||||||
|
output_path.set_extension("dat");
|
||||||
|
let mut file = std::fs::File::create(&output_path).unwrap();
|
||||||
|
subs.serialize(&exposed_vars_by_symbol, &mut file).unwrap();
|
||||||
|
}
|
|
@ -32,22 +32,6 @@ fn load<'a>(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const BOOL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Bool.dat")) as &[_];
|
|
||||||
|
|
||||||
fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) {
|
|
||||||
let (subs, slice) = Subs::deserialize(bytes);
|
|
||||||
|
|
||||||
(subs, slice.to_vec())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_cached_subs() -> MutMap<ModuleId, (Subs, Vec<(Symbol, Variable)>)> {
|
|
||||||
let mut output = MutMap::default();
|
|
||||||
|
|
||||||
output.insert(ModuleId::BOOL, deserialize_help(BOOL));
|
|
||||||
|
|
||||||
output
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load_and_monomorphize_from_str<'a>(
|
pub fn load_and_monomorphize_from_str<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
|
@ -120,3 +104,33 @@ pub fn load_and_typecheck<'a>(
|
||||||
TypeChecked(module) => Ok(module),
|
TypeChecked(module) => Ok(module),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
(subs, slice.to_vec())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_cached_subs() -> MutMap<ModuleId, (Subs, Vec<(Symbol, Variable)>)> {
|
||||||
|
let mut output = MutMap::default();
|
||||||
|
|
||||||
|
output.insert(ModuleId::BOOL, deserialize_help(BOOL));
|
||||||
|
// output.insert(ModuleId::RESULT, deserialize_help(RESULT));
|
||||||
|
// 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::NUM, deserialize_help(NUM));
|
||||||
|
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
|
@ -3171,8 +3171,6 @@ fn run_solve<'a>(
|
||||||
.filter(|(k, _)| exposed_symbols.contains(k))
|
.filter(|(k, _)| exposed_symbols.contains(k))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
dbg!(&exposed_vars_by_symbol);
|
|
||||||
|
|
||||||
let mut solved_subs = solved_subs;
|
let mut solved_subs = solved_subs;
|
||||||
let (storage_subs, stored_vars_by_symbol) =
|
let (storage_subs, stored_vars_by_symbol) =
|
||||||
roc_solve::module::exposed_types_storage_subs(&mut solved_subs, &exposed_vars_by_symbol);
|
roc_solve::module::exposed_types_storage_subs(&mut solved_subs, &exposed_vars_by_symbol);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue