mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
remove tag_id in favor of index
This commit is contained in:
parent
347431d1df
commit
90223022af
8 changed files with 32 additions and 33 deletions
|
@ -1438,12 +1438,13 @@ fn expr_spec<'a>(
|
|||
},
|
||||
UnionFieldPtrAtIndex {
|
||||
index,
|
||||
tag_id,
|
||||
structure,
|
||||
union_layout,
|
||||
..
|
||||
} => {
|
||||
debug_assert_ne!(index.len(), 0);
|
||||
let index = index[0];
|
||||
debug_assert!(index.len() >= 2);
|
||||
let tag_id = index[0] as u32;
|
||||
let index = index[1];
|
||||
let tag_value_id = env.symbols[structure];
|
||||
|
||||
let type_name_bytes = recursive_tag_union_name_bytes(union_layout).as_bytes();
|
||||
|
@ -1460,7 +1461,7 @@ fn expr_spec<'a>(
|
|||
builder.add_touch(block, heap_cell)?;
|
||||
|
||||
// next, unwrap the union at the tag id that we've got
|
||||
let variant_id = builder.add_unwrap_union(block, union_data, *tag_id as u32)?;
|
||||
let variant_id = builder.add_unwrap_union(block, union_data, tag_id)?;
|
||||
|
||||
let value = builder.add_get_tuple_field(block, variant_id, index as u32)?;
|
||||
|
||||
|
|
|
@ -851,12 +851,12 @@ trait Backend<'a> {
|
|||
}
|
||||
Expr::UnionFieldPtrAtIndex {
|
||||
structure,
|
||||
tag_id,
|
||||
union_layout,
|
||||
index,
|
||||
..
|
||||
} => {
|
||||
debug_assert_ne!(index.len(), 0);
|
||||
self.load_union_field_ptr_at_index(sym, structure, *tag_id, index[0], union_layout);
|
||||
debug_assert!(index.len() >= 2);
|
||||
self.load_union_field_ptr_at_index(sym, structure, index[0] as u16, index[1], union_layout);
|
||||
}
|
||||
Expr::GetTagId {
|
||||
structure,
|
||||
|
|
|
@ -2004,13 +2004,14 @@ pub(crate) fn build_exp_expr<'a, 'ctx>(
|
|||
}
|
||||
|
||||
UnionFieldPtrAtIndex {
|
||||
tag_id,
|
||||
structure,
|
||||
index,
|
||||
union_layout,
|
||||
..
|
||||
} => {
|
||||
debug_assert_ne!(index.len(), 0);
|
||||
let index = index[0] as usize;
|
||||
debug_assert!(index.len() >= 2);
|
||||
let tag_id = index[0];
|
||||
let index = index[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);
|
||||
|
@ -2020,7 +2021,7 @@ pub(crate) fn build_exp_expr<'a, 'ctx>(
|
|||
UnionLayout::Recursive(tag_layouts) => {
|
||||
debug_assert!(argument.is_pointer_value());
|
||||
|
||||
let field_layouts = tag_layouts[*tag_id as usize];
|
||||
let field_layouts = tag_layouts[tag_id as usize];
|
||||
|
||||
let ptr = tag_pointer_clear_tag_id(env, argument.into_pointer_value());
|
||||
let target_loaded_type = basic_type_from_layout(env, layout_interner, ret_repr);
|
||||
|
@ -2056,10 +2057,11 @@ pub(crate) fn build_exp_expr<'a, 'ctx>(
|
|||
other_tags,
|
||||
} => {
|
||||
debug_assert!(argument.is_pointer_value());
|
||||
debug_assert_ne!(*tag_id, *nullable_id);
|
||||
debug_assert_ne!(tag_id as u16, *nullable_id);
|
||||
|
||||
let tag_index = if *tag_id < *nullable_id {
|
||||
*tag_id
|
||||
let tag_id = tag_id as u16;
|
||||
let tag_index = if tag_id < *nullable_id {
|
||||
tag_id
|
||||
} else {
|
||||
tag_id - 1
|
||||
};
|
||||
|
@ -2084,7 +2086,7 @@ pub(crate) fn build_exp_expr<'a, 'ctx>(
|
|||
other_fields,
|
||||
} => {
|
||||
debug_assert!(argument.is_pointer_value());
|
||||
debug_assert_ne!(*tag_id != 0, *nullable_id);
|
||||
debug_assert_ne!(tag_id != 0, *nullable_id);
|
||||
|
||||
let field_layouts = other_fields;
|
||||
let struct_layout = LayoutRepr::struct_(field_layouts);
|
||||
|
|
|
@ -1101,16 +1101,16 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
|
|||
|
||||
Expr::UnionFieldPtrAtIndex {
|
||||
structure,
|
||||
tag_id,
|
||||
union_layout,
|
||||
index,
|
||||
..
|
||||
} => {
|
||||
debug_assert_ne!(index.len(), 0);
|
||||
debug_assert!(index.len() >= 2);
|
||||
self.expr_union_field_ptr_at_index(
|
||||
*structure,
|
||||
*tag_id,
|
||||
index[0] as u16,
|
||||
union_layout,
|
||||
index[0],
|
||||
index[1],
|
||||
storage,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -454,13 +454,13 @@ impl<'a, 'r> Ctx<'a, 'r> {
|
|||
}),
|
||||
&Expr::UnionFieldPtrAtIndex {
|
||||
structure,
|
||||
tag_id,
|
||||
union_layout,
|
||||
index,
|
||||
..
|
||||
} => self.with_sym_layout(structure, |ctx, _def_line, layout| {
|
||||
debug_assert_ne!(index.len(), 0);
|
||||
debug_assert!(index.len() >= 2);
|
||||
|
||||
ctx.check_union_field_ptr_at_index(structure, layout, union_layout, tag_id, index[0])
|
||||
ctx.check_union_field_ptr_at_index(structure, layout, union_layout, index[0] as _, index[1])
|
||||
}),
|
||||
Expr::Array { elem_layout, elems } => {
|
||||
for elem in elems.iter() {
|
||||
|
|
|
@ -206,11 +206,11 @@ fn specialize_drops_stmt<'a, 'i>(
|
|||
environment.symbol_tag.insert(*structure, *tag_id);
|
||||
}
|
||||
UnionFieldPtrAtIndex {
|
||||
structure, tag_id, ..
|
||||
structure, index, ..
|
||||
} => {
|
||||
// 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, *tag_id);
|
||||
environment.symbol_tag.insert(*structure, index[0] as u16);
|
||||
}
|
||||
Array {
|
||||
elems: children, ..
|
||||
|
|
|
@ -1894,7 +1894,6 @@ pub enum Expr<'a> {
|
|||
},
|
||||
UnionFieldPtrAtIndex {
|
||||
structure: Symbol,
|
||||
tag_id: TagIdIntType,
|
||||
union_layout: UnionLayout<'a>,
|
||||
index: &'a [u64],
|
||||
},
|
||||
|
@ -2154,18 +2153,18 @@ impl<'a> Expr<'a> {
|
|||
.append(symbol_to_doc(alloc, *structure, pretty)),
|
||||
|
||||
UnionFieldPtrAtIndex {
|
||||
tag_id,
|
||||
structure,
|
||||
index,
|
||||
..
|
||||
} => {
|
||||
let it = index.iter().map(|num| alloc.as_string(num));
|
||||
let it = alloc.intersperse(it, ", ");
|
||||
text!(
|
||||
alloc,
|
||||
"TODO: fixme, UnionFieldPtrAtIndex (Id {tag_id}) (Index [",
|
||||
"GetElementPointer (Indices [",
|
||||
)
|
||||
.append(alloc.intersperse(it, ", "))
|
||||
.append(alloc.text("])"))
|
||||
.append(it)
|
||||
.append(alloc.text("]) "))
|
||||
.append(symbol_to_doc(alloc, *structure, pretty))
|
||||
}
|
||||
// .append(alloc.intersperse(index.iter(), ", "))},
|
||||
|
@ -7950,13 +7949,11 @@ fn substitute_in_expr<'a>(
|
|||
// currently only used for tail recursion modulo cons (TRMC)
|
||||
UnionFieldPtrAtIndex {
|
||||
structure,
|
||||
tag_id,
|
||||
index,
|
||||
union_layout,
|
||||
} => match substitute(subs, *structure) {
|
||||
Some(structure) => Some(UnionFieldPtrAtIndex {
|
||||
structure,
|
||||
tag_id: *tag_id,
|
||||
index,
|
||||
union_layout: *union_layout,
|
||||
}),
|
||||
|
|
|
@ -907,12 +907,11 @@ impl<'a> TrmcEnv<'a> {
|
|||
reuse: None,
|
||||
};
|
||||
|
||||
let index = vec![in env.arena; recursive_field_index as u64].into_bump_slice();
|
||||
let index = 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 {
|
||||
structure: *symbol,
|
||||
tag_id: cons_info.tag_id,
|
||||
union_layout: cons_info.tag_layout,
|
||||
index,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue