forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…#4037) ## Description This PR is a subset of FuelLabs#3744. It introduces `DeclRef`, which is a smart wrapper type around `DeclId` and contains additional information aside from the `DeclId`. This allows us to make `DeclId` a copy type and remove excessive clones of `DeclId` and `DeclRef`. This PR is a subset of FuelLabs#3744, so while not explicitly necessary right now on `master`, there will be additional fields added to `DeclRef` in FuelLabs#3744. In detail, this PR: 1. Changes `DeclId` to a copy type defined as: ```rust #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] pub struct DeclId(usize); ``` 2. Creates a new `DeclRef` type which is a handle to a use of a declaration: (there will be more fields added to this in FuelLabs#3744) ```rust /// A reference to the use of a declaration. #[derive(Debug, Clone)] struct DeclRef { /// The name of the declaration. name: Ident, /// The index into the [DeclEngine]. id: DeclId, /// The [Span] of the entire declaration. decl_span: Span, } ``` 3. Changes the definition of the `TyDeclaration::FunctionDeclaration` variant to contain additional fields: (there will be more fields added to this in FuelLabs#3744) ```rust FunctionDeclaration { name: Ident, decl_id: DeclId, decl_span: Span, }, ``` 4. Changes the definiton of the `TyExpressionVariant::FunctionApplication` variant to contain a `DeclRef` instead of just the previous `DeclId`. The `TyExpressionVariant::FunctionApplication` variant gets a `DeclRef` because `DeclRef` is a handle to a declaration _usage_, while the `TyDeclaration::FunctionDeclaration` variant does not get a `DeclRef` because it is simply an AST node for the function declaration. This distinction will be more clear/necessary in FuelLabs#3744. 5. Changes the `DeclEngine` API to take `&T where ...`, allowing us to remove more unnecessary instances of `.clone()`. ## Checklist - [x] I have linked to any relevant issues. - [ ] 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). - [ ] I have added tests that prove my fix is effective or that my feature works. - [x] 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. --------- Co-authored-by: emilyaherbert <[email protected]>
- Loading branch information
1 parent
0c1e14e
commit 30cdb10
Showing
62 changed files
with
1,498 additions
and
1,043 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
Oops, something went wrong.