-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dereferencing as reassignment target (#5923)
## Description This PR implements dereferencing in reassignment targets, as defined in [references](https://github.com/FuelLabs/sway-rfcs/blob/ironcev/amend-references/files/0010-references.sw). The overall effort related to references is tracked in #5063. Up to now, it was only possible to read the values references refer to. This PR allows values to be written over `&mut` references. In other words, any `*<expression that results in &mut>`is now an l-values and can be used in left-hand sides (LHS) of assignments. In most of the cases, the `<expression>` will very likely be just a reference variable, but any expression that results in `&mut` is allowed and supported. E.g.; ```Sway *mut_ref_to_u64 = 42; *if condition { &mut x } else { &mut y } = 42; *max_mut(&mut x, &mut y) = 42; ``` Additionally, the PR: - fixes #5736 by properly replacing decls in reassignment LHSs. - fixes #5737 by properly substituting types in reassignment LHSs. - fixes #5920 by properly connecting expressions in array indices to the DCA graph. - fixes #5922 by type-cheking the array indices in reassignment LHSs and forcing them to be `u64`. - improves misplaced and misleading error messages when assigning to constants and other items (see demo below). - improves error message when assigning to immutable variables by pointing to variable declaration. - improves error message when expression cannot be assigned to by pointing to the problematic part of the expression. Since Sway is more restrictive here then Rust, the restrictions, without being explained, could cause confusion. That's why special attention was given to point to the exact issue and explain what is actually supported in Sway (see demo below). - reduces number of expected warnings in references E2E tests that were previously set high because of DCA issues that are fixed in the meantime. The PR also brings additional analysis and checks to IR optimizations. Among other things, it explicitly points out the cases in which a potential usage of a symbol cannot be deterministically confirmed or denied. In this PR properly reacting for such cases is done in some optimizations. Rolling it out fully will be done in a follow up PR #5924. More advanced escape analysis will be done later on, as a part of allocating values on the heap in case of referencing. This PR implements only dereferencing in LHS. Support for referenced elements in the element based access (without dereferencing) will be done in a separate step as an ongoing work on implementing #5063. Closes #5736, #5737, #5920, #5922. ## Demo Before:   After:   Expression cannot be assigned to:  ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
- Loading branch information
Showing
110 changed files
with
4,329 additions
and
665 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.