mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Remove TagDiscriminant low-level
This commit is contained in:
parent
cb96a64259
commit
792afe5457
7 changed files with 5 additions and 88 deletions
|
@ -84,7 +84,6 @@ macro_rules! map_symbol_to_lowlevel_and_arity {
|
|||
LowLevel::PtrCast => unimplemented!(),
|
||||
LowLevel::RefCountInc => unimplemented!(),
|
||||
LowLevel::RefCountDec => unimplemented!(),
|
||||
LowLevel::TagDiscriminant => unimplemented!(),
|
||||
|
||||
// these are not implemented, not sure why
|
||||
LowLevel::StrFromInt => unimplemented!(),
|
||||
|
|
|
@ -6575,7 +6575,7 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
unreachable!("these are higher order, and are handled elsewhere")
|
||||
}
|
||||
|
||||
BoxExpr | UnboxExpr | TagDiscriminant => {
|
||||
BoxExpr | UnboxExpr => {
|
||||
unreachable!("The {:?} operation is turned into mono Expr", op)
|
||||
}
|
||||
|
||||
|
|
|
@ -1858,7 +1858,7 @@ impl<'a> LowLevelCall<'a> {
|
|||
|
||||
Eq | NotEq => self.eq_or_neq(backend),
|
||||
|
||||
BoxExpr | UnboxExpr | TagDiscriminant => {
|
||||
BoxExpr | UnboxExpr => {
|
||||
unreachable!("The {:?} operation is turned into mono Expr", self.lowlevel)
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,6 @@ pub enum LowLevel {
|
|||
BoxExpr,
|
||||
UnboxExpr,
|
||||
Unreachable,
|
||||
TagDiscriminant,
|
||||
}
|
||||
|
||||
macro_rules! higher_order {
|
||||
|
@ -212,7 +211,6 @@ macro_rules! map_symbol_to_lowlevel {
|
|||
LowLevel::PtrCast => unimplemented!(),
|
||||
LowLevel::RefCountInc => unimplemented!(),
|
||||
LowLevel::RefCountDec => unimplemented!(),
|
||||
LowLevel::TagDiscriminant => unimplemented!(),
|
||||
|
||||
// these are not implemented, not sure why
|
||||
LowLevel::StrFromInt => unimplemented!(),
|
||||
|
|
|
@ -935,7 +935,7 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
|
|||
|
||||
ListIsUnique => arena.alloc_slice_copy(&[borrowed]),
|
||||
|
||||
BoxExpr | UnboxExpr | TagDiscriminant => {
|
||||
BoxExpr | UnboxExpr => {
|
||||
unreachable!("These lowlevel operations are turned into mono Expr's")
|
||||
}
|
||||
|
||||
|
|
|
@ -5444,13 +5444,6 @@ pub fn with_hole<'a>(
|
|||
|
||||
Stmt::Let(assigned, Expr::ExprUnbox { symbol: x }, layout, hole)
|
||||
}
|
||||
TagDiscriminant => {
|
||||
debug_assert_eq!(arg_symbols.len(), 1);
|
||||
let tag = arg_symbols[0];
|
||||
let tag_var = args[0].0;
|
||||
|
||||
build_tag_discriminant_expr(env, layout_cache, assigned, tag, tag_var, hole)
|
||||
}
|
||||
_ => {
|
||||
let call = self::Call {
|
||||
call_type: CallType::LowLevel {
|
||||
|
@ -5476,76 +5469,6 @@ pub fn with_hole<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
fn build_tag_discriminant_expr<'a>(
|
||||
env: &mut Env<'a, '_>,
|
||||
layout_cache: &mut LayoutCache<'a>,
|
||||
assigned: Symbol,
|
||||
tag_sym: Symbol,
|
||||
tag_var: Variable,
|
||||
hole: &'a Stmt<'a>,
|
||||
) -> Stmt<'a> {
|
||||
use crate::layout::UnionVariant::*;
|
||||
|
||||
let union_variant = {
|
||||
let mut layout_env =
|
||||
layout::Env::from_components(layout_cache, env.subs, env.arena, env.target_info);
|
||||
crate::layout::union_sorted_tags(&mut layout_env, tag_var)
|
||||
.expect("TagDiscriminant only built in derived impls, which must type-check")
|
||||
};
|
||||
|
||||
let build_cast_to_u16 = |env: &mut Env<'a, '_>, tag_id_sym| self::Call {
|
||||
call_type: CallType::LowLevel {
|
||||
op: LowLevel::NumIntCast,
|
||||
update_mode: env.next_update_mode_id(),
|
||||
},
|
||||
arguments: env.arena.alloc([tag_id_sym]),
|
||||
};
|
||||
|
||||
match union_variant {
|
||||
Never | Unit | Newtype { .. } | NewtypeByVoid { .. } => {
|
||||
// All trivial unions decay into `0` for their discriminant.
|
||||
Stmt::Let(
|
||||
assigned,
|
||||
Expr::Literal(Literal::Int(0u128.to_ne_bytes())),
|
||||
Layout::u16(),
|
||||
hole,
|
||||
)
|
||||
}
|
||||
BoolUnion { .. } | ByteUnion(..) => {
|
||||
// These are represented as integers at runtime, so we just need to cast them.
|
||||
let cast_to_u16 = build_cast_to_u16(env, tag_sym);
|
||||
|
||||
Stmt::Let(assigned, Expr::Call(cast_to_u16), Layout::u16(), hole)
|
||||
}
|
||||
Wrapped(..) => {
|
||||
let tag_layout = layout_cache.from_var(env.arena, tag_var, env.subs).unwrap();
|
||||
let tag_union_layout = match tag_layout {
|
||||
Layout::Union(un) => un,
|
||||
_ => internal_error!(
|
||||
"Somehow this is a `Wrapped` variant, but its layout is not a union"
|
||||
),
|
||||
};
|
||||
|
||||
let tag_id_layout = tag_union_layout.tag_id_layout();
|
||||
debug_assert!(tag_id_layout == Layout::u8() || tag_id_layout == Layout::u16());
|
||||
|
||||
let tag_id_sym = env.unique_symbol();
|
||||
let cast_to_u16 = build_cast_to_u16(env, tag_id_sym);
|
||||
|
||||
let hole = Stmt::Let(assigned, Expr::Call(cast_to_u16), Layout::u16(), hole);
|
||||
Stmt::Let(
|
||||
tag_id_sym,
|
||||
Expr::GetTagId {
|
||||
structure: tag_sym,
|
||||
union_layout: tag_union_layout,
|
||||
},
|
||||
tag_id_layout,
|
||||
env.arena.alloc(hole),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn late_resolve_ability_specialization<'a>(
|
||||
env: &mut Env<'a, '_>,
|
||||
|
|
|
@ -163,11 +163,8 @@ fn expr<'a>(c: &Ctx, p: EPrec, f: &'a Arena<'a>, e: &'a Expr) -> DocBuilder<'a,
|
|||
.nest(2)
|
||||
)
|
||||
}
|
||||
RunLowLevel { op, args, .. } => {
|
||||
let op = match op {
|
||||
LowLevel::TagDiscriminant => "@tag_discriminant",
|
||||
_ => unreachable!(),
|
||||
};
|
||||
RunLowLevel { args, .. } => {
|
||||
let op = "LowLevel";
|
||||
|
||||
maybe_paren!(
|
||||
Free,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue