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

Type checking for contract explicit storage base location #15528

Merged
merged 3 commits into from
Feb 26, 2025

Conversation

matheusaaguiar
Copy link
Collaborator

@matheusaaguiar matheusaaguiar commented Oct 21, 2024

@matheusaaguiar matheusaaguiar self-assigned this Oct 21, 2024
@matheusaaguiar matheusaaguiar changed the base branch from develop to storageLocationsParserSupport October 21, 2024 13:08
@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 5, 2024
@matheusaaguiar matheusaaguiar removed the stale The issue/PR was marked as stale because it has been open for too long. label Nov 8, 2024
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from bf640be to 666b499 Compare November 21, 2024 13:57
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch from d3cd13a to 5645314 Compare November 21, 2024 14:25
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from fb75168 to 2579486 Compare December 3, 2024 17:11
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch from 038b819 to 7f4eb69 Compare December 3, 2024 17:14
@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 25, 2024
@matheusaaguiar matheusaaguiar removed the stale The issue/PR was marked as stale because it has been open for too long. label 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
@matheusaaguiar matheusaaguiar removed the stale The issue/PR was marked as stale because it has been open for too long. label Jan 10, 2025
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 07f289c to 6b34e90 Compare January 13, 2025 17:52
@ethereum ethereum deleted a comment from stackenbotten Jan 13, 2025
@ethereum ethereum deleted a comment from stackenbotten Jan 13, 2025
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch from 82b5fec to 54451ed Compare January 13, 2025 19:04
@matheusaaguiar matheusaaguiar marked this pull request as ready for review January 13, 2025 19:04
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 6b34e90 to f0f7997 Compare January 17, 2025 15:14
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch from ff0c30b to f7f90be Compare January 17, 2025 15:14
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from f0f7997 to 2839eed Compare January 17, 2025 15:16
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch from f7f90be to 7473a01 Compare January 17, 2025 15:16
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 7a42733 to c2d5d9a Compare January 28, 2025 03:46
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch from 6257c02 to 9acfb2d Compare January 28, 2025 04:30
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 68f5886 to abca45e Compare January 28, 2025 23:11
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch from 7a1d6b2 to 6f29b3c Compare January 28, 2025 23:13
@cameel cameel added the has dependencies The PR depends on other PRs that must be merged first label Jan 31, 2025
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch 2 times, most recently from 785c28f to 5ba5933 Compare February 18, 2025 05:26
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 6a781f6 to 8db609a Compare February 19, 2025 18:54
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch from 155eb51 to 912e61c Compare February 20, 2025 03:00
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsParserSupport branch from 92a5f87 to 4a00499 Compare February 20, 2025 14:59
@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch 2 times, most recently from 54dab60 to 83cdafa Compare February 21, 2025 19:33
@cameel cameel force-pushed the storageLocationsParserSupport branch from 4a00499 to e844a8b Compare February 24, 2025 10:03
@cameel cameel force-pushed the storageLocationsTypeChecking branch from 83cdafa to 141de94 Compare February 24, 2025 10:10
Base automatically changed from storageLocationsParserSupport to develop February 24, 2025 12:56
@cameel cameel force-pushed the storageLocationsTypeChecking branch from 141de94 to 424ab79 Compare February 24, 2025 13:18
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 have just one suggestion on how to make the error reporting less annoying. It's not critical to the PR and everything else seems to have been addressed to I'm approving regardless of that. It's simple to fix so I think we should still do that though.

There were a few minor things in tests/messages that still needed some adjustment/cleanup but I decided to just push them as fixups to avoid stalling the PR. Please take a look and squash if you accept them.

Comment on lines +124 to +132
m_errorReporter.typeError(
8894_error,
_contract.location(),
SecondarySourceLocation().append(
"Storage layout was already specified here.",
ancestorContract->storageLayoutSpecifier()->location()
),
"Storage layout can only be specified in the most derived contract."
);
Copy link
Member

@cameel cameel Feb 24, 2025

Choose a reason for hiding this comment

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

Looking at test output, the errors generated by this may be a bit annoying. It reports an error for every specifier in the hierarchy of every contract, which may be a lot. Consider this example:

contract A      layout at 1 {}
contract B is A layout at 2 {}

contract C1 is B {}
contract C2 is A, B {}
contract C3 is B {}

contract D1 is C1 {}
contract D2 is C2 {}
contract D3 is C3 {}

You'll get 13 error messages here. I think it would be more useful to only report an error when a contract directly inherits from one with a layout specifier. The point where a fix needs to be applied is unlikely to be far from the specifier. It's either the specifier itself being applied to the wrong contract (secondary messages already point at this) or the first contract that inherits from it (that's what the primary message should point at). This would reduce the number of messages here to 5.

This should be very easy to implement simply by iterating over baseContracts() rather than the whole annotation().linearizedBaseContract. We could then point at the exact inheritance specifier that triggered the error rather than whole contract definition (baseContracts() contains specifiers rather than contract definitions, and we can easily report their locations).

We should also have the above as a test case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in #15900.

@clonker clonker removed the has dependencies The PR depends on other PRs that must be merged first label Feb 24, 2025
@cameel cameel force-pushed the storageLocationsTypeChecking branch from 424ab79 to 5224672 Compare February 24, 2025 13:28
@cameel
Copy link
Member

cameel commented Feb 24, 2025

As discussed on the call, we can just merge this and do #15528 (comment) as a separate PR on top.

Please remember to squash the fixups though :)

@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch 2 times, most recently from 466dcb9 to 28bb6bf Compare February 24, 2025 15:38
@cameel
Copy link
Member

cameel commented Feb 24, 2025

I see you squashed it all into one commit :) No need to go that extreme, I left it in a state that would nicely autosquash into 3 clean commits without conflicts and with test additions being done first and the effect of code changes visible separately. That's generally a structure that I'd recommend and much prefer over it being smooshed together. Can you restore that version?

@matheusaaguiar matheusaaguiar force-pushed the storageLocationsTypeChecking branch from 28bb6bf to 7ef0ef8 Compare February 24, 2025 18:23
@ekpyron ekpyron merged commit a7e6cb5 into develop Feb 26, 2025
74 checks passed
@ekpyron ekpyron deleted the storageLocationsTypeChecking branch February 26, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants