6565#include "clang/Sema/Redeclaration.h"
6666#include "clang/Sema/Scope.h"
6767#include "clang/Sema/SemaBase.h"
68+ #include "clang/Sema/SemaConcept.h"
6869#include "clang/Sema/TypoCorrection.h"
6970#include "clang/Sema/Weak.h"
7071#include "llvm/ADT/APInt.h"
@@ -11694,8 +11695,9 @@ class Sema final : public SemaBase {
1169411695 ExprResult
1169511696 CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
1169611697 const DeclarationNameInfo &ConceptNameInfo,
11697- NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
11698- const TemplateArgumentListInfo *TemplateArgs);
11698+ NamedDecl *FoundDecl, TemplateDecl *NamedConcept,
11699+ const TemplateArgumentListInfo *TemplateArgs,
11700+ bool DoCheckConstraintSatisfaction = true);
1169911701
1170011702 void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc);
1170111703 void diagnoseMissingTemplateArguments(const CXXScopeSpec &SS,
@@ -12025,6 +12027,13 @@ class Sema final : public SemaBase {
1202512027 bool UpdateArgsWithConversions = true,
1202612028 bool *ConstraintsNotSatisfied = nullptr);
1202712029
12030+ bool CheckTemplateArgumentList(
12031+ TemplateDecl *Template, TemplateParameterList *Params,
12032+ SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs,
12033+ const DefaultArguments &DefaultArgs, bool PartialTemplateArgs,
12034+ CheckTemplateArgumentInfo &CTAI, bool UpdateArgsWithConversions = true,
12035+ bool *ConstraintsNotSatisfied = nullptr);
12036+
1202812037 bool CheckTemplateTypeArgument(
1202912038 TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg,
1203012039 SmallVectorImpl<TemplateArgument> &SugaredConverted,
@@ -12783,6 +12792,18 @@ class Sema final : public SemaBase {
1278312792 void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
1278412793 unsigned Depth, llvm::SmallBitVector &Used);
1278512794
12795+ /// Mark which template parameters are named in a given expression.
12796+ ///
12797+ /// Unlike MarkUsedTemplateParameters, this excludes parameter that
12798+ /// are used but not directly named by an expression - i.e. it excludes
12799+ /// any template parameter that denotes the type of a referenced NTTP.
12800+ ///
12801+ /// \param Used a bit vector whose elements will be set to \c true
12802+ /// to indicate when the corresponding template parameter will be
12803+ /// deduced.
12804+ void MarkUsedTemplateParametersForSubsumptionParameterMapping(
12805+ const Expr *E, unsigned Depth, llvm::SmallBitVector &Used);
12806+
1278612807 /// Mark which template parameters can be deduced from a given
1278712808 /// template argument list.
1278812809 ///
@@ -12799,6 +12820,9 @@ class Sema final : public SemaBase {
1279912820 void MarkUsedTemplateParameters(ArrayRef<TemplateArgument> TemplateArgs,
1280012821 unsigned Depth, llvm::SmallBitVector &Used);
1280112822
12823+ void MarkUsedTemplateParameters(ArrayRef<TemplateArgumentLoc> TemplateArgs,
12824+ unsigned Depth, llvm::SmallBitVector &Used);
12825+
1280212826 void
1280312827 MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate,
1280412828 llvm::SmallBitVector &Deduced) {
@@ -13096,6 +13120,9 @@ class Sema final : public SemaBase {
1309613120 /// Whether we're substituting into constraints.
1309713121 bool InConstraintSubstitution;
1309813122
13123+ /// Whether we're substituting into the parameter mapping of a constraint.
13124+ bool InParameterMappingSubstitution;
13125+
1309913126 /// The point of instantiation or synthesis within the source code.
1310013127 SourceLocation PointOfInstantiation;
1310113128
@@ -13146,8 +13173,10 @@ class Sema final : public SemaBase {
1314613173 CodeSynthesisContext()
1314713174 : Kind(TemplateInstantiation),
1314813175 SavedInNonInstantiationSFINAEContext(false),
13149- InConstraintSubstitution(false), Entity(nullptr), Template(nullptr),
13150- TemplateArgs(nullptr), NumTemplateArgs(0), DeductionInfo(nullptr) {}
13176+ InConstraintSubstitution(false),
13177+ InParameterMappingSubstitution(false), Entity(nullptr),
13178+ Template(nullptr), TemplateArgs(nullptr), NumTemplateArgs(0),
13179+ DeductionInfo(nullptr) {}
1315113180
1315213181 /// Determines whether this template is an actual instantiation
1315313182 /// that should be counted toward the maximum instantiation depth.
@@ -13359,6 +13388,11 @@ class Sema final : public SemaBase {
1335913388 const MultiLevelTemplateArgumentList &TemplateArgs,
1336013389 TemplateArgumentListInfo &Outputs);
1336113390
13391+ bool SubstTemplateArgumentsInParameterMapping(
13392+ ArrayRef<TemplateArgumentLoc> Args, SourceLocation BaseLoc,
13393+ const MultiLevelTemplateArgumentList &TemplateArgs,
13394+ TemplateArgumentListInfo &Out, bool BuildPackExpansionTypes);
13395+
1336213396 /// Retrieve the template argument list(s) that should be used to
1336313397 /// instantiate the definition of the given declaration.
1336413398 ///
@@ -13820,6 +13854,12 @@ class Sema final : public SemaBase {
1382013854 CodeSynthesisContexts.back().InConstraintSubstitution;
1382113855 }
1382213856
13857+ bool inParameterMappingSubstitution() const {
13858+ return !CodeSynthesisContexts.empty() &&
13859+ CodeSynthesisContexts.back().InParameterMappingSubstitution &&
13860+ !inConstraintSubstitution();
13861+ }
13862+
1382313863 using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;
1382413864
1382513865 /// \brief create a Requirement::SubstitutionDiagnostic with only a
@@ -14704,6 +14744,10 @@ class Sema final : public SemaBase {
1470414744 SatisfactionStack.swap(NewSS);
1470514745 }
1470614746
14747+ using ConstrainedDeclOrNestedRequirement =
14748+ llvm::PointerUnion<const NamedDecl *,
14749+ const concepts::NestedRequirement *>;
14750+
1470714751 /// Check whether the given expression is a valid constraint expression.
1470814752 /// A diagnostic is emitted if it is not, false is returned, and
1470914753 /// PossibleNonPrimary will be set to true if the failure might be due to a
@@ -14728,44 +14772,12 @@ class Sema final : public SemaBase {
1472814772 /// \returns true if an error occurred and satisfaction could not be checked,
1472914773 /// false otherwise.
1473014774 bool CheckConstraintSatisfaction(
14731- const NamedDecl *Template ,
14775+ ConstrainedDeclOrNestedRequirement Entity ,
1473214776 ArrayRef<AssociatedConstraint> AssociatedConstraints,
1473314777 const MultiLevelTemplateArgumentList &TemplateArgLists,
14734- SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction) {
14735- llvm::SmallVector<Expr *, 4> Converted;
14736- return CheckConstraintSatisfaction(Template, AssociatedConstraints,
14737- Converted, TemplateArgLists,
14738- TemplateIDRange, Satisfaction);
14739- }
14740-
14741- /// \brief Check whether the given list of constraint expressions are
14742- /// satisfied (as if in a 'conjunction') given template arguments.
14743- /// Additionally, takes an empty list of Expressions which is populated with
14744- /// the instantiated versions of the ConstraintExprs.
14745- /// \param Template the template-like entity that triggered the constraints
14746- /// check (either a concept or a constrained entity).
14747- /// \param ConstraintExprs a list of constraint expressions, treated as if
14748- /// they were 'AND'ed together.
14749- /// \param ConvertedConstraints a out parameter that will get populated with
14750- /// the instantiated version of the ConstraintExprs if we successfully checked
14751- /// satisfaction.
14752- /// \param TemplateArgList the multi-level list of template arguments to
14753- /// substitute into the constraint expression. This should be relative to the
14754- /// top-level (hence multi-level), since we need to instantiate fully at the
14755- /// time of checking.
14756- /// \param TemplateIDRange The source range of the template id that
14757- /// caused the constraints check.
14758- /// \param Satisfaction if true is returned, will contain details of the
14759- /// satisfaction, with enough information to diagnose an unsatisfied
14760- /// expression.
14761- /// \returns true if an error occurred and satisfaction could not be checked,
14762- /// false otherwise.
14763- bool CheckConstraintSatisfaction(
14764- const NamedDecl *Template,
14765- ArrayRef<AssociatedConstraint> AssociatedConstraints,
14766- llvm::SmallVectorImpl<Expr *> &ConvertedConstraints,
14767- const MultiLevelTemplateArgumentList &TemplateArgList,
14768- SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction);
14778+ SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction,
14779+ const ConceptReference *TopLevelConceptId = nullptr,
14780+ Expr **ConvertedExpr = nullptr);
1476914781
1477014782 /// \brief Check whether the given non-dependent constraint expression is
1477114783 /// satisfied. Returns false and updates Satisfaction with the satisfaction
@@ -14831,16 +14843,17 @@ class Sema final : public SemaBase {
1483114843 /// \param First whether this is the first time an unsatisfied constraint is
1483214844 /// diagnosed for this error.
1483314845 void DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction,
14846+ SourceLocation Loc = {},
1483414847 bool First = true);
1483514848
1483614849 /// \brief Emit diagnostics explaining why a constraint expression was deemed
1483714850 /// unsatisfied.
1483814851 void
14839- DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction ,
14852+ DiagnoseUnsatisfiedConstraint(const ConceptSpecializationExpr *ConstraintExpr ,
1484014853 bool First = true);
1484114854
1484214855 const NormalizedConstraint *getNormalizedAssociatedConstraints(
14843- const NamedDecl *ConstrainedDecl ,
14856+ ConstrainedDeclOrNestedRequirement Entity ,
1484414857 ArrayRef<AssociatedConstraint> AssociatedConstraints);
1484514858
1484614859 /// \brief Check whether the given declaration's associated constraints are
@@ -14865,6 +14878,15 @@ class Sema final : public SemaBase {
1486514878 const NamedDecl *D1, ArrayRef<AssociatedConstraint> AC1,
1486614879 const NamedDecl *D2, ArrayRef<AssociatedConstraint> AC2);
1486714880
14881+ /// Cache the satisfaction of an atomic constraint.
14882+ /// The key is based on the unsubstituted expression and the parameter
14883+ /// mapping. This lets us not substituting the mapping more than once,
14884+ /// which is (very!) expensive.
14885+ /// FIXME: this should be private.
14886+ llvm::DenseMap<llvm::FoldingSetNodeID,
14887+ UnsubstitutedConstraintSatisfactionCacheResult>
14888+ UnsubstitutedConstraintSatisfactionCache;
14889+
1486814890private:
1486914891 /// Caches pairs of template-like decls whose associated constraints were
1487014892 /// checked for subsumption and whether or not the first's constraints did in
@@ -14875,8 +14897,11 @@ class Sema final : public SemaBase {
1487514897 /// constrained declarations). If an error occurred while normalizing the
1487614898 /// associated constraints of the template or concept, nullptr will be cached
1487714899 /// here.
14878- llvm::DenseMap<const NamedDecl *, NormalizedConstraint *> NormalizationCache;
14900+ llvm::DenseMap<ConstrainedDeclOrNestedRequirement, NormalizedConstraint *>
14901+ NormalizationCache;
1487914902
14903+ /// Cache whether the associated constraint of a declaration
14904+ /// is satisfied.
1488014905 llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &>
1488114906 SatisfactionCache;
1488214907
0 commit comments