diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index 83c6205ab7..9a38e3518d 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -489,9 +489,22 @@ pub fn types() -> MutMap { ), ); - // walkRight : List elem, (elem -> accum -> accum), accum -> accum + // walk : List elem, (elem -> accum -> accum), accum -> accum add_type( - Symbol::LIST_WALK_RIGHT, + Symbol::LIST_WALK, + top_level_function( + vec![ + list_type(flex(TVAR1)), + closure(vec![flex(TVAR1), flex(TVAR2)], TVAR3, Box::new(flex(TVAR2))), + flex(TVAR2), + ], + Box::new(flex(TVAR2)), + ), + ); + + // walkBackwards : List elem, (elem -> accum -> accum), accum -> accum + add_type( + Symbol::LIST_WALK_BACKWARDS, top_level_function( vec![ list_type(flex(TVAR1)), diff --git a/compiler/builtins/src/unique.rs b/compiler/builtins/src/unique.rs index 33ab33263e..2eacd19ffc 100644 --- a/compiler/builtins/src/unique.rs +++ b/compiler/builtins/src/unique.rs @@ -777,11 +777,38 @@ pub fn types() -> MutMap { ) }); - // walkRight : Attr (* | u) (List (Attr u a)) + // walk : Attr (* | u) (List (Attr u a)) // , Attr Shared (Attr u a -> b -> b) // , b // -> b - add_type(Symbol::LIST_WALK_RIGHT, { + add_type(Symbol::LIST_WALK, { + let_tvars! { u, a, b, star1, closure }; + + unique_function( + vec![ + SolvedType::Apply( + Symbol::ATTR_ATTR, + vec![ + container(star1, vec![u]), + SolvedType::Apply(Symbol::LIST_LIST, vec![attr_type(u, a)]), + ], + ), + shared(SolvedType::Func( + vec![attr_type(u, a), flex(b)], + Box::new(flex(closure)), + Box::new(flex(b)), + )), + flex(b), + ], + flex(b), + ) + }); + + // walkBackwards : Attr (* | u) (List (Attr u a)) + // , Attr Shared (Attr u a -> b -> b) + // , b + // -> b + add_type(Symbol::LIST_WALK_BACKWARDS, { let_tvars! { u, a, b, star1, closure }; unique_function( diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 271e9a9d82..fda8b43831 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -71,7 +71,8 @@ pub fn builtin_defs(var_store: &mut VarStore) -> MutMap { Symbol::LIST_JOIN => list_join, Symbol::LIST_MAP => list_map, Symbol::LIST_KEEP_IF => list_keep_if, - Symbol::LIST_WALK_RIGHT => list_walk_right, + Symbol::LIST_WALK => list_walk, + Symbol::LIST_WALK_BACKWARDS => list_walk_backwards, Symbol::NUM_ADD => num_add, Symbol::NUM_ADD_CHECKED => num_add_checked, Symbol::NUM_ADD_WRAP => num_add_wrap, @@ -1313,14 +1314,43 @@ fn list_join(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -/// List.walkRight : List elem, (elem -> accum -> accum), accum -> accum -fn list_walk_right(symbol: Symbol, var_store: &mut VarStore) -> Def { +/// List.walk : List elem, (elem -> accum -> accum), accum -> accum +fn list_walk(symbol: Symbol, var_store: &mut VarStore) -> Def { let list_var = var_store.fresh(); let func_var = var_store.fresh(); let accum_var = var_store.fresh(); let body = RunLowLevel { - op: LowLevel::ListWalkRight, + op: LowLevel::ListWalk, + args: vec![ + (list_var, Var(Symbol::ARG_1)), + (func_var, Var(Symbol::ARG_2)), + (accum_var, Var(Symbol::ARG_3)), + ], + ret_var: accum_var, + }; + + defn( + symbol, + vec![ + (list_var, Symbol::ARG_1), + (func_var, Symbol::ARG_2), + (accum_var, Symbol::ARG_3), + ], + var_store, + body, + accum_var, + ) +} + +/// List.walkBackwards : List elem, (elem -> accum -> accum), accum -> accum +fn list_walk_backwards(symbol: Symbol, var_store: &mut VarStore) -> Def { + let list_var = var_store.fresh(); + let func_var = var_store.fresh(); + let accum_var = var_store.fresh(); + + let body = RunLowLevel { + op: LowLevel::ListWalkBackwards, args: vec![ (list_var, Var(Symbol::ARG_1)), (func_var, Var(Symbol::ARG_2)), diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index fc226fe1a6..defff8359e 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -1,7 +1,7 @@ use crate::llvm::build_list::{ allocate_list, empty_list, empty_polymorphic_list, list_append, list_concat, list_contains, list_get_unsafe, list_join, list_keep_if, list_len, list_map, list_prepend, list_repeat, - list_reverse, list_set, list_single, list_sum, list_walk_right, + list_reverse, list_set, list_single, list_sum, list_walk, list_walk_backwards, }; use crate::llvm::build_str::{ str_concat, str_count_graphemes, str_len, str_split, str_starts_with, CHAR_LAYOUT, @@ -735,7 +735,12 @@ pub fn build_exp_expr<'a, 'ctx, 'env>( // Insert field exprs into struct_val for (index, field_val) in field_vals.into_iter().enumerate() { struct_val = builder - .build_insert_value(struct_val, field_val, index as u32, "insert_field") + .build_insert_value( + struct_val, + field_val, + index as u32, + "insert_record_field", + ) .unwrap(); } @@ -785,7 +790,12 @@ pub fn build_exp_expr<'a, 'ctx, 'env>( // Insert field exprs into struct_val for (index, field_val) in field_vals.into_iter().enumerate() { struct_val = builder - .build_insert_value(struct_val, field_val, index as u32, "insert_field") + .build_insert_value( + struct_val, + field_val, + index as u32, + "insert_single_tag_field", + ) .unwrap(); } @@ -848,7 +858,12 @@ pub fn build_exp_expr<'a, 'ctx, 'env>( // Insert field exprs into struct_val for (index, field_val) in field_vals.into_iter().enumerate() { struct_val = builder - .build_insert_value(struct_val, field_val, index as u32, "insert_field") + .build_insert_value( + struct_val, + field_val, + index as u32, + "insert_multi_tag_field", + ) .unwrap(); } @@ -2492,8 +2507,7 @@ fn run_low_level<'a, 'ctx, 'env>( list_contains(env, parent, elem, elem_layout, list, list_layout) } - ListWalkRight => { - // List.walkRight : List elem, (elem -> accum -> accum), accum -> accum + ListWalk => { debug_assert_eq!(args.len(), 3); let (list, list_layout) = load_symbol_and_layout(env, scope, &args[0]); @@ -2502,7 +2516,28 @@ fn run_low_level<'a, 'ctx, 'env>( let (default, default_layout) = load_symbol_and_layout(env, scope, &args[2]); - list_walk_right( + list_walk( + env, + parent, + list, + list_layout, + func, + func_layout, + default, + default_layout, + ) + } + ListWalkBackwards => { + // List.walkBackwards : List elem, (elem -> accum -> accum), accum -> accum + debug_assert_eq!(args.len(), 3); + + let (list, list_layout) = load_symbol_and_layout(env, scope, &args[0]); + + let (func, func_layout) = load_symbol_and_layout(env, scope, &args[1]); + + let (default, default_layout) = load_symbol_and_layout(env, scope, &args[2]); + + list_walk_backwards( env, parent, list, diff --git a/compiler/gen/src/llvm/build_list.rs b/compiler/gen/src/llvm/build_list.rs index 40837e4755..c79a1d64b5 100644 --- a/compiler/gen/src/llvm/build_list.rs +++ b/compiler/gen/src/llvm/build_list.rs @@ -809,9 +809,9 @@ pub fn list_sum<'a, 'ctx, 'env>( builder.build_load(accum_alloca, "load_final_acum") } -/// List.walkRight : List elem, (elem -> accum -> accum), accum -> accum +/// List.walk : List elem, (elem -> accum -> accum), accum -> accum #[allow(clippy::too_many_arguments)] -pub fn list_walk_right<'a, 'ctx, 'env>( +pub fn list_walk<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, parent: FunctionValue<'ctx>, list: BasicValueEnum<'ctx>, @@ -901,6 +901,98 @@ pub fn list_walk_right<'a, 'ctx, 'env>( builder.build_load(accum_alloca, "load_final_acum") } +/// List.walkBackwards : List elem, (elem -> accum -> accum), accum -> accum +#[allow(clippy::too_many_arguments)] +pub fn list_walk_backwards<'a, 'ctx, 'env>( + env: &Env<'a, 'ctx, 'env>, + parent: FunctionValue<'ctx>, + list: BasicValueEnum<'ctx>, + list_layout: &Layout<'a>, + func: BasicValueEnum<'ctx>, + func_layout: &Layout<'a>, + default: BasicValueEnum<'ctx>, + default_layout: &Layout<'a>, +) -> BasicValueEnum<'ctx> { + let ctx = env.context; + let builder = env.builder; + + let list_wrapper = list.into_struct_value(); + let len = list_len(env.builder, list_wrapper); + + let accum_type = basic_type_from_layout(env.arena, ctx, default_layout, env.ptr_bytes); + let accum_alloca = builder.build_alloca(accum_type, "alloca_walk_right_accum"); + builder.build_store(accum_alloca, default); + + let then_block = ctx.append_basic_block(parent, "then"); + let cont_block = ctx.append_basic_block(parent, "branchcont"); + + let condition = builder.build_int_compare( + IntPredicate::UGT, + len, + ctx.i64_type().const_zero(), + "list_non_empty", + ); + + builder.build_conditional_branch(condition, then_block, cont_block); + + builder.position_at_end(then_block); + + match (func, func_layout) { + (BasicValueEnum::PointerValue(func_ptr), Layout::FunctionPointer(_, _)) => { + let elem_layout = match list_layout { + Layout::Builtin(Builtin::List(_, layout)) => layout, + _ => unreachable!("can only fold over a list"), + }; + + let elem_type = basic_type_from_layout(env.arena, ctx, elem_layout, env.ptr_bytes); + let elem_ptr_type = get_ptr_type(&elem_type, AddressSpace::Generic); + + let list_ptr = load_list_ptr(builder, list_wrapper, elem_ptr_type); + + let walk_right_loop = |_, elem: BasicValueEnum<'ctx>| { + // load current accumulator + let current = builder.build_load(accum_alloca, "retrieve_accum"); + + let call_site_value = + builder.build_call(func_ptr, &[elem, current], "#walk_right_func"); + + // set the calling convention explicitly for this call + call_site_value.set_call_convention(crate::llvm::build::FAST_CALL_CONV); + + let new_current = call_site_value + .try_as_basic_value() + .left() + .unwrap_or_else(|| panic!("LLVM error: Invalid call by pointer.")); + + builder.build_store(accum_alloca, new_current); + }; + + decrementing_elem_loop( + builder, + ctx, + parent, + list_ptr, + len, + "#index", + walk_right_loop, + ); + } + + _ => { + unreachable!( + "Invalid function basic value enum or layout for List.keepIf : {:?}", + (func, func_layout) + ); + } + } + + builder.build_unconditional_branch(cont_block); + + builder.position_at_end(cont_block); + + builder.build_load(accum_alloca, "load_final_acum") +} + /// List.contains : List elem, elem -> Bool pub fn list_contains<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, @@ -1537,6 +1629,7 @@ where let current_index = builder .build_load(index_alloca, index_name) .into_int_value(); + let next_index = builder.build_int_sub(current_index, one, "nextindex"); builder.build_store(index_alloca, next_index); @@ -1546,7 +1639,7 @@ where // #index >= 0 let condition = builder.build_int_compare( - IntPredicate::UGE, + IntPredicate::SGE, next_index, ctx.i64_type().const_zero(), "bounds_check", diff --git a/compiler/gen/tests/gen_list.rs b/compiler/gen/tests/gen_list.rs index 7eaa12a48d..88b5c90789 100644 --- a/compiler/gen/tests/gen_list.rs +++ b/compiler/gen/tests/gen_list.rs @@ -237,11 +237,11 @@ mod gen_list { } #[test] - fn list_walk_right_empty_all_inline() { + fn list_walk_backwards_empty_all_inline() { assert_evals_to!( indoc!( r#" - List.walkRight [0x1] (\a, b -> a + b) 0 + List.walkBackwards [0x1] (\a, b -> a + b) 0 "# ), 1, @@ -255,7 +255,7 @@ mod gen_list { empty = [] - List.walkRight empty (\a, b -> a + b) 0 + List.walkBackwards empty (\a, b -> a + b) 0 "# ), 0, @@ -264,22 +264,22 @@ mod gen_list { } #[test] - fn list_walk_right_with_str() { + fn list_walk_backwards_with_str() { assert_evals_to!( - r#"List.walkRight [ "x", "y", "z" ] Str.concat "<""#, - RocStr::from("zyx<"), + r#"List.walkBackwards [ "x", "y", "z" ] Str.concat "<""#, + RocStr::from("xyz<"), RocStr ); assert_evals_to!( - r#"List.walkRight [ "Third", "Second", "First" ] Str.concat "Fourth""#, - RocStr::from("FirstSecondThirdFourth"), + r#"List.walkBackwards [ "Third", "Second", "First" ] Str.concat "Fourth""#, + RocStr::from("ThirdSecondFirstFourth"), RocStr ); } #[test] - fn list_walk_right_with_record() { + fn list_walk_backwards_with_record() { assert_evals_to!( indoc!( r#" @@ -295,7 +295,7 @@ mod gen_list { Zero -> { r & zeroes: r.zeroes + 1 } One -> { r & ones: r.ones + 1 } - finalCounts = List.walkRight byte acc initialCounts + finalCounts = List.walkBackwards byte acc initialCounts finalCounts.ones * 10 + finalCounts.zeroes "# @@ -305,6 +305,26 @@ mod gen_list { ); } + #[test] + fn list_walk_with_str() { + assert_evals_to!( + r#"List.walk [ "x", "y", "z" ] Str.concat "<""#, + RocStr::from("zyx<"), + RocStr + ); + + assert_evals_to!( + r#"List.walk [ "Third", "Second", "First" ] Str.concat "Fourth""#, + RocStr::from("FirstSecondThirdFourth"), + RocStr + ); + } + + #[test] + fn list_walk_substraction() { + assert_evals_to!(r#"List.walk [ 1, 2 ] Num.sub 1"#, 2, i64); + } + #[test] fn list_keep_if_empty_list_of_int() { assert_evals_to!( diff --git a/compiler/gen/tests/gen_records.rs b/compiler/gen/tests/gen_records.rs index b25c1f7c9b..b744222235 100644 --- a/compiler/gen/tests/gen_records.rs +++ b/compiler/gen/tests/gen_records.rs @@ -844,4 +844,49 @@ mod gen_records { (bool, bool) ); } + + #[test] + fn alignment_in_record() { + assert_evals_to!( + indoc!("{ c: 32, b: if True then Red else if True then Green else Blue, a: 1 == 1 }"), + (32i64, true, 2u8), + (i64, bool, u8) + ); + } + + #[test] + fn blue_and_present() { + assert_evals_to!( + indoc!( + r#" + f = \r -> + when r is + { x: Blue, y ? 3 } -> y + { x: Red, y ? 5 } -> y + + f { x: Blue, y: 7 } + "# + ), + 7, + i64 + ); + } + + #[test] + fn blue_and_absent() { + assert_evals_to!( + indoc!( + r#" + f = \r -> + when r is + { x: Blue, y ? 3 } -> y + { x: Red, y ? 5 } -> y + + f { x: Blue } + "# + ), + 3, + i64 + ); + } } diff --git a/compiler/gen/tests/gen_tags.rs b/compiler/gen/tests/gen_tags.rs index 0de5052058..2b30ed5579 100644 --- a/compiler/gen/tests/gen_tags.rs +++ b/compiler/gen/tests/gen_tags.rs @@ -481,7 +481,7 @@ mod gen_tags { assert_evals_to!( indoc!( r#" - wrapper = \{} -> + wrapper = \{} -> when 2 is 2 if False -> 0 _ -> 42 @@ -499,7 +499,7 @@ mod gen_tags { assert_evals_to!( indoc!( r#" - wrapper = \{} -> + wrapper = \{} -> when 2 is 2 if True -> 42 _ -> 0 @@ -517,7 +517,7 @@ mod gen_tags { assert_evals_to!( indoc!( r#" - wrapper = \{} -> + wrapper = \{} -> when 2 is _ if False -> 0 _ -> 42 @@ -637,7 +637,7 @@ mod gen_tags { x : Maybe (Maybe Int) x = Just (Just 41) - main = + main = x "# ), @@ -701,11 +701,11 @@ mod gen_tags { assert_evals_to!( indoc!( r#" - wrapper = \{} -> + wrapper = \{} -> x : [ Red, White, Blue ] x = Blue - y = + y = when x is Red -> 1 White -> 2 @@ -726,8 +726,8 @@ mod gen_tags { assert_evals_to!( indoc!( r#" - wrapper = \{} -> - y = + wrapper = \{} -> + y = when 1 + 2 is 3 -> 3 1 -> 1 @@ -745,7 +745,7 @@ mod gen_tags { assert_evals_to!( indoc!( r#" - y = + y = if 1 + 2 > 0 then 3 else @@ -758,4 +758,114 @@ mod gen_tags { i64 ); } + + #[test] + fn alignment_in_single_tag_construction() { + assert_evals_to!(indoc!("Three (1 == 1) 32"), (32i64, true), (i64, bool)); + + assert_evals_to!( + indoc!("Three (1 == 1) (if True then Red else if True then Green else Blue) 32"), + (32i64, true, 2u8), + (i64, bool, u8) + ); + } + + #[test] + fn alignment_in_single_tag_pattern_match() { + assert_evals_to!( + indoc!( + r"# + x = Three (1 == 1) 32 + + when x is + Three bool int -> + { bool, int } + #" + ), + (32i64, true), + (i64, bool) + ); + + assert_evals_to!( + indoc!( + r"# + x = Three (1 == 1) (if True then Red else if True then Green else Blue) 32 + + when x is + Three bool color int -> + { bool, color, int } + #" + ), + (32i64, true, 2u8), + (i64, bool, u8) + ); + } + + #[test] + fn alignment_in_multi_tag_construction() { + assert_evals_to!( + indoc!( + r"# + x : [ Three Bool Int, Empty ] + x = Three (1 == 1) 32 + + x + + #" + ), + (1, 32i64, true), + (i64, i64, bool) + ); + + assert_evals_to!( + indoc!( + r"# + x : [ Three Bool [ Red, Green, Blue ] Int, Empty ] + x = Three (1 == 1) (if True then Red else if True then Green else Blue) 32 + + x + #" + ), + (1, 32i64, true, 2u8), + (i64, i64, bool, u8) + ); + } + + #[test] + fn alignment_in_multi_tag_pattern_match() { + assert_evals_to!( + indoc!( + r"# + x : [ Three Bool Int, Empty ] + x = Three (1 == 1) 32 + + when x is + Three bool int -> + { bool, int } + + Empty -> + { bool: False, int: 0 } + #" + ), + (32i64, true), + (i64, bool) + ); + + assert_evals_to!( + indoc!( + r"# + x : [ Three Bool [ Red, Green, Blue ] Int, Empty ] + x = Three (1 == 1) (if True then Red else if True then Green else Blue) 32 + + when x is + Three bool color int -> + { bool, color, int } + Empty -> + { bool: False, color: Red, int: 0 } + #" + ), + (32i64, true, 2u8), + (i64, bool, u8) + ); + } } diff --git a/compiler/module/src/low_level.rs b/compiler/module/src/low_level.rs index 5c9a90f1ae..f2d03586b9 100644 --- a/compiler/module/src/low_level.rs +++ b/compiler/module/src/low_level.rs @@ -22,7 +22,8 @@ pub enum LowLevel { ListJoin, ListMap, ListKeepIf, - ListWalkRight, + ListWalk, + ListWalkBackwards, ListSum, NumAdd, NumAddWrap, diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 351edbee69..35a0b934f3 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -683,18 +683,18 @@ define_builtins! { 5 LIST_APPEND: "append" 6 LIST_MAP: "map" 7 LIST_LEN: "len" - 8 LIST_FOLDL: "foldl" - 9 LIST_WALK_RIGHT: "walkRight" - 10 LIST_CONCAT: "concat" - 11 LIST_FIRST: "first" - 12 LIST_SINGLE: "single" - 13 LIST_REPEAT: "repeat" - 14 LIST_REVERSE: "reverse" - 15 LIST_PREPEND: "prepend" - 16 LIST_JOIN: "join" - 17 LIST_KEEP_IF: "keepIf" - 18 LIST_CONTAINS: "contains" - 19 LIST_SUM: "sum" + 8 LIST_WALK_BACKWARDS: "walkBackwards" + 9 LIST_CONCAT: "concat" + 10 LIST_FIRST: "first" + 11 LIST_SINGLE: "single" + 12 LIST_REPEAT: "repeat" + 13 LIST_REVERSE: "reverse" + 14 LIST_PREPEND: "prepend" + 15 LIST_JOIN: "join" + 16 LIST_KEEP_IF: "keepIf" + 17 LIST_CONTAINS: "contains" + 18 LIST_SUM: "sum" + 19 LIST_WALK: "walk" } 5 RESULT: "Result" => { 0 RESULT_RESULT: "Result" imported // the Result.Result type alias diff --git a/compiler/mono/src/borrow.rs b/compiler/mono/src/borrow.rs index 82789d81e0..b6fd077d54 100644 --- a/compiler/mono/src/borrow.rs +++ b/compiler/mono/src/borrow.rs @@ -535,7 +535,8 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] { ListMap => arena.alloc_slice_copy(&[owned, irrelevant]), ListKeepIf => arena.alloc_slice_copy(&[owned, irrelevant]), ListContains => arena.alloc_slice_copy(&[borrowed, irrelevant]), - ListWalkRight => arena.alloc_slice_copy(&[borrowed, irrelevant, owned]), + ListWalk => arena.alloc_slice_copy(&[borrowed, irrelevant, owned]), + ListWalkBackwards => arena.alloc_slice_copy(&[borrowed, irrelevant, owned]), ListSum => arena.alloc_slice_copy(&[borrowed]), Eq | NotEq | And | Or | NumAdd | NumAddWrap | NumAddChecked | NumSub | NumMul | NumGt diff --git a/compiler/mono/src/decision_tree.rs b/compiler/mono/src/decision_tree.rs index f079b4d5eb..ec9fff2c5f 100644 --- a/compiler/mono/src/decision_tree.rs +++ b/compiler/mono/src/decision_tree.rs @@ -412,7 +412,7 @@ fn test_at_path<'a>(selected_path: &Path, branch: &Branch<'a>, all_tests: &mut V arguments.push((Pattern::Underscore, destruct.layout.clone())); } DestructType::Optional(_expr) => { - arguments.push((Pattern::Underscore, destruct.layout.clone())); + // do nothing } } } @@ -540,23 +540,27 @@ fn to_relevant_branch_help<'a>( .. } => { debug_assert!(test_name == &TagName::Global(RECORD_TAG_NAME.into())); - let sub_positions = destructs.into_iter().enumerate().map(|(index, destruct)| { - let pattern = match destruct.typ { - DestructType::Guard(guard) => guard.clone(), - DestructType::Required => Pattern::Underscore, - DestructType::Optional(_expr) => Pattern::Underscore, - }; + let sub_positions = destructs + .into_iter() + .filter(|destruct| !matches!(destruct.typ, DestructType::Optional(_))) + .enumerate() + .map(|(index, destruct)| { + let pattern = match destruct.typ { + DestructType::Guard(guard) => guard.clone(), + DestructType::Required => Pattern::Underscore, + DestructType::Optional(_expr) => unreachable!("because of the filter"), + }; - ( - Path::Index { - index: index as u64, - tag_id: *tag_id, - path: Box::new(path.clone()), - }, - Guard::NoGuard, - pattern, - ) - }); + ( + Path::Index { + index: index as u64, + tag_id: *tag_id, + path: Box::new(path.clone()), + }, + Guard::NoGuard, + pattern, + ) + }); start.extend(sub_positions); start.extend(end); diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 689eae51f0..72b5080199 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -907,7 +907,13 @@ where if PRETTY_PRINT_IR_SYMBOLS { alloc.text(format!("{:?}", symbol)) } else { - alloc.text(format!("{}", symbol)) + let text = format!("{}", symbol); + + if text.starts_with('.') { + alloc.text("Test").append(text) + } else { + alloc.text(text) + } } } @@ -917,7 +923,7 @@ where D::Doc: Clone, A: Clone, { - alloc.text(format!("{}", symbol.0)) + symbol_to_doc(alloc, symbol.0) } impl<'a> Expr<'a> { @@ -1101,7 +1107,9 @@ impl<'a> Stmt<'a> { .chain(std::iter::once(default_doc)); // alloc - .text(format!("switch {}:", cond_symbol)) + .text("switch ") + .append(symbol_to_doc(alloc, *cond_symbol)) + .append(":") .append(alloc.hardline()) .append( alloc.intersperse(branches_docs, alloc.hardline().append(alloc.hardline())), @@ -1115,7 +1123,9 @@ impl<'a> Stmt<'a> { fail, .. } => alloc - .text(format!("if {} then", branching_symbol)) + .text("if ") + .append(symbol_to_doc(alloc, *branching_symbol)) + .append(" then") .append(alloc.hardline()) .append(pass.to_doc(alloc).indent(4)) .append(alloc.hardline()) @@ -2384,7 +2394,7 @@ pub fn with_hole<'a>( Tag { variant_var, name: tag_name, - arguments: args, + arguments: mut args, .. } => { use crate::layout::UnionVariant::*; @@ -2421,11 +2431,34 @@ pub fn with_hole<'a>( } Unwrapped(field_layouts) => { + let mut field_symbols_temp = + Vec::with_capacity_in(field_layouts.len(), env.arena); + + for (var, arg) in args.drain(..) { + // Layout will unpack this unwrapped tack if it only has one (non-zero-sized) field + let layout = layout_cache + .from_var(env.arena, var, env.subs) + .unwrap_or_else(|err| { + panic!("TODO turn fn_var into a RuntimeError {:?}", err) + }); + + let alignment = layout.alignment_bytes(8); + + let symbol = possible_reuse_symbol(env, procs, &arg.value); + field_symbols_temp.push(( + alignment, + symbol, + ((var, arg), &*env.arena.alloc(symbol)), + )); + } + field_symbols_temp.sort_by(|a, b| b.0.cmp(&a.0)); + let mut field_symbols = Vec::with_capacity_in(field_layouts.len(), env.arena); - for (_, arg) in args.iter() { - field_symbols.push(possible_reuse_symbol(env, procs, &arg.value)); + for (_, symbol, _) in field_symbols_temp.iter() { + field_symbols.push(*symbol); } + let field_symbols = field_symbols.into_bump_slice(); // Layout will unpack this unwrapped tack if it only has one (non-zero-sized) field @@ -2438,7 +2471,7 @@ pub fn with_hole<'a>( // even though this was originally a Tag, we treat it as a Struct from now on let stmt = Stmt::Let(assigned, Expr::Struct(field_symbols), layout, hole); - let iter = args.into_iter().rev().zip(field_symbols.iter().rev()); + let iter = field_symbols_temp.into_iter().map(|(_, _, data)| data); assign_to_symbols(env, procs, layout_cache, iter, stmt) } Wrapped(sorted_tag_layouts) => { @@ -2449,12 +2482,33 @@ pub fn with_hole<'a>( .find(|(_, (key, _))| key == &tag_name) .expect("tag must be in its own type"); + let mut field_symbols_temp = Vec::with_capacity_in(args.len(), env.arena); + + for (var, arg) in args.drain(..) { + // Layout will unpack this unwrapped tack if it only has one (non-zero-sized) field + let layout = layout_cache + .from_var(env.arena, var, env.subs) + .unwrap_or_else(|err| { + panic!("TODO turn fn_var into a RuntimeError {:?}", err) + }); + + let alignment = layout.alignment_bytes(8); + + let symbol = possible_reuse_symbol(env, procs, &arg.value); + field_symbols_temp.push(( + alignment, + symbol, + ((var, arg), &*env.arena.alloc(symbol)), + )); + } + field_symbols_temp.sort_by(|a, b| b.0.cmp(&a.0)); + let mut field_symbols: Vec = Vec::with_capacity_in(args.len(), arena); let tag_id_symbol = env.unique_symbol(); field_symbols.push(tag_id_symbol); - for (_, arg) in args.iter() { - field_symbols.push(possible_reuse_symbol(env, procs, &arg.value)); + for (_, symbol, _) in field_symbols_temp.iter() { + field_symbols.push(*symbol); } let mut layouts: Vec<&'a [Layout<'a>]> = @@ -2475,7 +2529,11 @@ pub fn with_hole<'a>( }; let mut stmt = Stmt::Let(assigned, tag, layout, hole); - let iter = args.into_iter().rev().zip(field_symbols.iter().rev()); + let iter = field_symbols_temp + .drain(..) + .map(|x| x.2 .0) + .rev() + .zip(field_symbols.iter().rev()); stmt = assign_to_symbols(env, procs, layout_cache, iter, stmt); @@ -5290,6 +5348,20 @@ pub fn from_can_pattern<'a>( }], }; + let mut arguments = arguments.clone(); + + arguments.sort_by(|arg1, arg2| { + let ptr_bytes = 8; + + let layout1 = layout_cache.from_var(env.arena, arg1.0, env.subs).unwrap(); + let layout2 = layout_cache.from_var(env.arena, arg2.0, env.subs).unwrap(); + + let size1 = layout1.alignment_bytes(ptr_bytes); + let size2 = layout2.alignment_bytes(ptr_bytes); + + size2.cmp(&size1) + }); + let mut mono_args = Vec::with_capacity_in(arguments.len(), env.arena); for ((_, loc_pat), layout) in arguments.iter().zip(field_layouts.iter()) { mono_args.push(( @@ -5333,6 +5405,20 @@ pub fn from_can_pattern<'a>( let mut mono_args = Vec::with_capacity_in(arguments.len(), env.arena); // disregard the tag discriminant layout + let mut arguments = arguments.clone(); + + arguments.sort_by(|arg1, arg2| { + let ptr_bytes = 8; + + let layout1 = layout_cache.from_var(env.arena, arg1.0, env.subs).unwrap(); + let layout2 = layout_cache.from_var(env.arena, arg2.0, env.subs).unwrap(); + + let size1 = layout1.alignment_bytes(ptr_bytes); + let size2 = layout2.alignment_bytes(ptr_bytes); + + size2.cmp(&size1) + }); + // TODO make this assert pass, it currently does not because // 0-sized values are dropped out // debug_assert_eq!(arguments.len(), argument_layouts[1..].len()); @@ -5374,8 +5460,8 @@ pub fn from_can_pattern<'a>( // sorted fields based on the destruct let mut mono_destructs = Vec::with_capacity_in(destructs.len(), env.arena); - let mut destructs = destructs.clone(); - destructs.sort_by(|a, b| a.value.label.cmp(&b.value.label)); + let destructs_by_label = env.arena.alloc(MutMap::default()); + destructs_by_label.extend(destructs.iter().map(|x| (&x.value.label, x))); let mut field_layouts = Vec::with_capacity_in(sorted_fields.len(), env.arena); @@ -5387,119 +5473,96 @@ pub fn from_can_pattern<'a>( // in the source the field is not matche in the source language. // // Optional fields somewhat complicate the matter here - let mut it1 = sorted_fields.into_iter(); - let mut opt_sorted = it1.next(); - let mut it2 = destructs.iter(); - let mut opt_destruct = it2.next(); + for (label, variable, res_layout) in sorted_fields.into_iter() { + match res_layout { + Ok(field_layout) => { + // the field is non-optional according to the type - loop { - match (opt_sorted, opt_destruct) { - (Some((label, variable, Ok(field_layout))), Some(destruct)) => { - if destruct.value.label == label { - mono_destructs.push(from_can_record_destruct( - env, - layout_cache, - &destruct.value, - field_layout.clone(), - )); - - opt_sorted = it1.next(); - opt_destruct = it2.next(); - } else { - // insert underscore pattern - mono_destructs.push(RecordDestruct { - label: label.clone(), - symbol: env.unique_symbol(), - variable, - layout: field_layout.clone(), - typ: DestructType::Guard(Pattern::Underscore), - }); - - opt_sorted = it1.next(); + match destructs_by_label.remove(&label) { + Some(destruct) => { + // this field is destructured by the pattern + mono_destructs.push(from_can_record_destruct( + env, + layout_cache, + &destruct.value, + field_layout.clone(), + )); + } + None => { + // this field is not destructured by the pattern + // put in an underscore + mono_destructs.push(RecordDestruct { + label: label.clone(), + symbol: env.unique_symbol(), + variable, + layout: field_layout.clone(), + typ: DestructType::Guard(Pattern::Underscore), + }); + } } + + // the layout of this field is part of the layout of the record field_layouts.push(field_layout); } - (Some((label, variable, Err(field_layout))), Some(destruct)) => { - if destruct.value.label == label { - opt_destruct = it2.next(); - - mono_destructs.push(RecordDestruct { - label: destruct.value.label.clone(), - symbol: destruct.value.symbol, - layout: field_layout, - variable, - typ: match &destruct.value.typ { - roc_can::pattern::DestructType::Optional(_, loc_expr) => { - // if we reach this stage, the optional field is not present - // so use the default - DestructType::Optional(loc_expr.value.clone()) - } - _ => unreachable!( - "only optional destructs can be optional fields" - ), - }, - }); - } - opt_sorted = it1.next(); - } - - (Some((label, variable, Err(field_layout))), None) => { - // the remainder of the fields (from the type) is not matched on in - // this pattern; to fill it out, we put underscores - mono_destructs.push(RecordDestruct { - label: label.clone(), - symbol: env.unique_symbol(), - variable, - layout: field_layout.clone(), - typ: DestructType::Guard(Pattern::Underscore), - }); - - opt_sorted = it1.next(); - } - - (Some((label, variable, Ok(field_layout))), None) => { - // the remainder of the fields (from the type) is not matched on in - // this pattern; to fill it out, we put underscores - mono_destructs.push(RecordDestruct { - label: label.clone(), - symbol: env.unique_symbol(), - variable, - layout: field_layout.clone(), - typ: DestructType::Guard(Pattern::Underscore), - }); - - field_layouts.push(field_layout); - opt_sorted = it1.next(); - } - (None, Some(destruct)) => { - // destruct is not in the type, but is in the pattern - // it must be an optional field, and we will use the default - match &destruct.value.typ { - roc_can::pattern::DestructType::Optional(field_var, loc_expr) => { - let field_layout = layout_cache - .from_var(env.arena, *field_var, env.subs) - .unwrap_or_else(|err| { - panic!("TODO turn fn_var into a RuntimeError {:?}", err) - }); - + Err(field_layout) => { + // the field is optional according to the type + match destructs_by_label.remove(&label) { + Some(destruct) => { + // this field is destructured by the pattern mono_destructs.push(RecordDestruct { label: destruct.value.label.clone(), symbol: destruct.value.symbol, - variable: destruct.value.var, layout: field_layout, - typ: DestructType::Optional(loc_expr.value.clone()), - }) + variable, + typ: match &destruct.value.typ { + roc_can::pattern::DestructType::Optional(_, loc_expr) => { + // if we reach this stage, the optional field is not present + // so use the default + DestructType::Optional(loc_expr.value.clone()) + } + _ => unreachable!( + "only optional destructs can be optional fields" + ), + }, + }); + } + None => { + // this field is not destructured by the pattern + // put in an underscore + mono_destructs.push(RecordDestruct { + label: label.clone(), + symbol: env.unique_symbol(), + variable, + layout: field_layout.clone(), + typ: DestructType::Guard(Pattern::Underscore), + }); } - _ => unreachable!("only optional destructs can be optional fields"), } + } + } + } - opt_sorted = None; - opt_destruct = it2.next(); - } - (None, None) => { - break; + for (_, destruct) in destructs_by_label.drain() { + // this destruct is not in the type, but is in the pattern + // it must be an optional field, and we will use the default + match &destruct.value.typ { + roc_can::pattern::DestructType::Optional(field_var, loc_expr) => { + let field_layout = layout_cache + .from_var(env.arena, *field_var, env.subs) + .unwrap_or_else(|err| { + panic!("TODO turn fn_var into a RuntimeError {:?}", err) + }); + + mono_destructs.push(RecordDestruct { + label: destruct.value.label.clone(), + symbol: destruct.value.symbol, + variable: destruct.value.var, + layout: field_layout, + typ: DestructType::Optional(loc_expr.value.clone()), + }) } + _ => unreachable!("only optional destructs can be optional fields"), } } diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 0cd083738f..c54e39564f 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -4,6 +4,7 @@ use roc_collections::all::{default_hasher, MutMap, MutSet}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::{Interns, Symbol}; use roc_types::subs::{Content, FlatType, Subs, Variable}; +use roc_types::types::RecordField; use std::collections::HashMap; pub const MAX_ENUM_SIZE: usize = (std::mem::size_of::() * 8) as usize; @@ -789,59 +790,30 @@ fn layout_from_flat_type<'a>( } } Record(fields, ext_var) => { - // Sort the fields by label - let mut sorted_fields = Vec::with_capacity_in(fields.len(), arena); - sorted_fields.extend(fields.into_iter()); - // extract any values from the ext_var let mut fields_map = MutMap::default(); + fields_map.extend(fields); match roc_types::pretty_print::chase_ext_record(subs, ext_var, &mut fields_map) { Ok(()) | Err((_, Content::FlexVar(_))) => {} Err(_) => unreachable!("this would have been a type error"), } - sorted_fields.extend(fields_map.into_iter()); - - sorted_fields.sort_by(|(label1, _), (label2, _)| label1.cmp(label2)); + let sorted_fields = sort_record_fields_help(env, fields_map); // Determine the layouts of the fields, maintaining sort order let mut layouts = Vec::with_capacity_in(sorted_fields.len(), arena); - for (label, field) in sorted_fields { - use LayoutProblem::*; - - let field_var = { - use roc_types::types::RecordField::*; - match field { - Optional(_) => { - // when an optional field reaches this stage, the field was truly - // optional, and not unified to be demanded or required - // therefore, there is no such field on the record, and we ignore this - // field from now on. - continue; - } - Required(var) => var, - Demanded(var) => var, - } - }; - - match Layout::from_var(env, field_var) { + for (_, _, res_layout) in sorted_fields { + match res_layout { Ok(layout) => { // Drop any zero-sized fields like {}. if !layout.is_dropped_because_empty() { layouts.push(layout); } } - Err(UnresolvedTypeVar(v)) => { - // Invalid field! - panic!( - r"I hit an unresolved type var {:?} when determining the layout of {:?} of record field: {:?} : {:?}", - field_var, v, label, field - ); - } - Err(Erroneous) => { - // Invalid field! - panic!("TODO gracefully handle record with invalid field.var"); + Err(_) => { + // optional field, ignore + continue; } } } @@ -894,6 +866,15 @@ fn layout_from_flat_type<'a>( tag_layout.push(Layout::from_var(env, var)?); } + tag_layout.sort_by(|layout1, layout2| { + let ptr_bytes = 8; + + let size1 = layout1.alignment_bytes(ptr_bytes); + let size2 = layout2.alignment_bytes(ptr_bytes); + + size2.cmp(&size1) + }); + tag_layouts.push(tag_layout.into_bump_slice()); } @@ -924,39 +905,55 @@ pub fn sort_record_fields<'a>( }; match roc_types::pretty_print::chase_ext_record(subs, var, &mut fields_map) { - Ok(()) | Err((_, Content::FlexVar(_))) => { - // Sort the fields by label - let mut sorted_fields = Vec::with_capacity_in(fields_map.len(), arena); - - use roc_types::types::RecordField; - for (label, field) in fields_map { - let var = match field { - RecordField::Demanded(v) => v, - RecordField::Required(v) => v, - RecordField::Optional(v) => { - let layout = - Layout::from_var(&mut env, v).expect("invalid layout from var"); - sorted_fields.push((label, v, Err(layout))); - continue; - } - }; - - let layout = Layout::from_var(&mut env, var).expect("invalid layout from var"); - - // Drop any zero-sized fields like {} - if !layout.is_dropped_because_empty() { - sorted_fields.push((label, var, Ok(layout))); - } - } - - sorted_fields.sort_by(|(label1, _, _), (label2, _, _)| label1.cmp(label2)); - - sorted_fields - } + Ok(()) | Err((_, Content::FlexVar(_))) => sort_record_fields_help(&mut env, fields_map), Err(other) => panic!("invalid content in record variable: {:?}", other), } } +fn sort_record_fields_help<'a>( + env: &mut Env<'a, '_>, + fields_map: MutMap>, +) -> Vec<'a, (Lowercase, Variable, Result, Layout<'a>>)> { + // Sort the fields by label + let mut sorted_fields = Vec::with_capacity_in(fields_map.len(), env.arena); + + for (label, field) in fields_map { + let var = match field { + RecordField::Demanded(v) => v, + RecordField::Required(v) => v, + RecordField::Optional(v) => { + let layout = Layout::from_var(env, v).expect("invalid layout from var"); + sorted_fields.push((label, v, Err(layout))); + continue; + } + }; + + let layout = Layout::from_var(env, var).expect("invalid layout from var"); + + // Drop any zero-sized fields like {} + if !layout.is_dropped_because_empty() { + sorted_fields.push((label, var, Ok(layout))); + } + } + + sorted_fields.sort_by( + |(label1, _, res_layout1), (label2, _, res_layout2)| match res_layout1 { + Ok(layout1) | Err(layout1) => match res_layout2 { + Ok(layout2) | Err(layout2) => { + let ptr_bytes = 8; + + let size1 = layout1.alignment_bytes(ptr_bytes); + let size2 = layout2.alignment_bytes(ptr_bytes); + + size2.cmp(&size1).then(label1.cmp(label2)) + } + }, + }, + ); + + sorted_fields +} + #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum UnionVariant<'a> { Never, @@ -1059,6 +1056,15 @@ pub fn union_sorted_tags_help<'a>( } } + layouts.sort_by(|layout1, layout2| { + let ptr_bytes = 8; + + let size1 = layout1.alignment_bytes(ptr_bytes); + let size2 = layout2.alignment_bytes(ptr_bytes); + + size2.cmp(&size1) + }); + if layouts.is_empty() { if contains_zero_sized { UnionVariant::UnitWithArguments @@ -1102,6 +1108,15 @@ pub fn union_sorted_tags_help<'a>( } } + arg_layouts.sort_by(|layout1, layout2| { + let ptr_bytes = 8; + + let size1 = layout1.alignment_bytes(ptr_bytes); + let size2 = layout2.alignment_bytes(ptr_bytes); + + size2.cmp(&size1) + }); + answer.push((tag_name, arg_layouts.into_bump_slice())); } diff --git a/compiler/mono/tests/test_mono.rs b/compiler/mono/tests/test_mono.rs index d3cbc2eea7..c7d7ba58d6 100644 --- a/compiler/mono/tests/test_mono.rs +++ b/compiler/mono/tests/test_mono.rs @@ -153,9 +153,9 @@ mod test_mono { "#, indoc!( r#" - procedure .0 (): - let .1 = 5i64; - ret .1; + procedure Test.0 (): + let Test.1 = 5i64; + ret Test.1; "# ), ) @@ -171,9 +171,9 @@ mod test_mono { "#, indoc!( r#" - procedure .0 (): - let .1 = 5i64; - ret .1; + procedure Test.0 (): + let Test.1 = 5i64; + ret Test.1; "# ), ) @@ -189,19 +189,19 @@ mod test_mono { "#, indoc!( r#" - procedure .0 (): - let .8 = 0i64; - let .9 = 3i64; - let .2 = Just .8 .9; - let .5 = 0i64; - let .6 = Index 0 .2; - let .7 = lowlevel Eq .5 .6; - if .7 then - let .1 = Index 1 .2; - ret .1; + procedure Test.0 (): + let Test.9 = 0i64; + let Test.8 = 3i64; + let Test.2 = Just Test.9 Test.8; + let Test.5 = 0i64; + let Test.6 = Index 0 Test.2; + let Test.7 = lowlevel Eq Test.5 Test.6; + if Test.7 then + let Test.1 = Index 1 Test.2; + ret Test.1; else - let .4 = 0i64; - ret .4; + let Test.4 = 0i64; + ret Test.4; "# ), ) @@ -218,23 +218,23 @@ mod test_mono { "#, indoc!( r#" - procedure .0 (): - let .8 = 1i64; - let .9 = 1i64; - let .10 = 2i64; - let .4 = These .8 .9 .10; - switch .4: + procedure Test.0 (): + let Test.10 = 1i64; + let Test.8 = 1i64; + let Test.9 = 2i64; + let Test.4 = These Test.10 Test.8 Test.9; + switch Test.4: case 2: - let .1 = Index 1 .4; - ret .1; + let Test.1 = Index 1 Test.4; + ret Test.1; case 0: - let .2 = Index 1 .4; - ret .2; + let Test.2 = Index 1 Test.4; + ret Test.2; default: - let .3 = Index 1 .4; - ret .3; + let Test.3 = Index 1 Test.4; + ret Test.3; "# ), @@ -250,12 +250,12 @@ mod test_mono { "#, indoc!( r#" - procedure .0 (): - let .5 = 1i64; - let .6 = 3.14f64; - let .2 = Struct {.5, .6}; - let .1 = Index 0 .2; - ret .1; + procedure Test.0 (): + let Test.5 = 1i64; + let Test.6 = 3.14f64; + let Test.2 = Struct {Test.5, Test.6}; + let Test.1 = Index 0 Test.2; + ret Test.1; "# ), ) @@ -270,14 +270,14 @@ mod test_mono { indoc!( r#" procedure Num.14 (#Attr.2, #Attr.3): - let .4 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .4; + let Test.4 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.4; - procedure .0 (): - let .2 = 1i64; - let .3 = 2i64; - let .1 = CallByName Num.14 .2 .3; - ret .1; + procedure Test.0 (): + let Test.2 = 1i64; + let Test.3 = 2i64; + let Test.1 = CallByName Num.14 Test.2 Test.3; + ret Test.1; "# ), ) @@ -292,13 +292,13 @@ mod test_mono { indoc!( r#" procedure Num.36 (#Attr.2): - let .3 = lowlevel NumRound #Attr.2; - ret .3; + let Test.3 = lowlevel NumRound #Attr.2; + ret Test.3; - procedure .0 (): - let .2 = 3.6f64; - let .1 = CallByName Num.36 .2; - ret .1; + procedure Test.0 (): + let Test.2 = 3.6f64; + let Test.1 = CallByName Num.36 Test.2; + ret Test.1; "# ), ) @@ -315,32 +315,32 @@ mod test_mono { indoc!( r#" procedure Num.32 (#Attr.2, #Attr.3): - let .17 = 0i64; - let .13 = lowlevel NotEq #Attr.3 .17; - if .13 then - let .15 = 1i64; - let .16 = lowlevel NumDivUnchecked #Attr.2 #Attr.3; - let .14 = Ok .15 .16; - ret .14; + let Test.17 = 0i64; + let Test.13 = lowlevel NotEq #Attr.3 Test.17; + if Test.13 then + let Test.16 = 1i64; + let Test.15 = lowlevel NumDivUnchecked #Attr.2 #Attr.3; + let Test.14 = Ok Test.16 Test.15; + ret Test.14; else - let .11 = 0i64; - let .12 = Struct {}; - let .10 = Err .11 .12; - ret .10; + let Test.12 = 0i64; + let Test.11 = Struct {}; + let Test.10 = Err Test.12 Test.11; + ret Test.10; - procedure .0 (): - let .8 = 1000i64; - let .9 = 10i64; - let .2 = CallByName Num.32 .8 .9; - let .5 = 1i64; - let .6 = Index 0 .2; - let .7 = lowlevel Eq .5 .6; - if .7 then - let .1 = Index 1 .2; - ret .1; + procedure Test.0 (): + let Test.8 = 1000i64; + let Test.9 = 10i64; + let Test.2 = CallByName Num.32 Test.8 Test.9; + let Test.5 = 1i64; + let Test.6 = Index 0 Test.2; + let Test.7 = lowlevel Eq Test.5 Test.6; + if Test.7 then + let Test.1 = Index 1 Test.2; + ret Test.1; else - let .4 = -1i64; - ret .4; + let Test.4 = -1i64; + ret Test.4; "# ), ) @@ -358,14 +358,14 @@ mod test_mono { indoc!( r#" procedure Num.14 (#Attr.2, #Attr.3): - let .4 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .4; + let Test.4 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.4; - procedure .0 (): - let .1 = 3i64; - let .2 = 4i64; - let .3 = CallByName Num.14 .1 .2; - ret .3; + procedure Test.0 (): + let Test.1 = 3i64; + let Test.2 = 4i64; + let Test.3 = CallByName Num.14 Test.1 Test.2; + ret Test.3; "# ), ) @@ -385,24 +385,24 @@ mod test_mono { indoc!( r#" procedure Num.14 (#Attr.2, #Attr.3): - let .5 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .5; + let Test.5 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.5; - procedure .0 (): - let .10 = 0i64; - let .11 = 41i64; - let .1 = Just .10 .11; - let .7 = 0i64; - let .8 = Index 0 .1; - let .9 = lowlevel Eq .7 .8; - if .9 then - let .2 = Index 1 .1; - let .4 = 1i64; - let .3 = CallByName Num.14 .2 .4; - ret .3; + procedure Test.0 (): + let Test.11 = 0i64; + let Test.10 = 41i64; + let Test.1 = Just Test.11 Test.10; + let Test.7 = 0i64; + let Test.8 = Index 0 Test.1; + let Test.9 = lowlevel Eq Test.7 Test.8; + if Test.9 then + let Test.2 = Index 1 Test.1; + let Test.4 = 1i64; + let Test.3 = CallByName Num.14 Test.2 Test.4; + ret Test.3; else - let .6 = 1i64; - ret .6; + let Test.6 = 1i64; + ret Test.6; "# ), ) @@ -419,10 +419,10 @@ mod test_mono { "#, indoc!( r#" - procedure .0 (): - let .3 = 2i64; - let .1 = Struct {.3}; - ret .1; + procedure Test.0 (): + let Test.3 = 2i64; + let Test.1 = Struct {Test.3}; + ret Test.1; "# ), ) @@ -441,31 +441,31 @@ mod test_mono { "#, indoc!( r#" - procedure .1 (.2): - let .5 = 2i64; - joinpoint .11: - let .9 = 0i64; - ret .9; + procedure Test.1 (Test.2): + let Test.5 = 2i64; + joinpoint Test.11: + let Test.9 = 0i64; + ret Test.9; in - let .10 = 2i64; - let .13 = lowlevel Eq .10 .5; - if .13 then - joinpoint .7 .12: - if .12 then - let .6 = 42i64; - ret .6; + let Test.10 = 2i64; + let Test.13 = lowlevel Eq Test.10 Test.5; + if Test.13 then + joinpoint Test.7 Test.12: + if Test.12 then + let Test.6 = 42i64; + ret Test.6; else - jump .11; + jump Test.11; in - let .8 = false; - jump .7 .8; + let Test.8 = false; + jump Test.7 Test.8; else - jump .11; + jump Test.11; - procedure .0 (): - let .4 = Struct {}; - let .3 = CallByName .1 .4; - ret .3; + procedure Test.0 (): + let Test.4 = Struct {}; + let Test.3 = CallByName Test.1 Test.4; + ret Test.3; "# ), ) @@ -481,16 +481,16 @@ mod test_mono { indoc!( r#" procedure Num.14 (#Attr.2, #Attr.3): - let .5 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .5; + let Test.5 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.5; - procedure .0 (): - let .6 = 2i64; - let .2 = Struct {.6}; - let .1 = Index 0 .2; - let .4 = 3i64; - let .3 = CallByName Num.14 .1 .4; - ret .3; + procedure Test.0 (): + let Test.6 = 2i64; + let Test.2 = Struct {Test.6}; + let Test.1 = Index 0 Test.2; + let Test.4 = 3i64; + let Test.3 = CallByName Num.14 Test.1 Test.4; + ret Test.3; "# ), ) @@ -512,37 +512,37 @@ mod test_mono { indoc!( r#" procedure Num.14 (#Attr.2, #Attr.3): - let .6 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .6; + let Test.6 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.6; - procedure .0 (): - let .17 = 0i64; - let .19 = 0i64; - let .20 = 41i64; - let .18 = Just .19 .20; - let .2 = Just .17 .18; - joinpoint .14: - let .8 = 1i64; - ret .8; + procedure Test.0 (): + let Test.18 = 0i64; + let Test.20 = 0i64; + let Test.19 = 41i64; + let Test.17 = Just Test.20 Test.19; + let Test.2 = Just Test.18 Test.17; + joinpoint Test.14: + let Test.8 = 1i64; + ret Test.8; in - let .12 = 0i64; - let .13 = Index 0 .2; - let .16 = lowlevel Eq .12 .13; - if .16 then - let .9 = Index 1 .2; - let .10 = 0i64; - let .11 = Index 0 .9; - let .15 = lowlevel Eq .10 .11; - if .15 then - let .7 = Index 1 .2; - let .3 = Index 1 .7; - let .5 = 1i64; - let .4 = CallByName Num.14 .3 .5; - ret .4; + let Test.12 = 0i64; + let Test.13 = Index 0 Test.2; + let Test.16 = lowlevel Eq Test.12 Test.13; + if Test.16 then + let Test.9 = Index 1 Test.2; + let Test.10 = 0i64; + let Test.11 = Index 0 Test.9; + let Test.15 = lowlevel Eq Test.10 Test.11; + if Test.15 then + let Test.7 = Index 1 Test.2; + let Test.3 = Index 1 Test.7; + let Test.5 = 1i64; + let Test.4 = CallByName Num.14 Test.3 Test.5; + ret Test.4; else - jump .14; + jump Test.14; else - jump .14; + jump Test.14; "# ), ) @@ -559,33 +559,33 @@ mod test_mono { indoc!( r#" procedure Num.14 (#Attr.2, #Attr.3): - let .6 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .6; + let Test.6 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.6; - procedure .0 (): - let .14 = 2i64; - let .15 = 3i64; - let .3 = Struct {.14, .15}; - joinpoint .11: - let .1 = Index 0 .3; - let .2 = Index 1 .3; - let .5 = CallByName Num.14 .1 .2; - ret .5; + procedure Test.0 (): + let Test.15 = 3i64; + let Test.14 = 2i64; + let Test.3 = Struct {Test.14, Test.15}; + joinpoint Test.11: + let Test.1 = Index 0 Test.3; + let Test.2 = Index 1 Test.3; + let Test.5 = CallByName Num.14 Test.1 Test.2; + ret Test.5; in - let .9 = Index 1 .3; - let .10 = 3i64; - let .13 = lowlevel Eq .10 .9; - if .13 then - let .7 = Index 0 .3; - let .8 = 4i64; - let .12 = lowlevel Eq .8 .7; - if .12 then - let .4 = 9i64; - ret .4; + let Test.9 = Index 1 Test.3; + let Test.10 = 3i64; + let Test.13 = lowlevel Eq Test.10 Test.9; + if Test.13 then + let Test.7 = Index 0 Test.3; + let Test.8 = 4i64; + let Test.12 = lowlevel Eq Test.8 Test.7; + if Test.12 then + let Test.4 = 9i64; + ret Test.4; else - jump .11; + jump Test.11; else - jump .11; + jump Test.11; "# ), ) @@ -601,21 +601,21 @@ mod test_mono { "#, indoc!( r#" - procedure .1 (.2): - let .6 = 42i64; - let .5 = CallByName List.5 .2 .6; - ret .5; - procedure List.5 (#Attr.2, #Attr.3): - let .7 = lowlevel ListAppend #Attr.2 #Attr.3; - ret .7; + let Test.7 = lowlevel ListAppend #Attr.2 #Attr.3; + ret Test.7; - procedure .0 (): - let .8 = 1i64; - let .9 = 2i64; - let .4 = Array [.8, .9]; - let .3 = CallByName .1 .4; - ret .3; + procedure Test.1 (Test.2): + let Test.6 = 42i64; + let Test.5 = CallByName List.5 Test.2 Test.6; + ret Test.5; + + procedure Test.0 (): + let Test.8 = 1i64; + let Test.9 = 2i64; + let Test.4 = Array [Test.8, Test.9]; + let Test.3 = CallByName Test.1 Test.4; + ret Test.3; "# ), ) @@ -632,15 +632,15 @@ mod test_mono { indoc!( r#" procedure List.5 (#Attr.2, #Attr.3): - let .4 = lowlevel ListAppend #Attr.2 #Attr.3; - ret .4; + let Test.4 = lowlevel ListAppend #Attr.2 #Attr.3; + ret Test.4; - procedure .0 (): - let .5 = 1i64; - let .2 = Array [.5]; - let .3 = 2i64; - let .1 = CallByName List.5 .2 .3; - ret .1; + procedure Test.0 (): + let Test.5 = 1i64; + let Test.2 = Array [Test.5]; + let Test.3 = 2i64; + let Test.1 = CallByName List.5 Test.2 Test.3; + ret Test.1; "# ), ) @@ -658,30 +658,30 @@ mod test_mono { indoc!( r#" procedure List.7 (#Attr.2): - let .7 = lowlevel ListLen #Attr.2; - ret .7; + let Test.7 = lowlevel ListLen #Attr.2; + ret Test.7; procedure List.7 (#Attr.2): - let .8 = lowlevel ListLen #Attr.2; - ret .8; + let Test.8 = lowlevel ListLen #Attr.2; + ret Test.8; procedure Num.14 (#Attr.2, #Attr.3): - let .6 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .6; + let Test.6 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.6; - procedure .0 (): - let .10 = 1i64; - let .11 = 2i64; - let .12 = 3i64; - let .1 = Array [.10, .11, .12]; - let .9 = 1f64; - let .2 = Array [.9]; - let .4 = CallByName List.7 .1; - dec .1; - let .5 = CallByName List.7 .2; - dec .2; - let .3 = CallByName Num.14 .4 .5; - ret .3; + procedure Test.0 (): + let Test.10 = 1i64; + let Test.11 = 2i64; + let Test.12 = 3i64; + let Test.1 = Array [Test.10, Test.11, Test.12]; + let Test.9 = 1f64; + let Test.2 = Array [Test.9]; + let Test.4 = CallByName List.7 Test.1; + dec Test.1; + let Test.5 = CallByName List.7 Test.2; + dec Test.2; + let Test.3 = CallByName Num.14 Test.4 Test.5; + ret Test.3; "# ), ) @@ -707,29 +707,29 @@ mod test_mono { "#, indoc!( r#" - procedure .1 (.4): - let .2 = 0u8; - joinpoint .8 .3: - ret .3; + procedure Test.1 (Test.4): + let Test.2 = 0u8; + joinpoint Test.8 Test.3: + ret Test.3; in - switch .2: + switch Test.2: case 1: - let .9 = 1i64; - jump .8 .9; + let Test.9 = 1i64; + jump Test.8 Test.9; case 2: - let .10 = 2i64; - jump .8 .10; + let Test.10 = 2i64; + jump Test.8 Test.10; default: - let .11 = 3i64; - jump .8 .11; + let Test.11 = 3i64; + jump Test.8 Test.11; - procedure .0 (): - let .6 = Struct {}; - let .5 = CallByName .1 .6; - ret .5; + procedure Test.0 (): + let Test.6 = Struct {}; + let Test.5 = CallByName Test.1 Test.6; + ret Test.5; "# ), ) @@ -746,14 +746,14 @@ mod test_mono { "#, indoc!( r#" - procedure .0 (): - let .2 = true; - if .2 then - let .3 = 1i64; - ret .3; + procedure Test.0 (): + let Test.2 = true; + if Test.2 then + let Test.3 = 1i64; + ret Test.3; else - let .1 = 2i64; - ret .1; + let Test.1 = 2i64; + ret Test.1; "# ), ) @@ -772,19 +772,19 @@ mod test_mono { "#, indoc!( r#" - procedure .0 (): - let .4 = true; - if .4 then - let .5 = 1i64; - ret .5; + procedure Test.0 (): + let Test.4 = true; + if Test.4 then + let Test.5 = 1i64; + ret Test.5; else - let .2 = false; - if .2 then - let .3 = 2i64; - ret .3; + let Test.2 = false; + if Test.2 then + let Test.3 = 2i64; + ret Test.3; else - let .1 = 3i64; - ret .1; + let Test.1 = 3i64; + ret Test.1; "# ), ) @@ -809,34 +809,34 @@ mod test_mono { "#, indoc!( r#" - procedure .1 (.4): - let .18 = 1i64; - let .19 = 2i64; - let .2 = Ok .18 .19; - joinpoint .8 .3: - ret .3; + procedure Test.1 (Test.4): + let Test.19 = 1i64; + let Test.18 = 2i64; + let Test.2 = Ok Test.19 Test.18; + joinpoint Test.8 Test.3: + ret Test.3; in - let .15 = 1i64; - let .16 = Index 0 .2; - let .17 = lowlevel Eq .15 .16; - if .17 then - let .12 = Index 1 .2; - let .13 = 3i64; - let .14 = lowlevel Eq .13 .12; - if .14 then - let .9 = 1i64; - jump .8 .9; + let Test.15 = 1i64; + let Test.16 = Index 0 Test.2; + let Test.17 = lowlevel Eq Test.15 Test.16; + if Test.17 then + let Test.12 = Index 1 Test.2; + let Test.13 = 3i64; + let Test.14 = lowlevel Eq Test.13 Test.12; + if Test.14 then + let Test.9 = 1i64; + jump Test.8 Test.9; else - let .10 = 2i64; - jump .8 .10; + let Test.10 = 2i64; + jump Test.8 Test.10; else - let .11 = 3i64; - jump .8 .11; + let Test.11 = 3i64; + jump Test.8 Test.11; - procedure .0 (): - let .6 = Struct {}; - let .5 = CallByName .1 .6; - ret .5; + procedure Test.0 (): + let Test.6 = Struct {}; + let Test.5 = CallByName Test.1 Test.6; + ret Test.5; "# ), ) @@ -852,12 +852,12 @@ mod test_mono { "#, indoc!( r#" - procedure .0 (): - let .5 = 2i64; - let .6 = 3.14f64; - let .4 = Struct {.5, .6}; - let .1 = Index 0 .4; - ret .1; + procedure Test.0 (): + let Test.5 = 2i64; + let Test.6 = 3.14f64; + let Test.4 = Struct {Test.5, Test.6}; + let Test.1 = Index 0 Test.4; + ret Test.1; "# ), ) @@ -873,17 +873,17 @@ mod test_mono { "#, indoc!( r#" - procedure .0 (): - let .7 = 1i64; - let .8 = 3i64; - let .9 = 4i64; - let .5 = Array [.7, .8, .9]; - let .6 = 3.14f64; - let .4 = Struct {.5, .6}; - let .1 = Index 0 .4; - inc .1; - dec .4; - ret .1; + procedure Test.0 (): + let Test.7 = 1i64; + let Test.8 = 3i64; + let Test.9 = 4i64; + let Test.5 = Array [Test.7, Test.8, Test.9]; + let Test.6 = 3.14f64; + let Test.4 = Struct {Test.5, Test.6}; + let Test.1 = Index 0 Test.4; + inc Test.1; + dec Test.4; + ret Test.1; "# ), ) @@ -904,28 +904,28 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.3): - let .6 = 10i64; - joinpoint .8 .13: - if .13 then - let .7 = 0i64; - ret .7; - else - let .12 = 42i64; - ret .12; - in - let .10 = 5i64; - let .9 = CallByName Bool.5 .6 .10; - jump .8 .9; - procedure Bool.5 (#Attr.2, #Attr.3): - let .11 = lowlevel Eq #Attr.2 #Attr.3; - ret .11; + let Test.11 = lowlevel Eq #Attr.2 #Attr.3; + ret Test.11; - procedure .0 (): - let .5 = Struct {}; - let .4 = CallByName .1 .5; - ret .4; + procedure Test.1 (Test.3): + let Test.6 = 10i64; + joinpoint Test.8 Test.13: + if Test.13 then + let Test.7 = 0i64; + ret Test.7; + else + let Test.12 = 42i64; + ret Test.12; + in + let Test.10 = 5i64; + let Test.9 = CallByName Bool.5 Test.6 Test.10; + jump Test.8 Test.9; + + procedure Test.0 (): + let Test.5 = Struct {}; + let Test.4 = CallByName Test.1 Test.5; + ret Test.4; "# ), ) @@ -944,10 +944,10 @@ mod test_mono { ), indoc!( r#" - procedure .0 (): - let .1 = 5i64; - let .3 = 3i64; - ret .3; + procedure Test.0 (): + let Test.1 = 5i64; + let Test.3 = 3i64; + ret Test.3; "# ), ); @@ -963,9 +963,9 @@ mod test_mono { ), indoc!( r#" - procedure .0 (): - let .1 = 5i64; - ret .1; + procedure Test.0 (): + let Test.1 = 5i64; + ret Test.1; "# ), ) @@ -983,15 +983,15 @@ mod test_mono { ), indoc!( r#" - procedure .0 (): - let .2 = 0i64; - let .5 = 1i64; - let .6 = lowlevel Eq .5 .2; - if .6 then - let .3 = 12i64; - ret .3; + procedure Test.0 (): + let Test.2 = 0i64; + let Test.5 = 1i64; + let Test.6 = lowlevel Eq Test.5 Test.2; + if Test.6 then + let Test.3 = 12i64; + ret Test.3; else - ret .2; + ret Test.2; "# ), ) @@ -1013,28 +1013,28 @@ mod test_mono { ), indoc!( r#" - procedure .2 (.3): - let .6 = 0i64; - let .7 = 0i64; - let .5 = CallByName List.4 .3 .6 .7; - ret .5; - procedure List.4 (#Attr.2, #Attr.3, #Attr.4): - let .11 = lowlevel ListLen #Attr.2; - let .9 = lowlevel NumLt #Attr.3 .11; - if .9 then - let .10 = lowlevel ListSet #Attr.2 #Attr.3 #Attr.4; - ret .10; + let Test.11 = lowlevel ListLen #Attr.2; + let Test.9 = lowlevel NumLt #Attr.3 Test.11; + if Test.9 then + let Test.10 = lowlevel ListSet #Attr.2 #Attr.3 #Attr.4; + ret Test.10; else ret #Attr.2; - procedure .0 (): - let .12 = 1i64; - let .13 = 2i64; - let .14 = 3i64; - let .1 = Array [.12, .13, .14]; - let .4 = CallByName .2 .1; - ret .4; + procedure Test.2 (Test.3): + let Test.6 = 0i64; + let Test.7 = 0i64; + let Test.5 = CallByName List.4 Test.3 Test.6 Test.7; + ret Test.5; + + procedure Test.0 (): + let Test.12 = 1i64; + let Test.13 = 2i64; + let Test.14 = 3i64; + let Test.1 = Array [Test.12, Test.13, Test.14]; + let Test.4 = CallByName Test.2 Test.1; + ret Test.4; "# ), ) @@ -1055,22 +1055,22 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.2): - let .3 = Index 0 .2; - let .4 = Index 1 .2; - let .7 = CallByName Num.14 .3 .4; - ret .7; - procedure Num.14 (#Attr.2, #Attr.3): - let .8 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .8; + let Test.8 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.8; - procedure .0 (): - let .9 = 4i64; - let .10 = 9i64; - let .6 = Struct {.9, .10}; - let .5 = CallByName .1 .6; - ret .5; + procedure Test.1 (Test.2): + let Test.3 = Index 0 Test.2; + let Test.4 = Index 1 Test.2; + let Test.7 = CallByName Num.14 Test.3 Test.4; + ret Test.7; + + procedure Test.0 (): + let Test.9 = 4i64; + let Test.10 = 9i64; + let Test.6 = Struct {Test.9, Test.10}; + let Test.5 = CallByName Test.1 Test.6; + ret Test.5; "# ), ) @@ -1091,21 +1091,21 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.2): - let .3 = 10i64; - let .4 = Index 1 .2; - let .7 = CallByName Num.14 .3 .4; - ret .7; - procedure Num.14 (#Attr.2, #Attr.3): - let .8 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .8; + let Test.8 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.8; - procedure .0 (): - let .9 = 9i64; - let .6 = Struct {.9}; - let .5 = CallByName .1 .6; - ret .5; + procedure Test.1 (Test.2): + let Test.3 = 10i64; + let Test.4 = Index 1 Test.2; + let Test.7 = CallByName Num.14 Test.3 Test.4; + ret Test.7; + + procedure Test.0 (): + let Test.9 = 9i64; + let Test.6 = Struct {Test.9}; + let Test.5 = CallByName Test.1 Test.6; + ret Test.5; "# ), ) @@ -1124,22 +1124,22 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.4): - let .2 = Index 0 .4; - let .3 = Index 1 .4; - let .7 = CallByName Num.14 .2 .3; - ret .7; - procedure Num.14 (#Attr.2, #Attr.3): - let .8 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .8; + let Test.8 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.8; - procedure .0 (): - let .9 = 4i64; - let .10 = 9i64; - let .6 = Struct {.9, .10}; - let .5 = CallByName .1 .6; - ret .5; + procedure Test.1 (Test.4): + let Test.2 = Index 0 Test.4; + let Test.3 = Index 1 Test.4; + let Test.7 = CallByName Num.14 Test.2 Test.3; + ret Test.7; + + procedure Test.0 (): + let Test.9 = 4i64; + let Test.10 = 9i64; + let Test.6 = Struct {Test.9, Test.10}; + let Test.5 = CallByName Test.1 Test.6; + ret Test.5; "# ), ) @@ -1158,21 +1158,21 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.4): - let .2 = 10i64; - let .3 = Index 1 .4; - let .7 = CallByName Num.14 .2 .3; - ret .7; - procedure Num.14 (#Attr.2, #Attr.3): - let .8 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .8; + let Test.8 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.8; - procedure .0 (): - let .9 = 9i64; - let .6 = Struct {.9}; - let .5 = CallByName .1 .6; - ret .5; + procedure Test.1 (Test.4): + let Test.2 = 10i64; + let Test.3 = Index 1 Test.4; + let Test.7 = CallByName Num.14 Test.2 Test.3; + ret Test.7; + + procedure Test.0 (): + let Test.9 = 9i64; + let Test.6 = Struct {Test.9}; + let Test.5 = CallByName Test.1 Test.6; + ret Test.5; "# ), ) @@ -1202,70 +1202,70 @@ mod test_mono { indoc!( r#" procedure List.3 (#Attr.2, #Attr.3): - let .38 = lowlevel ListLen #Attr.2; - let .34 = lowlevel NumLt #Attr.3 .38; - if .34 then - let .36 = 1i64; - let .37 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; - let .35 = Ok .36 .37; - ret .35; + let Test.38 = lowlevel ListLen #Attr.2; + let Test.34 = lowlevel NumLt #Attr.3 Test.38; + if Test.34 then + let Test.36 = 1i64; + let Test.37 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; + let Test.35 = Ok Test.36 Test.37; + ret Test.35; else - let .32 = 0i64; - let .33 = Struct {}; - let .31 = Err .32 .33; - ret .31; + let Test.32 = 0i64; + let Test.33 = Struct {}; + let Test.31 = Err Test.32 Test.33; + ret Test.31; procedure List.4 (#Attr.2, #Attr.3, #Attr.4): - let .14 = lowlevel ListLen #Attr.2; - let .12 = lowlevel NumLt #Attr.3 .14; - if .12 then - let .13 = lowlevel ListSet #Attr.2 #Attr.3 #Attr.4; - ret .13; + let Test.14 = lowlevel ListLen #Attr.2; + let Test.12 = lowlevel NumLt #Attr.3 Test.14; + if Test.12 then + let Test.13 = lowlevel ListSet #Attr.2 #Attr.3 #Attr.4; + ret Test.13; else ret #Attr.2; - procedure .1 (.2): - let .39 = 0i64; - let .28 = CallByName List.3 .2 .39; - let .30 = 0i64; - let .29 = CallByName List.3 .2 .30; - let .7 = Struct {.28, .29}; - joinpoint .25: - let .18 = Array []; - ret .18; + procedure Test.1 (Test.2): + let Test.39 = 0i64; + let Test.28 = CallByName List.3 Test.2 Test.39; + let Test.30 = 0i64; + let Test.29 = CallByName List.3 Test.2 Test.30; + let Test.7 = Struct {Test.28, Test.29}; + joinpoint Test.25: + let Test.18 = Array []; + ret Test.18; in - let .19 = Index 0 .7; - let .20 = 1i64; - let .21 = Index 0 .19; - let .27 = lowlevel Eq .20 .21; - if .27 then - let .22 = Index 1 .7; - let .23 = 1i64; - let .24 = Index 0 .22; - let .26 = lowlevel Eq .23 .24; - if .26 then - let .17 = Index 0 .7; - let .3 = Index 1 .17; - let .16 = Index 1 .7; - let .4 = Index 1 .16; - let .15 = 0i64; - let .9 = CallByName List.4 .2 .15 .4; - let .10 = 0i64; - let .8 = CallByName List.4 .9 .10 .3; - ret .8; + let Test.19 = Index 0 Test.7; + let Test.20 = 1i64; + let Test.21 = Index 0 Test.19; + let Test.27 = lowlevel Eq Test.20 Test.21; + if Test.27 then + let Test.22 = Index 1 Test.7; + let Test.23 = 1i64; + let Test.24 = Index 0 Test.22; + let Test.26 = lowlevel Eq Test.23 Test.24; + if Test.26 then + let Test.17 = Index 0 Test.7; + let Test.3 = Index 1 Test.17; + let Test.16 = Index 1 Test.7; + let Test.4 = Index 1 Test.16; + let Test.15 = 0i64; + let Test.9 = CallByName List.4 Test.2 Test.15 Test.4; + let Test.10 = 0i64; + let Test.8 = CallByName List.4 Test.9 Test.10 Test.3; + ret Test.8; else - dec .2; - jump .25; + dec Test.2; + jump Test.25; else - dec .2; - jump .25; + dec Test.2; + jump Test.25; - procedure .0 (): - let .40 = 1i64; - let .41 = 2i64; - let .6 = Array [.40, .41]; - let .5 = CallByName .1 .6; - ret .5; + procedure Test.0 (): + let Test.40 = 1i64; + let Test.41 = 2i64; + let Test.6 = Array [Test.40, Test.41]; + let Test.5 = CallByName Test.1 Test.6; + ret Test.5; "# ), ) @@ -1296,71 +1296,71 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.2): - let .39 = 0i64; - let .28 = CallByName List.3 .2 .39; - let .30 = 0i64; - let .29 = CallByName List.3 .2 .30; - let .7 = Struct {.28, .29}; - joinpoint .25: - let .18 = Array []; - ret .18; - in - let .22 = Index 1 .7; - let .23 = 1i64; - let .24 = Index 0 .22; - let .27 = lowlevel Eq .23 .24; - if .27 then - let .19 = Index 0 .7; - let .20 = 1i64; - let .21 = Index 0 .19; - let .26 = lowlevel Eq .20 .21; - if .26 then - let .17 = Index 0 .7; - let .3 = Index 1 .17; - let .16 = Index 1 .7; - let .4 = Index 1 .16; - let .15 = 0i64; - let .9 = CallByName List.4 .2 .15 .4; - let .10 = 0i64; - let .8 = CallByName List.4 .9 .10 .3; - ret .8; - else - dec .2; - jump .25; - else - dec .2; - jump .25; - procedure List.3 (#Attr.2, #Attr.3): - let .38 = lowlevel ListLen #Attr.2; - let .34 = lowlevel NumLt #Attr.3 .38; - if .34 then - let .36 = 1i64; - let .37 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; - let .35 = Ok .36 .37; - ret .35; + let Test.38 = lowlevel ListLen #Attr.2; + let Test.34 = lowlevel NumLt #Attr.3 Test.38; + if Test.34 then + let Test.37 = 1i64; + let Test.36 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; + let Test.35 = Ok Test.37 Test.36; + ret Test.35; else - let .32 = 0i64; - let .33 = Struct {}; - let .31 = Err .32 .33; - ret .31; + let Test.33 = 0i64; + let Test.32 = Struct {}; + let Test.31 = Err Test.33 Test.32; + ret Test.31; procedure List.4 (#Attr.2, #Attr.3, #Attr.4): - let .14 = lowlevel ListLen #Attr.2; - let .12 = lowlevel NumLt #Attr.3 .14; - if .12 then - let .13 = lowlevel ListSet #Attr.2 #Attr.3 #Attr.4; - ret .13; + let Test.14 = lowlevel ListLen #Attr.2; + let Test.12 = lowlevel NumLt #Attr.3 Test.14; + if Test.12 then + let Test.13 = lowlevel ListSet #Attr.2 #Attr.3 #Attr.4; + ret Test.13; else ret #Attr.2; - procedure .0 (): - let .40 = 1i64; - let .41 = 2i64; - let .6 = Array [.40, .41]; - let .5 = CallByName .1 .6; - ret .5; + procedure Test.1 (Test.2): + let Test.39 = 0i64; + let Test.29 = CallByName List.3 Test.2 Test.39; + let Test.30 = 0i64; + let Test.28 = CallByName List.3 Test.2 Test.30; + let Test.7 = Struct {Test.28, Test.29}; + joinpoint Test.25: + let Test.18 = Array []; + ret Test.18; + in + let Test.22 = Index 1 Test.7; + let Test.23 = 1i64; + let Test.24 = Index 0 Test.22; + let Test.27 = lowlevel Eq Test.23 Test.24; + if Test.27 then + let Test.19 = Index 0 Test.7; + let Test.20 = 1i64; + let Test.21 = Index 0 Test.19; + let Test.26 = lowlevel Eq Test.20 Test.21; + if Test.26 then + let Test.17 = Index 0 Test.7; + let Test.3 = Index 1 Test.17; + let Test.16 = Index 1 Test.7; + let Test.4 = Index 1 Test.16; + let Test.15 = 0i64; + let Test.9 = CallByName List.4 Test.2 Test.15 Test.4; + let Test.10 = 0i64; + let Test.8 = CallByName List.4 Test.9 Test.10 Test.3; + ret Test.8; + else + dec Test.2; + jump Test.25; + else + dec Test.2; + jump Test.25; + + procedure Test.0 (): + let Test.40 = 1i64; + let Test.41 = 2i64; + let Test.6 = Array [Test.40, Test.41]; + let Test.5 = CallByName Test.1 Test.6; + ret Test.5; "# ), ) @@ -1496,33 +1496,33 @@ mod test_mono { "#, indoc!( r#" - procedure .1 (.2, .3): - joinpoint .7 .2 .3: - let .15 = 0i64; - let .16 = lowlevel Eq .15 .2; - if .16 then - ret .3; - else - let .13 = 1i64; - let .10 = CallByName Num.15 .2 .13; - let .11 = CallByName Num.16 .2 .3; - jump .7 .10 .11; - in - jump .7 .2 .3; - procedure Num.15 (#Attr.2, #Attr.3): - let .14 = lowlevel NumSub #Attr.2 #Attr.3; - ret .14; + let Test.14 = lowlevel NumSub #Attr.2 #Attr.3; + ret Test.14; procedure Num.16 (#Attr.2, #Attr.3): - let .12 = lowlevel NumMul #Attr.2 #Attr.3; - ret .12; + let Test.12 = lowlevel NumMul #Attr.2 #Attr.3; + ret Test.12; - procedure .0 (): - let .5 = 10i64; - let .6 = 1i64; - let .4 = CallByName .1 .5 .6; - ret .4; + procedure Test.1 (Test.2, Test.3): + joinpoint Test.7 Test.2 Test.3: + let Test.15 = 0i64; + let Test.16 = lowlevel Eq Test.15 Test.2; + if Test.16 then + ret Test.3; + else + let Test.13 = 1i64; + let Test.10 = CallByName Num.15 Test.2 Test.13; + let Test.11 = CallByName Num.16 Test.2 Test.3; + jump Test.7 Test.10 Test.11; + in + jump Test.7 Test.2 Test.3; + + procedure Test.0 (): + let Test.5 = 10i64; + let Test.6 = 1i64; + let Test.4 = CallByName Test.1 Test.5 Test.6; + ret Test.4; "# ), ) @@ -1545,26 +1545,26 @@ mod test_mono { "#, indoc!( r#" - procedure .1 (.3): - let .13 = true; - let .15 = Index 0 .3; - let .14 = 1i64; - let .16 = lowlevel Eq .14 .15; - let .12 = lowlevel And .16 .13; - if .12 then - let .10 = true; - ret .10; + procedure Test.1 (Test.3): + let Test.13 = true; + let Test.15 = Index 0 Test.3; + let Test.14 = 1i64; + let Test.16 = lowlevel Eq Test.14 Test.15; + let Test.12 = lowlevel And Test.16 Test.13; + if Test.12 then + let Test.10 = true; + ret Test.10; else - let .11 = false; - ret .11; + let Test.11 = false; + ret Test.11; - let .6 = 0i64; - let .7 = 2i64; - let .9 = 1i64; - let .8 = Nil .9; - let .5 = Cons .6 .7 .8; - let .4 = CallByName .1 .5; - ret .4; + let Test.6 = 0i64; + let Test.7 = 2i64; + let Test.9 = 1i64; + let Test.8 = Nil Test.9; + let Test.5 = Cons Test.6 Test.7 Test.8; + let Test.4 = CallByName Test.1 Test.5; + ret Test.4; "# ), ) @@ -1589,26 +1589,26 @@ mod test_mono { "#, indoc!( r#" - procedure .1 (.3): - let .13 = true; - let .15 = Index 0 .3; - let .14 = 1i64; - let .16 = lowlevel Eq .14 .15; - let .12 = lowlevel And .16 .13; - if .12 then - let .10 = true; - ret .10; + procedure Test.1 (Test.3): + let Test.13 = true; + let Test.15 = Index 0 Test.3; + let Test.14 = 1i64; + let Test.16 = lowlevel Eq Test.14 Test.15; + let Test.12 = lowlevel And Test.16 Test.13; + if Test.12 then + let Test.10 = true; + ret Test.10; else - let .11 = false; - ret .11; + let Test.11 = false; + ret Test.11; - let .6 = 0i64; - let .7 = 2i64; - let .9 = 1i64; - let .8 = Nil .9; - let .5 = Cons .6 .7 .8; - let .4 = CallByName .1 .5; - ret .4; + let Test.6 = 0i64; + let Test.7 = 2i64; + let Test.9 = 1i64; + let Test.8 = Nil Test.9; + let Test.5 = Cons Test.6 Test.7 Test.8; + let Test.4 = CallByName Test.1 Test.5; + ret Test.4; "# ), ) @@ -1629,18 +1629,18 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.2): - inc .2; - let .5 = Struct {.2, .2}; - ret .5; + procedure Test.1 (Test.2): + inc Test.2; + let Test.5 = Struct {Test.2, Test.2}; + ret Test.5; - procedure .0 (): - let .6 = 1i64; - let .7 = 2i64; - let .8 = 3i64; - let .4 = Array [.6, .7, .8]; - let .3 = CallByName .1 .4; - ret .3; + procedure Test.0 (): + let Test.6 = 1i64; + let Test.7 = 2i64; + let Test.8 = 3i64; + let Test.4 = Array [Test.6, Test.7, Test.8]; + let Test.3 = CallByName Test.1 Test.4; + ret Test.3; "# ), ) @@ -1661,23 +1661,23 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.2, .3): - inc .2; - ret .2; + procedure Test.1 (Test.2, Test.3): + inc Test.2; + ret Test.2; - procedure .0 (): - let .11 = 1i64; - let .12 = 2i64; - let .13 = 3i64; - let .5 = Array [.11, .12, .13]; - let .8 = 3i64; - let .9 = 2i64; - let .10 = 1i64; - let .6 = Array [.8, .9, .10]; - let .4 = CallByName .1 .5 .6; - dec .6; - dec .5; - ret .4; + procedure Test.0 (): + let Test.11 = 1i64; + let Test.12 = 2i64; + let Test.13 = 3i64; + let Test.5 = Array [Test.11, Test.12, Test.13]; + let Test.8 = 3i64; + let Test.9 = 2i64; + let Test.10 = 1i64; + let Test.6 = Array [Test.8, Test.9, Test.10]; + let Test.4 = CallByName Test.1 Test.5 Test.6; + dec Test.6; + dec Test.5; + ret Test.4; "# ), ) @@ -1702,46 +1702,46 @@ mod test_mono { ), indoc!( r#" - procedure .1 (): - let .11 = 1i64; - let .12 = 2i64; - let .13 = 3i64; - let .10 = Array [.11, .12, .13]; - ret .10; - - procedure .2 (.3): - let .17 = 0i64; - let .18 = 0i64; - let .16 = CallByName List.4 .3 .17 .18; - ret .16; - procedure List.4 (#Attr.2, #Attr.3, #Attr.4): - let .22 = lowlevel ListLen #Attr.2; - let .20 = lowlevel NumLt #Attr.3 .22; - if .20 then - let .21 = lowlevel ListSet #Attr.2 #Attr.3 #Attr.4; - ret .21; + let Test.22 = lowlevel ListLen #Attr.2; + let Test.20 = lowlevel NumLt #Attr.3 Test.22; + if Test.20 then + let Test.21 = lowlevel ListSet #Attr.2 #Attr.3 #Attr.4; + ret Test.21; else ret #Attr.2; procedure List.7 (#Attr.2): - let .9 = lowlevel ListLen #Attr.2; - ret .9; + let Test.9 = lowlevel ListLen #Attr.2; + ret Test.9; procedure Num.14 (#Attr.2, #Attr.3): - let .7 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .7; + let Test.7 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.7; - procedure .0 (): - let .15 = FunctionPointer .1; - let .14 = CallByName .2 .15; - let .5 = CallByName List.7 .14; - dec .14; - let .8 = FunctionPointer .1; - let .6 = CallByName List.7 .8; - dec .8; - let .4 = CallByName Num.14 .5 .6; - ret .4; + procedure Test.1 (): + let Test.11 = 1i64; + let Test.12 = 2i64; + let Test.13 = 3i64; + let Test.10 = Array [Test.11, Test.12, Test.13]; + ret Test.10; + + procedure Test.2 (Test.3): + let Test.17 = 0i64; + let Test.18 = 0i64; + let Test.16 = CallByName List.4 Test.3 Test.17 Test.18; + ret Test.16; + + procedure Test.0 (): + let Test.15 = FunctionPointer Test.1; + let Test.14 = CallByName Test.2 Test.15; + let Test.5 = CallByName List.7 Test.14; + dec Test.14; + let Test.8 = FunctionPointer Test.1; + let Test.6 = CallByName List.7 Test.8; + dec Test.8; + let Test.4 = CallByName Num.14 Test.5 Test.6; + ret Test.4; "# ), ) @@ -1760,34 +1760,34 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.2): - let .16 = 1i64; - let .17 = 2i64; - let .18 = 3i64; - let .6 = Array [.16, .17, .18]; - let .7 = 0i64; - let .5 = CallByName List.3 .6 .7; - dec .6; - ret .5; - procedure List.3 (#Attr.2, #Attr.3): - let .15 = lowlevel ListLen #Attr.2; - let .11 = lowlevel NumLt #Attr.3 .15; - if .11 then - let .13 = 1i64; - let .14 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; - let .12 = Ok .13 .14; - ret .12; + let Test.15 = lowlevel ListLen #Attr.2; + let Test.11 = lowlevel NumLt #Attr.3 Test.15; + if Test.11 then + let Test.14 = 1i64; + let Test.13 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; + let Test.12 = Ok Test.14 Test.13; + ret Test.12; else - let .9 = 0i64; - let .10 = Struct {}; - let .8 = Err .9 .10; - ret .8; + let Test.10 = 0i64; + let Test.9 = Struct {}; + let Test.8 = Err Test.10 Test.9; + ret Test.8; - procedure .0 (): - let .4 = Struct {}; - let .3 = CallByName .1 .4; - ret .3; + procedure Test.1 (Test.2): + let Test.16 = 1i64; + let Test.17 = 2i64; + let Test.18 = 3i64; + let Test.6 = Array [Test.16, Test.17, Test.18]; + let Test.7 = 0i64; + let Test.5 = CallByName List.3 Test.6 Test.7; + dec Test.6; + ret Test.5; + + procedure Test.0 (): + let Test.4 = Struct {}; + let Test.3 = CallByName Test.1 Test.4; + ret Test.3; "# ), ) @@ -1808,16 +1808,16 @@ mod test_mono { ), indoc!( r#" - procedure .0 (): - let .4 = 0i64; - let .6 = 0i64; - let .8 = 0i64; - let .10 = 1i64; - let .9 = Z .10; - let .7 = S .8 .9; - let .5 = S .6 .7; - let .2 = S .4 .5; - ret .2; + procedure Test.0 (): + let Test.5 = 0i64; + let Test.7 = 0i64; + let Test.9 = 0i64; + let Test.10 = 1i64; + let Test.8 = Z Test.10; + let Test.6 = S Test.9 Test.8; + let Test.4 = S Test.7 Test.6; + let Test.2 = S Test.5 Test.4; + ret Test.2; "# ), ) @@ -1840,25 +1840,25 @@ mod test_mono { ), indoc!( r#" - procedure .0 (): - let .8 = 0i64; - let .10 = 0i64; - let .12 = 0i64; - let .14 = 1i64; - let .13 = Z .14; - let .11 = S .12 .13; - let .9 = S .10 .11; - let .2 = S .8 .9; - let .5 = 1i64; - let .6 = Index 0 .2; - dec .2; - let .7 = lowlevel Eq .5 .6; - if .7 then - let .3 = 0i64; - ret .3; + procedure Test.0 (): + let Test.9 = 0i64; + let Test.11 = 0i64; + let Test.13 = 0i64; + let Test.14 = 1i64; + let Test.12 = Z Test.14; + let Test.10 = S Test.13 Test.12; + let Test.8 = S Test.11 Test.10; + let Test.2 = S Test.9 Test.8; + let Test.5 = 1i64; + let Test.6 = Index 0 Test.2; + dec Test.2; + let Test.7 = lowlevel Eq Test.5 Test.6; + if Test.7 then + let Test.3 = 0i64; + ret Test.3; else - let .4 = 1i64; - ret .4; + let Test.4 = 1i64; + ret Test.4; "# ), ) @@ -1882,38 +1882,38 @@ mod test_mono { ), indoc!( r#" - procedure .0 (): - let .14 = 0i64; - let .16 = 0i64; - let .18 = 0i64; - let .20 = 1i64; - let .19 = Z .20; - let .17 = S .18 .19; - let .15 = S .16 .17; - let .2 = S .14 .15; - let .11 = 0i64; - let .12 = Index 0 .2; - let .13 = lowlevel Eq .11 .12; - if .13 then - let .7 = Index 1 .2; - inc .7; - let .8 = 0i64; - let .9 = Index 0 .7; - dec .7; - let .10 = lowlevel Eq .8 .9; - if .10 then - let .4 = Index 1 .2; - dec .2; - let .3 = 1i64; - ret .3; + procedure Test.0 (): + let Test.15 = 0i64; + let Test.17 = 0i64; + let Test.19 = 0i64; + let Test.20 = 1i64; + let Test.18 = Z Test.20; + let Test.16 = S Test.19 Test.18; + let Test.14 = S Test.17 Test.16; + let Test.2 = S Test.15 Test.14; + let Test.11 = 0i64; + let Test.12 = Index 0 Test.2; + let Test.13 = lowlevel Eq Test.11 Test.12; + if Test.13 then + let Test.7 = Index 1 Test.2; + inc Test.7; + let Test.8 = 0i64; + let Test.9 = Index 0 Test.7; + dec Test.7; + let Test.10 = lowlevel Eq Test.8 Test.9; + if Test.10 then + let Test.4 = Index 1 Test.2; + dec Test.2; + let Test.3 = 1i64; + ret Test.3; else - dec .2; - let .5 = 0i64; - ret .5; + dec Test.2; + let Test.5 = 0i64; + ret Test.5; else - dec .2; - let .6 = 0i64; - ret .6; + dec Test.2; + let Test.6 = 0i64; + ret Test.6; "# ), ) @@ -1939,51 +1939,51 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.6): - let .18 = Index 0 .6; - let .19 = false; - let .20 = lowlevel Eq .19 .18; - if .20 then - let .8 = Index 1 .6; - ret .8; - else - let .10 = Index 1 .6; - ret .10; - - procedure .1 (.6): - let .29 = Index 0 .6; - let .30 = false; - let .31 = lowlevel Eq .30 .29; - if .31 then - let .8 = 3i64; - ret .8; - else - let .10 = 5i64; - ret .10; - procedure Num.16 (#Attr.2, #Attr.3): - let .13 = lowlevel NumMul #Attr.2 #Attr.3; - ret .13; + let Test.13 = lowlevel NumMul #Attr.2 #Attr.3; + ret Test.13; - procedure .0 (): - let .34 = true; - let .33 = Struct {.34}; - let .5 = CallByName .1 .33; - let .32 = false; - let .26 = Struct {.32}; - let .3 = CallByName .1 .26; - let .24 = true; - let .25 = 11i64; - let .23 = Struct {.24, .25}; - let .4 = CallByName .1 .23; - let .21 = false; - let .22 = 7i64; - let .15 = Struct {.21, .22}; - let .2 = CallByName .1 .15; - let .14 = CallByName Num.16 .2 .3; - let .12 = CallByName Num.16 .14 .4; - let .11 = CallByName Num.16 .12 .5; - ret .11; + procedure Test.1 (Test.6): + let Test.18 = Index 1 Test.6; + let Test.19 = false; + let Test.20 = lowlevel Eq Test.19 Test.18; + if Test.20 then + let Test.8 = Index 0 Test.6; + ret Test.8; + else + let Test.10 = Index 0 Test.6; + ret Test.10; + + procedure Test.1 (Test.6): + let Test.29 = Index 0 Test.6; + let Test.30 = false; + let Test.31 = lowlevel Eq Test.30 Test.29; + if Test.31 then + let Test.8 = 3i64; + ret Test.8; + else + let Test.10 = 5i64; + ret Test.10; + + procedure Test.0 (): + let Test.34 = true; + let Test.33 = Struct {Test.34}; + let Test.5 = CallByName Test.1 Test.33; + let Test.32 = false; + let Test.26 = Struct {Test.32}; + let Test.3 = CallByName Test.1 Test.26; + let Test.24 = 11i64; + let Test.25 = true; + let Test.23 = Struct {Test.24, Test.25}; + let Test.4 = CallByName Test.1 Test.23; + let Test.21 = 7i64; + let Test.22 = false; + let Test.15 = Struct {Test.21, Test.22}; + let Test.2 = CallByName Test.1 Test.15; + let Test.14 = CallByName Num.16 Test.2 Test.3; + let Test.12 = CallByName Num.16 Test.14 Test.4; + let Test.11 = CallByName Num.16 Test.12 Test.5; + ret Test.11; "# ), ) @@ -2007,37 +2007,37 @@ mod test_mono { indoc!( r#" procedure Num.14 (#Attr.2, #Attr.3): - let .6 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .6; + let Test.6 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.6; - procedure .0 (): - let .17 = 0i64; - let .19 = 0i64; - let .20 = 41i64; - let .18 = Just .19 .20; - let .2 = Just .17 .18; - joinpoint .14: - let .8 = 1i64; - ret .8; + procedure Test.0 (): + let Test.18 = 0i64; + let Test.20 = 0i64; + let Test.19 = 41i64; + let Test.17 = Just Test.20 Test.19; + let Test.2 = Just Test.18 Test.17; + joinpoint Test.14: + let Test.8 = 1i64; + ret Test.8; in - let .12 = 0i64; - let .13 = Index 0 .2; - let .16 = lowlevel Eq .12 .13; - if .16 then - let .9 = Index 1 .2; - let .10 = 0i64; - let .11 = Index 0 .9; - let .15 = lowlevel Eq .10 .11; - if .15 then - let .7 = Index 1 .2; - let .3 = Index 1 .7; - let .5 = 1i64; - let .4 = CallByName Num.14 .3 .5; - ret .4; + let Test.12 = 0i64; + let Test.13 = Index 0 Test.2; + let Test.16 = lowlevel Eq Test.12 Test.13; + if Test.16 then + let Test.9 = Index 1 Test.2; + let Test.10 = 0i64; + let Test.11 = Index 0 Test.9; + let Test.15 = lowlevel Eq Test.10 Test.11; + if Test.15 then + let Test.7 = Index 1 Test.2; + let Test.3 = Index 1 Test.7; + let Test.5 = 1i64; + let Test.4 = CallByName Num.14 Test.3 Test.5; + ret Test.4; else - jump .14; + jump Test.14; else - jump .14; + jump Test.14; "# ), ) @@ -2066,34 +2066,34 @@ mod test_mono { indoc!( r#" procedure Num.14 (#Attr.2, #Attr.3): - let .9 = lowlevel NumAdd #Attr.2 #Attr.3; - ret .9; + let Test.9 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Test.9; - procedure .3 (.4): - let .15 = true; - let .16 = 1i64; - let .17 = Index 0 .4; - let .18 = lowlevel Eq .16 .17; - let .14 = lowlevel And .18 .15; - if .14 then - dec .4; - let .10 = 0i64; - ret .10; + procedure Test.3 (Test.4): + let Test.15 = true; + let Test.16 = 1i64; + let Test.17 = Index 0 Test.4; + let Test.18 = lowlevel Eq Test.16 Test.17; + let Test.14 = lowlevel And Test.18 Test.15; + if Test.14 then + dec Test.4; + let Test.10 = 0i64; + ret Test.10; else - let .5 = Index 2 .4; - dec .4; - let .12 = 1i64; - let .13 = CallByName .3 .5; - let .11 = CallByName Num.14 .12 .13; - ret .11; + let Test.5 = Index 2 Test.4; + dec Test.4; + let Test.12 = 1i64; + let Test.13 = CallByName Test.3 Test.5; + let Test.11 = CallByName Num.14 Test.12 Test.13; + ret Test.11; - procedure .0 (): - let .20 = 1i64; - let .2 = Nil .20; - let .7 = CallByName .3 .2; - let .8 = CallByName .3 .2; - let .6 = CallByName Num.14 .7 .8; - ret .6; + procedure Test.0 (): + let Test.20 = 1i64; + let Test.2 = Nil Test.20; + let Test.7 = CallByName Test.3 Test.2; + let Test.8 = CallByName Test.3 Test.2; + let Test.6 = CallByName Num.14 Test.7 Test.8; + ret Test.6; "# ), ) @@ -2125,68 +2125,68 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.2, .3, .4): - let .31 = CallByName List.3 .4 .2; - let .32 = CallByName List.3 .4 .3; - let .12 = Struct {.31, .32}; - joinpoint .28: - let .21 = Array []; - ret .21; - in - let .25 = Index 1 .12; - let .26 = 1i64; - let .27 = Index 0 .25; - let .30 = lowlevel Eq .26 .27; - if .30 then - let .22 = Index 0 .12; - let .23 = 1i64; - let .24 = Index 0 .22; - let .29 = lowlevel Eq .23 .24; - if .29 then - let .20 = Index 0 .12; - let .5 = Index 1 .20; - let .19 = Index 1 .12; - let .6 = Index 1 .19; - let .14 = CallByName List.4 .4 .2 .6; - let .13 = CallByName List.4 .14 .3 .5; - ret .13; - else - dec .4; - jump .28; - else - dec .4; - jump .28; - procedure List.3 (#Attr.2, #Attr.3): - let .40 = lowlevel ListLen #Attr.2; - let .36 = lowlevel NumLt #Attr.3 .40; - if .36 then - let .38 = 1i64; - let .39 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; - let .37 = Ok .38 .39; - ret .37; + let Test.40 = lowlevel ListLen #Attr.2; + let Test.36 = lowlevel NumLt #Attr.3 Test.40; + if Test.36 then + let Test.39 = 1i64; + let Test.38 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; + let Test.37 = Ok Test.39 Test.38; + ret Test.37; else - let .34 = 0i64; - let .35 = Struct {}; - let .33 = Err .34 .35; - ret .33; + let Test.35 = 0i64; + let Test.34 = Struct {}; + let Test.33 = Err Test.35 Test.34; + ret Test.33; procedure List.4 (#Attr.2, #Attr.3, #Attr.4): - let .18 = lowlevel ListLen #Attr.2; - let .16 = lowlevel NumLt #Attr.3 .18; - if .16 then - let .17 = lowlevel ListSet #Attr.2 #Attr.3 #Attr.4; - ret .17; + let Test.18 = lowlevel ListLen #Attr.2; + let Test.16 = lowlevel NumLt #Attr.3 Test.18; + if Test.16 then + let Test.17 = lowlevel ListSet #Attr.2 #Attr.3 #Attr.4; + ret Test.17; else ret #Attr.2; - procedure .0 (): - let .9 = 0i64; - let .10 = 0i64; - let .41 = 1i64; - let .11 = Array [.41]; - let .8 = CallByName .1 .9 .10 .11; - ret .8; + procedure Test.1 (Test.2, Test.3, Test.4): + let Test.32 = CallByName List.3 Test.4 Test.3; + let Test.31 = CallByName List.3 Test.4 Test.2; + let Test.12 = Struct {Test.31, Test.32}; + joinpoint Test.28: + let Test.21 = Array []; + ret Test.21; + in + let Test.25 = Index 1 Test.12; + let Test.26 = 1i64; + let Test.27 = Index 0 Test.25; + let Test.30 = lowlevel Eq Test.26 Test.27; + if Test.30 then + let Test.22 = Index 0 Test.12; + let Test.23 = 1i64; + let Test.24 = Index 0 Test.22; + let Test.29 = lowlevel Eq Test.23 Test.24; + if Test.29 then + let Test.20 = Index 0 Test.12; + let Test.5 = Index 1 Test.20; + let Test.19 = Index 1 Test.12; + let Test.6 = Index 1 Test.19; + let Test.14 = CallByName List.4 Test.4 Test.2 Test.6; + let Test.13 = CallByName List.4 Test.14 Test.3 Test.5; + ret Test.13; + else + dec Test.4; + jump Test.28; + else + dec Test.4; + jump Test.28; + + procedure Test.0 (): + let Test.9 = 0i64; + let Test.10 = 0i64; + let Test.41 = 1i64; + let Test.11 = Array [Test.41]; + let Test.8 = CallByName Test.1 Test.9 Test.10 Test.11; + ret Test.8; "# ), ) @@ -2211,11 +2211,11 @@ mod test_mono { ), indoc!( r#" - procedure .0 (): - let .1 = 5i64; - let .4 = 17i64; - let .2 = 1337i64; - ret .2; + procedure Test.0 (): + let Test.1 = 5i64; + let Test.4 = 17i64; + let Test.2 = 1337i64; + ret Test.2; "# ), ) @@ -2243,14 +2243,14 @@ mod test_mono { ), indoc!( r#" - procedure .0 (): - let .1 = 5i64; - let .4 = 17i64; - let .5 = 1i64; - let .2 = 1337i64; - let .7 = Struct {.2, .4}; - let .6 = Index 0 .7; - ret .6; + procedure Test.0 (): + let Test.1 = 5i64; + let Test.4 = 17i64; + let Test.5 = 1i64; + let Test.2 = 1337i64; + let Test.7 = Struct {Test.2, Test.4}; + let Test.6 = Index 0 Test.7; + ret Test.6; "# ), ) @@ -2275,24 +2275,24 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.5): - let .2 = 42i64; - let .13 = FunctionPointer .3; - let .3 = Struct {.13, .2}; - ret .3; + procedure Test.1 (Test.5): + let Test.2 = 42i64; + let Test.13 = FunctionPointer Test.3; + let Test.3 = Struct {Test.13, Test.2}; + ret Test.3; - procedure .3 (.11, #Attr.12): - let .2 = Index 0 #Attr.12; - ret .2; + procedure Test.3 (Test.11, #Attr.12): + let Test.2 = Index 0 #Attr.12; + ret Test.2; - procedure .0 (): - let .10 = Struct {}; - let .4 = CallByName .1 .10; - let .7 = Struct {}; - let .8 = Index 1 .4; - let .9 = Index 0 .4; - let .6 = CallByPointer .9 .7 .8; - ret .6; + procedure Test.0 (): + let Test.10 = Struct {}; + let Test.4 = CallByName Test.1 Test.10; + let Test.7 = Struct {}; + let Test.8 = Index 1 Test.4; + let Test.9 = Index 0 Test.4; + let Test.6 = CallByPointer Test.9 Test.7 Test.8; + ret Test.6; "# ), ) @@ -2320,27 +2320,27 @@ mod test_mono { ), indoc!( r#" - procedure .1 (.5): - let .2 = 41i64; - let .12 = FunctionPointer .3; - let .11 = Struct {.12, .2}; - let .10 = Array [.11]; - ret .10; - - procedure .3 (.9, #Attr.12): - let .2 = Index 0 #Attr.12; - ret .2; - procedure List.7 (#Attr.2): - let .7 = lowlevel ListLen #Attr.2; - ret .7; + let Test.7 = lowlevel ListLen #Attr.2; + ret Test.7; - procedure .0 (): - let .8 = Struct {}; - let .4 = CallByName .1 .8; - let .6 = CallByName List.7 .4; - dec .4; - ret .6; + procedure Test.1 (Test.5): + let Test.2 = 41i64; + let Test.12 = FunctionPointer Test.3; + let Test.11 = Struct {Test.12, Test.2}; + let Test.10 = Array [Test.11]; + ret Test.10; + + procedure Test.3 (Test.9, #Attr.12): + let Test.2 = Index 0 #Attr.12; + ret Test.2; + + procedure Test.0 (): + let Test.8 = Struct {}; + let Test.4 = CallByName Test.1 Test.8; + let Test.6 = CallByName List.7 Test.4; + dec Test.4; + ret Test.6; "# ), ) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 96b3223265..b4b1fc2085 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -2928,11 +2928,11 @@ mod solve_expr { } #[test] - fn list_walk_right() { + fn list_walk_backwards() { infer_eq_without_problem( indoc!( r#" - List.walkRight + List.walkBackwards "# ), "List a, (a, b -> b), b -> b", @@ -2940,7 +2940,7 @@ mod solve_expr { } #[test] - fn list_walk_right_example() { + fn list_walk_backwards_example() { infer_eq_without_problem( indoc!( r#" @@ -2948,7 +2948,7 @@ mod solve_expr { empty = [] - List.walkRight empty (\a, b -> a + b) 0 + List.walkBackwards empty (\a, b -> a + b) 0 "# ), "Int", diff --git a/compiler/solve/tests/solve_uniq_expr.rs b/compiler/solve/tests/solve_uniq_expr.rs index 73613ae3d3..b2f107040a 100644 --- a/compiler/solve/tests/solve_uniq_expr.rs +++ b/compiler/solve/tests/solve_uniq_expr.rs @@ -2236,11 +2236,11 @@ mod solve_uniq_expr { } #[test] - fn list_walk_right_sum() { + fn list_walk_backwards_sum() { infer_eq( indoc!( r#" - sum = \list -> List.walkRight list Num.add 0 + sum = \list -> List.walkBackwards list Num.add 0 sum "# @@ -2321,11 +2321,11 @@ mod solve_uniq_expr { } #[test] - fn list_walk_right_reverse() { + fn list_walk_backwards_reverse() { infer_eq( indoc!( r#" - reverse = \list -> List.walkRight list (\e, l -> List.append l e) [] + reverse = \list -> List.walkBackwards list (\e, l -> List.append l e) [] reverse "# @@ -3133,11 +3133,11 @@ mod solve_uniq_expr { } #[test] - fn list_walk_right() { + fn list_walk_backwards() { infer_eq( indoc!( r#" - List.walkRight + List.walkBackwards "# ), "Attr * (Attr (* | b) (List (Attr b a)), Attr Shared (Attr b a, c -> c), c -> c)", @@ -3145,7 +3145,7 @@ mod solve_uniq_expr { } #[test] - fn list_walk_right_example() { + fn list_walk_backwards_example() { infer_eq( indoc!( r#" @@ -3153,7 +3153,7 @@ mod solve_uniq_expr { empty = [] - List.walkRight empty (\a, b -> a + b) 0 + List.walkBackwards empty (\a, b -> a + b) 0 "# ), "Attr a Int",