Skip to content

Commit

Permalink
Temporarily revert partially applied concepts to simplify the diff
Browse files Browse the repository at this point in the history
  • Loading branch information
cor3ntin committed Oct 4, 2024
1 parent b93e741 commit d658277
Show file tree
Hide file tree
Showing 28 changed files with 25 additions and 551 deletions.
48 changes: 0 additions & 48 deletions clang/include/clang/AST/ASTConcept.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,54 +281,6 @@ class TypeConstraint {

};

class PartiallyAppliedConcept : public ConceptReference,
public llvm::FoldingSetNode {

SourceLocation ConceptKWLoc;
PartiallyAppliedConcept(NestedNameSpecifierLoc NNS,
DeclarationNameInfo ConceptNameInfo,
SourceLocation ConceptKWLoc, NamedDecl *FoundDecl,
TemplateDecl *NamedConcept,
const ASTTemplateArgumentListInfo *ArgsAsWritten)
: ConceptReference(NNS, /*TemplateKWLoc=*/SourceLocation(),
ConceptNameInfo, FoundDecl, NamedConcept,
ArgsAsWritten),
ConceptKWLoc(ConceptKWLoc) {}

public:
static PartiallyAppliedConcept *
Create(const ASTContext &C, NestedNameSpecifierLoc NNS,
DeclarationNameInfo ConceptNameInfo, SourceLocation ConceptKWLoc,
NamedDecl *FoundDecl, TemplateDecl *NamedConcept,
const TemplateArgumentListInfo &TemplateArgs);

TemplateArgumentDependence getDependence() const;

bool isDependent() const {
return getDependence() & TemplateArgumentDependence::Dependent;
}

bool isInstantiationDependent() const {
return getDependence() & TemplateArgumentDependence::Instantiation;
}

void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) const {
Profile(ID, C, getNamedConcept(), getTemplateArgsAsWritten());
}

static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C,
const TemplateDecl *NamedConcept,
const ASTTemplateArgumentListInfo *ArgsAsWritten);

SourceLocation getConceptKWLoc() const { return ConceptKWLoc; }

SourceRange getSourceRange() const {
return {ConceptKWLoc, ArgsAsWritten->getRAngleLoc()};
}

friend const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
PartiallyAppliedConcept &C);
};

} // clang

Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class ObjCTypeParamDecl;
class OMPTraitInfo;
class ParentMapContext;
struct ParsedTargetAttr;
class PartiallyAppliedConcept;
class Preprocessor;
class ProfileList;
class StoredDeclsMap;
Expand Down
16 changes: 0 additions & 16 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -904,14 +904,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
case TemplateArgument::Pack:
return getDerived().TraverseTemplateArguments(Arg.pack_elements());

case TemplateArgument::Concept: {
PartiallyAppliedConcept *C = Arg.getAsPartiallyAppliedConcept();
TRY_TO(getDerived().TraverseDecl(C->getNamedConcept()));
for (const TemplateArgumentLoc &Arg :
C->getTemplateArgsAsWritten()->arguments())
TRY_TO(TraverseTemplateArgument(Arg.getArgument()));
return true;
}
case TemplateArgument::Universal:
case TemplateArgument::UniversalExpansion: {
UniversalTemplateParameterName *UTPN =
Expand Down Expand Up @@ -965,14 +957,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
case TemplateArgument::Pack:
return getDerived().TraverseTemplateArguments(Arg.pack_elements());

case TemplateArgument::Concept: {
PartiallyAppliedConcept *C = Arg.getAsPartiallyAppliedConcept();
TRY_TO(getDerived().TraverseDecl(C->getNamedConcept()));
for (const TemplateArgumentLoc &Arg :
C->getTemplateArgsAsWritten()->arguments())
TRY_TO(TraverseTemplateArgument(Arg.getArgument()));
return true;
}
}

