Skip to content

Commit b2738f5

Browse files
Revert "[Clang] Add a builtin that deduplicate types into a pack (llvm#106730)"
This reverts commits 85043c1 and 65de318. The first commit above triggers the following warnings: clang/lib/Sema/SemaTemplateVariadic.cpp:1069:22: error: variable 'TST' set but not used [-Werror,-Wunused-but-set-variable] lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4148:11: error: enumeration value 'SubstBuiltinTemplatePack' not handled in switch [-Werror,-Wswitch] 4148 | switch (qual_type->getTypeClass()) { | ^~~~~~~~~~~~~~~~~~~~~~~~~ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4852:11: error: enumeration value 'SubstBuiltinTemplatePack' not handled in switch [-Werror,-Wswitch] 4852 | switch (qual_type->getTypeClass()) { | ^~~~~~~~~~~~~~~~~~~~~~~~~ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:5153:11: error: enumeration value 'SubstBuiltinTemplatePack' not handled in switch [-Werror,-Wswitch] 5153 | switch (qual_type->getTypeClass()) { | ^~~~~~~~~~~~~~~~~~~~~~~~~
1 parent 4e6c88b commit b2738f5

40 files changed

+237
-1239
lines changed

clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,6 @@ TEST_F(TargetDeclTest, BuiltinTemplates) {
731731
using type_pack_element = [[__type_pack_element]]<N, Pack...>;
732732
)cpp";
733733
EXPECT_DECLS("TemplateSpecializationTypeLoc", );
734-
735-
Code = R"cpp(
736-
template <template <class...> class Templ, class... Types>
737-
using dedup_types = Templ<[[__builtin_dedup_pack]]<Types...>...>;
738-
)cpp";
739-
EXPECT_DECLS("TemplateSpecializationTypeLoc", );
740734
}
741735

742736
TEST_F(TargetDeclTest, MemberOfTemplate) {

clang/docs/LanguageExtensions.rst

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,37 +1829,6 @@ __make_integer_seq
18291829

18301830
This alias returns ``IntSeq`` instantiated with ``IntSeqT = T``and ``Ints`` being the pack ``0, ..., N - 1``.
18311831

1832-
__builtin_dedup_pack
1833-
--------------------
1834-
1835-
.. code-block:: c++
1836-
1837-
template <class... Ts>
1838-
using __builtin_dedup_pack = ...;
1839-
1840-
This alias takes a template parameter pack ``Ts`` and produces a new unexpanded pack containing the unique types
1841-
from ``Ts``, with the order of the first occurrence of each type preserved.
1842-
It is useful in template metaprogramming to normalize type lists.
1843-
1844-
The resulting pack can be expanded in contexts like template argument lists or base specifiers.
1845-
1846-
**Example of Use**:
1847-
1848-
.. code-block:: c++
1849-
1850-
template <typename...> struct TypeList;
1851-
1852-
// The resulting type is TypeList<int, double, char>
1853-
template <typename ...ExtraTypes>
1854-
using MyTypeList = TypeList<__builtin_dedup_pack<int, double, int, char, double, ExtraTypes...>...>;
1855-
1856-
**Limitations**:
1857-
1858-
* This builtin can only be used inside a template.
1859-
* The resulting pack is currently only supported for expansion in template argument lists and base specifiers.
1860-
* This builtin cannot be assigned to a template template parameter.
1861-
1862-
18631832
Type Trait Primitives
18641833
=====================
18651834

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,6 @@ Non-comprehensive list of changes in this release
148148
correct method to check for these features is to test for the ``__PTRAUTH__``
149149
macro.
150150

151-
- Added a new builtin, ``__builtin_dedup_pack``, to remove duplicate types from a parameter pack.
152-
This feature is particularly useful in template metaprogramming for normalizing type lists.
153-
The builtin produces a new, unexpanded parameter pack that can be used in contexts like template
154-
argument lists or base specifiers.
155-
156-
.. code-block:: c++
157-
158-
template <typename...> struct TypeList;
159-
160-
// The resulting type is TypeList<int, double, char>
161-
using MyTypeList = TypeList<__builtin_dedup_pack<int, double, int, char, double>...>;
162-
163-
Currently, the use of ``__builtin_dedup_pack`` is limited to template arguments and base
164-
specifiers, it also must be used within a template context.
165-
166-
167151
New Compiler Flags
168152
------------------
169153
- New option ``-fno-sanitize-annotate-debug-info-traps`` added to disable emitting trap reasons into the debug info when compiling with trapping UBSan (e.g. ``-fsanitize-trap=undefined``).

clang/include/clang/AST/ASTContext.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
230230
SubstTemplateTypeParmTypes;
231231
mutable llvm::FoldingSet<SubstTemplateTypeParmPackType>
232232
SubstTemplateTypeParmPackTypes;
233-
mutable llvm::FoldingSet<SubstBuiltinTemplatePackType>
234-
SubstBuiltinTemplatePackTypes;
235233
mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
236234
TemplateSpecializationTypes;
237235
mutable llvm::FoldingSet<ParenType> ParenTypes{GeneralTypesLog2InitSize};
@@ -1897,7 +1895,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
18971895
QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl,
18981896
unsigned Index, bool Final,
18991897
const TemplateArgument &ArgPack);
1900-
QualType getSubstBuiltinTemplatePack(const TemplateArgument &ArgPack);
19011898

19021899
QualType
19031900
getTemplateTypeParmType(unsigned Depth, unsigned Index,

clang/include/clang/AST/DeclTemplate.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,10 +1796,7 @@ class BuiltinTemplateDecl : public TemplateDecl {
17961796
}
17971797

17981798
BuiltinTemplateKind getBuiltinTemplateKind() const { return BTK; }
1799-
1800-
bool isPackProducingBuiltinTemplate() const;
18011799
};
1802-
bool isPackProducingBuiltinTemplateName(TemplateName N);
18031800

18041801
/// Provides information about an explicit instantiation of a variable or class
18051802
/// template.

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,6 @@ template <typename Derived> class RecursiveASTVisitor {
492492
bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
493493
unsigned Count);
494494
bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
495-
bool TraverseSubstPackTypeHelper(SubstPackType *T);
496-
bool TraverseSubstPackTypeLocHelper(SubstPackTypeLoc TL);
497495
bool TraverseRecordHelper(RecordDecl *D);
498496
bool TraverseCXXRecordHelper(CXXRecordDecl *D);
499497
bool TraverseDeclaratorHelper(DeclaratorDecl *D);
@@ -1140,10 +1138,9 @@ DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
11401138
DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {
11411139
TRY_TO(TraverseType(T->getReplacementType()));
11421140
})
1143-
DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType,
1144-
{ TRY_TO(TraverseSubstPackTypeHelper(T)); })
1145-
DEF_TRAVERSE_TYPE(SubstBuiltinTemplatePackType,
1146-
{ TRY_TO(TraverseSubstPackTypeHelper(T)); })
1141+
DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {
1142+
TRY_TO(TraverseTemplateArgument(T->getArgumentPack()));
1143+
})
11471144

