Skip to content

Commit

Permalink
this and super don't generate references
Browse files Browse the repository at this point in the history
This avoids some oddities, such as `this` used in libraries which we previously
had to bind to an artificial built-in.
  • Loading branch information
ggiraldez committed Nov 25, 2024
1 parent 90a4f26 commit d5823c0
Show file tree
Hide file tree
Showing 52 changed files with 94 additions and 238 deletions.
37 changes: 9 additions & 28 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,6 @@ inherit .star_extension
edge heir.ns -> ns_member
edge ns_member -> @type_name.push_begin

; Resolve the "super" keyword reference to the inherited type
edge heir.super -> @type_name.push_begin

if (version-matches "< 0.7.0") {
; `using` directives are inherited in Solidity < 0.7.0, so connect them to
; our own extensions scope
Expand Down Expand Up @@ -401,12 +398,6 @@ inherit .star_extension
edge @contract.lexical_scope -> this
edge this -> member

; ... and resolves to the contract itself
node name_push
attr (name_push) push_symbol = (source-text @name)
edge this -> name_push
edge name_push -> @contract.lexical_scope

;; Modifiers are available as a contract type members through a special '@modifier' guard
node modifier
attr (modifier) pop_symbol = "@modifier"
Expand Down Expand Up @@ -525,9 +516,6 @@ inherit .star_extension
attr (super_instance) push_symbol = "@instance"
edge @contract.super_import -> super_instance
edge super_instance -> @contract.super_scope

; NOTE: The keyword "super" itself resolves to each of its parent contracts.
; See the related rules in the InheritanceSpecifier section above.
}

@contract [ContractDefinition [InheritanceSpecifier [InheritanceTypes
Expand Down Expand Up @@ -743,9 +731,6 @@ inherit .star_extension
@interface [InterfaceDefinition @specifier [InheritanceSpecifier]] {
let @specifier.heir = @interface
attr (@interface.def) parents = @specifier.parent_refs

; Define a dummy "super" node required by the rules for InheritanceSpecifier
node @interface.super
}

@interface [InterfaceDefinition [InterfaceMembers
Expand Down Expand Up @@ -816,16 +801,6 @@ inherit .star_extension
edge type -> type_library_type
edge type_library_type -> @library.lexical_scope

; Define `this` inside libraries to resolve to a special built-in placeholder
node this
attr (this) pop_symbol = "this"
node this_built_in
attr (this_built_in) push_symbol = "%this"

edge @library.lexical_scope -> this
edge this -> this_built_in
edge this_built_in -> @library.parent_scope

; This is the connection point to resolve attached functions by `using for *`
node @library.star_extension
attr (@library.star_extension) push_symbol = "@*"
Expand Down Expand Up @@ -2387,9 +2362,7 @@ inherit .star_extension
}

;; Identifier expressions
@expr [Expression @name (
variant: [Identifier] | variant: [SuperKeyword] | variant: [ThisKeyword]
)] {
@expr [Expression @name [Identifier]] {
node ref
attr (ref) node_reference = @name
attr (ref) parents = [@expr.enclosing_def]
Expand All @@ -2398,6 +2371,14 @@ inherit .star_extension
edge @expr.output -> ref
}

@expr [Expression @keyword ([ThisKeyword] | [SuperKeyword])] {
; This is almost equivalent to the above rule, except it doesn't generate a reference
node keyword
attr (keyword) push_symbol = (source-text @keyword)
edge keyword -> @expr.lexical_scope
edge @expr.output -> keyword
}

;; Member access expressions
@expr [Expression [MemberAccessExpression
@operand operand: [Expression]
Expand Down
3 changes: 1 addition & 2 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7041,7 +7041,6 @@ codegen_language_macros::compile!(Language(
BuiltInVariable(definition = "$MessageType msg"),
BuiltInVariable(definition = "uint now", enabled = Till("0.7.0")),
BuiltInVariable(definition = "$StringType $string"),
BuiltInVariable(definition = "$TransactionType tx"),
BuiltInVariable(definition = "$ThisType $this")
BuiltInVariable(definition = "$TransactionType tx")
]
));

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ References and definitions:
│ │
│ ╰─── ref: built-in
9 │ uint256 v10 = address(this).balance;
│ ─┬─ ──┬─ ───┬───
│ ─┬─ ───┬───
│ ╰─────────────────────────── def: 12
│ │ │
│ ╰──────────── ref: 1
│ │
│ ╰───── ref: built-in
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ References and definitions:
│ │
│ ╰─── ref: built-in
9 │ uint256 v10 = address(this).balance;
│ ─┬─ ──┬─ ───┬───
│ ─┬─ ───┬───
│ ╰─────────────────────────── def: 12
│ │ │
│ ╰──────────── ref: 1
│ │
│ ╰───── ref: built-in
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ References and definitions:
│ ──┬─
│ ╰─── def: 2
3 │ bytes4 v1 = this.test.selector;
│ ─┬ ──┬─ ──┬─ ────┬───
│ ─┬ ──┬─ ────┬───
│ ╰─────────────────────── def: 3
│ │ │ │
│ ╰───────────────── ref: 1
│ │ │
│ ╰──────────── ref: 2
│ │
│ ╰───── unresolved
4 │ address v2 = this.test.address;
│ ─┬ ──┬─ ──┬─ ───┬───
│ ─┬ ──┬─ ───┬───
│ ╰────────────────────── def: 4
│ │ │ │
│ ╰──────────────── ref: 1
│ │ │
│ ╰─────────── ref: 2
│ │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ References and definitions:
│ ──┬─
│ ╰─── def: 2
3 │ bytes4 v1 = this.test.selector;
│ ─┬ ──┬─ ──┬─ ────┬───
│ ─┬ ──┬─ ────┬───
│ ╰─────────────────────── def: 3
│ │ │ │
│ ╰───────────────── ref: 1
│ │ │
│ ╰──────────── ref: 2
│ │
│ ╰───── ref: built-in
4 │ address v2 = this.test.address;
│ ─┬ ──┬─ ──┬─ ───┬───
│ ─┬ ──┬─ ───┬───
│ ╰────────────────────── def: 4
│ │ │ │
│ ╰──────────────── ref: 1
│ │ │
│ ╰─────────── ref: 2
│ │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ References and definitions:
│ ──┬─
│ ╰─── def: 2
3 │ bytes4 v1 = this.test.selector;
│ ─┬ ──┬─ ──┬─ ────┬───
│ ─┬ ──┬─ ────┬───
│ ╰─────────────────────── def: 3
│ │ │ │
│ ╰───────────────── ref: 1
│ │ │
│ ╰──────────── ref: 2
│ │
│ ╰───── ref: built-in
4 │ address v2 = this.test.address;
│ ─┬ ──┬─ ──┬─ ───┬───
│ ─┬ ──┬─ ───┬───
│ ╰────────────────────── def: 4
│ │ │ │
│ ╰──────────────── ref: 1
│ │ │
│ ╰─────────── ref: 2
│ │
Expand Down
Loading

0 comments on commit d5823c0

Please sign in to comment.