Update List.replace to no longer use Nat

This commit is contained in:
Richard Feldman 2024-01-22 23:37:39 -05:00
parent a8918a4e3b
commit 5b2998966b
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
2 changed files with 9 additions and 7 deletions

View file

@ -938,7 +938,7 @@ pub fn listConcat(list_a: RocList, list_b: RocList, alignment: u32, element_widt
pub fn listReplaceInPlace(
list: RocList,
index: usize,
index: u64,
element: Opaque,
element_width: usize,
out_element: ?[*]u8,
@ -948,14 +948,15 @@ pub fn listReplaceInPlace(
// at the time of writing, the function is implemented roughly as
// `if inBounds then LowLevelListReplace input index item else input`
// so we don't do a bounds check here. Hence, the list is also non-empty,
// because inserting into an empty list is always out of bounds
return listReplaceInPlaceHelp(list, index, element, element_width, out_element);
// because inserting into an empty list is always out of bounds,
// and it's always safe to cast index to usize.
return listReplaceInPlaceHelp(list, @as(usize, @intCast(index)), element, element_width, out_element);
}
pub fn listReplace(
list: RocList,
alignment: u32,
index: usize,
index: u64,
element: Opaque,
element_width: usize,
out_element: ?[*]u8,
@ -965,8 +966,9 @@ pub fn listReplace(
// at the time of writing, the function is implemented roughly as
// `if inBounds then LowLevelListReplace input index item else input`
// so we don't do a bounds check here. Hence, the list is also non-empty,
// because inserting into an empty list is always out of bounds
return listReplaceInPlaceHelp(list.makeUnique(alignment, element_width), index, element, element_width, out_element);
// because inserting into an empty list is always out of bounds,
// and it's always safe to cast index to usize.
return listReplaceInPlaceHelp(list.makeUnique(alignment, element_width), @as(usize, @intCast(index)), element, element_width, out_element);
}
inline fn listReplaceInPlaceHelp(

View file

@ -322,7 +322,7 @@ pub(crate) fn list_drop_at<'a, 'ctx>(
)
}
/// List.replace_unsafe : List elem, Nat, elem -> { list: List elem, value: elem }
/// List.replace_unsafe : List elem, U64, elem -> { list: List elem, value: elem }
pub(crate) fn list_replace_unsafe<'a, 'ctx>(
env: &Env<'a, 'ctx, '_>,
layout_interner: &STLayoutInterner<'a>,