This is an archive of the discontinued LLVM Phabricator instance.

[CommandLine] Reset option to its default if its Default field is undefined
ClosedPublic

Authored by yrouban on Dec 9 2021, 1:17 AM.

Details

Summary

This patch makes opt::setDefaultImpl() set the option value to the option type's default value if the Default field is not set. This results in option value reset by Option::reset() or ResetAllOptionOccurrences() even if the cl::init() is not specified.

Example:

StackOption<std::string> Str("str"); // No cl::init().
Str = "some value";
cl::ResetAllOptionOccurrences();
EXPECT_EQ("", Str); // The Str is reset.

Diff Detail

Event Timeline

yrouban requested review of this revision.Dec 9 2021, 1:17 AM
yrouban created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2021, 1:17 AM
yrouban updated this revision to Diff 393067.Dec 9 2021, 1:24 AM

added context lines

ping, please review.

What is the motivation for this change? I can argue for maintaining the current behavior., If I pass a cl::init to an option and call ResetAllOptionOccurrences I would expect that cl::init value to be used to reset the option. There are compiler flows that rely on that behavior.

beanz added a comment.Jan 10 2022, 8:55 AM

What is the motivation for this change? I can argue for maintaining the current behavior., If I pass a cl::init to an option and call ResetAllOptionOccurrences I would expect that cl::init value to be used to reset the option. There are compiler flows that rely on that behavior.

IIUC, the point of this change is not to alter the behavior for options that have a cl::init, but rather to alter behavior for options that _don't_ have a default provided. Right now, those options don't get reset when ResetAllOptionOccurrences is called. With this patch, options _without_ cl::init should get reset to the default-constructed value of the option type, and options with cl::init get initialized to the default value.

yrouban edited the summary of this revision. (Show Details)Jan 10 2022, 7:06 PM

... With this patch, options _without_ cl::init should get reset to the default-constructed value of the option type, and options with cl::init get initialized to the default value.

+1. I have fixed the summary to make it clearer.

IIUC, the point of this change is not to alter the behavior for options that have a cl::init, but rather to alter behavior for options that _don't_ have a default provided. Right now, those options don't get reset when ResetAllOptionOccurrences is called. With this patch, options _without_ cl::init should get reset to the default-constructed value of the option type, and options with cl::init get initialized to the default value.

Ah, ok, thank you!

ping, please review.

lattner accepted this revision.Feb 25 2022, 12:40 PM

Looks ok to me. To make code review smoother, I'd recommend making the motivation stronger in the commit message. Instead of starting by the "what", start by the goal, e.g.:

"Make ResetAllOptionOccurrences work better for xxx by doing YYY; this solves zz problem"

instead of "change low level behavior of something from xx to yy..."

This revision is now accepted and ready to land.Feb 25 2022, 12:40 PM

... To make code review smoother, I'd recommend making the motivation stronger in the commit message.

ok. Thank you Chris.

This revision was landed with ongoing or failed builds.Feb 27 2022, 5:58 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2022, 5:27 PM