fix(ssa): Empty array of higher order functions#8677
fix(ssa): Empty array of higher order functions#8677
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 86b7da9 | Previous: eb3eef9 | Ratio |
|---|---|---|---|
test_report_zkpassport_noir_rsa_ |
3 s |
2 s |
1.50 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
| // It is safe to remove these functions. | ||
| // We also check whether the type of the instruction is a field as all function pointers | ||
| // are transformed to field IDs during defunctionalization. | ||
| Value::Instruction { typ, .. } if typ.is_field() => true, |
There was a problem hiding this comment.
I'm not 100% on this. Maybe we could add an assertion that the instruction originates from an array get where the array is of length zero? Although if it is a slice maybe we won't know the length?
There was a problem hiding this comment.
Yeah we could check the length of the array in an array get but it breaks with slices. With slices we would have to track backwards to see whether it originated from an empty make array (or track slice capacities as we do in RemoveIfElse), which I think would be overkill.
I'm also not a big fan of this solution. Even with #8676, if we eventually allow escaping unconditional panics this issue will arise again. I'll think of something else. Going to switch this back to a draft.
|
Here is an alternative #8697 which I prefer. |
|
Superceded by #8697 |
Description
Problem*
Builds upon #8674
Resolves the final panic in the linked issue that is slightly separate from lambdas in arrays:
Summary*
This is the SSA for the above snippet pre-DIE:
If we leave
call v4()this leads to issues in the underconstrained check and then during ACIR as function pointers are not supported. Also, the fact that we still have a function as a value means that there are no function variants and we should be able to safely remove this function.We now have this final SSA:
This matches the final SSA and behavior of an empty array:
Additional Context
I'm not really sure in what other case we may have a function value which is an instruction. This seems like the only case. However, I'm not a huge fan of this solution as it makes assumptions across passes. I think a better solution would be to simply error out on accessing an empty array at compile-time #8676.
Documentation*
Check one:
PR Checklist*
cargo fmton default settings.