Skip to content

Commit 73fda83

Browse files
authored
[Clang] Do not put the definition of concept nodes in the Sema library (#141104)
It is a layering violation
1 parent 13e1a2c commit 73fda83

File tree

2 files changed

+59
-58
lines changed

2 files changed

+59
-58
lines changed

clang/lib/AST/ASTConcept.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "clang/AST/ASTConcept.h"
1515
#include "clang/AST/ASTContext.h"
16+
#include "clang/AST/ExprConcepts.h"
1617
#include "clang/AST/PrettyPrinter.h"
1718
#include "llvm/ADT/StringExtras.h"
1819

@@ -107,3 +108,61 @@ void ConceptReference::print(llvm::raw_ostream &OS,
107108
OS << ">";
108109
}
109110
}
111+
112+
concepts::ExprRequirement::ExprRequirement(
113+
Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
114+
ReturnTypeRequirement Req, SatisfactionStatus Status,
115+
ConceptSpecializationExpr *SubstitutedConstraintExpr)
116+
: Requirement(IsSimple ? RK_Simple : RK_Compound, Status == SS_Dependent,
117+
Status == SS_Dependent &&
118+
(E->containsUnexpandedParameterPack() ||
119+
Req.containsUnexpandedParameterPack()),
120+
Status == SS_Satisfied),
121+
Value(E), NoexceptLoc(NoexceptLoc), TypeReq(Req),
122+
SubstitutedConstraintExpr(SubstitutedConstraintExpr), Status(Status) {
123+
assert((!IsSimple || (Req.isEmpty() && NoexceptLoc.isInvalid())) &&
124+
"Simple requirement must not have a return type requirement or a "
125+
"noexcept specification");
126+
assert((Status > SS_TypeRequirementSubstitutionFailure &&
127+
Req.isTypeConstraint()) == (SubstitutedConstraintExpr != nullptr));
128+
}
129+
130+
concepts::ExprRequirement::ExprRequirement(
131+
SubstitutionDiagnostic *ExprSubstDiag, bool IsSimple,
132+
SourceLocation NoexceptLoc, ReturnTypeRequirement Req)
133+
: Requirement(IsSimple ? RK_Simple : RK_Compound, Req.isDependent(),
134+
Req.containsUnexpandedParameterPack(), /*IsSatisfied=*/false),
135+
Value(ExprSubstDiag), NoexceptLoc(NoexceptLoc), TypeReq(Req),
136+
Status(SS_ExprSubstitutionFailure) {
137+
assert((!IsSimple || (Req.isEmpty() && NoexceptLoc.isInvalid())) &&
138+
"Simple requirement must not have a return type requirement or a "
139+
"noexcept specification");
140+
}
141+
142+
concepts::ExprRequirement::ReturnTypeRequirement::ReturnTypeRequirement(
143+
TemplateParameterList *TPL)
144+
: TypeConstraintInfo(TPL, false) {
145+
assert(TPL->size() == 1);
146+
const TypeConstraint *TC =
147+
cast<TemplateTypeParmDecl>(TPL->getParam(0))->getTypeConstraint();
148+
assert(TC &&
149+
"TPL must have a template type parameter with a type constraint");
150+
auto *Constraint =
151+
cast<ConceptSpecializationExpr>(TC->getImmediatelyDeclaredConstraint());
152+
bool Dependent =
153+
Constraint->getTemplateArgsAsWritten() &&
154+
TemplateSpecializationType::anyInstantiationDependentTemplateArguments(
155+
Constraint->getTemplateArgsAsWritten()->arguments().drop_front(1));
156+
TypeConstraintInfo.setInt(Dependent ? true : false);
157+
}
158+
159+
concepts::TypeRequirement::TypeRequirement(TypeSourceInfo *T)
160+
: Requirement(RK_Type, T->getType()->isInstantiationDependentType(),
161+
T->getType()->containsUnexpandedParameterPack(),
162+
// We reach this ctor with either dependent types (in which
163+
// IsSatisfied doesn't matter) or with non-dependent type in
164+
// which the existence of the type indicates satisfaction.
165+
/*IsSatisfied=*/true),
166+
Value(T),
167+
Status(T->getType()->isInstantiationDependentType() ? SS_Dependent
168+
: SS_Satisfied) {}

