-
Notifications
You must be signed in to change notification settings - Fork 49
[v2] Compute linearised members of all contracts in a new semantic pass #1805
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
Open
ggiraldez
wants to merge
5
commits into
main
Choose a base branch
from
ggiraldez/v2-cache-linearisations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3fcd91f
Cache linearised collection of contract's function, variables, etc
ggiraldez 78fc92d
Address PR comments; change `find_contract_by_name` to return an iter…
ggiraldez 6e4d156
Update public-api.txt snapshots
ggiraldez 4a41621
Build `ContractData` in a new semantic pass
ggiraldez a798fad
Reorder semantic passes
ggiraldez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
crates/solidity-v2/outputs/cargo/ast/generated/public_api.txt
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
39 changes: 0 additions & 39 deletions
39
crates/solidity-v2/outputs/cargo/ast/src/ast/node_extensions/function_definition.rs
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
crates/solidity-v2/outputs/cargo/ast/src/ast/node_extensions/interface_definition.rs
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
7 changes: 6 additions & 1 deletion
7
crates/solidity-v2/outputs/cargo/semantic/generated/public_api.txt
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
crates/solidity-v2/outputs/cargo/semantic/src/context/contract_data.rs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| use std::collections::HashMap; | ||
|
|
||
| use slang_solidity_v2_common::nodes::NodeId; | ||
| use slang_solidity_v2_ir::ir; | ||
|
|
||
| /// Pre-computed member linearisations for a single contract. | ||
| #[allow(clippy::struct_field_names)] | ||
| pub(crate) struct ContractLinearisations { | ||
| pub(crate) functions: Vec<ir::FunctionDefinition>, | ||
| pub(crate) state_variables: Vec<ir::StateVariableDefinition>, | ||
| pub(crate) errors: Vec<ir::ErrorDefinition>, | ||
| pub(crate) events: Vec<ir::EventDefinition>, | ||
| } | ||
|
|
||
| /// Cache of derived data about contracts stored on the `SemanticContext`. Every | ||
| /// contract's `NodeId` has an entry in `data`. | ||
| pub(crate) struct ContractData { | ||
| /// All contract definitions in this compilation unit, in registration | ||
| /// order (deterministic iteration for `all_contracts`). | ||
| contracts: Vec<ir::ContractDefinition>, | ||
| /// Per-contract linearised members, keyed by contract `NodeId`. | ||
| linearisations: HashMap<NodeId, ContractLinearisations>, | ||
| } | ||
|
|
||
| impl ContractData { | ||
| pub(crate) fn new( | ||
| contracts: Vec<ir::ContractDefinition>, | ||
| data: HashMap<NodeId, ContractLinearisations>, | ||
| ) -> Self { | ||
| Self { | ||
| contracts, | ||
| linearisations: data, | ||
| } | ||
| } | ||
|
|
||
| fn get(&self, contract_id: NodeId) -> &ContractLinearisations { | ||
| self.linearisations | ||
| .get(&contract_id) | ||
| .expect("contract_id is a registered contract") | ||
| } | ||
|
|
||
| pub(super) fn all_contracts(&self) -> impl Iterator<Item = &ir::ContractDefinition> { | ||
| self.contracts.iter() | ||
| } | ||
|
|
||
| pub(super) fn find_contract_by_name<'a>( | ||
| &'a self, | ||
| name: &'a str, | ||
| ) -> impl Iterator<Item = ir::ContractDefinition> + use<'a> { | ||
| self.contracts | ||
| .iter() | ||
| .filter(move |contract| contract.name.unparse() == name) | ||
| .cloned() | ||
| } | ||
|
|
||
| pub(super) fn linearised_functions(&self, contract_id: NodeId) -> &[ir::FunctionDefinition] { | ||
| &self.get(contract_id).functions | ||
| } | ||
|
|
||
| pub(super) fn linearised_state_variables( | ||
| &self, | ||
| contract_id: NodeId, | ||
| ) -> &[ir::StateVariableDefinition] { | ||
| &self.get(contract_id).state_variables | ||
| } | ||
|
|
||
| pub(super) fn linearised_errors(&self, contract_id: NodeId) -> &[ir::ErrorDefinition] { | ||
| &self.get(contract_id).errors | ||
| } | ||
|
|
||
| pub(super) fn linearised_events(&self, contract_id: NodeId) -> &[ir::EventDefinition] { | ||
| &self.get(contract_id).events | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Doesn't need to be on this PR, but it'd be interested to have a benchmark tracking how these values are used. For example, for some big benchmarks, iterate all linearised definitions for all contracts and use them trivially (compute the hash of their selectors)