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

Catch unimplementedFeatureErrors and report them as errors #15168

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

matheusaaguiar
Copy link
Collaborator

First attempt on partially closing #15139.
This is focusing on making #15001 pass our CI tests and hopefully will serve as a base for future tasks of the issue mentioned before.

@matheusaaguiar matheusaaguiar self-assigned this May 31, 2024
@matheusaaguiar matheusaaguiar force-pushed the catchSolUnimplementedFeatureErrors branch from 0ae72b2 to fd86f5b Compare June 2, 2024 14:37
@ethereum ethereum deleted a comment from stackenbotten Jun 2, 2024
@matheusaaguiar matheusaaguiar marked this pull request as ready for review June 3, 2024 14:49
@matheusaaguiar matheusaaguiar force-pushed the catchSolUnimplementedFeatureErrors branch from 345b55e to 2e99c16 Compare June 4, 2024 17:39
@ethereum ethereum deleted a comment from stackenbotten Jun 4, 2024
@matheusaaguiar matheusaaguiar changed the title Catch solUnimplementedFeatureErrors and report them as errors Catch unimplementedFeatureErrors and report them as errors Jun 4, 2024
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.

That one was really tough to review. Not because of what the PR itself does but because the way error handling is done in the compiler is just too messy, inconsistent and slightly wrong in many annoying ways. I had a really hard time giving suggestions here on how to do it properly without just saying to rewrite it all :)

In any case, this needs some changes, but the fundamental approach is good. I like the idea of making parse(), analyze() and compile() responsible for catching unimplemented feature errors rather than doing it outside.

I'd actually move even more handlers in there (e.g. YulException and CompilerError should IMO be handled inside compile()), but that's out of the scope of the PR so let's not do that here. But overall, I think that all exceptions that are considered a normal part of the compiler operation and are not a result of a bug should be handled inside the respective "stack" class. Everything else that escapes should then just bubble up to the top-level handler.

test/libsolidity/SyntaxTest.cpp Outdated Show resolved Hide resolved
libsolidity/interface/CompilerStack.cpp Outdated Show resolved Hide resolved
libsolidity/interface/StandardCompiler.cpp Outdated Show resolved Hide resolved
libsolidity/interface/StandardCompiler.cpp Outdated Show resolved Hide resolved
solc/CommandLineInterface.cpp Outdated Show resolved Hide resolved
@matheusaaguiar matheusaaguiar force-pushed the catchSolUnimplementedFeatureErrors branch from 44750e3 to a68961d Compare June 13, 2024 02:04
@ethereum ethereum deleted a comment from stackenbotten Jun 13, 2024
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.

Still a few things to clean up.

libsolidity/interface/CompilerStack.cpp Outdated Show resolved Hide resolved
libsolidity/interface/StandardCompiler.cpp Outdated Show resolved Hide resolved
libyul/YulStack.cpp Outdated Show resolved Hide resolved
reportUnimplementedFeatureError(_error);
}

if (m_errorReporter.errors().empty())
Copy link
Member

@cameel cameel Jun 14, 2024

Choose a reason for hiding this comment

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

Suggested change
if (m_errorReporter.errors().empty())
if (!m_errorReporter.hasErrors())

Oh, this is actually a minor bug (not in the PR - it was here already). Checking errors().empty() will count warnings and infos as errors, which is wrong - those should not fail compilatiohn. Turns out we don't have any warnings in Yul parser though, which is probably why it went unnoticed, but we should fix it nevertheless.

I see there are overall 16 uses of errors().empty() in the codebase and some of them might be intended but some look like bugs. Maybe it would be better to fix them in a separate PR. At least this one had no user-visible effects (and the fix does not require a changelog entry) but others might have.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Member

Choose a reason for hiding this comment

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

This is something you should at least put in a separate commit with its own description. It shouldn't be mixed in with other, unrelated changes, especially in a refactor like this. Like I said, I'd even go as far as to leave it as is here and only fix it in a separate PR along with the other instances.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah right, I was thinking about checking the other cases later in another PR. I removed this change and will leave it for this future PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PR created.

test/libsolidity/SyntaxTest.cpp Outdated Show resolved Hide resolved
@cameel
Copy link
Member

cameel commented Jun 14, 2024

Two more things:

  • You should wrap YulStack::optimize() in a handler too.
  • This needs a changelog entry. It's either a bugfix or a minor compiler feature: unimplemented features are now properly reported as errors instead of being handled as if they were bugs.

Copy link
Collaborator Author

@matheusaaguiar matheusaaguiar left a comment

Choose a reason for hiding this comment

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

@cameel, I added a changelog and addressed your comments.

You should wrap YulStack::optimize() in a handler too.

It was already wrapped... or are you referring to YulStack::optimize(Object& _object, bool _isCreation) ? This latter one is private and only called by YulStack::optimize().

Changelog.md Show resolved Hide resolved
@cameel
Copy link
Member

cameel commented Jun 17, 2024

You should wrap YulStack::optimize() in a handler too.

It was already wrapped... or are you referring to YulStack::optimize(Object& _object, bool _isCreation) ? This latter one is private and only called by YulStack::optimize().

Ah, you're right! I completely forgot that we decided to do this in the top-level optimize() because this one is recursive.

cameel
cameel previously approved these changes Jun 17, 2024
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.

There are two remaining things to resolve, but they're minor enough that I'm already approving the PR as a whole.

libyul/YulStack.cpp Outdated Show resolved Hide resolved
reportUnimplementedFeatureError(_error);
}

if (m_errorReporter.errors().empty())
Copy link
Member

Choose a reason for hiding this comment

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

This is something you should at least put in a separate commit with its own description. It shouldn't be mixed in with other, unrelated changes, especially in a refactor like this. Like I said, I'd even go as far as to leave it as is here and only fix it in a separate PR along with the other instances.

@matheusaaguiar matheusaaguiar force-pushed the catchSolUnimplementedFeatureErrors branch from 97c9383 to bb16848 Compare June 17, 2024 13:24
@matheusaaguiar
Copy link
Collaborator Author

@cameel, I addressed your last review and squashed the commits.
Please approve again.

@cameel cameel merged commit 7f25267 into develop Jun 17, 2024
72 checks passed
@cameel cameel deleted the catchSolUnimplementedFeatureErrors branch June 17, 2024 18:00
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.

None yet

2 participants