This is an archive of the discontinued LLVM Phabricator instance.

[Concepts] Constraint enforcement and diagnostics
ClosedPublic

Authored by saar.raz on Dec 24 2017, 1:13 PM.

Details

Summary
  • Associated constraints (requires clauses, currently) are now enforced when instantiating/specializing templates and when considering partial specializations and function overloads.
  • Elaborated diagnostics give helpful insight as to why the constraints were not satisfied.

This patch depends upon D41284

Diff Detail

Event Timeline

saar.raz created this revision.Dec 24 2017, 1:13 PM
saar.raz updated this revision to Diff 129306.Jan 10 2018, 10:39 AM
  • Better handling of diagnostics in ConceptSpecializationExprs, correctly written to and read from module files.
  • Modified Error messages according to some user feedback

Updating D41569: Summary:

Constraint enforcement and diagnostics

saar.raz updated this revision to Diff 132576.Feb 2 2018, 6:10 AM
  • When a conjunction constraint expression has both sides false, both sides will now be diagnosed.

Updating D41569: Summary:

Constraint enforcement and diagnostics

saar.raz updated this revision to Diff 137907.Mar 10 2018, 4:02 AM

Fixed crash caused by substitution of pack expansion into non-pack parameters in constraint expressions.

Updating D41569: Summary:

Constraint enforcement and diagnostics

saar.raz retitled this revision from Summary: Constraint enforcement and diagnostics to [Concepts] Constraint enforcement and diagnostics.Mar 10 2018, 4:26 AM
saar.raz updated this revision to Diff 138501.Mar 15 2018, 12:38 AM

Adjusted to changes in D41217

saar.raz updated this revision to Diff 138505.Mar 15 2018, 1:58 AM

Fixed SpecializedConcept reference to NamedConcept.

saar.raz updated this revision to Diff 138509.Mar 15 2018, 2:29 AM

Fixed another SpecializedConcept reference to NamedConcept.

saar.raz updated this revision to Diff 141248.Apr 5 2018, 5:48 PM

Adjusted to piecewise substitution.

  • Constraint satisfaction will no longer happen for depenent CSEs (was originally needed for normalization, but not worth the trouble with the new piecewise substitution and the fact that it prevents short-circuting)
  • Constraint satisfaction checking now breaks down unsatisfied constraint exprs into atomic constraints with the ill-formed diagnostic or the substituted constraint expression for each, later consumed by the diagnostic functions.
saar.raz updated this revision to Diff 159242.Aug 5 2018, 10:45 PM
  • Adjusted to switch to ASTTemplateArgumentList
saar.raz updated this revision to Diff 161348.Aug 17 2018, 3:22 PM
  • Adjusted to new CodeSynthesisContexts, added tests for them.
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2019, 4:31 PM
saar.raz updated this revision to Diff 195009.EditedApr 13 2019, 3:38 AM

Rebase onto trunk, add static assert diagnostics

saar.raz updated this revision to Diff 196091.Apr 22 2019, 10:36 AM

Adjusted to changes in getAssociatedConstraints interface

saar.raz updated this revision to Diff 204352.Jun 12 2019, 1:57 PM

Fix incorrect handling of recovered-from errors in constraint substitutions.

saar.raz updated this revision to Diff 204782.Jun 14 2019, 9:12 AM

Add support for CSE mangling

saar.raz updated this revision to Diff 207209.Jun 29 2019, 1:14 PM

Create ASTConstraintSatisfaction for correctly storing constraint satisfaction data in AST nodes.

saar.raz updated this revision to Diff 209689.EditedJul 13 2019, 6:39 AM

Rebase onto trunk.

saar.raz updated this revision to Diff 209695.Jul 13 2019, 8:07 AM

Move ConstraintSatisfaction to ASTConcept.h

rsmith added inline comments.Oct 15 2019, 2:46 PM
lib/AST/ItaniumMangle.cpp
4127 ↗(On Diff #209695)

These mangling changes look like they could be separated out from the rest of the patch. These plus the associated test look fine to check in as-is.

lib/Sema/SemaConcept.cpp
104

We should store the diagnostic as a PartialDiagnostic rather than as a string. (Currently that's a pain: we don't have serialization support for PartialDiagnostics, and they have a huge storage cost -- probably even larger than the fully-formatted string. But it's the right thing to do in the longer term. We want to expose the structured diagnostic to tools (such as IDEs) that want to present them in different ways, and if we ever support translation of diagnostics, we don't want the contents of module files to depend on the diagnostic language used when building the module file.)

Please add a FIXME for this.

lib/Sema/SemaDeclCXX.cpp
14032 ↗(On Diff #209695)

Would it be reasonable and feasible to unify findFailedBooleanCondition and diagnoseWellFormedUnsatisfiedConstraintExpr? They seem to be doing quite similar things.

lib/Sema/SemaTemplate.cpp
7441–7443

Can we move this into CheckTemplateArgumentList? Would that make sense in the bigger picture?

(Please put the && on the previous line.)

lib/Sema/SemaTemplateDeduction.cpp
2665

Style nit: space before & not after

2671

Style nit: || on previous line

2722–2724

This should be done in (or maybe immediately after) ConvertDeducedTemplateArguments (called by FinishTemplateArgumentDeduction), rather than here: that way, we'll convert the deduced arguments to the right kind, and pick up (and substitute into) any default template arguments as necessary before checking constraint satisfaction. We probably typically get away with this for now because partial specializations can't have default arguments, but we really should be forming the complete finalized argument list before checking satisfaction.

2767–2770

Likewise.

2881–2884

Is this check justified by some wording in the standard? Checking a dependent set of constraints (before we've done any deduction) seems surprising.

(I asked this on the core reflector, and it sounds like the status quo answer is no: we should not check constraints before we have all the template arguments for a function template. I'm not convinced that's really the right answer going forward, but we can at least run with it for the time being, to collect evidence to support a different rule if nothing else.)

reverted in r374985, it wasn't obvious to me how to unbreak the test. Sorry!

saar.raz updated this revision to Diff 225418.Oct 17 2019, 6:24 AM

Address CR comments by rsmith.

saar.raz marked 8 inline comments as done.Oct 17 2019, 6:28 AM
rsmith accepted this revision.Oct 17 2019, 12:22 PM
rsmith added inline comments.
clang/lib/Sema/SemaOverload.cpp
594 ↗(On Diff #225418)

Please add a documentation comment.

10707 ↗(On Diff #225418)

I think we should probably rank this higher -- maybe at the same level as a deduction or substitution failure, or maybe just above that. But I'm happy to wait and iterate on that once we have library code to experiment with.

clang/lib/Sema/SemaTemplate.cpp
4235 ↗(On Diff #225418)

(Not directly related to this patch, feel free to address separately:) Passing false for UpdateArgsWithConversion here seems surprising: shouldn't we be using the converted arguments in the satisfaction check and storing the converted arguments on the AST?

This revision is now accepted and ready to land.Oct 17 2019, 12:22 PM
saar.raz closed this revision.Oct 24 2019, 2:36 PM

Committed ffa214ef22892d75340dc6720271863901dc2c90

I noticed in Decl.cpp your change deleted some whitespace that belonged there. Not a big deal, just try to remember to run clang-format-diff when you're submitting for review. Thanks!