This class is a helper for 'parser-like' use cases of LogicalResult
where the implicit conversion to bool is tolerable. It is used by the
operation asmparsers, but is more generic functionality that is closely
aligned with LogicalResult. Hoist it up to LogicalResult.h to make it
more accessible. This is part of Issue #54884
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
mlir/lib/Tools/PDLL/AST/Diagnostic.cpp | ||
---|---|---|
18 ↗ | (On Diff #422745) | Just FYI, this is required because pdll uses the same class name as mlir core. |
mlir/include/mlir/Support/LogicalResult.h | ||
---|---|---|
88 | Isn't there a parser header that could host this? |
I'd like to hoist this whole file up to LLVM/Support. LLVM has lots of parsers, and doesn't have a unified system for building these. "ParseResult" is perhaps misnamed - it is really "LogicalResult that is implicitly convertible to bool"
I have concerned about implicit conversion to bool in the context of LogicalResult though, it was very intentional that LogicalResult does not convert to bool implicitly. We only carved out a specific exception for the parser because of this somehow pre-existing common pattern of chaining the calls, so it isn't a "misname": it was very intentional to keep this scoped and localized.
It is so small (10 lines of code) that I would have each of the LLVM parser defining their own ParseResult if they which to do so. But if you really want to have this in llvm/Support, then llvm/Support/ParseResult.h would do it as well?
Something else that shows in this patch is a "layering violation" where the mlir/IR/Diagnostics.h classes are now exposed here.
Something else that shows in this patch is a "layering violation" where the mlir/IR/Diagnostics.h classes are now exposed here.
I agree, I'll work on this.
I have concerned about implicit conversion to bool in the context of LogicalResult though, it was very intentional that LogicalResult does not convert to bool implicitly. We only carved out a specific exception for the parser because of this somehow pre-existing common pattern of chaining the calls, so it isn't a "misname": it was very intentional to keep this scoped and localized.
I don't understand your concern here. This patch isn't making LogicalResult convertible to bool (fwiw, River is also staunchly opposed to this). I'm pretty aware of this history here. This patch is just moving the ParseResult class into LogicalResult.h.
You are correct that we could define a new ParseResult.h next to LogicalResult, but I don't see how a 5 line class warrants its own header, and there is nothing "dangerous" about what the patch is proposing. I also don't see how putting this in a Utils.h is better.
Are you /opposed/ to this moving into LogicalResult.h or are you just discussing?
-Chris
Move the implicit conversion from ParseResult.
It makes more sense to put these on InflightDiagnostic and Diagnostic,
which already have the corresponding conversion to LogicalResult.
Diagnostic.h already includes LogicalResult.h as well. This fixes a
layering issue.
Update class comments, clarifying rationale and further dissuading people
from using it for general error handling.
I'm LGTM on having this moved to LogicalResult in general, having seen various copies or places using raw bool. Whether this is in LogicalResult.h or some ParseResult.h doesn't matter a lot to me (given how small it is at this point), the big thing to me is that the class has significant documentation that covers rationale/when it should be used/when it shouldn't. The important part to me is that any conversions to bool are well contained, and have documentation (I would have some concerns about this implicitness leaking outside of the places that it should).
mlir/lib/Tools/PDLL/AST/Diagnostic.cpp | ||
---|---|---|
18 ↗ | (On Diff #422745) | Is this still required? |
You're right, the PDL change isn't needed anymore, dropped from the patch.
Do the comments on the class work for you, or do you recommend anything more in particular?
Right: sorry I added confusion to the discussion :)
You wrote that it is conceptually "LogicalResult that is implicitly convertible to bool" and I was just trying to say that I don't think we want ParseResult to be marketed that way and folks starting to use it widely outside of the context of the parser.
With the layering resolved by moving the conversions for InflightDiagnostic and Diagnostic, the current patch LGTM :)
nit: Can we move this class to the bottom of the file?