11481145
DEF_TRAVERSE_TYPE(AttributedType,
11491146
{ TRY_TO(TraverseType(T->getModifiedType())); })
@@ -1484,26 +1481,9 @@ DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
14841481
DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {
14851482
TRY_TO(TraverseType(TL.getTypePtr()->getReplacementType()));
14861483
})
1487-
1488-
template <typename Derived>
1489-
bool RecursiveASTVisitor<Derived>::TraverseSubstPackTypeLocHelper(
1490-
SubstPackTypeLoc TL) {
1484+
DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {
14911485
TRY_TO(TraverseTemplateArgument(TL.getTypePtr()->getArgumentPack()));
1492-
return true;
1493-
}
1494-
1495-
template <typename Derived>
1496-
bool RecursiveASTVisitor<Derived>::TraverseSubstPackTypeHelper(
1497-
SubstPackType *T) {
1498-
TRY_TO(TraverseTemplateArgument(T->getArgumentPack()));
1499-
return true;
1500-
}
1501-
1502-
DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType,
1503-
{ TRY_TO(TraverseSubstPackTypeLocHelper(TL)); })
1504-
1505-
DEF_TRAVERSE_TYPELOC(SubstBuiltinTemplatePackType,
1506-
{ TRY_TO(TraverseSubstPackTypeLocHelper(TL)); })
1486+
})
15071487

15081488
DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
15091489

clang/include/clang/AST/Type.h

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,24 +2210,20 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
22102210
unsigned PackIndex : 15;
22112211
};
22122212

