diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index 05b17057e4..fe5d2afdd1 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -144,12 +144,10 @@ pub fn types() -> MutMap { ); // sub or (-) : Num a, Num a -> Num a - add_type!( + add_top_level_function_type!( Symbol::NUM_SUB, - top_level_function( - vec![num_type(flex(TVAR1)), num_type(flex(TVAR1))], - Box::new(num_type(flex(TVAR1))), - ), + vec![num_type(flex(TVAR1)), num_type(flex(TVAR1))], + Box::new(num_type(flex(TVAR1))), ); // subWrap : Int range, Int range -> Int range @@ -391,12 +389,10 @@ pub fn types() -> MutMap { ); // mod : Int a, Int a -> Result (Int a) [ DivByZero ]* - add_type!( + add_top_level_function_type!( Symbol::NUM_MOD_INT, - top_level_function( - vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], - Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), - ), + vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], + Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), ); // isMultipleOf : Int a, Int a -> Bool @@ -850,9 +846,11 @@ pub fn types() -> MutMap { }); // keepErrs: List before, (before -> Result * after) -> List after - add_type!(Symbol::LIST_KEEP_ERRS, { + { let_tvars! { star, cvar, before, after}; - top_level_function( + + add_top_level_function_type!( + Symbol::LIST_KEEP_ERRS, vec![ list_type(flex(before)), closure( @@ -863,7 +861,7 @@ pub fn types() -> MutMap { ], Box::new(list_type(flex(after))), ) - }); + }; // range : Int a, Int a -> List (Int a) add_type!(Symbol::LIST_RANGE, { @@ -910,11 +908,12 @@ pub fn types() -> MutMap { ) }); - // map3 : List a, List b, List c, (a, b, c -> d) -> List d - add_type!(Symbol::LIST_MAP3, { + { let_tvars! {a, b, c, d, cvar}; - top_level_function( + // map3 : List a, List b, List c, (a, b, c -> d) -> List d + add_top_level_function_type!( + Symbol::LIST_MAP3, vec![ list_type(flex(a)), list_type(flex(b)), @@ -923,7 +922,7 @@ pub fn types() -> MutMap { ], Box::new(list_type(flex(d))), ) - }); + }; // append : List elem, elem -> List elem add_type!( @@ -1263,15 +1262,13 @@ pub fn types() -> MutMap { ); // mapErr : Result a x, (x -> y) -> Result a x - add_type!( + add_top_level_function_type!( Symbol::RESULT_MAP_ERR, - top_level_function( - vec![ - result_type(flex(TVAR1), flex(TVAR3)), - closure(vec![flex(TVAR3)], TVAR4, Box::new(flex(TVAR2))), - ], - Box::new(result_type(flex(TVAR1), flex(TVAR2))), - ), + vec![ + result_type(flex(TVAR1), flex(TVAR3)), + closure(vec![flex(TVAR3)], TVAR4, Box::new(flex(TVAR2))), + ], + Box::new(result_type(flex(TVAR1), flex(TVAR2))), ); // after : Result a err, (a -> Result b err) -> Result b err diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index 776b168f0b..455bb7c87e 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -3069,6 +3069,8 @@ pub fn build_proc_header_new<'a, 'ctx, 'env>( ) -> FunctionValue<'ctx> { let layout = env.arena.alloc(layout).full(); + dbg!(symbol, layout); + build_proc_header(env, layout_ids, symbol, &layout, proc) } diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 762796505a..c636f46c4e 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -7524,6 +7524,7 @@ fn lowlevel_match_on_lambda_set<'a, F>( where F: Fn(Symbol, Symbol) -> Call<'a> + Copy, { + dbg!(lambda_set); match dbg!(lambda_set.runtime_representation()) { Layout::Union(_) => { let closure_tag_id_symbol = env.unique_symbol(); diff --git a/compiler/test_gen/src/gen_list.rs b/compiler/test_gen/src/gen_list.rs index 96cddca5c8..4ec2a79c99 100644 --- a/compiler/test_gen/src/gen_list.rs +++ b/compiler/test_gen/src/gen_list.rs @@ -1807,10 +1807,20 @@ fn list_keep_errs() { assert_evals_to!("List.keepErrs [] (\\x -> x)", 0, i64); assert_evals_to!("List.keepErrs [1,2] (\\x -> Err x)", &[1, 2], &[i64]); assert_evals_to!( - "List.keepErrs [0,1,2] (\\x -> x % 0 |> Result.mapErr (\\_ -> 32))", + indoc!( + r#" + mapErr = \result, f -> + when result is + Err e -> Err ( f e ) + Ok v -> Ok v + + List.keepErrs [0,1,2] (\x -> x % 0 |> mapErr (\_ -> 32)) + "# + ), &[32, 32, 32], &[i64] ); + assert_evals_to!("List.keepErrs [Ok 1, Err 2] (\\x -> x)", &[2], &[i64]); }