return true;
Expand Down
2 changes: 0 additions & 2 deletions clang/include/clang/AST/TemplateArgumentVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class Base {
DISPATCH(TemplateExpansion);
DISPATCH(Expression);
DISPATCH(Pack);
DISPATCH(Concept);
DISPATCH(Universal);
DISPATCH(UniversalExpansion);
}
Expand All @@ -68,7 +67,6 @@ class Base {
VISIT_METHOD(TemplateExpansion);
VISIT_METHOD(Expression);
VISIT_METHOD(Pack);
VISIT_METHOD(Concept);
VISIT_METHOD(Universal);
VISIT_METHOD(UniversalExpansion);

Expand Down
35 changes: 4 additions & 31 deletions clang/include/clang/AST/TemplateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class Expr;
struct PrintingPolicy;
class TypeSourceInfo;
class ValueDecl;
class PartiallyAppliedConcept;

/// Represents a template argument.
class TemplateArgument {
Expand Down Expand Up @@ -109,9 +108,6 @@ class TemplateArgument {
/// in the Args struct.
Pack,

// A concept with argument
Concept,

/// The template argument refers to a universal template parameter
Universal,

Expand Down Expand Up @@ -183,12 +179,6 @@ class TemplateArgument {
uintptr_t V;
};

struct ConceptData {
unsigned Kind : 31;
unsigned IsDefaulted : 1;
PartiallyAppliedConcept *C;
};

struct UniversalTpl {
unsigned Kind : 31;
unsigned IsDefaulted : 1;
Expand All @@ -203,7 +193,6 @@ class TemplateArgument {
struct A Args;
struct TA TemplateArg;
struct TV TypeOrValue;
struct ConceptData PartialConcept;
struct UniversalTpl UniversalArg;
};

Expand Down Expand Up @@ -311,13 +300,6 @@ class TemplateArgument {
this->Args.NumArgs = Args.size();
}

explicit TemplateArgument(PartiallyAppliedConcept *C,
bool IsDefaulted = false) {
PartialConcept.Kind = Concept;
PartialConcept.IsDefaulted = IsDefaulted;
PartialConcept.C = C;
}

explicit TemplateArgument(UniversalTemplateParameterName *U,
bool IsDefaulted = false) {
UniversalArg.Kind = Universal;
Expand Down Expand Up @@ -411,11 +393,6 @@ class TemplateArgument {
return TemplateName::getFromVoidPointer(TemplateArg.Name);
}

PartiallyAppliedConcept *getAsPartiallyAppliedConcept() const {
assert((getKind() == Concept) && "Unexpected kind");
return PartialConcept.C;
}

UniversalTemplateParameterName *getAsUniversalTemplateParameterName() const {
assert((getKind() == Universal) && "Unexpected kind");
return UniversalArg.D;
Expand Down Expand Up @@ -647,8 +624,7 @@ class TemplateArgumentLoc {
: Argument(Argument),
LocInfo(Ctx, QualifierLoc, TemplateNameLoc, EllipsisLoc) {
assert(Argument.getKind() == TemplateArgument::Template ||
Argument.getKind() == TemplateArgument::TemplateExpansion ||
Argument.getKind() == TemplateArgument::Concept);
Argument.getKind() == TemplateArgument::TemplateExpansion);
}

TemplateArgumentLoc(ASTContext &Ctx, const TemplateArgument &Argument,
Expand All @@ -662,8 +638,7 @@ class TemplateArgumentLoc {
/// - Fetches the primary location of the argument.
SourceLocation getLocation() const {
if (Argument.getKind() == TemplateArgument::Template ||
Argument.getKind() == TemplateArgument::TemplateExpansion ||
Argument.getKind() == TemplateArgument::Concept)
Argument.getKind() == TemplateArgument::TemplateExpansion)
return getTemplateNameLoc();

return getSourceRange().getBegin();
Expand Down Expand Up @@ -709,16 +684,14 @@ class TemplateArgumentLoc {

NestedNameSpecifierLoc getTemplateQualifierLoc() const {
if (Argument.getKind() != TemplateArgument::Template &&
Argument.getKind() != TemplateArgument::TemplateExpansion &&
Argument.getKind() != TemplateArgument::Concept)
Argument.getKind() != TemplateArgument::TemplateExpansion)
return NestedNameSpecifierLoc();
return LocInfo.getTemplateQualifierLoc();
}

SourceLocation getTemplateNameLoc() const {
if (Argument.getKind() != TemplateArgument::Template &&
Argument.getKind() != TemplateArgument::TemplateExpansion &&
Argument.getKind() != TemplateArgument::Concept)
Argument.getKind() != TemplateArgument::TemplateExpansion)
return SourceLocation();
return LocInfo.getTemplateNameLoc();
}
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/TypeProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ let Class = AutoType in {
}
def : Property<"typeConstraintConcept", Optional<TemplateDeclRef>> {
let Read = [{ makeOptionalFromPointer(
const_cast<const TemplateDecl*>(node->getTypeConstraintConcept())) }];
node->getTypeConstraintConcept()) }];
}
def : Property<"typeConstraintArguments", Array<TemplateArgument>> {
let Read = [{ node->getTypeConstraintArguments() }];
Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3865,7 +3865,6 @@ class Parser : public CodeCompletionHandler {
bool IsClassName = false);
bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
TemplateTy Template, SourceLocation OpenLoc);
ParsedTemplateArgument ParsePartiallyAppliedConceptTemplateArgument();
ParsedTemplateArgument ParseTemplateTemplateArgument();
ParsedTemplateArgument ParseUniversalTemplateParamNameArgument();
ParsedTemplateArgument ParseTemplateArgument();
Expand Down
15 changes: 1 addition & 14 deletions clang/include/clang/Sema/ParsedTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <new>

namespace clang {
class PartiallyAppliedConcept;

/// Represents the parsed form of a C++ template argument.
class ParsedTemplateArgument {
Expand All @@ -39,8 +38,6 @@ class ParsedTemplateArgument {
NonType,
/// A template template argument, stored as a template name.
Template,
/// A partially applied concept
PartiallyAppliedConcept,
/// The name of a Universal Template Parameter
Universal
};
Expand Down Expand Up @@ -71,11 +68,6 @@ class ParsedTemplateArgument {
: Kind(ParsedTemplateArgument::Template), Arg(Template.getAsOpaquePtr()),
SS(SS), Loc(TemplateLoc) {}

ParsedTemplateArgument(class PartiallyAppliedConcept *Concept,
SourceLocation TemplateLoc)
: Kind(ParsedTemplateArgument::PartiallyAppliedConcept), Arg(Concept),
Loc(TemplateLoc) {}

ParsedTemplateArgument(UniversalTemplateParamNameTy ParamName,
SourceLocation Loc)
: Kind(ParsedTemplateArgument::Universal),
Expand Down Expand Up @@ -105,11 +97,6 @@ class ParsedTemplateArgument {
return ParsedTemplateTy::getFromOpaquePtr(Arg);
}

class PartiallyAppliedConcept *getAsConcept() const {
assert(Kind == PartiallyAppliedConcept && "Not a concept argument");
return reinterpret_cast<class PartiallyAppliedConcept *>(Arg);
}

UniversalTemplateParamNameTy getAsUniversalTemplateParamName() const {
assert(Kind == Universal &&
"Not a reference to a universal template parameter");
Expand All @@ -122,7 +109,7 @@ class ParsedTemplateArgument {
/// Retrieve the nested-name-specifier that precedes the template
/// name in a template template argument.
const CXXScopeSpec &getScopeSpec() const {
assert((Kind == Template || Kind == PartiallyAppliedConcept) &&
assert((Kind == Template) &&
"Only template template arguments can have a scope specifier");
return SS;
}
Expand Down
14 changes: 0 additions & 14 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,6 @@ class Sema final : public SemaBase {

typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
typedef OpaquePtr<TemplateName> TemplateTy;
typedef OpaquePtr<PartiallyAppliedConcept> ConceptTy;
typedef OpaquePtr<UniversalTemplateParameterName *>
UniversalTemplateParamNameTy;
typedef OpaquePtr<QualType> TypeTy;
Expand Down Expand Up @@ -11537,15 +11536,6 @@ class Sema final : public SemaBase {
bool EnteringContext, TemplateTy &Template,
bool AllowInjectedClassName = false);

PartiallyAppliedConcept *BuildPartiallyAppliedConcept(
NestedNameSpecifierLoc NNS, SourceLocation ConceptKWLoc,
DeclarationNameInfo ConceptName, TemplateDecl *TD,
const TemplateArgumentListInfo &TemplateArgs);
PartiallyAppliedConcept *
ActOnPartiallyAppliedConcept(Scope *S, CXXScopeSpec &SS,
SourceLocation ConceptKWLoc,
TemplateIdAnnotation *TemplateId);

bool
ActOnUniversalTemplateParameterName(Scope *S, const UnqualifiedId &Name,
bool EnteringContext,
Expand Down Expand Up @@ -11836,10 +11826,6 @@ class Sema final : public SemaBase {
TemplateArgument &SugaredConverted,
TemplateArgument &CanonicalConverted,
CheckTemplateArgumentKind CTAK);
bool
CheckPartiallyAppliedConceptTemplateArgument(TemplateTemplateParmDecl *Param,
TemplateParameterList *Params,
TemplateArgumentLoc &Arg);

/// Check a template argument against its corresponding
/// template template parameter.
Expand Down
52 changes: 0 additions & 52 deletions clang/lib/AST/ASTConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,55 +113,3 @@ void ConceptReference::print(llvm::raw_ostream &OS,
OS << ">";
}
}


PartiallyAppliedConcept *PartiallyAppliedConcept::Create(
const ASTContext &C, NestedNameSpecifierLoc NNS,
DeclarationNameInfo ConceptNameInfo, SourceLocation ConceptKWLoc,
NamedDecl *FoundDecl, TemplateDecl *NamedConcept,
const TemplateArgumentListInfo &TemplateArgs) {

return new (C) PartiallyAppliedConcept(
NNS, ConceptNameInfo, ConceptKWLoc, FoundDecl, NamedConcept,
ASTTemplateArgumentListInfo::Create(C, TemplateArgs));
}

TemplateArgumentDependence PartiallyAppliedConcept::getDependence() const {
auto TA = TemplateArgumentDependence::None;
if (isa<TemplateTemplateParmDecl>(getNamedConcept())) {
TA |= TemplateArgumentDependence::DependentInstantiation;
}
const auto InterestingDeps = TemplateArgumentDependence::Instantiation |
TemplateArgumentDependence::UnexpandedPack;
for (const TemplateArgumentLoc &ArgLoc :
getTemplateArgsAsWritten()->arguments()) {
TA |= ArgLoc.getArgument().getDependence() & InterestingDeps;
if (TA == InterestingDeps)
break;
}
return TA;
}

void PartiallyAppliedConcept::Profile(
llvm::FoldingSetNodeID &ID, const ASTContext &C,
const TemplateDecl *NamedConcept,
const ASTTemplateArgumentListInfo *ArgsAsWritten) {
ID.AddPointer(NamedConcept);
ID.AddInteger(ArgsAsWritten->getNumTemplateArgs());
for (auto &Arg : ArgsAsWritten->arguments())
Arg.getArgument().Profile(ID, C);
}

const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB,
PartiallyAppliedConcept &C) {
std::string NameStr;
llvm::raw_string_ostream OS(NameStr);
LangOptions LO;
LO.CPlusPlus = true;
LO.Bool = true;
OS << '\'';
C.print(OS, PrintingPolicy(LO));
OS << '\'';
OS.flush();
return DB << NameStr;
}
4 changes: 0 additions & 4 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7308,10 +7308,6 @@ ASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const {
case TemplateArgument::Expression:
return Arg;

// FIXME corentin: do concept needs to be canonicalized?
case TemplateArgument::Concept:
return Arg;

case TemplateArgument::Declaration: {
auto *D = cast<ValueDecl>(Arg.getAsDecl()->getCanonicalDecl());
return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()),
Expand Down
Loading

0 comments on commit d658277

Please sign in to comment.