Skip to content
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

Parser support for explicit storage locations #15463

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

matheusaaguiar
Copy link
Collaborator

First step for #597.

@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
@@ -591,6 +593,7 @@ class ContractDefinition: public Declaration, public StructurallyDocumented, pub
std::vector<ASTPointer<ASTNode>> m_subNodes;
ContractKind m_contractKind;
bool m_abstract{false};
ASTPointer<Expression> m_storageBaseLocationExpression;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we create a dedicated AST node for it?

Copy link
Member

Choose a reason for hiding this comment

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

We'll likely allow more and more expressions in the future - just packing it into an expression seems fine to me.
We can still promote it to a full AST node, once we add more complex layout specifiers.

);

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
Copy link

This pull request is stale because it has been open for 14 days with no activity.
It will be closed in 7 days unless the stale label is removed.

@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
Copy link

This pull request is stale because it has been open for 14 days with no activity.
It will be closed in 7 days unless the stale label is removed.

@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
Copy link

This pull request was closed due to a lack of activity for 7 days after it was stale.

@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
Copy link

This pull request is stale because it has been open for 14 days with no activity.
It will be closed in 7 days unless the stale label is removed.

@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.

m_errorReporter.parserError(
6668_error,
m_scanner->currentLocation(),
SecondarySourceLocation().append("First inheritance definition is here", baseContracts[0]->location()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this actually output anywhere? I can't see the secondary source location messages anywhere in the tests (not just for this particular one, but all of them in general).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They appear in the CLI, not sure if they do in the JSON output.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, weird, I did a bit of grepping around and didn't see any occurrences in the tests, but I might be mistaken.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I hadn't added any cmdline tests, so the secondary source location/error message was not showing.
I added two more tests covering this case (inheritance) and the repetead base location definition.

Changelog.md Outdated Show resolved Hide resolved
@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.

libsolidity/ast/AST.h Outdated Show resolved Hide resolved
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 7a42733 to c2d5d9a Compare January 28, 2025 03:46
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.

4 participants