Skip to content

Yul identifiers accept dots #16047

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
DaniPopes opened this issue May 13, 2025 · 7 comments · May be fixed by #16051
Open

Yul identifiers accept dots #16047

DaniPopes opened this issue May 13, 2025 · 7 comments · May be fixed by #16051
Assignees
Labels
documentation 📖 low effort There is not much implementation work to be done. The task is very easy or tiny. low impact Changes are not very noticeable or potential benefits are limited. must have eventually Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.

Comments

@DaniPopes
Copy link
Contributor

I can declare identifiers in Yul with dots, but this is not documented in the grammar

let a.b := 0
mstore(a.b, a.b)
@cameel
Copy link
Member

cameel commented May 14, 2025

We're planning to disallow that soon. See #15540 (comment) for context.

@cameel cameel closed this as completed May 14, 2025
@cameel
Copy link
Member

cameel commented May 14, 2025

Actually, wait. #15540 is only about object names. For arbitrary identifiers we actually do need dots (e.g. x.slot and x.offset are identifiers). So it's more of a documentation issue.

@cameel cameel reopened this May 14, 2025
@cameel cameel added documentation 📖 low effort There is not much implementation work to be done. The task is very easy or tiny. low impact Changes are not very noticeable or potential benefits are limited. must have eventually Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it. and removed bug 🐛 labels May 14, 2025
@cameel
Copy link
Member

cameel commented May 14, 2025

It actually is documented, in multiple places.

Yul > Syntax

There is one exception: Identifiers in Yul can contain dots: ..

Language Grammar > YulIdentifier

Yul identifiers consist of letters, dollar signs, underscores and numbers, but may not start with a number. In inline assembly there cannot be dots in user-defined identifiers. Instead see yulPath for expressions consisting of identifiers with dots.

Solidity v0.7.0 Breaking Changes > Inline Assembly

  • Disallow . in user-defined function and variable names in inline assembly. It is still valid if you use Solidity in Yul-only mode.

Though looks like we don't mention it under Inline Assembly. We should add it there as well.

Also note that Language Grammar reflects Solidity grammar. The one for pure Yul is under Yul > Specification of Yul.

@cameel
Copy link
Member

cameel commented May 14, 2025

Actually, it's already on the Inline Assembly page as well:

Since Solidity 0.7.0, variables and functions declared inside the
inline assembly block may not contain ., but using . is
valid to access Solidity variables from outside the inline assembly block.

@DaniPopes
Copy link
Contributor Author

The language grammar specifies yul-variable-declaration: let yul-identifier := ..., yul-identifier = [a-zA-Z$_][a-zA-Z0-9$_]* so it's mismatched with the description or with uses of this rule; also dotted identifier paths are apparently treated as single identifiers AFAICT in the source code.

@matheusaaguiar
Copy link
Collaborator

The Solidity grammar for yul identifiers states that In inline assembly there cannot be dots in user-defined identifiers.

Yul identifiers consist of letters, dollar signs, underscores and numbers, but may not start with a number. In inline assembly there cannot be dots in user-defined identifiers. Instead see yulPath for expressions consisting of identifiers with dot

The Yul specification defines an identifier with the rule Identifier = [a-zA-Z_$] [a-zA-Z_$0-9.]*, i.e, dots are accepted.

So, to be clear, in Solidity, yul code, which can only appear inside inline assembly blocks, doesn't accept dots in user-defined identifiers, albeit it accepts dots if they are referencing variables outside the scope of the block (such as .slot or .offset for storage variables). On the other hand, pure Yul code accepts dots in identifiers, regardless if they are user-defined or not.

Examples:
Solidity doesn't accept dots in user-defined identifiers:

contract A {
    function f() public pure returns (uint x) {
        assembly {
                let z.a := mload(0)
                x := z.a
        }
    }
}

Error: User-defined identifiers in inline assembly cannot contain '.'.

Pure Yul does accept dots in user-defined identifiers:

{
    let z.a := mload(0)
    let x.y.z := add(z.a, 0x2A)
    mstore(z.a, x.y.z)
}

Pretty printed source:
object "object" {
code {
{
let z.a := mload(0)
let x.y.z := add(z.a, 0x2A)
mstore(z.a, x.y.z)
}
}
}
Binary representation:
5f51602a8101905200
Text representation:
/* "test.yul":68:69 /
0x00
/
"test.yul":62:70 /
mload
/
"test.yul":105:109 /
0x2a
/
"test.yul":96:110 /
dup2
add
/
"test.yul":123:141 /
swap1
mstore
/
"test.yul":27:157 */
stop

@matheusaaguiar
Copy link
Collaborator

also dotted identifier paths are apparently treated as single identifiers AFAICT in the source code.

Only in Yul mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation 📖 low effort There is not much implementation work to be done. The task is very easy or tiny. low impact Changes are not very noticeable or potential benefits are limited. must have eventually Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.
Projects
None yet
3 participants