Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
rsmith accepted this revision. This revision is now accepted and ready to land. Comment at: lib/AST/ASTImporter.cpp:2253-2254 @@ +2252,4 @@ + return nullptr; + } + else { +ToRequiresClause = nullptr; `else` on same line as `}` please. https://reviews.llvm.org/D19322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
hubert.reinterpretcast added a comment. Ping. http://reviews.llvm.org/D19322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
hubert.reinterpretcast added a comment. Ping (#2). http://reviews.llvm.org/D19322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
hubert.reinterpretcast updated this revision to Diff 57216. hubert.reinterpretcast added a comment. Set requires-clause when creating TemplateParameterLists; NFC Removes the default argument for the requires-clause constraint expression in TemplateParameterList::Create. An appropriate argument is supplied at the various call sites. Serialization changes will be left until the feature is otherwise complete so that the version number does not need to be bumped multiple times. http://reviews.llvm.org/D19322 Files: include/clang/AST/DeclTemplate.h lib/AST/ASTContext.cpp lib/AST/ASTImporter.cpp lib/AST/DeclTemplate.cpp lib/Sema/SemaLambda.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp Index: lib/Serialization/ASTWriter.cpp === --- lib/Serialization/ASTWriter.cpp +++ lib/Serialization/ASTWriter.cpp @@ -5359,6 +5359,7 @@ AddSourceLocation(TemplateParams->getTemplateLoc()); AddSourceLocation(TemplateParams->getLAngleLoc()); AddSourceLocation(TemplateParams->getRAngleLoc()); + // TODO: Concepts Record->push_back(TemplateParams->size()); for (const auto &P : *TemplateParams) AddDeclRef(P); Index: lib/Serialization/ASTReader.cpp === --- lib/Serialization/ASTReader.cpp +++ lib/Serialization/ASTReader.cpp @@ -7892,9 +7892,10 @@ while (NumParams--) Params.push_back(ReadDeclAs(F, Record, Idx)); + // TODO: Concepts TemplateParameterList* TemplateParams = TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, - Params, RAngleLoc); + Params, RAngleLoc, nullptr); return TemplateParams; } Index: lib/Sema/SemaTemplateInstantiateDecl.cpp === --- lib/Sema/SemaTemplateInstantiateDecl.cpp +++ lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2947,10 +2947,14 @@ if (Invalid) return nullptr; + // Note: we substitute into associated constraints later + Expr *const UninstantiatedRequiresClause = L->getRequiresClause(); + TemplateParameterList *InstL = TemplateParameterList::Create(SemaRef.Context, L->getTemplateLoc(), L->getLAngleLoc(), Params, -L->getRAngleLoc()); +L->getRAngleLoc(), +UninstantiatedRequiresClause); return InstL; } Index: lib/Sema/SemaTemplateDeduction.cpp === --- lib/Sema/SemaTemplateDeduction.cpp +++ lib/Sema/SemaTemplateDeduction.cpp @@ -4022,8 +4022,8 @@ nullptr, false, false); QualType TemplArg = QualType(TemplParam->getTypeForDecl(), 0); NamedDecl *TemplParamPtr = TemplParam; - FixedSizeTemplateParameterListStorage<1> TemplateParamsSt( - Loc, Loc, TemplParamPtr, Loc); + FixedSizeTemplateParameterListStorage<1, false> TemplateParamsSt( + Loc, Loc, TemplParamPtr, Loc, nullptr); QualType FuncParam = SubstituteAutoTransform(*this, TemplArg).Apply(Type); assert(!FuncParam.isNull() && Index: lib/Sema/SemaTemplate.cpp === --- lib/Sema/SemaTemplate.cpp +++ lib/Sema/SemaTemplate.cpp @@ -831,11 +831,10 @@ if (ExportLoc.isValid()) Diag(ExportLoc, diag::warn_template_export_unsupported); - // FIXME: store RequiresClause return TemplateParameterList::Create( Context, TemplateLoc, LAngleLoc, llvm::makeArrayRef((NamedDecl *const *)Params.data(), Params.size()), - RAngleLoc); + RAngleLoc, RequiresClause); } static void SetNestedNameSpecifier(TagDecl *T, const CXXScopeSpec &SS) { @@ -1953,7 +1952,7 @@ // Fabricate an empty template parameter list for the invented header. return TemplateParameterList::Create(Context, SourceLocation(), SourceLocation(), None, - SourceLocation()); + SourceLocation(), nullptr); } return nullptr; Index: lib/Sema/SemaLambda.cpp === --- lib/Sema/SemaLambda.cpp +++ lib/Sema/SemaLambda.cpp @@ -235,7 +235,7 @@ /*Template kw loc*/ SourceLocation(), LAngleLoc, llvm::makeArrayRef((NamedDecl *const *)LSI->AutoTemplateParams.data(), LSI->AutoTemplateParams.size()), -RAngleLoc); +RAngleLoc, nullptr); } return LSI->GLTemplateParameterList; } Index: lib/AST/DeclTemplate.cpp === --- lib/AST/DeclTemplate.cpp +++ lib/AST/DeclTe
Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
hubert.reinterpretcast added a comment. Ping. http://reviews.llvm.org/D19322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
hubert.reinterpretcast marked 2 inline comments as done. hubert.reinterpretcast added a comment. @rsmith; I've addressed Faisal's comment. Please let me know if this patch (and http://reviews.llvm.org/D19770) is good to go. If it isn't ready yet, I'd like your opinion on http://reviews.llvm.org/D19770+http://reviews.llvm.org/D19771. http://reviews.llvm.org/D19322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
hubert.reinterpretcast updated this revision to Diff 55850. hubert.reinterpretcast added a comment. Address Faisal's comment; supercedes http://reviews.llvm.org/D19771 Replaces the custom FixedSizeTemplateParameterListStorage implementation with one that follows the interface provided by llvm::TrailingObjects. http://reviews.llvm.org/D19322 Files: include/clang/AST/DeclTemplate.h lib/AST/DeclTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp Index: lib/Sema/SemaTemplateDeduction.cpp === --- lib/Sema/SemaTemplateDeduction.cpp +++ lib/Sema/SemaTemplateDeduction.cpp @@ -4022,8 +4022,8 @@ nullptr, false, false); QualType TemplArg = QualType(TemplParam->getTypeForDecl(), 0); NamedDecl *TemplParamPtr = TemplParam; - FixedSizeTemplateParameterListStorage<1> TemplateParamsSt( - Loc, Loc, TemplParamPtr, Loc); + FixedSizeTemplateParameterListStorage<1, false> TemplateParamsSt( + Loc, Loc, TemplParamPtr, Loc, nullptr); QualType FuncParam = SubstituteAutoTransform(*this, TemplArg).Apply(Type); assert(!FuncParam.isNull() && Index: lib/AST/DeclTemplate.cpp === --- lib/AST/DeclTemplate.cpp +++ lib/AST/DeclTemplate.cpp @@ -31,9 +31,11 @@ TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc) + SourceLocation RAngleLoc, + Expr *RequiresClause) : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), -NumParams(Params.size()), ContainsUnexpandedParameterPack(false) { +NumParams(Params.size()), ContainsUnexpandedParameterPack(false), +HasRequiresClause(static_cast(RequiresClause)) { assert(this->NumParams == NumParams && "Too many template parameters"); for (unsigned Idx = 0; Idx < NumParams; ++Idx) { NamedDecl *P = Params[Idx]; @@ -52,15 +54,21 @@ // template parameter list does too. } } + if (RequiresClause) { +*getTrailingObjects() = RequiresClause; + } } -TemplateParameterList *TemplateParameterList::Create( -const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, -ArrayRef Params, SourceLocation RAngleLoc) { - void *Mem = C.Allocate(totalSizeToAlloc(Params.size()), +TemplateParameterList * +TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc, + SourceLocation LAngleLoc, + ArrayRef Params, + SourceLocation RAngleLoc, Expr *RequiresClause) { + void *Mem = C.Allocate(totalSizeToAlloc( + Params.size(), RequiresClause ? 1u : 0u), llvm::alignOf()); return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, - RAngleLoc); + RAngleLoc, RequiresClause); } unsigned TemplateParameterList::getMinRequiredArguments() const { Index: include/clang/AST/DeclTemplate.h === --- include/clang/AST/DeclTemplate.h +++ include/clang/AST/DeclTemplate.h @@ -46,7 +46,8 @@ /// \brief Stores a list of template parameters for a TemplateDecl and its /// derived classes. class TemplateParameterList final -: private llvm::TrailingObjects { +: private llvm::TrailingObjects { /// The location of the 'template' keyword. SourceLocation TemplateLoc; @@ -56,26 +57,36 @@ /// The number of template parameters in this template /// parameter list. - unsigned NumParams : 31; + unsigned NumParams : 30; /// Whether this template parameter list contains an unexpanded parameter /// pack. unsigned ContainsUnexpandedParameterPack : 1; + /// Whether this template parameter list has an associated requires-clause + unsigned HasRequiresClause : 1; + protected: size_t numTrailingObjects(OverloadToken) const { return NumParams; } + size_t numTrailingObjects(OverloadToken) const { +return HasRequiresClause; + } + TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, -ArrayRef Params, SourceLocation RAngleLoc); +ArrayRef Params, SourceLocation RAngleLoc, +Expr *RequiresClause); public: + // FIXME: remove default argument for RequiresClause static TemplateParameterList *Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, -
Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
hubert.reinterpretcast added inline comments. Comment at: include/clang/AST/DeclTemplate.h:175 @@ -152,2 +174,3 @@ + Expr *RequiresClause; public: faisalv wrote: > Yuk - this entire guy (FizedSizeTemplateParameterListStorage) seems quite > fragile (dependent on object layout) - are the gains (in the single use below > during auto-type deduction) in preformance really worth the introduction of > this fragility/ugliness? > Unless there is a clear win from this strategy, I think i'd favor (perhaps in > a later patch) - either just removing this structure and using TPL for the > use-case in auto-type below, or using placement new and creating the stack > TPL on a stack unsigned char array? > Thoughts? > I don't like the class here either; however, I would not like to introduce heap allocation just to remove it. placement-new is certainly part of the solution. I think that `TrailingObjects` should have an alias for a type that can be used as aligned storage (templated in the style of `totalSizeToAlloc`). I would like to keep that endeavour to a separate patch though. http://reviews.llvm.org/D19322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
faisalv added inline comments. Comment at: include/clang/AST/DeclTemplate.h:175 @@ -152,2 +174,3 @@ + Expr *RequiresClause; public: Yuk - this entire guy (FizedSizeTemplateParameterListStorage) seems quite fragile (dependent on object layout) - are the gains (in the single use below during auto-type deduction) in preformance really worth the introduction of this fragility/ugliness? Unless there is a clear win from this strategy, I think i'd favor (perhaps in a later patch) - either just removing this structure and using TPL for the use-case in auto-type below, or using placement new and creating the stack TPL on a stack unsigned char array? Thoughts? http://reviews.llvm.org/D19322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
hubert.reinterpretcast updated this revision to Diff 54456. hubert.reinterpretcast added a comment. Actually add parens this time http://reviews.llvm.org/D19322 Files: include/clang/AST/DeclTemplate.h lib/AST/DeclTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp Index: lib/Sema/SemaTemplateDeduction.cpp === --- lib/Sema/SemaTemplateDeduction.cpp +++ lib/Sema/SemaTemplateDeduction.cpp @@ -4034,8 +4034,8 @@ nullptr, false, false); QualType TemplArg = QualType(TemplParam->getTypeForDecl(), 0); NamedDecl *TemplParamPtr = TemplParam; - FixedSizeTemplateParameterListStorage<1> TemplateParamsSt( - Loc, Loc, TemplParamPtr, Loc); + FixedSizeTemplateParameterListStorage<1, false> TemplateParamsSt( + Loc, Loc, TemplParamPtr, Loc, nullptr); QualType FuncParam = SubstituteAutoTransform(*this, TemplArg).Apply(Type); assert(!FuncParam.isNull() && Index: lib/AST/DeclTemplate.cpp === --- lib/AST/DeclTemplate.cpp +++ lib/AST/DeclTemplate.cpp @@ -31,9 +31,11 @@ TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc) + SourceLocation RAngleLoc, + Expr *RequiresClause) : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), -NumParams(Params.size()), ContainsUnexpandedParameterPack(false) { +NumParams(Params.size()), ContainsUnexpandedParameterPack(false), +HasRequiresClause(static_cast(RequiresClause)) { assert(this->NumParams == NumParams && "Too many template parameters"); for (unsigned Idx = 0; Idx < NumParams; ++Idx) { NamedDecl *P = Params[Idx]; @@ -52,15 +54,21 @@ // template parameter list does too. } } + if (RequiresClause) { +*getTrailingObjects() = RequiresClause; + } } -TemplateParameterList *TemplateParameterList::Create( -const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, -ArrayRef Params, SourceLocation RAngleLoc) { - void *Mem = C.Allocate(totalSizeToAlloc(Params.size()), +TemplateParameterList * +TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc, + SourceLocation LAngleLoc, + ArrayRef Params, + SourceLocation RAngleLoc, Expr *RequiresClause) { + void *Mem = C.Allocate(totalSizeToAlloc( + Params.size(), RequiresClause ? 1u : 0u), llvm::alignOf()); return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, - RAngleLoc); + RAngleLoc, RequiresClause); } unsigned TemplateParameterList::getMinRequiredArguments() const { Index: include/clang/AST/DeclTemplate.h === --- include/clang/AST/DeclTemplate.h +++ include/clang/AST/DeclTemplate.h @@ -46,7 +46,8 @@ /// \brief Stores a list of template parameters for a TemplateDecl and its /// derived classes. class TemplateParameterList final -: private llvm::TrailingObjects { +: private llvm::TrailingObjects { /// The location of the 'template' keyword. SourceLocation TemplateLoc; @@ -56,26 +57,36 @@ /// The number of template parameters in this template /// parameter list. - unsigned NumParams : 31; + unsigned NumParams : 30; /// Whether this template parameter list contains an unexpanded parameter /// pack. unsigned ContainsUnexpandedParameterPack : 1; + /// Whether this template parameter list has an associated requires-clause + unsigned HasRequiresClause : 1; + protected: size_t numTrailingObjects(OverloadToken) const { return NumParams; } + size_t numTrailingObjects(OverloadToken) const { +return HasRequiresClause; + } + TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, -ArrayRef Params, SourceLocation RAngleLoc); +ArrayRef Params, SourceLocation RAngleLoc, +Expr *RequiresClause); public: + // FIXME: remove default argument for RequiresClause static TemplateParameterList *Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc); + SourceLocation RAngleLoc, + Expr *RequiresClause =
Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC
hubert.reinterpretcast updated this revision to Diff 54455. hubert.reinterpretcast added a comment. Store the RequiresClause expression into the created storage; add accessor; add unnecessary parens to silence warning http://reviews.llvm.org/D19322 Files: include/clang/AST/DeclTemplate.h lib/AST/DeclTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp Index: lib/Sema/SemaTemplateDeduction.cpp === --- lib/Sema/SemaTemplateDeduction.cpp +++ lib/Sema/SemaTemplateDeduction.cpp @@ -4034,8 +4034,8 @@ nullptr, false, false); QualType TemplArg = QualType(TemplParam->getTypeForDecl(), 0); NamedDecl *TemplParamPtr = TemplParam; - FixedSizeTemplateParameterListStorage<1> TemplateParamsSt( - Loc, Loc, TemplParamPtr, Loc); + FixedSizeTemplateParameterListStorage<1, false> TemplateParamsSt( + Loc, Loc, TemplParamPtr, Loc, nullptr); QualType FuncParam = SubstituteAutoTransform(*this, TemplArg).Apply(Type); assert(!FuncParam.isNull() && Index: lib/AST/DeclTemplate.cpp === --- lib/AST/DeclTemplate.cpp +++ lib/AST/DeclTemplate.cpp @@ -31,9 +31,11 @@ TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc) + SourceLocation RAngleLoc, + Expr *RequiresClause) : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), -NumParams(Params.size()), ContainsUnexpandedParameterPack(false) { +NumParams(Params.size()), ContainsUnexpandedParameterPack(false), +HasRequiresClause(static_cast(RequiresClause)) { assert(this->NumParams == NumParams && "Too many template parameters"); for (unsigned Idx = 0; Idx < NumParams; ++Idx) { NamedDecl *P = Params[Idx]; @@ -52,15 +54,21 @@ // template parameter list does too. } } + if (RequiresClause) { +*getTrailingObjects() = RequiresClause; + } } -TemplateParameterList *TemplateParameterList::Create( -const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, -ArrayRef Params, SourceLocation RAngleLoc) { - void *Mem = C.Allocate(totalSizeToAlloc(Params.size()), +TemplateParameterList * +TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc, + SourceLocation LAngleLoc, + ArrayRef Params, + SourceLocation RAngleLoc, Expr *RequiresClause) { + void *Mem = C.Allocate(totalSizeToAlloc( + Params.size(), RequiresClause ? 1u : 0u), llvm::alignOf()); return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, - RAngleLoc); + RAngleLoc, RequiresClause); } unsigned TemplateParameterList::getMinRequiredArguments() const { Index: include/clang/AST/DeclTemplate.h === --- include/clang/AST/DeclTemplate.h +++ include/clang/AST/DeclTemplate.h @@ -46,7 +46,8 @@ /// \brief Stores a list of template parameters for a TemplateDecl and its /// derived classes. class TemplateParameterList final -: private llvm::TrailingObjects { +: private llvm::TrailingObjects { /// The location of the 'template' keyword. SourceLocation TemplateLoc; @@ -56,26 +57,36 @@ /// The number of template parameters in this template /// parameter list. - unsigned NumParams : 31; + unsigned NumParams : 30; /// Whether this template parameter list contains an unexpanded parameter /// pack. unsigned ContainsUnexpandedParameterPack : 1; + /// Whether this template parameter list has an associated requires-clause + unsigned HasRequiresClause : 1; + protected: size_t numTrailingObjects(OverloadToken) const { return NumParams; } + size_t numTrailingObjects(OverloadToken) const { +return HasRequiresClause; + } + TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, -ArrayRef Params, SourceLocation RAngleLoc); +ArrayRef Params, SourceLocation RAngleLoc, +Expr *RequiresClause); public: + // FIXME: remove default argument for RequiresClause static TemplateParameterList *Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc); + S