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

Fix custom cleanup sequence missing from metadata when other optimizer settings have default values #15859

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

Conversation

clonker
Copy link
Member

@clonker clonker commented Feb 13, 2025

Extracted from PR #15834, see #15834 (comment).

The previous implementation did not make use of the yulOptimiserCleanupSteps. As @cameel suspected, providing a custom cleanup sequence under the default optimization sequence previously simply yielded a "optimizer": "enabled":true, "runs": 200} which potentially (or: most likely) doesn't reproduce the original compilation results.

I think it is a bit mitigated by there not being a specific field for the cleanup sequence in the standard-json input but one would rather have to reproduce the entire default optimization sequence, add a colon, and then modify the cleanup sequence.

@cameel
Copy link
Member

cameel commented Feb 13, 2025

This needs a changelog entry and a regression test that reproduces it.

Also, pinging @kuzdogan. Sourcify may need a workaround for this.

We should check which versions are affected (I guess it was introduced along with the cleanup sequence?).

@cameel cameel changed the title Default comparison operators for frontend optimiser settings Fix custom cleanup sequence missing from metadata when other optimizer settings have default values Feb 13, 2025
@clonker clonker force-pushed the fix_comparison_operators_for_optimizer_settings branch from 7aaf41b to cc03b19 Compare February 13, 2025 14:13
@clonker
Copy link
Member Author

clonker commented Feb 13, 2025

We should check which versions are affected (I guess it was introduced along with the cleanup sequence?).

The setting was introduced in v0.8.18 (including it not being part of operator==, PR #13376).
But actually the bug first occurs in v0.8.26 - probably due to some refactoring in correspondence to the metadata output of the optimization settings and in that, relying on the bad comparison operators. I initially failed to take into account that the default sequence changed. It is indeed broken since it has been introduced in v0.8.18.

@clonker clonker force-pushed the fix_comparison_operators_for_optimizer_settings branch 2 times, most recently from 8e704f5 to c1c10ac Compare February 13, 2025 15:19
"yulDetails": {
// default optimization sequence with a custom (truncated) cleanup sequence.
// 0.8.18 - 0.8.28 this would spuriously be interpreted as defaulted optimizer settings in metadata.
"optimizerSteps": "dhfoDgvulfnTUtnIf[xa[r]EscLMcCTUtTOntnfDIulLculVcul [j]Tpeulxa[rul]xa[r]cLgvifCTUca[r]LSsTFOtfDnca[r]Iulc]jmul[jul] VcTOcul jmul:D"
Copy link
Member Author

@clonker clonker Feb 13, 2025

Choose a reason for hiding this comment

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

I don't like this test so much actually. We won't regress if the default sequence changes at some point and it goes unnoticed to update it here as well. Something more elaborate would be first asserting that with the correct sequence it does produce default output and then truncating it in one of these ~-prefixed tests...

Copy link
Member

Choose a reason for hiding this comment

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

Another option would be to add this case to boost-based metadata tests:

std::vector<std::tuple<std::string, std::string>> sequences =
{
// {"<optimizer sequence>", "<optimizer cleanup sequence>"}
{"", ""},
{"", "fDn"},
{"dhfoDgvulfnTUtnIf", "" },
{"dhfoDgvulfnTUtnIf", "fDn"}
};

There you can refer to OptimiserSettings and the default sequence without hard-coding it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice, yeah, much better! I had to refactor it a bit because it was testing against minimal settings plus yul optimizations which was already caught by the old comparison operator. For the regression to kick in, I now take standard settings and modify only the cleanup sequence.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's just make it loop over all presets (OptimisationPreset)? This bug shows that we can't really assume that this is completely independent of other settings so this would give us a bit more coverage and also make the test more regular.

For completness, we should also have a test that non-default main sequence and default cleanup works.

We also don't really test that minimal translates to just enabled: false, standard to enabled: false and other presets to different things and we should.

Copy link
Member Author

Choose a reason for hiding this comment

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

Increased the coverage accordingly.

Changelog.md Outdated Show resolved Hide resolved
"yulDetails": {
// default optimization sequence with a custom (truncated) cleanup sequence.
// 0.8.18 - 0.8.28 this would spuriously be interpreted as defaulted optimizer settings in metadata.
"optimizerSteps": "dhfoDgvulfnTUtnIf[xa[r]EscLMcCTUtTOntnfDIulLculVcul [j]Tpeulxa[rul]xa[r]cLgvifCTUca[r]LSsTFOtfDnca[r]Iulc]jmul[jul] VcTOcul jmul:D"
Copy link
Member

Choose a reason for hiding this comment

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

Another option would be to add this case to boost-based metadata tests:

std::vector<std::tuple<std::string, std::string>> sequences =
{
// {"<optimizer sequence>", "<optimizer cleanup sequence>"}
{"", ""},
{"", "fDn"},
{"dhfoDgvulfnTUtnIf", "" },
{"dhfoDgvulfnTUtnIf", "fDn"}
};

There you can refer to OptimiserSettings and the default sequence without hard-coding it.

@clonker clonker force-pushed the fix_comparison_operators_for_optimizer_settings branch 2 times, most recently from f3afc4f to 38d9c50 Compare February 14, 2025 09:11
cameel
cameel previously approved these changes Feb 14, 2025
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.

In terms of fixing things everything seems in order. We might want to still refactor the test a bit more to give us more coverage. See my previous comment.

@clonker clonker force-pushed the fix_comparison_operators_for_optimizer_settings branch from 38d9c50 to db7a569 Compare February 18, 2025 08:09
@clonker clonker force-pushed the fix_comparison_operators_for_optimizer_settings branch from db7a569 to ea37c3b Compare February 19, 2025 07:43
@clonker clonker requested a review from cameel February 19, 2025 12:19
@ekpyron ekpyron added this to the 0.8.29 milestone Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants