Split ListLen into ListLenU64 and ListLenUsize

The usize one gets used internally for things like
pattern matches. This is both more efficient (means
they don't have to do unnecessary casts) and also
less error-prone due to e.g. comparing length to
capacity, which is usize.
This commit is contained in:
Richard Feldman 2024-02-14 20:41:52 -05:00
parent a15cc0589c
commit ada83561e5
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
17 changed files with 88 additions and 48 deletions

View file

@ -668,8 +668,8 @@ fn eq_list<'a>(
let len_1 = root.create_symbol(ident_ids, "len_1");
let len_2 = root.create_symbol(ident_ids, "len_2");
let len_1_stmt = |next| let_lowlevel(arena, layout_isize, len_1, ListLen, &[ARG_1], next);
let len_2_stmt = |next| let_lowlevel(arena, layout_isize, len_2, ListLen, &[ARG_2], next);
let len_1_stmt = |next| let_lowlevel(arena, layout_isize, len_1, ListLenUsize, &[ARG_1], next);
let len_2_stmt = |next| let_lowlevel(arena, layout_isize, len_2, ListLenUsize, &[ARG_2], next);
let eq_len = root.create_symbol(ident_ids, "eq_len");
let eq_len_stmt = |next| let_lowlevel(arena, LAYOUT_BOOL, eq_len, Eq, &[len_1, len_2], next);

View file

@ -926,7 +926,7 @@ fn refcount_list<'a>(
//
let len = root.create_symbol(ident_ids, "len");
let len_stmt = |next| let_lowlevel(arena, layout_isize, len, ListLen, &[structure], next);
let len_stmt = |next| let_lowlevel(arena, layout_isize, len, ListLenUsize, &[structure], next);
// let zero = 0
let zero = root.create_symbol(ident_ids, "zero");

View file

@ -1533,8 +1533,8 @@ fn low_level_no_rc(lowlevel: &LowLevel) -> RC {
match lowlevel {
Unreachable => RC::Uknown,
ListLen | StrIsEmpty | StrCountUtf8Bytes | ListGetCapacity | ListWithCapacity
| StrWithCapacity => RC::NoRc,
ListLenU64 | ListLenUsize | StrIsEmpty | StrCountUtf8Bytes | ListGetCapacity
| ListWithCapacity | StrWithCapacity => RC::NoRc,
ListReplaceUnsafe => RC::Rc,
StrGetUnsafe | ListGetUnsafe => RC::NoRc,
ListConcat => RC::Rc,

View file

@ -1283,7 +1283,7 @@ fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[Ownership] {
match op {
Unreachable => arena.alloc_slice_copy(&[irrelevant]),
DictPseudoSeed => arena.alloc_slice_copy(&[irrelevant]),
ListLen | StrIsEmpty | StrCountUtf8Bytes | ListGetCapacity => {
ListLenU64 | ListLenUsize | StrIsEmpty | StrCountUtf8Bytes | ListGetCapacity => {
arena.alloc_slice_copy(&[borrowed])
}
ListWithCapacity | StrWithCapacity => arena.alloc_slice_copy(&[irrelevant]),

View file

@ -1769,7 +1769,7 @@ fn test_to_comparison<'a>(
LayoutRepr::Builtin(Builtin::List(_elem_layout)) => {
let real_len_expr = Expr::Call(Call {
call_type: CallType::LowLevel {
op: LowLevel::ListLen,
op: LowLevel::ListLenUsize,
update_mode: env.next_update_mode_id(),
},
arguments: env.arena.alloc([list_sym]),
@ -2346,7 +2346,7 @@ fn decide_to_branching<'a>(
let len_expr = Expr::Call(Call {
call_type: CallType::LowLevel {
op: LowLevel::ListLen,
op: LowLevel::ListLenUsize,
update_mode: env.next_update_mode_id(),
},
arguments: env.arena.alloc([inner_cond_symbol]),

View file

@ -1412,7 +1412,7 @@ pub(crate) fn build_list_index_probe<'a>(
let len_sym = env.unique_symbol();
let len_expr = Expr::Call(Call {
call_type: CallType::LowLevel {
op: LowLevel::ListLen,
op: LowLevel::ListLenUsize,
update_mode: env.next_update_mode_id(),
},
arguments: env.arena.alloc([list_sym]),
@ -1570,7 +1570,7 @@ fn store_list_rest<'a>(
let list_len_sym = env.unique_symbol();
let list_len_expr = Expr::Call(Call {
call_type: CallType::LowLevel {
op: LowLevel::ListLen,
op: LowLevel::ListLenUsize,
update_mode: env.next_update_mode_id(),
},
arguments: env.arena.alloc([list_sym]),

View file

@ -69,7 +69,8 @@ enum FirstOrder {
StrToUtf8,
StrRepeat,
StrFromFloat,
ListLen,
ListLenU64,
ListLenUsize,
ListGetUnsafe,
ListSublist,
ListDropAt,