Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssa): Fix slice intrinsic handling in the capacity tracker #4643

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl<'a> SliceCapacityTracker<'a> {
Intrinsic::SlicePopFront => (Some(1), results.len() - 1),
// The slice capacity of these intrinsics is not determined by the arguments of the function.
Intrinsic::ToBits(_) | Intrinsic::ToRadix(_) => (None, 1),
Intrinsic::AsSlice => (Some(0), 1),
_ => return,
};
let result_slice = results[result_index];
Expand All @@ -90,6 +91,7 @@ impl<'a> SliceCapacityTracker<'a> {
self.compute_slice_capacity(*arg, slice_sizes);
}
}

if let Some(contents_capacity) = slice_sizes.get(&slice_contents) {
let new_capacity = *contents_capacity + 1;
slice_sizes.insert(result_slice, new_capacity);
Expand All @@ -102,9 +104,6 @@ impl<'a> SliceCapacityTracker<'a> {
.expect("ICE: Should have an argument index for slice intrinsics");
let slice_contents = arguments[argument_index];

// We do not decrement the size on intrinsics that could remove values from a slice.
// This is because we could potentially go back to the smaller slice and not fill in dummies.
// This pass should be tracking the potential max that a slice ***could be***
if let Some(contents_capacity) = slice_sizes.get(&slice_contents) {
let new_capacity = *contents_capacity - 1;
slice_sizes.insert(result_slice, new_capacity);
Expand All @@ -121,6 +120,15 @@ impl<'a> SliceCapacityTracker<'a> {
slice_sizes
.insert(result_slice, FieldElement::max_num_bytes() as usize);
}
Intrinsic::AsSlice => {
let argument_index = argument_index
.expect("ICE: Should have an argument index for AsSlice builtin");
let array_size = self
.dfg
.try_get_array_length(arguments[argument_index])
.expect("ICE: Should be have an array length for AsSlice input");
slice_sizes.insert(result_slice, array_size);
}
_ => {}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "regression_capacity_tracker"
type = "bin"
authors = [""]
compiler_version = ">=0.26.0"

[dependencies]
Loading
Loading