diff --git a/crates/compiler/mono/src/ir.rs b/crates/compiler/mono/src/ir.rs index 58884bbad67..db98654e6b6 100644 --- a/crates/compiler/mono/src/ir.rs +++ b/crates/compiler/mono/src/ir.rs @@ -3069,9 +3069,7 @@ fn specialize_host_specializations<'a>( let Some(from_platform) = opt_from_platform else { continue }; // now run the lambda set numbering scheme - let mut layout_env = - layout::Env::from_components(layout_cache, env.subs, env.arena, env.target_info); - let hels = find_lambda_sets(&mut layout_env, from_platform); + let hels = find_lambda_sets(env.arena, env.subs, from_platform); // now unify let mut unify_env = roc_unify::Env::new( @@ -10009,16 +10007,17 @@ impl LambdaSetId { } } -fn find_lambda_sets<'a>( - env: &mut crate::layout::Env<'a, '_>, +pub fn find_lambda_sets( + arena: &Bump, + subs: &Subs, initial: Variable, ) -> MutMap { - let mut stack = bumpalo::collections::Vec::new_in(env.arena); + let mut stack = bumpalo::collections::Vec::new_in(arena); // ignore the lambda set of top-level functions - match env.subs.get_without_compacting(initial).content { + match subs.get_without_compacting(initial).content { Content::Structure(FlatType::Func(arguments, _, result)) => { - let arguments = &env.subs.variables[arguments.indices()]; + let arguments = &subs.variables[arguments.indices()]; stack.extend(arguments.iter().copied()); stack.push(result); @@ -10028,10 +10027,10 @@ fn find_lambda_sets<'a>( } } - find_lambda_sets_help(env.subs, stack) + find_lambda_sets_help(subs, stack) } -pub fn find_lambda_sets_help( +fn find_lambda_sets_help( subs: &Subs, mut stack: Vec<'_, Variable>, ) -> MutMap { diff --git a/crates/glue/src/types.rs b/crates/glue/src/types.rs index d1580b123d0..2a030f42039 100644 --- a/crates/glue/src/types.rs +++ b/crates/glue/src/types.rs @@ -111,8 +111,7 @@ impl Types { target, ); - let variables: Vec<_> = entry_points.values().copied().collect(); - for var in variables { + for (_symbol, var) in entry_points.clone() { env.lambda_set_ids = env.find_lambda_sets(var); let id = env.add_toplevel_type(var, &mut types); @@ -1223,8 +1222,7 @@ impl<'a> Env<'a> { } fn find_lambda_sets(&self, root: Variable) -> MutMap { - let stack = bumpalo::vec![in self.arena; root]; - roc_mono::ir::find_lambda_sets_help(self.subs, stack) + roc_mono::ir::find_lambda_sets(self.arena, self.subs, root) } fn add_toplevel_type(&mut self, var: Variable, types: &mut Types) -> TypeId { @@ -1268,8 +1266,13 @@ fn add_function_type<'a>( let name = format!("RocFunction_{closure_var:?}"); - let id = env.lambda_set_ids.get(&closure_var).unwrap(); - let extern_name = format!("roc__mainForHost_{}_caller", id.0); + let extern_name = match env.lambda_set_ids.get(&closure_var) { + Some(id) => format!("roc__mainForHost_{}_caller", id.0), + None => { + debug_assert!(is_toplevel); + String::from("this_extern_should_not_be_used_this_is_a_bug") + } + }; for arg_var in args { let arg_layout = env