This is an archive of the discontinued LLVM Phabricator instance.

[clang][Sema] Remove irrelevant diagnostics from constraint satisfaction failure
ClosedPublic

Authored by hazohelet on Aug 9 2023, 10:47 AM.

Details

Summary

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.

Fixes https://github.com/llvm/llvm-project/issues/54678

Diff Detail

Event Timeline

hazohelet created this revision.Aug 9 2023, 10:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2023, 10:47 AM
hazohelet requested review of this revision.Aug 9 2023, 10:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2023, 10:47 AM

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:

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.

hazohelet updated this revision to Diff 556227.Sep 7 2023, 10:38 PM
hazohelet marked an inline comment as done.

Added comment and FIXME

LGTM, but please wait a few days for @erichkeane

erichkeane accepted this revision.Sep 8 2023, 6:38 AM

I think this is alright. Please see if you can figure out and fix what the pre-commit clang-format issue is.

This revision is now accepted and ready to land.Sep 8 2023, 6:38 AM

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 revision was landed with ongoing or failed builds.Sep 18 2023, 2:15 AM
This revision was automatically updated to reflect the committed changes.