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> {}

View File

@ -1,8 +1,8 @@
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_mono::layout::GlobalLayoutInterner;
use roc_packaging::cache::{self, RocCacheDir};
use roc_reporting::report::{RenderTarget, DEFAULT_PALETTE};
use roc_target::{Architecture, OperatingSystem, TargetInfo};
@ -150,7 +150,7 @@ pub fn load_types(
}
});
let layout_interner = GlobalInterner::with_capacity(128);
let layout_interner = GlobalLayoutInterner::with_capacity(128);
let architectures = Architecture::iter();
let mut types_and_targets = Vec::with_capacity(architectures.len());

View File

@ -6,10 +6,9 @@ use roc_collections::all::MutSet;
use roc_gen_llvm::llvm::build::LlvmBackendMode;
use roc_gen_llvm::llvm::externs::add_default_roc_externs;
use roc_gen_llvm::{run_jit_function, run_jit_function_dynamic_type};
use roc_intern::SingleThreadedInterner;
use roc_load::{EntryPoint, MonomorphizedModule};
use roc_mono::ir::OptLevel;
use roc_mono::layout::Layout;
use roc_mono::layout::STLayoutInterner;
use roc_parse::ast::Expr;
use roc_repl_eval::eval::jit_to_ast;
use roc_repl_eval::gen::{compile_to_mono, format_answer, Problems, ReplOutput};
@ -181,15 +180,7 @@ fn mono_module_to_dylib<'a>(
target: Triple,
loaded: MonomorphizedModule<'a>,
opt_level: OptLevel,
) -> Result<
(
libloading::Library,
&'a str,
Subs,
SingleThreadedInterner<'a, Layout<'a>>,
),
libloading::Error,
> {
) -> Result<(libloading::Library, &'a str, Subs, STLayoutInterner<'a>), libloading::Error> {
let target_info = TargetInfo::from(&target);
let MonomorphizedModule {

View File

@ -1,17 +1,15 @@
//! Supports evaluating `expect` and printing contextual information when they fail.
#[cfg(not(windows))]
use {
roc_intern::GlobalInterner,
roc_module::symbol::Interns,
roc_mono::{
ir::ProcLayout,
layout::{Layout, LayoutCache, Niche},
layout::{GlobalLayoutInterner, LayoutCache, Niche},
},
roc_parse::ast::Expr,
roc_repl_eval::{eval::jit_to_ast, ReplAppMemory},
roc_target::TargetInfo,
roc_types::subs::{Subs, Variable},
std::sync::Arc,
};
#[cfg(not(windows))]
@ -29,7 +27,7 @@ pub fn get_values<'a>(
arena: &'a bumpalo::Bump,
subs: &Subs,
interns: &'a Interns,
layout_interner: &Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: &GlobalLayoutInterner<'a>,
start: *const u8,
start_offset: usize,
number_of_lookups: usize,

View File

@ -18,10 +18,12 @@ use roc_gen_llvm::{
run_roc::RocCallResult,
run_roc_dylib,
};
use roc_intern::{GlobalInterner, SingleThreadedInterner};
use roc_load::{Expectations, MonomorphizedModule};
use roc_module::symbol::{Interns, ModuleId, Symbol};
use roc_mono::{ir::OptLevel, layout::Layout};
use roc_mono::{
ir::OptLevel,
layout::{GlobalLayoutInterner, STLayoutInterner},
};
use roc_region::all::Region;
use roc_reporting::{error::expect::Renderer, report::RenderTarget};
use roc_target::TargetInfo;
@ -129,7 +131,7 @@ pub fn run_inline_expects<'a, W: std::io::Write>(
render_target: RenderTarget,
arena: &'a Bump,
interns: &'a Interns,
layout_interner: &Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: &GlobalLayoutInterner<'a>,
lib: &libloading::Library,
expectations: &mut VecMap<ModuleId, Expectations>,
expects: ExpectFunctions<'_>,
@ -156,7 +158,7 @@ pub fn run_toplevel_expects<'a, W: std::io::Write>(
render_target: RenderTarget,
arena: &'a Bump,
interns: &'a Interns,
layout_interner: &Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: &GlobalLayoutInterner<'a>,
lib: &libloading::Library,
expectations: &mut VecMap<ModuleId, Expectations>,
expects: ExpectFunctions<'_>,
@ -183,7 +185,7 @@ pub(crate) fn run_expects_with_memory<'a, W: std::io::Write>(
render_target: RenderTarget,
arena: &'a Bump,
interns: &'a Interns,
layout_interner: &Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: &GlobalLayoutInterner<'a>,
lib: &libloading::Library,
expectations: &mut VecMap<ModuleId, Expectations>,
expects: ExpectFunctions<'_>,
@ -241,7 +243,7 @@ fn run_expect_pure<'a, W: std::io::Write>(
render_target: RenderTarget,
arena: &'a Bump,
interns: &'a Interns,
layout_interner: &Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: &GlobalLayoutInterner<'a>,
lib: &libloading::Library,
expectations: &mut VecMap<ModuleId, Expectations>,
shared_memory: &mut ExpectMemory,
@ -299,7 +301,7 @@ fn run_expect_fx<'a, W: std::io::Write>(
render_target: RenderTarget,
arena: &'a Bump,
interns: &'a Interns,
layout_interner: &Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: &GlobalLayoutInterner<'a>,
lib: &libloading::Library,
expectations: &mut VecMap<ModuleId, Expectations>,
parent_memory: &mut ExpectMemory,
@ -399,7 +401,7 @@ pub fn render_expects_in_memory<'a>(
arena: &'a Bump,
expectations: &mut VecMap<ModuleId, Expectations>,
interns: &'a Interns,
layout_interner: &Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: &GlobalLayoutInterner<'a>,
memory: &ExpectMemory,
) -> std::io::Result<usize> {
let shared_ptr = memory.ptr;
@ -438,7 +440,7 @@ pub fn render_dbgs_in_memory<'a>(
arena: &'a Bump,
expectations: &mut VecMap<ModuleId, Expectations>,
interns: &'a Interns,
layout_interner: &Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: &GlobalLayoutInterner<'a>,
memory: &ExpectMemory,
) -> std::io::Result<usize> {
let shared_ptr = memory.ptr;
@ -499,7 +501,7 @@ fn render_dbg_failure<'a>(
arena: &'a Bump,
expectations: &mut VecMap<ModuleId, Expectations>,
interns: &'a Interns,
layout_interner: &Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: &GlobalLayoutInterner<'a>,
start: *const u8,
offset: usize,
) -> std::io::Result<usize> {
@ -547,7 +549,7 @@ fn render_expect_failure<'a>(
expect: Option<ToplevelExpect>,
expectations: &mut VecMap<ModuleId, Expectations>,
interns: &'a Interns,
layout_interner: &Arc<GlobalInterner<'a, Layout<'a>>>,
layout_interner: &GlobalLayoutInterner<'a>,
start: *const u8,
offset: usize,
) -> std::io::Result<usize> {
@ -706,7 +708,7 @@ pub fn expect_mono_module_to_dylib<'a>(
(
libloading::Library,
ExpectFunctions<'a>,
SingleThreadedInterner<'a, Layout<'a>>,
STLayoutInterner<'a>,
),
libloading::Error,
> {