-
Notifications
You must be signed in to change notification settings - Fork 204
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
chore(ssa refactor): Fix loading from mutable parameters #1248
Conversation
Co-authored-by: kevaundray <[email protected]>
…r-lang/noir into jf/ssa-first-class-functions
Update: Fixed storing to mutable arrays as well. Previously the code fn main() {
let mut my_array = [1, 2];
my_array[1] = 3;
} Would result in the IR:
Note the final v12 that is never used and that we're storing to v9 (the start of the array) rather than (start + 1).
For the curious the v12 Edit: The root cause seems to have actually been a bug in insert_load not inserting the address addition if the offset was not a constant. I've fixed this but kept the previous fix as well since it seems more correct to not insert the loads in the first place rather than removing them later. |
After some more testing I've determined this is the final bugfix PR needed for the new ssa gen pass 🎉. It likely still has bugs but none that I can find by running any of our examples and looking at the output manually. Note that this is except for one known failure: The first-class-functions test fails completely when we attempt to use a value from another function without importing it as a parameter first. This is by design, but fixing it means we need to do proper closure conversion. Proper closure conversion was needed previously due to a known bug when using closures but for the most part the old SSA ir was fine with using these values without importing them so it worked for the most part. I've opened an appropriate issue for this. |
Yay :D Great work on getting the ssa gen pass complete! Can you link the issue for poper closure conversion? Spoke too soon, its #1254 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - one nit but not blocking
Sidenote: I love the way blocks/functions are printed now :) |
* master: (223 commits) chore(noir): Release 0.5.0 (#1202) chore(ci): Utilize new workflow to build binaries (#1250) chore(ssa refactor): Fix loading from mutable parameters (#1248) fix(wasm): add std after dependencies (#1245) chore(ssa refactor): Fix no returns & duplicate main (#1243) chore(ssa refactor): Implement intrinsics (#1241) chore(ssa refactor): Implement first-class functions (#1238) chore: address clippy warnings (#1239) chore(ssa refactor): Implement function calls (#1235) chore(ssa refactor): Implement mutable and immutable variables (#1234) chore(ssa refactor): Fix recursive printing of blocks (#1230) feat(noir): added assert keyword (#1227) chore(ssa refactor): Implement ssa-gen for indexing, cast, constrain, if, unary (#1225) feat(noir): added `distinct` keyword (#1219) chore(nargo): update panic message to suggest searching for similar issues (#1224) chore(ssa refactor): Update how instruction result types are retrieved (#1222) chore(ssa refactor): Implement ssa-gen for binary, block, tuple, extract-tuple-field, and semi expressions (#1217) chore: add RUST_BACKTRACE environment variable to nix config (#1216) chore(ssa): Add intial control flow graph (#1200) chore(ssa refactor): Handle codegen for literals (#1209) ...
* Implement first-class functions * Update crates/noirc_evaluator/src/ssa_refactor/ir/dfg.rs Co-authored-by: kevaundray <[email protected]> * Implement intrinsics * Fix no return & duplicate main * bad git. remove duplicated functions * Remove Option<Function> in builder * Undo debug printing in driver * Fix loading from mutable parameters * Grammar * Fix storing to mutable arrays * Fix unused variable * Fix array loading * Change terminology --------- Co-authored-by: kevaundray <[email protected]>
* master: (63 commits) feat(nargo): Remove usage of `CompiledProgram` in CLI code and use separate ABI/bytecode (#1269) feat: add integration tests for bitshift operators (#1272) chore: Replace explicit if-elses with `FieldElement::from<bool>()` for boolean fields (#1266) chore(noir): constrain expr; -> assert(expr); (#1276) chore: fix clippy warning (#1270) chore(ssa refactor): Add all remaining doc comments to ssa generation pass (#1256) chore(noir): Release 0.5.1 (#1264) fix: Add Poseidon examples into integration tests (#1257) chore(nargo): replace `aztec_backend` with `acvm-backend-barretenberg` (#1226) chore(noir): Release 0.5.0 (#1202) chore(ci): Utilize new workflow to build binaries (#1250) chore(ssa refactor): Fix loading from mutable parameters (#1248) fix(wasm): add std after dependencies (#1245) chore(ssa refactor): Fix no returns & duplicate main (#1243) chore(ssa refactor): Implement intrinsics (#1241) chore(ssa refactor): Implement first-class functions (#1238) chore: address clippy warnings (#1239) chore(ssa refactor): Implement function calls (#1235) chore(ssa refactor): Implement mutable and immutable variables (#1234) chore(ssa refactor): Fix recursive printing of blocks (#1230) ...
Related issue(s)
Resolves #
Description
Summary of changes
Fixes a couple bugs with mutable parameters:
Instruction::Load
'ed from automatically because they were not wrapped inValue::Mutable
. This lead to a later panic in mutate_load_into_store.lhs = rhs;
we generate a load from lhs before we evaluate rhs and store to it. To create the store however, we replaced the load with a store previously, which would then create astore
instruction storing rhs before rhs was even evaluated. So the IR would resemblestore v3 at v1; v3 = ...
. Since the store should be after everything else, I've replacedmutate_load_into_store
with a new function to instead remove the old load and insert a new store at the end of the current block.This PR depends on the previous fixes PR which is in the process of being merged. Until then this PR will show those changes as well.Dependency additions / changes
Test additions / changes
Checklist
cargo fmt
with default settings.Documentation needs
Additional context