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

Accept empty optimizer sequence with Yul optimizer disabled #14657

Conversation

nikola-matic
Copy link
Collaborator

@nikola-matic nikola-matic commented Oct 30, 2023

Fixes: #14621

@nikola-matic nikola-matic added this to the 0.8.23 milestone Oct 30, 2023
@nikola-matic nikola-matic self-assigned this Oct 30, 2023
@nikola-matic nikola-matic force-pushed the accept-empty-optimizer-sequence-with-yul-optimizer-disabled branch 3 times, most recently from e183552 to 100474a Compare October 31, 2023 10:56
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.

Seems correct in terms of logic. Still needs a changelog entry and docs.

And can be simplified in many ways - see my comments below.

solc/CommandLineParser.h Outdated Show resolved Hide resolved
solc/CommandLineParser.cpp Outdated Show resolved Hide resolved
libsolidity/interface/StandardCompiler.cpp Outdated Show resolved Hide resolved
libsolidity/interface/StandardCompiler.cpp Outdated Show resolved Hide resolved
libsolidity/interface/StandardCompiler.cpp Outdated Show resolved Hide resolved
libyul/YulStack.cpp Show resolved Hide resolved
@nikola-matic nikola-matic force-pushed the accept-empty-optimizer-sequence-with-yul-optimizer-disabled branch 3 times, most recently from d778c59 to b44e88d Compare November 2, 2023 14:47
libsolidity/interface/StandardCompiler.cpp Outdated Show resolved Hide resolved
libyul/YulStack.cpp Show resolved Hide resolved
libyul/YulStack.cpp Show resolved Hide resolved
docs/internals/optimizer.rst Outdated Show resolved Hide resolved
@nikola-matic nikola-matic force-pushed the accept-empty-optimizer-sequence-with-yul-optimizer-disabled branch 2 times, most recently from 0a35d7f to 4b646b3 Compare November 2, 2023 19:46
@nikola-matic nikola-matic marked this pull request as ready for review November 3, 2023 08:49
cameel
cameel previously approved these changes Nov 3, 2023
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 still things we could improve but nothing so horrible that it would prevent us from shipping this :)

@nikola-matic nikola-matic force-pushed the accept-empty-optimizer-sequence-with-yul-optimizer-disabled branch 2 times, most recently from 69eecc1 to 5855731 Compare November 5, 2023 11:58
@nikola-matic nikola-matic requested a review from cameel November 5, 2023 12:35
Comment on lines +387 to +403
{
size_t delimiterCount{0};
for (char const step: _sequence)
switch (step)
{
case ':':
if (++delimiterCount > 1)
return false;
break;
case ' ':
case '\n':
break;
default:
return false;
}
return true;
}
Copy link
Member

@ekpyron ekpyron Nov 6, 2023

Choose a reason for hiding this comment

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

I mean, I'm very much fine with leaving this as is - but given that I think I even already saw some discussion in the channel around this on the side, I can't help but wonder: why the special handling of different counts of colons in here and all the fuzz (the sequence will separately be validated and arguably it even makes more sense to treat "::" as empty but malformed rather than as non-empty...)?

This could just be (inline):

Suggested change
{
size_t delimiterCount{0};
for (char const step: _sequence)
switch (step)
{
case ':':
if (++delimiterCount > 1)
return false;
break;
case ' ':
case '\n':
break;
default:
return false;
}
return true;
}
{
return ranges::any_of(_sequence, [](auto _step) { return _step != ':' && _step != ' ' && _step != '\n'; });
}

in one case - and in the second case for standard json even simpler...

@ekpyron
Copy link
Member

ekpyron commented Nov 6, 2023

Without looking through this fully: how exactly does this bypass the fact that we don't enter the sequence to metadata if runYulOptimiser is false? I'd expect to see some change accounting for that (i.e. in CompilerStack::createMetadata), but I don't on a quick glance.

{
if (_details.isMember(_name))
{
if (_details[_name].isString())
{
std::string const fullSequence = _details[_name].asString();
if (!_runYulOptimizer && !OptimiserSuite::isEmptyOptimizerSequence(fullSequence))
return formatFatalError(Error::Type::JSONError, "If Yul optimizer is disabled, only an empty optimizerSteps sequence is accepted.");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return formatFatalError(Error::Type::JSONError, "If Yul optimizer is disabled, only an empty optimizerSteps sequence is accepted.");
return formatFatalError(Error::Type::JSONError, "When Yul optimizer is disabled, only an empty optimizerSteps sequence is accepted.");

libsolidity/interface/StandardCompiler.cpp Show resolved Hide resolved
libyul/optimiser/Suite.cpp Show resolved Hide resolved
libyul/YulStack.cpp Show resolved Hide resolved
@nikola-matic nikola-matic force-pushed the accept-empty-optimizer-sequence-with-yul-optimizer-disabled branch from 10136ff to 1cbcc8e Compare November 6, 2023 16:19
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.

Without looking through this fully: how exactly does this bypass the fact that we don't enter the sequence to metadata if runYulOptimiser is false? I'd expect to see some change accounting for that (i.e. in CompilerStack::createMetadata), but I don't on a quick glance.

Right, good catch, it doesn't. createMetadata() will skip the sequence when runYulOptimiser is false and this will result in metadata not recreating the bytecode. This needs to be fixed before we can merge the PR.

libsolidity/interface/StandardCompiler.cpp Show resolved Hide resolved
libyul/YulStack.cpp Show resolved Hide resolved
@nikola-matic
Copy link
Collaborator Author

Without looking through this fully: how exactly does this bypass the fact that we don't enter the sequence to metadata if runYulOptimiser is false? I'd expect to see some change accounting for that (i.e. in CompilerStack::createMetadata), but I don't on a quick glance.

Right, good catch, it doesn't. createMetadata() will skip the sequence when runYulOptimiser is false and this will result in metadata not recreating the bytecode. This needs to be fixed before we can merge the PR.

This was implemented this morning though.

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.

Needs some asserts. Other than that seems good.

This was implemented this morning though.

An, right. Somehow I missed that when I skimmed though the PR and thought the changes were not applied yet.

Comment on lines 1677 to 1678
else if
(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
else if
(
else if(

libsolidity/interface/CompilerStack.cpp Outdated Show resolved Hide resolved
Whitespace and newline validation for empty sequence

Changelog and docs

Kamil

Revert "fixup! Accept empty optimizer sequence with Yul optimizer disabled"

This reverts commit 1cbcc8e.
@nikola-matic nikola-matic force-pushed the accept-empty-optimizer-sequence-with-yul-optimizer-disabled branch from f0618dc to d899d9c Compare November 7, 2023 14:19
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.

Accept empty optimizer sequence even with Yul optimizer disabled
4 participants