Skip to content

Commit b2a598b

Browse files
authored
Do not normalize empty FoldExprs? (#55)
* Do not normalize empty FoldExprs? * Refactor substituteParameterMappings. NFC * Establish a mapping on fold exprs * Remove unused return * Fix another crash where we accidentally transformed the requires expression where we shouldn't We might be evaluating a constraint when establishing parameter mappings * Do not expand too much packs within a FoldExpr * Revert "Do not expand too much packs within a FoldExpr" This reverts commit 542eb27. * Reapply "Do not expand too much packs within a FoldExpr" This reverts commit 11c2ce0. * Fix another assertion * Avoid extra expansions by not building PackExpansionTypes * [do not merge] debugging * Revert "[do not merge] debugging" This reverts commit 03d9aba. * Cache? * Atomic concept cache? * Avoid computing cache with SubstitutionInTemplateArguments That is a heavy operation!
1 parent bb4e716 commit b2a598b

File tree

9 files changed

+606
-123
lines changed

9 files changed

+606
-123
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13339,7 +13339,7 @@ class Sema final : public SemaBase {
1333913339
bool SubstTemplateArgumentsInParameterMapping(
1334013340
ArrayRef<TemplateArgumentLoc> Args, SourceLocation BaseLoc,
1334113341
const MultiLevelTemplateArgumentList &TemplateArgs,
13342-
TemplateArgumentListInfo &Out);
13342+
TemplateArgumentListInfo &Out, bool BuildPackExpansionTypes);
1334313343

1334413344
/// Retrieve the template argument list(s) that should be used to
1334513345
/// instantiate the definition of the given declaration.
@@ -13799,15 +13799,15 @@ class Sema final : public SemaBase {
1379913799
}
1380013800

1380113801
/// Determine whether we are currently performing constraint substitution.
13802-
// FIXME: Rename it
1380313802
bool inConstraintSubstitution() const {
1380413803
return !CodeSynthesisContexts.empty() &&
1380513804
CodeSynthesisContexts.back().InConstraintSubstitution;
1380613805
}
1380713806

1380813807
bool inParameterMappingSubstitution() const {
1380913808
return !CodeSynthesisContexts.empty() &&
13810-
CodeSynthesisContexts.back().InParameterMappingSubstitution;
13809+
CodeSynthesisContexts.back().InParameterMappingSubstitution &&
13810+
!inConstraintSubstitution();
1381113811
}
1381213812

1381313813
using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;
@@ -14819,6 +14819,9 @@ class Sema final : public SemaBase {
1481914819
const NamedDecl *D1, ArrayRef<AssociatedConstraint> AC1,
1482014820
const NamedDecl *D2, ArrayRef<AssociatedConstraint> AC2);
1482114821

14822+
llvm::DenseMap<unsigned, CachedConceptIdConstraint>
14823+
ConceptIdSatisfactionCache;
14824+
1482214825
private:
1482314826
/// Caches pairs of template-like decls whose associated constraints were
1482414827
/// checked for subsumption and whether or not the first's constraints did in

clang/include/clang/Sema/SemaConcept.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "clang/AST/ExprConcepts.h"
2020
#include "clang/Basic/SourceLocation.h"
2121
#include "clang/Basic/UnsignedOrNone.h"
22+
#include "clang/Sema/Ownership.h"
2223
#include "llvm/ADT/ArrayRef.h"
2324
#include "llvm/ADT/FoldingSet.h"
2425
#include "llvm/ADT/STLForwardCompat.h"
@@ -67,7 +68,7 @@ struct NormalizedConstraint {
6768
unsigned Kind : 5;
6869
unsigned Placeholder : 1;
6970
unsigned PackSubstitutionIndex : 26;
70-
llvm::SmallBitVector Indexes;
71+
OccurenceList Indexes;
7172
TemplateArgumentLoc *Args;
7273
TemplateParameterList *ParamList;
7374
ExprOrConcept ConstraintExpr;
@@ -84,6 +85,7 @@ struct NormalizedConstraint {
8485
TemplateArgumentLoc *Args;
8586
TemplateParameterList *ParamList;
8687
const Expr *Pattern;
88+
const NamedDecl *ConstraintDecl;
8789
NormalizedConstraint *Constraint;
8890
};
8991

@@ -128,14 +130,16 @@ struct NormalizedConstraint {
128130
ConstraintDecl} {}
129131

130132
NormalizedConstraint(const Expr *Pattern, FoldOperatorKind OpKind,
131-
NormalizedConstraint *Constraint)
133+
NormalizedConstraint *Constraint,
134+
const NamedDecl *ConstraintDecl)
132135
: FoldExpanded{llvm::to_underlying(ConstraintKind::FoldExpanded),
133136
llvm::to_underlying(OpKind),
134137
/*Placeholder=*/0,
135138
/*Indexes=*/{},
136139
/*Args=*/nullptr,
137140
/*ParamList=*/nullptr,
138141
Pattern,
142+
ConstraintDecl,
139143
Constraint} {}
140144

141145
NormalizedConstraint(const ConceptReference *ConceptId,
@@ -323,14 +327,17 @@ class AtomicConstraint : public NormalizedConstraintWithParamMapping {
323327
}
324328
};
325329

326-
class FoldExpandedConstraint : public NormalizedConstraint {
327-
using NormalizedConstraint::NormalizedConstraint;
330+
class FoldExpandedConstraint : public NormalizedConstraintWithParamMapping {
331+
using NormalizedConstraintWithParamMapping::
332+
NormalizedConstraintWithParamMapping;
328333

329334
public:
330335
static FoldExpandedConstraint *Create(ASTContext &Ctx, const Expr *Pattern,
336+
const NamedDecl *ConstraintDecl,
331337
FoldOperatorKind OpKind,
332338
NormalizedConstraint *Constraint) {
333-
return new (Ctx) FoldExpandedConstraint(Pattern, OpKind, Constraint);
339+
return new (Ctx)
340+
FoldExpandedConstraint(Pattern, OpKind, Constraint, ConstraintDecl);
334341
}
335342

336343
using NormalizedConstraint::hasMatchingParameterMapping;
@@ -383,6 +390,11 @@ class ConceptIdConstraint : public NormalizedConstraintWithParamMapping {
383390
NormalizedConstraint &getNormalizedConstraint() { return *ConceptId.Sub; }
384391
};
385392

393+
struct CachedConceptIdConstraint {
394+
ExprResult SubstExpr;
395+
ConstraintSatisfaction Satisfaction;
396+
};
397+
386398
/// \brief SubsumptionChecker establishes subsumption
387399
/// between two set of constraints.
388400
class SubsumptionChecker {
@@ -482,6 +494,6 @@ class SubsumptionChecker {
482494
uint16_t getNewLiteralId();
483495
};
484496

485-
} // clang
497+
} // namespace clang
486498

487499
#endif // LLVM_CLANG_SEMA_SEMACONCEPT_H

0 commit comments

Comments
 (0)