-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Conversation
42172bc
to
a632251
Compare
libsolidity/parsing/Parser.cpp
Outdated
); | ||
|
||
advance(); | ||
return parseExpression(); |
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.
I guess it should be something more specific, because expression will accept anything. Or is it fine?
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.
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.
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.
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.
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.
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.
test/libsolidity/syntaxTests/contractBaseLocation/contract_named_at.sol
Outdated
Show resolved
Hide resolved
fef6ff4
to
26bb5e5
Compare
26bb5e5
to
bf640be
Compare
bf640be
to
666b499
Compare
fb75168
to
2579486
Compare
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.
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.
f0f7997
to
2839eed
Compare
I just created #15727 in order to keep track of the tasks. |
7a42733
to
c2d5d9a
Compare
24a63fc
to
f4ddc29
Compare
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.
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.
test/cmdlineTests/inheritance_repeated_definition_error/input.json
Outdated
Show resolved
Hide resolved
test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_binary_expression.sol
Show resolved
Hide resolved
test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_binary_expression.sol
Show resolved
Hide resolved
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.
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).
test/libsolidity/syntaxTests/storageLayoutSpecifier/struct_layout_specificier.sol
Outdated
Show resolved
Hide resolved
test/cmdlineTests/ast_compact_json_storage_layout_specifier/input.sol
Outdated
Show resolved
Hide resolved
"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. | ||
", |
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.
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:
solidity/solc/CommandLineInterface.cpp
Lines 981 to 996 in 868154c
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.
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.
Done.
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.
Please remember to add it to the issue though.
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.
Added already.
test/cmdlineTests/ast_compact_json_storage_layout_specifier/args
Outdated
Show resolved
Hide resolved
test/cmdlineTests/storage_layout_specifier_repeated_definition_error/output.json
Outdated
Show resolved
Hide resolved
3cb10d4
to
205c8d5
Compare
@@ -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 |
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.
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.
@cameel , I think I addressed all of your comments. |
01579e0
to
98e108c
Compare
test/libsolidity/syntaxTests/storageLayoutSpecifier/natspec.sol
Outdated
Show resolved
Hide resolved
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.
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.
test/cmdlineTests/storage_layout_specifier_storage_layout_output_error/input.json
Outdated
Show resolved
Hide resolved
test/libsolidity/syntaxTests/storageLayoutSpecifier/library.sol
Outdated
Show resolved
Hide resolved
6a781f6
to
8db609a
Compare
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.
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.
92a5f87
to
4a00499
Compare
4a00499
to
e844a8b
Compare
First step for #597/#15727.