Skip to content

Commit

Permalink
make glue and mono look at the same type
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Aug 8, 2023
1 parent 4c17caa commit bec0e52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
19 changes: 9 additions & 10 deletions crates/compiler/mono/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<Variable, LambdaSetId> {
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);
Expand All @@ -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<Variable, LambdaSetId> {
Expand Down
15 changes: 9 additions & 6 deletions crates/glue/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -1223,8 +1222,7 @@ impl<'a> Env<'a> {
}

fn find_lambda_sets(&self, root: Variable) -> MutMap<Variable, LambdaSetId> {
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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bec0e52

Please sign in to comment.