mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Serialize abilities store and solved implementations with subs
This commit is contained in:
parent
46eb427393
commit
7e79ff55f1
7 changed files with 281 additions and 80 deletions
|
@ -20,6 +20,7 @@ roc_builtins = { path = "../builtins" }
|
|||
roc_module = { path = "../module" }
|
||||
roc_reporting = { path = "../../reporting" }
|
||||
roc_target = { path = "../roc_target" }
|
||||
roc_can = { path = "../can" }
|
||||
bumpalo = { version = "3.11.0", features = ["collections"] }
|
||||
|
||||
[target.'cfg(not(windows))'.build-dependencies]
|
||||
|
|
|
@ -46,26 +46,27 @@ fn write_subs_for_module(module_id: ModuleId, filename: &str) {
|
|||
|
||||
#[cfg(not(windows))]
|
||||
if SKIP_SUBS_CACHE {
|
||||
write_subs_for_module_dummy(&output_path)
|
||||
write_types_for_module_dummy(&output_path)
|
||||
} else {
|
||||
write_subs_for_module_real(module_id, filename, &output_path)
|
||||
write_types_for_module_real(module_id, filename, &output_path)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let _ = SKIP_SUBS_CACHE;
|
||||
let _ = module_id;
|
||||
write_subs_for_module_dummy(&output_path)
|
||||
write_types_for_module_dummy(&output_path)
|
||||
}
|
||||
}
|
||||
|
||||
fn write_subs_for_module_dummy(output_path: &Path) {
|
||||
fn write_types_for_module_dummy(output_path: &Path) {
|
||||
// write out a dummy file
|
||||
std::fs::write(output_path, &[]).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn write_subs_for_module_real(module_id: ModuleId, filename: &str, output_path: &Path) {
|
||||
fn write_types_for_module_real(module_id: ModuleId, filename: &str, output_path: &Path) {
|
||||
use roc_can::module::TypeState;
|
||||
use roc_load_internal::file::{LoadingProblem, Threading};
|
||||
|
||||
let arena = Bump::new();
|
||||
|
@ -94,9 +95,19 @@ fn write_subs_for_module_real(module_id: ModuleId, filename: &str, output_path:
|
|||
}
|
||||
};
|
||||
|
||||
let subs = module.solved.inner();
|
||||
let subs = module.solved.into_inner();
|
||||
let exposed_vars_by_symbol: Vec<_> = module.exposed_to_host.into_iter().collect();
|
||||
let abilities = module.abilities_store;
|
||||
let solved_implementations = module.resolved_implementations;
|
||||
|
||||
let mut file = std::fs::File::create(&output_path).unwrap();
|
||||
subs.serialize(&exposed_vars_by_symbol, &mut file).unwrap();
|
||||
|
||||
let type_state = TypeState {
|
||||
subs,
|
||||
exposed_vars_by_symbol,
|
||||
abilities,
|
||||
solved_implementations,
|
||||
};
|
||||
|
||||
type_state.serialize(&mut file).unwrap();
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use bumpalo::Bump;
|
||||
use roc_can::module::ExposedByModule;
|
||||
use roc_can::module::{ExposedByModule, TypeState};
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_module::symbol::ModuleId;
|
||||
use roc_reporting::report::RenderTarget;
|
||||
use roc_target::TargetInfo;
|
||||
use roc_types::subs::{Subs, Variable};
|
||||
use std::path::PathBuf;
|
||||
|
||||
const SKIP_SUBS_CACHE: bool = {
|
||||
|
@ -27,9 +26,9 @@ fn load<'a>(
|
|||
exposed_types: ExposedByModule,
|
||||
load_config: LoadConfig,
|
||||
) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
|
||||
let cached_subs = read_cached_subs();
|
||||
let cached_types = read_cached_types();
|
||||
|
||||
roc_load_internal::file::load(arena, load_start, exposed_types, cached_subs, load_config)
|
||||
roc_load_internal::file::load(arena, load_start, exposed_types, cached_types, load_config)
|
||||
}
|
||||
|
||||
/// Load using only a single thread; used when compiling to webassembly
|
||||
|
@ -41,7 +40,7 @@ pub fn load_single_threaded<'a>(
|
|||
render: RenderTarget,
|
||||
exec_mode: ExecutionMode,
|
||||
) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
|
||||
let cached_subs = read_cached_subs();
|
||||
let cached_subs = read_cached_types();
|
||||
|
||||
roc_load_internal::file::load_single_threaded(
|
||||
arena,
|
||||
|
@ -166,13 +165,14 @@ 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);
|
||||
fn deserialize_help(bytes: &[u8]) -> TypeState {
|
||||
let (state, _offset) = TypeState::deserialize(bytes);
|
||||
debug_assert_eq!(bytes.len(), _offset);
|
||||
|
||||
(subs, slice.to_vec())
|
||||
state
|
||||
}
|
||||
|
||||
fn read_cached_subs() -> MutMap<ModuleId, (Subs, Vec<(Symbol, Variable)>)> {
|
||||
fn read_cached_types() -> MutMap<ModuleId, TypeState> {
|
||||
let mut output = MutMap::default();
|
||||
|
||||
// Wasm seems to re-order definitions between build time and runtime, but only in release mode.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue