This commit is contained in:
Folkert 2021-08-18 20:33:59 +02:00
parent 1c7301ea58
commit 6be68b0d21
2 changed files with 95 additions and 25 deletions

View file

@ -2517,18 +2517,6 @@ fn specialize_solved_type<'a>(
raw
};
// TODO this module_thunks.contains check will be important
// let raw = match attempted_layout {
// Layout::Closure(a, lambda_set, c) => {
// if procs.module_thunks.contains(&proc_name) {
// RawFunctionLayout::ZeroArgumentThunk(lambda_set.runtime_representation())
// } else {
// RawFunctionLayout::Function(a, lambda_set, c)
// }
// }
// _ => RawFunctionLayout::ZeroArgumentThunk(attempted_layout),
// };
// make sure rigid variables in the annotation are converted to flex variables
instantiate_rigids(env.subs, partial_proc.annotation);
@ -2601,15 +2589,6 @@ impl<'a> ProcLayout<'a> {
}
}
// TODO remove!!!!!
fn from_layout(_arena: &'a Bump, _layout: Layout<'a>) -> Self {
panic!();
// ProcLayout {
// arguments: &[],
// result: layout,
// }
}
pub fn from_raw(arena: &'a Bump, raw: RawFunctionLayout<'a>) -> Self {
match raw {
RawFunctionLayout::Function(arguments, lambda_set, result) => {
@ -6030,12 +6009,21 @@ fn reuse_function_symbol<'a>(
None => {
match arg_var {
Some(arg_var) if env.is_imported_symbol(original) => {
let layout = layout_cache
.from_var(env.arena, arg_var, env.subs)
let raw = layout_cache
.raw_from_var(env.arena, arg_var, env.subs)
.expect("creating layout does not fail");
if procs.imported_module_thunks.contains(&original) {
let top_level = ProcLayout::new(env.arena, &[], layout);
let layout = match raw {
RawFunctionLayout::ZeroArgumentThunk(layout) => layout,
RawFunctionLayout::Function(_, lambda_set, _) => {
lambda_set.runtime_representation()
}
};
let raw = RawFunctionLayout::ZeroArgumentThunk(layout);
let top_level = ProcLayout::from_raw(env.arena, raw);
procs.insert_passed_by_name(
env,
arg_var,
@ -6046,7 +6034,7 @@ fn reuse_function_symbol<'a>(
force_thunk(env, original, layout, symbol, env.arena.alloc(result))
} else {
let top_level = ProcLayout::from_layout(env.arena, layout);
let top_level = ProcLayout::from_raw(env.arena, raw);
procs.insert_passed_by_name(
env,
arg_var,

View file

@ -2657,3 +2657,85 @@ fn lambda_set_enum_byte_byte() {
i64
);
}
#[test]
fn list_walk_until() {
// see https://github.com/rtfeldman/roc/issues/1576
assert_evals_to!(
indoc!(
r#"
app "test" provides [ main ] to "./platform"
satisfyA : {} -> List {}
satisfyA = \_ -> []
oneOfResult =
List.walkUntil [ satisfyA ] (\_, _ -> Stop []) []
main =
when oneOfResult is
_ -> 32
"#
),
32,
i64
);
}
#[test]
#[ignore]
fn int_literal_not_specialized() {
// see https://github.com/rtfeldman/roc/issues/1600
assert_evals_to!(
indoc!(
r#"
app "test" provides [ main ] to "./platform"
satisfy : (U8 -> Bool) -> Str
satisfy = \_ -> "foo"
main : I64
main =
p1 = (\u -> u == 97)
satisfyA = satisfy p1
when satisfyA is
_ -> 32
"#
),
32,
i64
);
}
#[test]
#[ignore]
fn unresolved_tvar_when_capture_is_unused() {
// see https://github.com/rtfeldman/roc/issues/1585
assert_evals_to!(
indoc!(
r#"
app "test" provides [ main ] to "./platform"
main : I64
main =
r : Bool
r = False
# underscore does not change the problem, maybe it's type-related? We don 't really know what `Green` refers to below
p1 = (\x -> r == (1 == 1))
oneOfResult = List.map [p1] (\p -> p Green)
when oneOfResult is
_ -> 32
"#
),
32,
i64
);
}