mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
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:
parent
a15cc0589c
commit
ada83561e5
17 changed files with 88 additions and 48 deletions
|
@ -2830,8 +2830,13 @@ impl<
|
|||
}
|
||||
}
|
||||
|
||||
fn build_list_len(&mut self, dst: &Symbol, list: &Symbol) {
|
||||
self.storage_manager.list_len(&mut self.buf, dst, list);
|
||||
fn build_list_len_usize(&mut self, dst: &Symbol, list: &Symbol) {
|
||||
self.storage_manager
|
||||
.list_len_usize(&mut self.buf, dst, list);
|
||||
}
|
||||
|
||||
fn build_list_len_u64(&mut self, dst: &Symbol, list: &Symbol) {
|
||||
self.storage_manager.list_len_u64(&mut self.buf, dst, list);
|
||||
}
|
||||
|
||||
fn build_list_clone(
|
||||
|
|
|
@ -694,7 +694,7 @@ impl<
|
|||
}
|
||||
|
||||
// Loads the dst to be the later 64 bits of a list (its length).
|
||||
pub fn list_len(&mut self, _buf: &mut Vec<'a, u8>, dst: &Symbol, list: &Symbol) {
|
||||
pub fn list_len_u64(&mut self, _buf: &mut Vec<'a, u8>, dst: &Symbol, list: &Symbol) {
|
||||
let owned_data = self.remove_allocation_for_sym(list);
|
||||
self.allocation_map.insert(*list, Rc::clone(&owned_data));
|
||||
self.allocation_map.insert(*dst, owned_data);
|
||||
|
@ -709,6 +709,11 @@ impl<
|
|||
);
|
||||
}
|
||||
|
||||
/// In a 64-bit backend, this is the same as list_len_u64
|
||||
pub fn list_len_usize(&mut self, buf: &mut Vec<'a, u8>, dst: &Symbol, list: &Symbol) {
|
||||
self.list_len_u64(buf, dst, list)
|
||||
}
|
||||
|
||||
/// Creates a struct on the stack, moving the data in fields into the struct.
|
||||
pub fn create_struct(
|
||||
&mut self,
|
||||
|
|
|
@ -1484,13 +1484,21 @@ trait Backend<'a> {
|
|||
|
||||
self.build_fn_call(sym, intrinsic.to_string(), args, arg_layouts, ret_layout)
|
||||
}
|
||||
LowLevel::ListLen => {
|
||||
LowLevel::ListLenU64 => {
|
||||
debug_assert_eq!(
|
||||
1,
|
||||
args.len(),
|
||||
"ListLen: expected to have exactly one argument"
|
||||
"ListLenU64: expected to have exactly one argument"
|
||||
);
|
||||
self.build_list_len(sym, &args[0])
|
||||
self.build_list_len_u64(sym, &args[0])
|
||||
}
|
||||
LowLevel::ListLenUsize => {
|
||||
debug_assert_eq!(
|
||||
1,
|
||||
args.len(),
|
||||
"ListLenUsize: expected to have exactly one argument"
|
||||
);
|
||||
self.build_list_len_usize(sym, &args[0])
|
||||
}
|
||||
LowLevel::ListWithCapacity => {
|
||||
debug_assert_eq!(
|
||||
|
@ -2372,8 +2380,11 @@ trait Backend<'a> {
|
|||
/// build_sqrt stores the result of `sqrt(src)` into dst.
|
||||
fn build_num_sqrt(&mut self, dst: Symbol, src: Symbol, float_width: FloatWidth);
|
||||
|
||||
/// build_list_len returns the length of a list.
|
||||
fn build_list_len(&mut self, dst: &Symbol, list: &Symbol);
|
||||
/// build_list_len_usize returns the length of a list as a usize. This is for internal use only.
|
||||
fn build_list_len_usize(&mut self, dst: &Symbol, list: &Symbol);
|
||||
|
||||
/// build_list_len_u64 returns the length of a list and casts it from usize to u64. This is for the public List.len.
|
||||
fn build_list_len_u64(&mut self, dst: &Symbol, list: &Symbol);
|
||||
|
||||
/// generate a call to a higher-order lowlevel
|
||||
fn build_higher_order_lowlevel(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue