BEFORE this patch, when clang handles constraints like C1 || C2 where C1 evaluates to false and C2 evaluates to true, it emitted irrelevant diagnostics about the falsity of C1.
This patch removes the irrelevant diagnostic information generated during the evaluation of C1 if C2 evaluates to true.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Generally LGTM, but the erase call could do with a comment before. And I'll let someone with more concepts experience handle whether this should be accepted or not.
Sorry for the delay in review, I'm still on vacation. However, I don't like the idea of removing the satisfaction. I have to think about it more, but optimally we'd just not add the detail until we knew what the RHS value was, though our design doesn't particularly support that currently.
To generate only the necessary diagnostic information, we need to know the evaluation result of the entire constraint expression.
So, the ideal way I can think of would be first to evaluate the nodes and, simultaneously, cache the results using DenseMap or something, and then traverse the nodes again to generate diagnostic information.
I was going in this way, but (https://github.com/llvm/llvm-project/blob/6f8b17703da2fbabba974b82578530b152b79c26/clang/lib/Sema/SemaConcept.cpp#L365) needs to use TemplateDeductionInfo::takeSFINAEDiagnostic to generate the diagnostic information. Generating this TemplateDeductionInfo in the second traversal seems unreasonable or impossible because it involves template instantiation.
Also, I'm unsure whether this refactor is worth the additional traversal and the cache data cost.
I would like to hear opinions about the direction from reviewers.
Note: The current implementation adds diagnostic information in the following places:
- https://github.com/llvm/llvm-project/blob/6f8b17703da2fbabba974b82578530b152b79c26/clang/lib/Sema/SemaConcept.cpp#L258
- https://github.com/llvm/llvm-project/blob/6f8b17703da2fbabba974b82578530b152b79c26/clang/lib/Sema/SemaConcept.cpp#L288
- https://github.com/llvm/llvm-project/blob/6f8b17703da2fbabba974b82578530b152b79c26/clang/lib/Sema/SemaConcept.cpp#L378
Given that we still need to check for substitution errors in untaken branches, this look reasonable (especially as i think you are right that alternative approaches are likely to be more complex) however i think it does require a comment, and I'd like @erichkeane to have the final say.
clang/lib/Sema/SemaConcept.cpp | ||
---|---|---|
222–226 | This really needs a comment explaining that we are pruning details that do not matter for satisfaction, and a FIXME along the line of what Erich suggested. |
I think this is alright. Please see if you can figure out and fix what the pre-commit clang-format issue is.
When I first ran git clang-format locally, it somehow forced 4-space indent.
After starting to use clang-format from the trunk, I haven't seen the suspicious behavior locally, but the CI format check failure might be caused by that.
The format seems okay as-is, so I'll push this change without addressing the CI clang-format failure.
This really needs a comment explaining that we are pruning details that do not matter for satisfaction, and a FIXME along the line of what Erich suggested.