2213-
class SubstPackTypeBitfields {
2214-
friend class SubstPackType;
2213+
class SubstTemplateTypeParmPackTypeBitfields {
22152214
friend class SubstTemplateTypeParmPackType;
22162215

22172216
LLVM_PREFERRED_TYPE(TypeBitfields)
22182217
unsigned : NumTypeBits;
22192218

2219+
// The index of the template parameter this substitution represents.
2220+
unsigned Index : 16;
2221+
22202222
/// The number of template arguments in \c Arguments, which is
22212223
/// expected to be able to hold at least 1024 according to [implimits].
22222224
/// However as this limit is somewhat easy to hit with template
22232225
/// metaprogramming we'd prefer to keep it as large as possible.
22242226
unsigned NumArgs : 16;
2225-
2226-
// The index of the template parameter this substitution represents.
2227-
// Only used by SubstTemplateTypeParmPackType. We keep it in the same
2228-
// class to avoid dealing with complexities of bitfields that go over
2229-
// the size of `unsigned`.
2230-
unsigned SubstTemplTypeParmPackIndex : 16;
22312227
};
22322228

22332229
class TemplateSpecializationTypeBitfields {
@@ -2344,7 +2340,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
23442340
VectorTypeBitfields VectorTypeBits;
23452341
TemplateTypeParmTypeBitfields TemplateTypeParmTypeBits;
23462342
SubstTemplateTypeParmTypeBitfields SubstTemplateTypeParmTypeBits;
2347-
SubstPackTypeBitfields SubstPackTypeBits;
2343+
SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits;
23482344
TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits;
23492345
DependentTemplateSpecializationTypeBitfields
23502346
DependentTemplateSpecializationTypeBits;
@@ -6996,56 +6992,6 @@ class SubstTemplateTypeParmType final
69966992
}
69976993
};
69986994

