-
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.
## Description This PR brings [references](https://github.com/FuelLabs/sway-rfcs/blob/ironcev/amend-references/files/0010-references.sw) to the language. The overall effort is tracked in #5063. In the below description, when talking about references we mean `&T` references - references to immutable values. `&mut T` will be implemented in upcoming PRs. The PR implements the following features: - References exist in the type system and can be declared, aliased, dereferenced using `*` operator, etc. - Reference expressions (referencing) are fully supported on all expressions including the nonsensical one like e.g. `&return;` - Semantic analysis and checks are implemented for the current functionality. - References can be embedded in aggregates. - References can reference parts of aggreagates. - References can be passed to and returned from ASM blocks. - References can be passed to and returned from functions. - References can be mutable: `let mut r_x = &x` - Impls can be implemented for non-generic reference types. - Traits can be implemented for non-generic reference types. - References work with generics, means `&T` works as expected. - References can reference references. - References can be dereferenced using the `*` operator. - Dereference expressions (dereferencing) are fully supported on all expressions including the nonsensical one like e.g. `*&return;` Known limitations: - When declaring references on references, currently a space (' ') is mandatory between two ampersands. E.g., `&&a` emits error and must be written as `& &a`. Extending parser to support, e.g., arbitrary `&&...&&a` will be done in upcoming PRs. - Referencing function parameters for copy types works but not with 100% proper semantics (creates a copy of the parameter). On the IR level, references are pointers stored as `u64` and do not exist as a separate concept. They play well with all the existing IR optimizations. Since `core::ops::Eq` and `__addr_of()` are still not implemented for references, checking for equality in tests is done by converting references to `raw_ptr`s and checking raw pointers. This is essentially fine and will one day be turned into converting references to typed pointers which are tests we will anyhow want to have. Next steps are listed in #5063. The documentation will be done in a separate PR and provided separately once feature is considered ready for public usage. There are several todos in code marked as `TODO-IG`. They will be resolved in upcoming PRs. # Demo For extensive demos of implemented features, see the tests in this PR. An example of a semantic check:  ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [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
128 changed files
with
4,360 additions
and
230 deletions.
There are no files selected for viewing
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
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.