ensure symbol passed to jump is properly specialized

This commit is contained in:
Folkert 2021-05-10 13:23:28 +02:00
parent f1a8b75196
commit e95d42dda3
2 changed files with 23 additions and 37 deletions

View file

@ -2511,31 +2511,30 @@ fn specialize_naked_symbol<'a>(
} }
} }
// A bit ugly, but it does the job let result = match hole {
match hole {
Stmt::Jump(id, _) => Stmt::Jump(*id, env.arena.alloc([symbol])), Stmt::Jump(id, _) => Stmt::Jump(*id, env.arena.alloc([symbol])),
_ => { _ => Stmt::Ret(symbol),
let result = Stmt::Ret(symbol); };
let original = symbol;
// we don't have a more accurate variable available, which means the variable // if the symbol is a function symbol, ensure it is properly specialized!
// from the partial_proc will be used. So far that has given the correct let original = symbol;
// result, but I'm not sure this will continue to be the case in more complex
// examples.
let opt_fn_var = None;
// if this is a function symbol, ensure that it's properly specialized! // we don't have a more accurate variable available, which means the variable
reuse_function_symbol( // from the partial_proc will be used. So far that has given the correct
env, // result, but I'm not sure this will continue to be the case in more complex
procs, // examples.
layout_cache, let opt_fn_var = None;
opt_fn_var,
symbol, // if this is a function symbol, ensure that it's properly specialized!
result, reuse_function_symbol(
original, env,
) procs,
} layout_cache,
} opt_fn_var,
symbol,
result,
original,
)
} }
pub fn with_hole<'a>( pub fn with_hole<'a>(
@ -7555,18 +7554,6 @@ fn lambda_set_to_switch<'a>(
} }
} }
// Switch {
// /// This *must* stand for an integer, because Switch potentially compiles to a jump table.
// cond_symbol: Symbol,
// cond_layout: Layout<'a>,
// /// The u64 in the tuple will be compared directly to the condition Expr.
// /// If they are equal, this branch will be taken.
// branches: &'a [(u64, BranchInfo<'a>, Stmt<'a>)],
// /// If no other branches pass, this default branch will be taken.
// default_branch: (BranchInfo<'a>, &'a Stmt<'a>),
// /// Each branch must return a value of this type.
// ret_layout: Layout<'a>,
// },
fn lambda_set_to_switch_make_branch<'a>( fn lambda_set_to_switch_make_branch<'a>(
env: &mut Env<'a, '_>, env: &mut Env<'a, '_>,
join_point_id: JoinPointId, join_point_id: JoinPointId,

View file

@ -2478,10 +2478,9 @@ mod test_mono {
double = \x -> if b then x * two else x double = \x -> if b then x * two else x
# TODO removing these identity functions causes issues. investigate! # TODO removing these identity functions causes issues. investigate!
f = (if True then (\x -> x) increment else (\x -> x) double) f = (if True then increment else double)
when 3 is apply f 42
_ -> apply f 42
"# "#
), ),
indoc!( indoc!(