This is an archive of the discontinued LLVM Phabricator instance.

[mlir:PassOptions] Fix parsing of nested option values/better handle escaping
ClosedPublic

Authored by rriddle on Jan 24 2022, 2:30 PM.

Details

Summary

The option parser currently does not properly handle nested options, meaning that
in some cases we can print pass pipelines that we can't actually parse back in. For example,
from #52885 we currently can't parse in inliner pipelines that have nested pipeline strings.

This commit adds handling for string values (e.g. "...") and nested options
(e.g. foo{baz{bar=10 pizza=11}}).

Fixes #52885

Diff Detail

Event Timeline

rriddle created this revision.Jan 24 2022, 2:30 PM
rriddle requested review of this revision.Jan 24 2022, 2:30 PM
rriddle updated this revision to Diff 402669.Jan 24 2022, 2:32 PM
mehdi_amini added inline comments.Jan 24 2022, 2:41 PM
mlir/lib/Pass/PassRegistry.cpp
192

Could write this as a while(true) since it isn't supposed to finish?

199

This wouldn't support a string with an escaped double quote right?

"foo\"bar" would hit the \" at the middle as the end of the quote I think

213

Similar question about parsing pipeline = { option = "}" }

rriddle added inline comments.Jan 24 2022, 4:58 PM
mlir/lib/Pass/PassRegistry.cpp
192

I used a for because it was simpler to define the variables + update them. Do you have a preference here? Maybe add a true to the condition to make it more obvious?

199

Correct. I'm not sure what our policy here should be given that right now we don't support character escaping of any kind (also gets kind of weird from a command line perspective). I guess the thing interpreting the option would know that it's escaped?

213

Conceptually yes, but there is another of the parser that needs to be updated to support that.

This is going to help a lot :)

mlir/lib/Pass/PassRegistry.cpp
160

This is different than most of the stringref manipulating ones - in this case you might get a std::pair<std::pair<StringRef, StringRef>, StringRef> and have the string updated that way. I think the majority returns the remainder again rather than ref param.

192

SGTM (keeps the variable scope small and easier to spot)

199

Would the reproducer dump produce such a string?

mehdi_amini added inline comments.Jan 24 2022, 5:47 PM
mlir/lib/Pass/PassRegistry.cpp
192

In general I reserve for to regular iteration space ; I feel that using for for other purposes is abusing the language construct.

199

what about a string option containing a non-escaped " character though?

213

OK, I guess this patch is already one step forward...

mehdi_amini accepted this revision.Jan 24 2022, 5:47 PM
This revision is now accepted and ready to land.Jan 24 2022, 5:47 PM
rriddle marked 3 inline comments as done.Jan 26 2022, 3:11 PM
rriddle added inline comments.
mlir/lib/Pass/PassRegistry.cpp
199

Such a string option (at this point) wouldn't work given that we've only really considered use cases for simple things (largely given the terminal
command line origins/llvm CL library usage). String options are printed raw (i.e. no escaping), so I'm not sure that would even parse properly in most shells.

mehdi_amini added inline comments.Jan 26 2022, 3:22 PM
mlir/lib/Pass/PassRegistry.cpp
199

But we could escape things couldn't we?

My main target isn't "shells" convenience, but the reproducer that opt known how to load natively :)

rriddle marked an inline comment as done.Jan 26 2022, 3:26 PM
rriddle added inline comments.
mlir/lib/Pass/PassRegistry.cpp
199

We could yes, I was just answering on if it is currently possible. I didn't mean to imply that we shouldn't just because it's convenient from a shell point of view, just that adding support requires reworking other parts of the infra (namely printing) to make it work. Was originally intending to explore this in a followup (to allow for the current bug to be fixed first), unless you have a preference for rolling it into this one?

rriddle updated this revision to Diff 403424.Jan 26 2022, 3:50 PM
mehdi_amini added inline comments.Jan 26 2022, 4:46 PM
mlir/lib/Pass/PassRegistry.cpp
199

Same as in the other thread: this patch seems like a step forward, still LGTM

This revision was landed with ongoing or failed builds.Jan 26 2022, 9:38 PM
This revision was automatically updated to reflect the committed changes.