Skip to content

Parser support for explicit storage locations #15463

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

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

matheusaaguiar
Copy link
Collaborator

@matheusaaguiar matheusaaguiar commented Sep 28, 2024

First step for #597/#15727.

@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 42172bc to a632251 Compare September 28, 2024 19:59
@matheusaaguiar matheusaaguiar self-assigned this Sep 28, 2024
);

advance();
return parseExpression();
Copy link
Collaborator Author

@matheusaaguiar matheusaaguiar Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it should be something more specific, because expression will accept anything. Or is it fine?

Copy link
Member

@r0qs r0qs Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I also believe that we should have something more specific. If I recall correctly, it must be a constant expression that can be evaluate at compile-time. So maybe we should have a new parse function that is restricted to TokenTraits::isArithmeticOp, Literals and the erc7201 helper only.

Copy link
Collaborator Author

@matheusaaguiar matheusaaguiar Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming that we will check those kind of things later (constant, compile-time eval, etc) at type checking phase.
I am worried about parsing something weird (like a function declaration or a nested contract declaration), but I think I should look more closely to the behaviour of parseExpression to get a better feeling for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing arbitrary expressions here and then rejecting complex expressions later (in type checking or even already in syntax checking) seems fine to me.
Might be valuable to quickly confirm that there's no really pathological weird cases that may arise because of it, but I don't anticipate any out of my head.

@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from fef6ff4 to 26bb5e5 Compare October 14, 2024 13:16
@matheusaaguiar matheusaaguiar marked this pull request as ready for review October 14, 2024 18:34
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 26bb5e5 to bf640be Compare October 21, 2024 01:32
@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Nov 14, 2024
@matheusaaguiar matheusaaguiar removed the stale The issue/PR was marked as stale because it has been open for too long. label Nov 15, 2024
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from bf640be to 666b499 Compare November 21, 2024 13:57
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from fb75168 to 2579486 Compare December 3, 2024 17:11
@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Dec 18, 2024
@github-actions github-actions bot closed this Dec 26, 2024
@matheusaaguiar matheusaaguiar removed stale The issue/PR was marked as stale because it has been open for too long. closed-due-inactivity labels Dec 26, 2024
@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Jan 10, 2025
@nikola-matic nikola-matic removed the stale The issue/PR was marked as stale because it has been open for too long. label Jan 10, 2025
Copy link
Collaborator

@nikola-matic nikola-matic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First step for #597.

Do we have another issue detailing the actual steps? I.e. syntax/parsing (this), type checking/analysis, code gen, docs, etc.?

Otherwise, this particular PR looks good, you seem to have covered all of the edge cases I could think of.

@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch 3 times, most recently from f0f7997 to 2839eed Compare January 17, 2025 15:16
@matheusaaguiar
Copy link
Collaborator Author

Do we have another issue detailing the actual steps? I.e. syntax/parsing (this), type checking/analysis, code gen, docs, etc.?

I just created #15727 in order to keep track of the tasks.

@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 7a42733 to c2d5d9a Compare January 28, 2025 03:46
@ethereum ethereum deleted a comment from github-actions bot Jan 31, 2025
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch 4 times, most recently from 24a63fc to f4ddc29 Compare February 6, 2025 21:16
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm done with the review. The biggest problem I found is that the parser will set the location wrong for multi-token expressions.

Other than that only minor stuff: missing sanity checks, naming (especially in AST export), smart vs naked ptrs, etc.

And of course could use a few more tests. Especially one showing the AST structure.

Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location of the layout specifier produced by the parser still seems a bit off (it now overlaps the inheritance specifier).

Also some test corrections are still needed (we don't want to test ICE output; unimplemented feature errors need coverage too; use ASTJSON tests).

Comment on lines 5 to 9
"formattedMessage": "Unknown exception during compilation: /solidity/libsolidity/interface/StandardCompiler.cpp(1383): Throw in function solidity::Json solidity::frontend::StandardCompiler::compileSolidity(InputsAndSettings)
Dynamic exception type: boost::wrapexcept<solidity::util::Exception>
std::exception::what: Failed to import AST: Expected field 'baseSlotExpression' is missing.
[solidity::util::tag_comment*] = Failed to import AST: Expected field 'baseSlotExpression' is missing.
",
Copy link
Member

@cameel cameel Feb 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, so we're not even handling those AST asserts in Standard JSON mode? Let's replace it with a test that uses the CLI interface, the ICE output is not meant to be tested. It's not portable between platforms. This is why t_osx_cli is failing.

Also please mention in #15854 that currently only the CommandLineInterface catches the exceptions in any way:

try
{
m_compiler->importASTs(parseAstFromInput());
if (!m_compiler->analyze())
{
formatter.printErrorInformation(m_compiler->errors());
astAssert(false, "Analysis of the AST failed");
}
}
catch (Exception const& _exc)
{
// FIXME: AST import is missing proper validations. This hack catches failing
// assertions and presents them as if they were compiler errors.
solThrow(CommandLineExecutionError, "Failed to import AST: "s + _exc.what());
}

StandardCompiler does not, which makes it non-testable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remember to add it to the issue though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added already.

@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch 2 times, most recently from 3cb10d4 to 205c8d5 Compare February 17, 2025 23:21
@@ -379,7 +384,7 @@ expression:
expression LBrack index=expression? RBrack # IndexAccess
| expression LBrack startIndex=expression? Colon endIndex=expression? RBrack # IndexRangeAccess
| expression Period (identifier | Address) # MemberAccess
| expression LBrace (namedArgument (Comma namedArgument)*)? RBrace # FunctionCallOptions
| expression LBrace (namedArgument (Comma namedArgument)*) RBrace # FunctionCallOptions
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the PR, but it was inconsistent with the compiler parser.
I added test/libsolidity/syntaxTests/functionCalls/empty_call_options.sol which would be accepted by the grammar before this change.

@matheusaaguiar
Copy link
Collaborator Author

@cameel , I think I addressed all of your comments.

@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 01579e0 to 98e108c Compare February 18, 2025 05:19
cameel
cameel previously approved these changes Feb 19, 2025
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine in terms of functionality so approving. You may want to clean up the things pointed out by @nikola-matic though.

Also, would be nice to replace the Standard JSON tests with ones using CLI. The current ones work, but are much more verbose than they really need to be. Especially when testing secondary source locations, you really care only about the error and not all the noisy JSON details.

Copy link
Collaborator

@nikola-matic nikola-matic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say merging this (after squashing) would be best; if there are any small issues, we'll likely notice them in the analysis and codegen PRs, so no need to delay this one.

@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 92a5f87 to 4a00499 Compare February 20, 2025 14:59
@cameel cameel force-pushed the storageLocationsParserSupport branch from 4a00499 to e844a8b Compare February 24, 2025 10:03
@ekpyron ekpyron merged commit cc6422b into develop Feb 24, 2025
74 checks passed
@ekpyron ekpyron deleted the storageLocationsParserSupport branch February 24, 2025 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

5 participants