mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
List.unreachable
This commit is contained in:
parent
543615292a
commit
506e374642
7 changed files with 36 additions and 0 deletions
|
@ -790,3 +790,5 @@ iterHelp = \list, state, f, index, length ->
|
|||
Break b
|
||||
else
|
||||
Continue state
|
||||
|
||||
unreachable : [] -> a
|
||||
|
|
|
@ -100,6 +100,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
|
|||
STR_TO_I16 => str_to_num,
|
||||
STR_TO_U8 => str_to_num,
|
||||
STR_TO_I8 => str_to_num,
|
||||
LIST_UNREACHABLE => roc_unreachable,
|
||||
LIST_LEN => list_len,
|
||||
LIST_WITH_CAPACITY => list_with_capacity,
|
||||
LIST_GET_UNSAFE => list_get_unsafe,
|
||||
|
@ -2475,6 +2476,11 @@ fn list_walk_until(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
lowlevel_3(symbol, LowLevel::ListWalkUntil, var_store)
|
||||
}
|
||||
|
||||
/// List.unreachable : [] -> a
|
||||
fn roc_unreachable(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
lowlevel_1(symbol, LowLevel::Unreachable, var_store)
|
||||
}
|
||||
|
||||
/// List.map : List before, (before -> after) -> List after
|
||||
fn list_map(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
lowlevel_2(symbol, LowLevel::ListMap, var_store)
|
||||
|
|
|
@ -6068,6 +6068,20 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
PtrCast | RefCountInc | RefCountDec => {
|
||||
unreachable!("Not used in LLVM backend: {:?}", op);
|
||||
}
|
||||
|
||||
Unreachable => match RocReturn::from_layout(env, layout) {
|
||||
RocReturn::Return => {
|
||||
let basic_type = basic_type_from_layout(env, layout);
|
||||
basic_type.const_zero()
|
||||
}
|
||||
RocReturn::ByPointer => {
|
||||
let basic_type = basic_type_from_layout(env, layout);
|
||||
let ptr = env.builder.build_alloca(basic_type, "unreachable_alloca");
|
||||
env.builder.build_store(ptr, basic_type.const_zero());
|
||||
|
||||
ptr.into()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1631,6 +1631,17 @@ impl<'a> LowLevelCall<'a> {
|
|||
BoxExpr | UnboxExpr => {
|
||||
unreachable!("The {:?} operation is turned into mono Expr", self.lowlevel)
|
||||
}
|
||||
|
||||
Unreachable => match self.ret_storage {
|
||||
StoredValue::VirtualMachineStack { value_type, .. }
|
||||
| StoredValue::Local { value_type, .. } => match value_type {
|
||||
ValueType::I32 => backend.code_builder.i32_const(0),
|
||||
ValueType::I64 => backend.code_builder.i64_const(0),
|
||||
ValueType::F32 => backend.code_builder.f32_const(0.0),
|
||||
ValueType::F64 => backend.code_builder.f64_const(0.0),
|
||||
},
|
||||
StoredValue::StackMemory { .. } => { /* do nothing */ }
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,7 @@ pub enum LowLevel {
|
|||
RefCountDec,
|
||||
BoxExpr,
|
||||
UnboxExpr,
|
||||
Unreachable,
|
||||
}
|
||||
|
||||
macro_rules! higher_order {
|
||||
|
|
|
@ -1255,6 +1255,7 @@ define_builtins! {
|
|||
61 LIST_REPLACE_UNSAFE: "replaceUnsafe"
|
||||
62 LIST_WITH_CAPACITY: "withCapacity"
|
||||
63 LIST_ITERATE: "iterate"
|
||||
64 LIST_UNREACHABLE: "unreachable"
|
||||
}
|
||||
6 RESULT: "Result" => {
|
||||
0 RESULT_RESULT: "Result" // the Result.Result type alias
|
||||
|
|
|
@ -890,6 +890,7 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
|
|||
// - arguments that we may want to update destructively must be Owned
|
||||
// - other refcounted arguments are Borrowed
|
||||
match op {
|
||||
Unreachable => arena.alloc_slice_copy(&[irrelevant]),
|
||||
ListLen | StrIsEmpty | StrCountGraphemes => arena.alloc_slice_copy(&[borrowed]),
|
||||
ListWithCapacity => arena.alloc_slice_copy(&[irrelevant]),
|
||||
ListReplaceUnsafe => arena.alloc_slice_copy(&[owned, irrelevant, irrelevant]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue