65
65
#include "clang/Sema/Redeclaration.h"
66
66
#include "clang/Sema/Scope.h"
67
67
#include "clang/Sema/SemaBase.h"
68
+ #include "clang/Sema/SemaConcept.h"
68
69
#include "clang/Sema/TypoCorrection.h"
69
70
#include "clang/Sema/Weak.h"
70
71
#include "llvm/ADT/APInt.h"
@@ -11694,8 +11695,9 @@ class Sema final : public SemaBase {
11694
11695
ExprResult
11695
11696
CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
11696
11697
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);
11699
11701
11700
11702
void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc);
11701
11703
void diagnoseMissingTemplateArguments(const CXXScopeSpec &SS,
@@ -12025,6 +12027,13 @@ class Sema final : public SemaBase {
12025
12027
bool UpdateArgsWithConversions = true,
12026
12028
bool *ConstraintsNotSatisfied = nullptr);
12027
12029
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
+
12028
12037
bool CheckTemplateTypeArgument(
12029
12038
TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg,
12030
12039
SmallVectorImpl<TemplateArgument> &SugaredConverted,
@@ -12783,6 +12792,18 @@ class Sema final : public SemaBase {
12783
12792
void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
12784
12793
unsigned Depth, llvm::SmallBitVector &Used);
12785
12794
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
+
12786
12807
/// Mark which template parameters can be deduced from a given
12787
12808
/// template argument list.
12788
12809
///
@@ -12799,6 +12820,9 @@ class Sema final : public SemaBase {
12799
12820
void MarkUsedTemplateParameters(ArrayRef<TemplateArgument> TemplateArgs,
12800
12821
unsigned Depth, llvm::SmallBitVector &Used);
12801
12822
12823
+ void MarkUsedTemplateParameters(ArrayRef<TemplateArgumentLoc> TemplateArgs,
12824
+ unsigned Depth, llvm::SmallBitVector &Used);
12825
+
12802
12826
void
12803
12827
MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate,
12804
12828
llvm::SmallBitVector &Deduced) {
@@ -13096,6 +13120,9 @@ class Sema final : public SemaBase {
13096
13120
/// Whether we're substituting into constraints.
13097
13121
bool InConstraintSubstitution;
13098
13122
13123
+ /// Whether we're substituting into the parameter mapping of a constraint.
13124
+ bool InParameterMappingSubstitution;
13125
+
13099
13126
/// The point of instantiation or synthesis within the source code.
13100
13127
SourceLocation PointOfInstantiation;
13101
13128
@@ -13359,6 +13386,11 @@ class Sema final : public SemaBase {
13359
13386
const MultiLevelTemplateArgumentList &TemplateArgs,
13360
13387
TemplateArgumentListInfo &Outputs);
13361
13388
13389
+ bool SubstTemplateArgumentsInParameterMapping(
13390
+ ArrayRef<TemplateArgumentLoc> Args, SourceLocation BaseLoc,
13391
+ const MultiLevelTemplateArgumentList &TemplateArgs,
13392
+ TemplateArgumentListInfo &Out, bool BuildPackExpansionTypes);
13393
+
13362
13394
/// Retrieve the template argument list(s) that should be used to
13363
13395
/// instantiate the definition of the given declaration.
13364
13396
///
@@ -13820,6 +13852,12 @@ class Sema final : public SemaBase {
13820
13852
CodeSynthesisContexts.back().InConstraintSubstitution;
13821
13853
}
13822
13854
13855
+ bool inParameterMappingSubstitution() const {
13856
+ return !CodeSynthesisContexts.empty() &&
13857
+ CodeSynthesisContexts.back().InParameterMappingSubstitution &&
13858
+ !inConstraintSubstitution();
13859
+ }
13860
+
13823
13861
using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;
13824
13862
13825
13863
/// \brief create a Requirement::SubstitutionDiagnostic with only a
@@ -14704,6 +14742,10 @@ class Sema final : public SemaBase {
14704
14742
SatisfactionStack.swap(NewSS);
14705
14743
}
14706
14744
14745
+ using ConstrainedDeclOrNestedRequirement =
14746
+ llvm::PointerUnion<const NamedDecl *,
14747
+ const concepts::NestedRequirement *>;
14748
+
14707
14749
/// Check whether the given expression is a valid constraint expression.
14708
14750
/// A diagnostic is emitted if it is not, false is returned, and
14709
14751
/// PossibleNonPrimary will be set to true if the failure might be due to a
@@ -14728,44 +14770,12 @@ class Sema final : public SemaBase {
14728
14770
/// \returns true if an error occurred and satisfaction could not be checked,
14729
14771
/// false otherwise.
14730
14772
bool CheckConstraintSatisfaction(
14731
- const NamedDecl *Template ,
14773
+ ConstrainedDeclOrNestedRequirement Entity ,
14732
14774
ArrayRef<AssociatedConstraint> AssociatedConstraints,
14733
14775
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);
14776
+ SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction,
14777
+ const ConceptReference *TopLevelConceptId = nullptr,
14778
+ Expr **ConvertedExpr = nullptr);
14769
14779
14770
14780
/// \brief Check whether the given non-dependent constraint expression is
14771
14781
/// satisfied. Returns false and updates Satisfaction with the satisfaction
@@ -14831,16 +14841,17 @@ class Sema final : public SemaBase {
14831
14841
/// \param First whether this is the first time an unsatisfied constraint is
14832
14842
/// diagnosed for this error.
14833
14843
void DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction,
14844
+ SourceLocation Loc = {},
14834
14845
bool First = true);
14835
14846
14836
14847
/// \brief Emit diagnostics explaining why a constraint expression was deemed
14837
14848
/// unsatisfied.
14838
14849
void
14839
- DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction ,
14850
+ DiagnoseUnsatisfiedConstraint(const ConceptSpecializationExpr *ConstraintExpr ,
14840
14851
bool First = true);
14841
14852
14842
14853
const NormalizedConstraint *getNormalizedAssociatedConstraints(
14843
- const NamedDecl *ConstrainedDecl ,
14854
+ ConstrainedDeclOrNestedRequirement Entity ,
14844
14855
ArrayRef<AssociatedConstraint> AssociatedConstraints);
14845
14856
14846
14857
/// \brief Check whether the given declaration's associated constraints are
@@ -14865,6 +14876,15 @@ class Sema final : public SemaBase {
14865
14876
const NamedDecl *D1, ArrayRef<AssociatedConstraint> AC1,
14866
14877
const NamedDecl *D2, ArrayRef<AssociatedConstraint> AC2);
14867
14878
14879
+ /// Cache the satisfaction of an atomic constraint.
14880
+ /// The key is based on the unsubstituted expression and the parameter
14881
+ /// mapping. This lets us not substituting the mapping more than once,
14882
+ /// which is (very!) expensive.
14883
+ /// FIXME: this should be private.
14884
+ llvm::DenseMap<llvm::FoldingSetNodeID,
14885
+ UnsubstitutedConstraintSatisfactionCacheResult>
14886
+ UnsubstitutedConstraintSatisfactionCache;
14887
+
14868
14888
private:
14869
14889
/// Caches pairs of template-like decls whose associated constraints were
14870
14890
/// checked for subsumption and whether or not the first's constraints did in
@@ -14875,8 +14895,11 @@ class Sema final : public SemaBase {
14875
14895
/// constrained declarations). If an error occurred while normalizing the
14876
14896
/// associated constraints of the template or concept, nullptr will be cached
14877
14897
/// here.
14878
- llvm::DenseMap<const NamedDecl *, NormalizedConstraint *> NormalizationCache;
14898
+ llvm::DenseMap<ConstrainedDeclOrNestedRequirement, NormalizedConstraint *>
14899
+ NormalizationCache;
14879
14900
14901
+ /// Cache whether the associated constraint of a declaration
14902
+ /// is satisfied.
14880
14903
llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &>
14881
14904
SatisfactionCache;
14882
14905
0 commit comments