Push the layout interner through the backends

This commit is contained in:
Ayaz Hafiz 2022-08-31 12:19:51 -05:00
parent c5466810a4
commit ed04c2040a
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
11 changed files with 34 additions and 14 deletions

View file

@ -256,6 +256,7 @@ pub fn gen_from_mono_module_llvm(
// Compile and add all the Procs before adding main
let env = roc_gen_llvm::llvm::build::Env {
arena,
layout_interner: &loaded.layout_interner,
builder: &builder,
dibuilder: &dibuilder,
compile_unit: &compile_unit,
@ -473,6 +474,7 @@ fn gen_from_mono_module_dev_wasm32(
module_id,
procedures,
mut interns,
layout_interner,
..
} = loaded;
@ -485,6 +487,7 @@ fn gen_from_mono_module_dev_wasm32(
let env = roc_gen_wasm::Env {
arena,
layout_interner: &layout_interner,
module_id,
exposed_to_host,
stack_bytes: wasm_dev_stack_bytes.unwrap_or(roc_gen_wasm::Env::DEFAULT_STACK_BYTES),

View file

@ -268,7 +268,9 @@ fn build_transform_caller_help<'a, 'ctx, 'env>(
}
match (
closure_data_layout.is_represented().is_some(),
closure_data_layout
.is_represented(env.layout_interner)
.is_some(),
closure_data_layout.runtime_representation(),
) {
(false, _) => {

View file

@ -57,7 +57,7 @@ use roc_mono::ir::{
};
use roc_mono::layout::{
Builtin, CapturesNiche, LambdaName, LambdaSet, Layout, LayoutIds, RawFunctionLayout,
TagIdIntType, UnionLayout,
STLayoutInterner, TagIdIntType, UnionLayout,
};
use roc_std::RocDec;
use roc_target::{PtrWidth, TargetInfo};
@ -203,6 +203,7 @@ impl LlvmBackendMode {
pub struct Env<'a, 'ctx, 'env> {
pub arena: &'a Bump,
pub layout_interner: &'env STLayoutInterner<'a>,
pub context: &'ctx Context,
pub builder: &'env Builder<'ctx>,
pub dibuilder: &'env DebugInfoBuilder<'ctx>,

View file

@ -16,7 +16,7 @@ use roc_collections::all::{MutMap, MutSet};
use roc_module::symbol::{Interns, ModuleId, Symbol};
use roc_mono::code_gen_help::CodeGenHelp;
use roc_mono::ir::{Proc, ProcLayout};
use roc_mono::layout::LayoutIds;
use roc_mono::layout::{LayoutIds, STLayoutInterner};
use roc_target::TargetInfo;
use wasm_module::parse::ParseError;
@ -43,6 +43,7 @@ pub const STACK_POINTER_NAME: &str = "__stack_pointer";
pub struct Env<'a> {
pub arena: &'a Bump,
pub layout_interner: &'a STLayoutInterner<'a>,
pub module_id: ModuleId,
pub exposed_to_host: MutSet<Symbol>,
pub stack_bytes: u32,

View file

@ -2136,7 +2136,10 @@ pub fn call_higher_order_lowlevel<'a>(
let (closure_data_layout, closure_data_exists) =
match backend.storage.symbol_layouts[captured_environment] {
Layout::LambdaSet(lambda_set) => {
if lambda_set.is_represented().is_some() {
if lambda_set
.is_represented(backend.env.layout_interner)
.is_some()
{
(lambda_set.runtime_representation(), true)
} else {
// Closure data is a lambda set, which *itself* has no closure data!

View file

@ -5232,6 +5232,7 @@ pub fn with_hole<'a>(
RawFunctionLayout::Function(_, lambda_set, _) => {
lowlevel_match_on_lambda_set(
env,
layout_cache,
lambda_set,
op,
closure_data_symbol,
@ -6025,7 +6026,7 @@ fn register_capturing_closure<'a>(
match lambda_set_layout {
Ok(lambda_set) => {
if lambda_set.is_represented().is_none() {
if lambda_set.is_represented(&layout_cache.interner).is_none() {
CapturedSymbols::None
} else {
let mut temp = Vec::from_iter_in(captured_symbols, env.arena);
@ -9349,6 +9350,7 @@ type ToLowLevelCallArguments<'a> = (
#[allow(clippy::too_many_arguments)]
fn lowlevel_match_on_lambda_set<'a, ToLowLevelCall>(
env: &mut Env<'a, '_>,
layout_cache: &LayoutCache<'a>,
lambda_set: LambdaSet<'a>,
op: LowLevel,
closure_data_symbol: Symbol,
@ -9371,7 +9373,7 @@ where
closure_tag_id_symbol,
union_layout.tag_id_layout(),
closure_data_symbol,
lambda_set.is_represented(),
lambda_set.is_represented(&layout_cache.interner),
to_lowlevel_call,
return_layout,
assigned,
@ -9398,7 +9400,7 @@ where
let call = to_lowlevel_call((
lambda_name,
closure_data_symbol,
lambda_set.is_represented(),
lambda_set.is_represented(&layout_cache.interner),
call_spec_id,
update_mode,
));
@ -9427,7 +9429,7 @@ where
let call = to_lowlevel_call((
lambda_name,
closure_data_symbol,
lambda_set.is_represented(),
lambda_set.is_represented(&layout_cache.interner),
call_spec_id,
update_mode,
));
@ -9444,7 +9446,7 @@ where
closure_tag_id_symbol,
Layout::Builtin(Builtin::Bool),
closure_data_symbol,
lambda_set.is_represented(),
lambda_set.is_represented(&layout_cache.interner),
to_lowlevel_call,
return_layout,
assigned,
@ -9460,7 +9462,7 @@ where
closure_tag_id_symbol,
Layout::Builtin(Builtin::Int(IntWidth::U8)),
closure_data_symbol,
lambda_set.is_represented(),
lambda_set.is_represented(&layout_cache.interner),
to_lowlevel_call,
return_layout,
assigned,

View file

@ -4,7 +4,7 @@ use bumpalo::Bump;
use roc_builtins::bitcode::{FloatWidth, IntWidth};
use roc_collections::all::{default_hasher, FnvMap, MutMap};
use roc_error_macros::{internal_error, todo_abilities};
use roc_intern::ThreadLocalInterner;
use roc_intern::{Interner, SingleThreadedInterner, ThreadLocalInterner};
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::{Interns, Symbol};
use roc_problem::can::RuntimeError;
@ -97,6 +97,7 @@ macro_rules! inc_stat {
}
pub type LayoutInterner<'a> = ThreadLocalInterner<'a, Layout<'a>>;
pub type STLayoutInterner<'a> = SingleThreadedInterner<'a, Layout<'a>>;
/// Layout cache to avoid recomputing [Layout] from a [Variable] multiple times.
#[derive(Debug)]
@ -105,8 +106,7 @@ pub struct LayoutCache<'a> {
cache: std::vec::Vec<CacheLayer<LayoutResult<'a>>>,
raw_function_cache: std::vec::Vec<CacheLayer<RawFunctionLayoutResult<'a>>>,
#[allow(unused)] // TODO remove me
interner: LayoutInterner<'a>,
pub(crate) interner: LayoutInterner<'a>,
/// Statistics on the usage of the layout cache.
#[cfg(debug_assertions)]
@ -1247,7 +1247,10 @@ impl<'a> LambdaSet<'a> {
self.set.iter().any(|(s, _)| *s == symbol)
}
pub fn is_represented(&self) -> Option<Layout<'a>> {
pub fn is_represented<I>(&self, _interner: &I) -> Option<Layout<'a>>
where
I: Interner<'a, Layout<'a>>,
{
if self.has_unwrapped_capture_repr() {
Some(*self.representation)
} else if self.has_enum_dispatch_repr() {

View file

@ -95,6 +95,7 @@ fn create_llvm_module<'a>(
procedures,
entry_point,
interns,
layout_interner,
..
} = loaded;
@ -211,6 +212,7 @@ fn create_llvm_module<'a>(
// Compile and add all the Procs before adding main
let env = roc_gen_llvm::llvm::build::Env {
arena,
layout_interner: &layout_interner,
builder: &builder,
dibuilder: &dibuilder,
compile_unit: &compile_unit,

View file

@ -243,6 +243,7 @@ pub fn mono_module_to_dylib<'a>(
// Compile and add all the Procs before adding main
let env = roc_gen_llvm::llvm::build::Env {
arena,
layout_interner: &layout_interner,
builder: &builder,
dibuilder: &dibuilder,
compile_unit: &compile_unit,

View file

@ -521,6 +521,7 @@ pub fn expect_mono_module_to_dylib<'a>(
// Compile and add all the Procs before adding main
let env = roc_gen_llvm::llvm::build::Env {
arena,
layout_interner: &layout_interner,
builder: &builder,
dibuilder: &dibuilder,
compile_unit: &compile_unit,

View file

@ -213,6 +213,7 @@ pub async fn entrypoint_from_js(src: String) -> Result<String, String> {
let app_module_bytes = {
let env = roc_gen_wasm::Env {
arena,
layout_interner: &layout_interner,
module_id,
stack_bytes: roc_gen_wasm::Env::DEFAULT_STACK_BYTES,
exposed_to_host: exposed_to_host