diff --git a/crates/compiler/alias_analysis/src/lib.rs b/crates/compiler/alias_analysis/src/lib.rs index bdc115f236e..452a90567a3 100644 --- a/crates/compiler/alias_analysis/src/lib.rs +++ b/crates/compiler/alias_analysis/src/lib.rs @@ -1436,15 +1436,15 @@ fn expr_spec<'a>( builder.add_get_tuple_field(block, variant_id, index) } }, - UnionFieldPtrAtIndex { - index, + GetElementPointer { + indices, structure, union_layout, .. } => { - debug_assert!(index.len() >= 2); - let tag_id = index[0] as u32; - let index = index[1]; + debug_assert!(indices.len() >= 2); + let tag_id = indices[0] as u32; + let index = indices[1]; let tag_value_id = env.symbols[structure]; let type_name_bytes = recursive_tag_union_name_bytes(union_layout).as_bytes(); diff --git a/crates/compiler/gen_dev/src/lib.rs b/crates/compiler/gen_dev/src/lib.rs index 6458b328d0e..e80cbc33fb8 100644 --- a/crates/compiler/gen_dev/src/lib.rs +++ b/crates/compiler/gen_dev/src/lib.rs @@ -182,7 +182,7 @@ impl<'a> LastSeenMap<'a> { Expr::UnionAtIndex { structure, .. } => { self.set_last_seen(*structure, stmt); } - Expr::UnionFieldPtrAtIndex { structure, .. } => { + Expr::GetElementPointer { structure, .. } => { self.set_last_seen(*structure, stmt); } Expr::Array { elems, .. } => { @@ -849,14 +849,14 @@ trait Backend<'a> { } => { self.load_union_at_index(sym, structure, *tag_id, *index, union_layout); } - Expr::UnionFieldPtrAtIndex { + Expr::GetElementPointer { structure, union_layout, - index, + indices, .. } => { - debug_assert!(index.len() >= 2); - self.load_union_field_ptr_at_index(sym, structure, index[0] as u16, index[1], union_layout); + debug_assert!(indices.len() >= 2); + self.load_union_field_ptr_at_index(sym, structure, indices[0] as u16, indices[1], union_layout); } Expr::GetTagId { structure, diff --git a/crates/compiler/gen_llvm/src/llvm/build.rs b/crates/compiler/gen_llvm/src/llvm/build.rs index b91b4c15229..903fde78f23 100644 --- a/crates/compiler/gen_llvm/src/llvm/build.rs +++ b/crates/compiler/gen_llvm/src/llvm/build.rs @@ -2003,15 +2003,15 @@ pub(crate) fn build_exp_expr<'a, 'ctx>( } } - UnionFieldPtrAtIndex { + GetElementPointer { structure, - index, + indices, union_layout, .. } => { - debug_assert!(index.len() >= 2); - let tag_id = index[0]; - let index = index[1] as usize; + debug_assert!(indices.len() >= 2); + let tag_id = indices[0]; + let index = indices[1] as usize; // cast the argument bytes into the desired shape for this tag let argument = scope.load_symbol(structure); let ret_repr = layout_interner.get_repr(layout); diff --git a/crates/compiler/gen_wasm/src/backend.rs b/crates/compiler/gen_wasm/src/backend.rs index 28090919df0..329fb106b99 100644 --- a/crates/compiler/gen_wasm/src/backend.rs +++ b/crates/compiler/gen_wasm/src/backend.rs @@ -1099,18 +1099,18 @@ impl<'a, 'r> WasmBackend<'a, 'r> { index, } => self.expr_union_at_index(*structure, *tag_id, union_layout, *index, sym), - Expr::UnionFieldPtrAtIndex { + Expr::GetElementPointer { structure, union_layout, - index, + indices, .. } => { - debug_assert!(index.len() >= 2); + debug_assert!(indices.len() >= 2); self.expr_union_field_ptr_at_index( *structure, - index[0] as u16, + indices[0] as u16, union_layout, - index[1], + indices[1], storage, ) } diff --git a/crates/compiler/mono/src/debug/checker.rs b/crates/compiler/mono/src/debug/checker.rs index e927dea50ff..b33bdaa8c8d 100644 --- a/crates/compiler/mono/src/debug/checker.rs +++ b/crates/compiler/mono/src/debug/checker.rs @@ -452,15 +452,15 @@ impl<'a, 'r> Ctx<'a, 'r> { } => self.with_sym_layout(structure, |ctx, _def_line, layout| { ctx.check_union_at_index(structure, layout, union_layout, tag_id, index) }), - &Expr::UnionFieldPtrAtIndex { + &Expr::GetElementPointer { structure, union_layout, - index, + indices, .. } => self.with_sym_layout(structure, |ctx, _def_line, layout| { - debug_assert!(index.len() >= 2); + debug_assert!(indices.len() >= 2); - ctx.check_union_field_ptr_at_index(structure, layout, union_layout, index[0] as _, index[1]) + ctx.check_union_field_ptr_at_index(structure, layout, union_layout, indices[0] as _, indices[1]) }), Expr::Array { elem_layout, elems } => { for elem in elems.iter() { diff --git a/crates/compiler/mono/src/drop_specialization.rs b/crates/compiler/mono/src/drop_specialization.rs index c2437149b2b..1317aa53bf8 100644 --- a/crates/compiler/mono/src/drop_specialization.rs +++ b/crates/compiler/mono/src/drop_specialization.rs @@ -205,12 +205,12 @@ fn specialize_drops_stmt<'a, 'i>( // So if we UnionAtIndex, we must know the tag and we can use it to specialize the drop. environment.symbol_tag.insert(*structure, *tag_id); } - UnionFieldPtrAtIndex { - structure, index, .. + GetElementPointer { + structure, indices, .. } => { // Generated code might know the tag of the union without switching on it. - // So if we UnionFieldPtrAtIndex, we must know the tag and we can use it to specialize the drop. - environment.symbol_tag.insert(*structure, index[0] as u16); + // So if we GetElementPointer, we must know the tag and we can use it to specialize the drop. + environment.symbol_tag.insert(*structure, indices[0] as u16); } Array { elems: children, .. diff --git a/crates/compiler/mono/src/inc_dec.rs b/crates/compiler/mono/src/inc_dec.rs index 64a1c9a4291..96c529bbb1b 100644 --- a/crates/compiler/mono/src/inc_dec.rs +++ b/crates/compiler/mono/src/inc_dec.rs @@ -925,7 +925,7 @@ fn insert_refcount_operations_binding<'a>( Expr::GetTagId { structure, .. } | Expr::StructAtIndex { structure, .. } | Expr::UnionAtIndex { structure, .. } - | Expr::UnionFieldPtrAtIndex { structure, .. } => { + | Expr::GetElementPointer { structure, .. } => { // All structures are alive at this point and don't have to be copied in order to take an index out/get tag id/copy values to the stack. // But we do want to make sure to decrement this item if it is the last reference. let new_stmt = dec_borrowed!([*structure], stmt); @@ -938,7 +938,7 @@ fn insert_refcount_operations_binding<'a>( match expr { Expr::StructAtIndex { .. } | Expr::UnionAtIndex { .. } - | Expr::UnionFieldPtrAtIndex { .. } => { + | Expr::GetElementPointer { .. } => { insert_inc_stmt(arena, *binding, 1, new_stmt) } // No usage of an element of a reference counted symbol. No need to increment. diff --git a/crates/compiler/mono/src/ir.rs b/crates/compiler/mono/src/ir.rs index aac76efe082..40faaebe9cb 100644 --- a/crates/compiler/mono/src/ir.rs +++ b/crates/compiler/mono/src/ir.rs @@ -1892,10 +1892,10 @@ pub enum Expr<'a> { union_layout: UnionLayout<'a>, index: u64, }, - UnionFieldPtrAtIndex { + GetElementPointer { structure: Symbol, union_layout: UnionLayout<'a>, - index: &'a [u64], + indices: &'a [u64], }, Array { @@ -2152,12 +2152,12 @@ impl<'a> Expr<'a> { } => text!(alloc, "UnionAtIndex (Id {tag_id}) (Index {index}) ") .append(symbol_to_doc(alloc, *structure, pretty)), - UnionFieldPtrAtIndex { + GetElementPointer { structure, - index, + indices, .. } => { - let it = index.iter().map(|num| alloc.as_string(num)); + let it = indices.iter().map(|num| alloc.as_string(num)); let it = alloc.intersperse(it, ", "); text!( alloc, @@ -7947,14 +7947,14 @@ fn substitute_in_expr<'a>( }, // currently only used for tail recursion modulo cons (TRMC) - UnionFieldPtrAtIndex { + GetElementPointer { structure, - index, + indices, union_layout, } => match substitute(subs, *structure) { - Some(structure) => Some(UnionFieldPtrAtIndex { + Some(structure) => Some(GetElementPointer { structure, - index, + indices, union_layout: *union_layout, }), None => None, diff --git a/crates/compiler/mono/src/tail_recursion.rs b/crates/compiler/mono/src/tail_recursion.rs index cbed5d27a23..1b63d1f809e 100644 --- a/crates/compiler/mono/src/tail_recursion.rs +++ b/crates/compiler/mono/src/tail_recursion.rs @@ -907,13 +907,13 @@ impl<'a> TrmcEnv<'a> { reuse: None, }; - let index = vec![in env.arena; cons_info.tag_id as u64, recursive_field_index as u64].into_bump_slice(); + let indices = vec![in env.arena; cons_info.tag_id as u64, recursive_field_index as u64].into_bump_slice(); let let_tag = |next| Stmt::Let(*symbol, tag_expr, *layout, next); - let get_reference_expr = Expr::UnionFieldPtrAtIndex { + let get_reference_expr = Expr::GetElementPointer { structure: *symbol, union_layout: cons_info.tag_layout, - index, + indices, }; let new_hole_symbol = env.named_unique_symbol("newHole"); @@ -1091,7 +1091,7 @@ fn expr_contains_symbol(expr: &Expr, needle: Symbol) -> bool { Expr::StructAtIndex { structure, .. } | Expr::GetTagId { structure, .. } | Expr::UnionAtIndex { structure, .. } - | Expr::UnionFieldPtrAtIndex { structure, .. } => needle == *structure, + | Expr::GetElementPointer { structure, .. } => needle == *structure, Expr::Array { elems, .. } => elems.iter().any(|element| match element { crate::ir::ListLiteralElement::Literal(_) => false, crate::ir::ListLiteralElement::Symbol(symbol) => needle == *symbol, diff --git a/crates/compiler/test_mono/generated/linked_list_filter.txt b/crates/compiler/test_mono/generated/linked_list_filter.txt index 8c2fe7be778..2daa0e1a299 100644 --- a/crates/compiler/test_mono/generated/linked_list_filter.txt +++ b/crates/compiler/test_mono/generated/linked_list_filter.txt @@ -27,7 +27,7 @@ procedure Test.2 (#Derived_gen.0, #Derived_gen.1): if Test.19 then let #Derived_gen.9 : [, C I64 *self] = NullPointer; let Test.20 : [, C I64 *self] = Reuse #Derived_gen.14 UpdateModeId { id: 1 } TagId(0) Test.7 #Derived_gen.9; - let #Derived_gen.10 : Ptr([, C I64 *self]) = UnionFieldPtrAtIndex (Id 0) (Index 1) Test.20; + let #Derived_gen.10 : Ptr([, C I64 *self]) = GetElementPointer (Indices [0, 1]) Test.20; let #Derived_gen.11 : {} = lowlevel PtrStore #Derived_gen.5 Test.20; jump #Derived_gen.4 Test.8 Test.5 #Derived_gen.10 #Derived_gen.6; else diff --git a/crates/compiler/test_mono/generated/linked_list_map.txt b/crates/compiler/test_mono/generated/linked_list_map.txt index 1da88ff4488..c77b3e477fa 100644 --- a/crates/compiler/test_mono/generated/linked_list_map.txt +++ b/crates/compiler/test_mono/generated/linked_list_map.txt @@ -26,7 +26,7 @@ procedure Test.2 (#Derived_gen.0, #Derived_gen.1): let Test.20 : I64 = CallByName Test.10 Test.7; let #Derived_gen.9 : [, C I64 *self] = NullPointer; let Test.19 : [, C I64 *self] = Reuse #Derived_gen.14 UpdateModeId { id: 1 } TagId(0) Test.20 #Derived_gen.9; - let #Derived_gen.10 : Ptr([, C I64 *self]) = UnionFieldPtrAtIndex (Id 0) (Index 1) Test.19; + let #Derived_gen.10 : Ptr([, C I64 *self]) = GetElementPointer (Indices [0, 1]) Test.19; let #Derived_gen.11 : {} = lowlevel PtrStore #Derived_gen.5 Test.19; jump #Derived_gen.4 Test.4 Test.8 #Derived_gen.10 #Derived_gen.6; in diff --git a/crates/compiler/test_mono/generated/rb_tree_fbip.txt b/crates/compiler/test_mono/generated/rb_tree_fbip.txt index 335d49d6992..bcd691966f2 100644 --- a/crates/compiler/test_mono/generated/rb_tree_fbip.txt +++ b/crates/compiler/test_mono/generated/rb_tree_fbip.txt @@ -37,7 +37,7 @@ procedure Test.3 (#Derived_gen.0, #Derived_gen.1, #Derived_gen.2): let Test.232 : Int1 = false; let #Derived_gen.10 : [C *self I64 *self I32 Int1, ] = NullPointer; let Test.231 : [C *self I64 *self I32 Int1, ] = Reuse #Derived_gen.166 UpdateModeId { id: 56 } TagId(1) #Derived_gen.10 Test.18 Test.19 Test.17 Test.232; - let #Derived_gen.11 : Ptr([C *self I64 *self I32 Int1, ]) = UnionFieldPtrAtIndex (Id 1) (Index 0) Test.231; + let #Derived_gen.11 : Ptr([C *self I64 *self I32 Int1, ]) = GetElementPointer (Indices [1, 0]) Test.231; let #Derived_gen.12 : {} = lowlevel PtrStore #Derived_gen.6 Test.231; jump #Derived_gen.5 Test.16 Test.10 Test.11 #Derived_gen.11 #Derived_gen.7; in @@ -206,7 +206,7 @@ procedure Test.3 (#Derived_gen.0, #Derived_gen.1, #Derived_gen.2): let Test.170 : Int1 = false; let #Derived_gen.21 : [C *self I64 *self I32 Int1, ] = NullPointer; let Test.169 : [C *self I64 *self I32 Int1, ] = Reuse #Derived_gen.288 UpdateModeId { id: 196 } TagId(1) Test.16 Test.18 #Derived_gen.21 Test.17 Test.170; - let #Derived_gen.22 : Ptr([C *self I64 *self I32 Int1, ]) = UnionFieldPtrAtIndex (Id 1) (Index 2) Test.169; + let #Derived_gen.22 : Ptr([C *self I64 *self I32 Int1, ]) = GetElementPointer (Indices [1, 2]) Test.169; let #Derived_gen.23 : {} = lowlevel PtrStore #Derived_gen.6 Test.169; jump #Derived_gen.5 Test.19 Test.10 Test.11 #Derived_gen.22 #Derived_gen.7; in @@ -412,7 +412,7 @@ procedure Test.3 (#Derived_gen.0, #Derived_gen.1, #Derived_gen.2): let Test.249 : Int1 = true; let #Derived_gen.34 : [C *self I64 *self I32 Int1, ] = NullPointer; let Test.248 : [C *self I64 *self I32 Int1, ] = Reuse #Derived_gen.364 UpdateModeId { id: 284 } TagId(1) #Derived_gen.34 Test.98 Test.99 Test.97 Test.249; - let #Derived_gen.35 : Ptr([C *self I64 *self I32 Int1, ]) = UnionFieldPtrAtIndex (Id 1) (Index 0) Test.248; + let #Derived_gen.35 : Ptr([C *self I64 *self I32 Int1, ]) = GetElementPointer (Indices [1, 0]) Test.248; let #Derived_gen.36 : {} = lowlevel PtrStore #Derived_gen.6 Test.248; jump #Derived_gen.5 Test.96 Test.10 Test.11 #Derived_gen.35 #Derived_gen.7; else @@ -421,7 +421,7 @@ procedure Test.3 (#Derived_gen.0, #Derived_gen.1, #Derived_gen.2): let Test.245 : Int1 = true; let #Derived_gen.37 : [C *self I64 *self I32 Int1, ] = NullPointer; let Test.244 : [C *self I64 *self I32 Int1, ] = Reuse #Derived_gen.364 UpdateModeId { id: 284 } TagId(1) Test.96 Test.98 #Derived_gen.37 Test.97 Test.245; - let #Derived_gen.38 : Ptr([C *self I64 *self I32 Int1, ]) = UnionFieldPtrAtIndex (Id 1) (Index 2) Test.244; + let #Derived_gen.38 : Ptr([C *self I64 *self I32 Int1, ]) = GetElementPointer (Indices [1, 2]) Test.244; let #Derived_gen.39 : {} = lowlevel PtrStore #Derived_gen.6 Test.244; jump #Derived_gen.5 Test.99 Test.10 Test.11 #Derived_gen.38 #Derived_gen.7; else