6999-
/// Represents the result of substituting a set of types as a template argument
7000-
/// that needs to be expanded later.
7001-
///
7002-
/// These types are always dependent and produced depending on the situations:
7003-
/// - SubstTemplateTypeParmPack is an expansion that had to be delayed,
7004-
/// - SubstBuiltinTemplatePackType is an expansion from a builtin.
7005-
class SubstPackType : public Type, public llvm::FoldingSetNode {
7006-
friend class ASTContext;
7007-
7008-
/// A pointer to the set of template arguments that this
7009-
/// parameter pack is instantiated with.
7010-
const TemplateArgument *Arguments;
7011-
7012-
protected:
7013-
SubstPackType(TypeClass Derived, QualType Canon,
7014-
const TemplateArgument &ArgPack);
7015-
7016-
public:
7017-
unsigned getNumArgs() const { return SubstPackTypeBits.NumArgs; }
7018-
7019-
TemplateArgument getArgumentPack() const;
7020-
7021-
void Profile(llvm::FoldingSetNodeID &ID);
7022-
static void Profile(llvm::FoldingSetNodeID &ID,
7023-
const TemplateArgument &ArgPack);
7024-
7025-
static bool classof(const Type *T) {
7026-
return T->getTypeClass() == SubstTemplateTypeParmPack ||
7027-
T->getTypeClass() == SubstBuiltinTemplatePack;
7028-
}
7029-
};
7030-
7031-
/// Represents the result of substituting a builtin template as a pack.
7032-
class SubstBuiltinTemplatePackType : public SubstPackType {
7033-
friend class ASTContext;
7034-
7035-
SubstBuiltinTemplatePackType(QualType Canon, const TemplateArgument &ArgPack);
7036-
7037-
public:
7038-
bool isSugared() const { return false; }
7039-
QualType desugar() const { return QualType(this, 0); }
7040-
7041-
/// Mark that we reuse the Profile. We do not introduce new fields.
7042-
using SubstPackType::Profile;
7043-
7044-
static bool classof(const Type *T) {
7045-
return T->getTypeClass() == SubstBuiltinTemplatePack;
7046-
}
7047-
};
7048-
70496995
/// Represents the result of substituting a set of types for a template
70506996
/// type parameter pack.
70516997
///
@@ -7058,7 +7004,7 @@ class SubstBuiltinTemplatePackType : public SubstPackType {
70587004
/// that pack expansion (e.g., when all template parameters have corresponding
70597005
/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
70607006
/// at the current pack substitution index.
7061-
class SubstTemplateTypeParmPackType : public SubstPackType {
7007+
class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
70627008
friend class ASTContext;
70637009

70647010
/// A pointer to the set of template arguments that this
@@ -7084,17 +7030,21 @@ class SubstTemplateTypeParmPackType : public SubstPackType {
70847030

70857031
/// Returns the index of the replaced parameter in the associated declaration.
70867032
/// This should match the result of `getReplacedParameter()->getIndex()`.
7087-
unsigned getIndex() const {
7088-
return SubstPackTypeBits.SubstTemplTypeParmPackIndex;
7089-
}
7033+
unsigned getIndex() const { return SubstTemplateTypeParmPackTypeBits.Index; }
70907034

70917035
// This substitution will be Final, which means the substitution will be fully
70927036
// sugared: it doesn't need to be resugared later.
70937037
bool getFinal() const;
70947038

7039+
unsigned getNumArgs() const {
7040+
return SubstTemplateTypeParmPackTypeBits.NumArgs;
7041+
}
7042+
70957043
bool isSugared() const { return false; }
70967044
QualType desugar() const { return QualType(this, 0); }
70977045

7046+
TemplateArgument getArgumentPack() const;
7047+
70987048
void Profile(llvm::FoldingSetNodeID &ID);
70997049
static void Profile(llvm::FoldingSetNodeID &ID, const Decl *AssociatedDecl,
71007050
unsigned Index, bool Final,
@@ -7329,7 +7279,9 @@ class TemplateSpecializationType : public TypeWithKeyword,
73297279
TemplateSpecializationTypeBits.NumArgs};
73307280
}
73317281

7332-
bool isSugared() const;
7282+
bool isSugared() const {
7283+
return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
7284+
}
73337285

73347286
QualType desugar() const {
73357287
return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal();

clang/include/clang/AST/TypeLoc.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -989,22 +989,12 @@ class SubstTemplateTypeParmTypeLoc :
989989
SubstTemplateTypeParmType> {
990990
};
991991

992-
/// Abstract type representing delayed type pack expansions.
993-
class SubstPackTypeLoc
994-
: public InheritingConcreteTypeLoc<TypeSpecTypeLoc, SubstPackTypeLoc,
995-
SubstPackType> {};
996-
997-
/// Wrapper for substituted template type parameters.
998-
class SubstTemplateTypeParmPackTypeLoc
999-
: public InheritingConcreteTypeLoc<SubstPackTypeLoc,
1000-
SubstTemplateTypeParmPackTypeLoc,
1001-
SubstTemplateTypeParmPackType> {};
1002-
1003-
/// Wrapper for substituted template type parameters.
1004-
class SubstBuiltinTemplatePackTypeLoc
1005-
: public InheritingConcreteTypeLoc<SubstPackTypeLoc,
1006-
SubstBuiltinTemplatePackTypeLoc,
1007-
SubstBuiltinTemplatePackType> {};
992+
/// Wrapper for substituted template type parameters.
993+
class SubstTemplateTypeParmPackTypeLoc :
994+
public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
995+
SubstTemplateTypeParmPackTypeLoc,
996+
SubstTemplateTypeParmPackType> {
997+
};
1008998

1009999
struct AttributedLocInfo {
10101000
const Attr *TypeAttr;

clang/include/clang/AST/TypeProperties.td

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -820,33 +820,26 @@ let Class = PackExpansionType in {
820820
}]>;
821821
}
822822

823-
let Class = SubstPackType in {
824-
def : Property<"replacementPack", TemplateArgument> {
825-
let Read = [{ node->getArgumentPack() }];
826-
}
827-
}
828-
829823
let Class = SubstTemplateTypeParmPackType in {
830824
def : Property<"associatedDecl", DeclRef> {
831825
let Read = [{ node->getAssociatedDecl() }];
832826
}
833827
def : Property<"Index", UInt32> {
834828
let Read = [{ node->getIndex() }];
835829
}
836-
def : Property<"Final", Bool> { let Read = [{ node->getFinal() }]; }
830+
def : Property<"Final", Bool> {
831+
let Read = [{ node->getFinal() }];
832+
}
833+
def : Property<"replacementPack", TemplateArgument> {
834+
let Read = [{ node->getArgumentPack() }];
835+
}
837836

838837
def : Creator<[{
839838
return ctx.getSubstTemplateTypeParmPackType(
840839
associatedDecl, Index, Final, replacementPack);
841840
}]>;
842841
}
843842

844-
let Class = SubstBuiltinTemplatePackType in {
845-
def : Creator<[{
846-
return ctx.getSubstBuiltinTemplatePack(replacementPack);
847-
}]>;
848-
}
849-
850843
let Class = BuiltinType in {
851844
def : Property<"kind", BuiltinTypeKind> {
852845
let Read = [{ node->getKind() }];

clang/include/clang/Basic/BuiltinTemplates.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,3 @@ def __builtin_common_type : CPlusPlusBuiltinTemplate<
6262
// typename ...Operands>
6363
def __hlsl_spirv_type : HLSLBuiltinTemplate<
6464
[Uint32T, Uint32T, Uint32T, Class<"Operands", /*is_variadic=*/1>]>;
65-
66-
// template <class ...Args>
67-
def __builtin_dedup_pack
68-
: CPlusPlusBuiltinTemplate<[Class<"Args", /*is_variadic=*/1>]>;

0 commit comments

Comments
 (0)