clang/lib/Sema/SemaConcept.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,64 +1782,6 @@ bool Sema::MaybeEmitAmbiguousAtomicConstraintsDiagnostic(
17821782
return true;
17831783
}
17841784

1785-
concepts::ExprRequirement::ExprRequirement(
1786-
Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
1787-
ReturnTypeRequirement Req, SatisfactionStatus Status,
1788-
ConceptSpecializationExpr *SubstitutedConstraintExpr) :
1789-
Requirement(IsSimple ? RK_Simple : RK_Compound, Status == SS_Dependent,
1790-
Status == SS_Dependent &&
1791-
(E->containsUnexpandedParameterPack() ||
1792-
Req.containsUnexpandedParameterPack()),
1793-
Status == SS_Satisfied), Value(E), NoexceptLoc(NoexceptLoc),
1794-
TypeReq(Req), SubstitutedConstraintExpr(SubstitutedConstraintExpr),
1795-
Status(Status) {
1796-
assert((!IsSimple || (Req.isEmpty() && NoexceptLoc.isInvalid())) &&
1797-
"Simple requirement must not have a return type requirement or a "
1798-
"noexcept specification");
1799-
assert((Status > SS_TypeRequirementSubstitutionFailure && Req.isTypeConstraint()) ==
1800-
(SubstitutedConstraintExpr != nullptr));
1801-
}
1802-
1803-
concepts::ExprRequirement::ExprRequirement(
1804-
SubstitutionDiagnostic *ExprSubstDiag, bool IsSimple,
1805-
SourceLocation NoexceptLoc, ReturnTypeRequirement Req) :
1806-
Requirement(IsSimple ? RK_Simple : RK_Compound, Req.isDependent(),
1807-
Req.containsUnexpandedParameterPack(), /*IsSatisfied=*/false),
1808-
Value(ExprSubstDiag), NoexceptLoc(NoexceptLoc), TypeReq(Req),
1809-
Status(SS_ExprSubstitutionFailure) {
1810-
assert((!IsSimple || (Req.isEmpty() && NoexceptLoc.isInvalid())) &&
1811-
"Simple requirement must not have a return type requirement or a "
1812-
"noexcept specification");
1813-
}
1814-
1815-
concepts::ExprRequirement::ReturnTypeRequirement::
1816-
ReturnTypeRequirement(TemplateParameterList *TPL) :
1817-
TypeConstraintInfo(TPL, false) {
1818-
assert(TPL->size() == 1);
1819-
const TypeConstraint *TC =
1820-
cast<TemplateTypeParmDecl>(TPL->getParam(0))->getTypeConstraint();
1821-
assert(TC &&
1822-
"TPL must have a template type parameter with a type constraint");
1823-
auto *Constraint =
1824-
cast<ConceptSpecializationExpr>(TC->getImmediatelyDeclaredConstraint());
1825-
bool Dependent =
1826-
Constraint->getTemplateArgsAsWritten() &&
1827-
TemplateSpecializationType::anyInstantiationDependentTemplateArguments(
1828-
Constraint->getTemplateArgsAsWritten()->arguments().drop_front(1));
1829-
TypeConstraintInfo.setInt(Dependent ? true : false);
1830-
}
1831-
1832-
concepts::TypeRequirement::TypeRequirement(TypeSourceInfo *T) :
1833-
Requirement(RK_Type, T->getType()->isInstantiationDependentType(),
1834-
T->getType()->containsUnexpandedParameterPack(),
1835-
// We reach this ctor with either dependent types (in which
1836-
// IsSatisfied doesn't matter) or with non-dependent type in
1837-
// which the existence of the type indicates satisfaction.
1838-
/*IsSatisfied=*/true),
1839-
Value(T),
1840-
Status(T->getType()->isInstantiationDependentType() ? SS_Dependent
1841-
: SS_Satisfied) {}
1842-
18431785
NormalizedConstraint::CompoundConstraintKind
18441786
NormalizedConstraint::getCompoundKind() const {
18451787
assert(isCompound() && "getCompoundKind on a non-compound constraint..");

0 commit comments

Comments
 (0)