Add LayoutInterner to LayoutCache

Adds a thread-local interner of layouts to LayoutCache, and updates all
references appropriately.

This is a bit suboptimal for single-threaded workloads that will look at
creating layout caches again, like the REPL, but I think that's okay for
now - since the global interner will be uncontested for those workloads, it
should still be plenty fast to access the interner, even behind a lock.
This commit is contained in:
Ayaz Hafiz 2022-08-31 12:03:30 -05:00
parent 9d170be5c7
commit c5466810a4
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
19 changed files with 177 additions and 86 deletions

View file

@ -1,6 +1,7 @@
use crate::rust_glue;
use crate::types::{Env, Types};
use bumpalo::Bump;
use roc_intern::GlobalInterner;
use roc_load::{ExecutionMode, LoadConfig, LoadedModule, LoadingProblem, Threading};
use roc_reporting::report::RenderTarget;
use roc_target::{Architecture, OperatingSystem, TargetInfo};
@ -77,7 +78,7 @@ pub fn load_types(
mut type_problems,
mut declarations_by_id,
mut solved,
mut interns,
interns,
..
} = roc_load::load_and_typecheck(
arena,
@ -136,17 +137,24 @@ pub fn load_types(
}
});
let types_and_targets = Architecture::iter()
.map(|arch| {
let target_info = TargetInfo {
architecture: arch,
operating_system: OperatingSystem::Unix,
};
let mut env = Env::new(arena, subs, &mut interns, target_info);
let layout_interner = GlobalInterner::with_capacity(128);
(env.vars_to_types(variables.clone()), target_info)
})
.collect();
let architectures = Architecture::iter();
let mut types_and_targets = Vec::with_capacity(architectures.len());
for arch in architectures {
let target_info = TargetInfo {
architecture: arch,
operating_system: OperatingSystem::Unix,
};
let types = {
let mut env = Env::new(arena, subs, &interns, layout_interner.fork(), target_info);
env.vars_to_types(variables.clone())
};
types_and_targets.push((types, target_info));
}
Ok(types_and_targets)
}

View file

@ -13,7 +13,7 @@ use roc_module::{
};
use roc_mono::layout::{
cmp_fields, ext_var_is_empty_tag_union, round_up_to_alignment, Builtin, Discriminant, Layout,
LayoutCache, UnionLayout,
LayoutCache, LayoutInterner, UnionLayout,
};
use roc_target::TargetInfo;
use roc_types::{
@ -608,7 +608,8 @@ impl<'a> Env<'a> {
pub fn new(
arena: &'a Bump,
subs: &'a Subs,
interns: &'a mut Interns,
interns: &'a Interns,
layout_interner: LayoutInterner<'a>,
target: TargetInfo,
) -> Self {
Env {
@ -619,7 +620,7 @@ impl<'a> Env<'a> {
enum_names: Default::default(),
pending_recursive_types: Default::default(),
known_recursive_types: Default::default(),
layout_cache: LayoutCache::new(target),
layout_cache: LayoutCache::new(layout_interner, target),
target,
}
}