Push wrapped layout interners through

This commit is contained in:
Ayaz Hafiz 2023-01-03 10:51:33 -06:00
parent 947158b17e
commit b60d5c0251
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
7 changed files with 86 additions and 40 deletions

View file

@ -24,7 +24,6 @@ use roc_debug_flags::{
};
use roc_derive::SharedDerivedModule;
use roc_error_macros::internal_error;
use roc_intern::{GlobalInterner, SingleThreadedInterner};
use roc_late_solve::{AbilitiesView, WorldAbilities};
use roc_module::ident::{Ident, ModuleName, QualifiedModuleName};
use roc_module::symbol::{
@ -35,7 +34,9 @@ use roc_mono::ir::{
CapturedSymbols, ExternalSpecializations, PartialProc, Proc, ProcLayout, Procs, ProcsBase,
UpdateModeIds,
};
use roc_mono::layout::{LambdaName, Layout, LayoutCache, LayoutProblem, Niche, STLayoutInterner};
use roc_mono::layout::{
GlobalLayoutInterner, LambdaName, Layout, LayoutCache, LayoutProblem, Niche, STLayoutInterner,
};
use roc_packaging::cache::{self, RocCacheDir};
#[cfg(not(target_family = "wasm"))]
use roc_packaging::https::PackageMetadata;
@ -749,7 +750,7 @@ pub struct MonomorphizedModule<'a> {
pub module_id: ModuleId,
pub interns: Interns,
pub subs: Subs,
pub layout_interner: SingleThreadedInterner<'a, Layout<'a>>,
pub layout_interner: STLayoutInterner<'a>,
pub output_path: Box<Path>,
pub can_problems: MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
pub type_problems: MutMap<ModuleId, Vec<TypeError>>,
@ -766,7 +767,7 @@ pub struct MonomorphizedModule<'a> {
/// Values used to render expect output
pub struct ExpectMetadata<'a> {
pub interns: Interns,
pub layout_interner: SingleThreadedInterner<'a, Layout<'a>>,
pub layout_interner: STLayoutInterner<'a>,
pub expectations: VecMap<ModuleId, Expectations>,
}
@ -1013,7 +1014,7 @@ struct State<'a> {
// cached types (used for builtin modules, could include packages in the future too)
cached_types: CachedTypeState,
layout_interner: Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: GlobalLayoutInterner<'a>,
}
type CachedTypeState = Arc<Mutex<MutMap<ModuleId, TypeState>>>;
@ -1071,7 +1072,7 @@ impl<'a> State<'a> {
exec_mode,
make_specializations_pass: MakeSpecializationsPass::Pass(1),
world_abilities: Default::default(),
layout_interner: GlobalInterner::with_capacity(128),
layout_interner: GlobalLayoutInterner::with_capacity(128),
}
}
}
@ -3071,7 +3072,7 @@ fn update<'a>(
}
let layout_interner = {
let mut taken = GlobalInterner::with_capacity(0);
let mut taken = GlobalLayoutInterner::with_capacity(0);
std::mem::swap(&mut state.layout_interner, &mut taken);
taken
};

View file

@ -23,7 +23,7 @@ use std::hash::{Hash, Hasher};
use ven_pretty::{DocAllocator, DocBuilder};
mod intern;
pub use intern::{STLayoutInterner, TLLayoutInterner};
pub use intern::{GlobalLayoutInterner, LayoutInterner, STLayoutInterner, TLLayoutInterner};
// if your changes cause this number to go down, great!
// please change it to the lower number.

View file

@ -1,6 +1,60 @@
use roc_intern::{SingleThreadedInterner, ThreadLocalInterner};
use std::sync::Arc;
use roc_intern::{GlobalInterner, Interned, Interner, SingleThreadedInterner, ThreadLocalInterner};
use super::Layout;
pub type TLLayoutInterner<'a> = ThreadLocalInterner<'a, Layout<'a>>;
pub type STLayoutInterner<'a> = SingleThreadedInterner<'a, Layout<'a>>;
pub trait LayoutInterner<'a>: Interner<'a, Layout<'a>> {}
#[derive(Debug)]
pub struct GlobalLayoutInterner<'a>(Arc<GlobalInterner<'a, Layout<'a>>>);
#[derive(Debug)]
pub struct TLLayoutInterner<'a>(ThreadLocalInterner<'a, Layout<'a>>);
#[derive(Debug)]
pub struct STLayoutInterner<'a>(SingleThreadedInterner<'a, Layout<'a>>);
impl<'a> GlobalLayoutInterner<'a> {
pub fn with_capacity(capacity: usize) -> Self {
Self(GlobalInterner::with_capacity(capacity))
}
pub fn fork(&self) -> TLLayoutInterner<'a> {
TLLayoutInterner(self.0.fork())
}
pub fn unwrap(self) -> Result<STLayoutInterner<'a>, Self> {
match self.0.unwrap() {
Ok(st) => Ok(STLayoutInterner(st)),
Err(global) => Err(Self(global)),
}
}
}
impl<'a> STLayoutInterner<'a> {
pub fn with_capacity(capacity: usize) -> Self {
Self(SingleThreadedInterner::with_capacity(capacity))
}
pub fn into_global(self) -> GlobalLayoutInterner<'a> {
GlobalLayoutInterner(self.0.into_global())
}
}
impl<'a> Interner<'a, Layout<'a>> for TLLayoutInterner<'a> {
fn insert(&mut self, value: &'a Layout<'a>) -> Interned<Layout<'a>> {
self.0.insert(value)
}
fn get(&self, key: Interned<Layout<'a>>) -> &'a Layout<'a> {
self.0.get(key)
}
}
impl<'a> LayoutInterner<'a> for TLLayoutInterner<'a> {}
impl<'a> Interner<'a, Layout<'a>> for STLayoutInterner<'a> {
fn insert(&mut self, value: &'a Layout<'a>) -> Interned<Layout<'a>> {
self.0.insert(value)
}
fn get(&self, key: Interned<Layout<'a>>) -> &'a Layout<'a> {
self.0.get(key)
}
}
impl<'a> LayoutInterner<'a> for STLayoutInterner<'a> {}