Skip to content

Commit a5c18fc

Browse files
committed
Revert "[clang] Instantiate alias templates with sugar"
This reverts commit 279fe62, which causes non-linear compilation time growth. See https://reviews.llvm.org/D136565#3914755
1 parent b5d91ab commit a5c18fc

File tree

11 files changed

+64
-39
lines changed

11 files changed

+64
-39
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ class Foo final {})cpp";
10671067
HI.LocalScope = "";
10681068
HI.Kind = index::SymbolKind::TypeAlias;
10691069
HI.Definition = "template <typename T> using AA = A<T>";
1070-
HI.Type = {"A<T>", "T"};
1070+
HI.Type = {"A<T>", "type-parameter-0-0"}; // FIXME: should be 'T'
10711071
HI.TemplateParameters = {{{"typename"}, std::string("T"), llvm::None}};
10721072
}},
10731073
{// Constant array

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,8 +3854,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
38543854

38553855
// Only substitute for the innermost template argument list.
38563856
MultiLevelTemplateArgumentList TemplateArgLists;
3857-
TemplateArgLists.addOuterTemplateArguments(Template, SugaredConverted,
3858-
/*Final=*/true);
3857+
TemplateArgLists.addOuterTemplateArguments(Template, CanonicalConverted,
3858+
/*Final=*/false);
38593859
TemplateArgLists.addOuterRetainedLevels(
38603860
AliasTemplate->getTemplateParameters()->getDepth());
38613861

clang/test/AST/ast-dump-template-decls.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,31 +120,47 @@ using type2 = typename C<int>::type1<void>;
120120
// CHECK-NEXT: TemplateArgument type 'void'
121121
// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
122122
// CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
123+
// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 0 index 0 U
124+
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
123125
// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
124126
// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 T
125127
// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
126128
// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'
127129
} // namespace PR55886
128130

129131
namespace PR56099 {
132+
template <typename... As> struct Y;
133+
template <typename... Bs> using Z = Y<Bs...>;
134+
template <typename... Cs> struct foo {
135+
template <typename... Ds> using bind = Z<Ds..., Cs...>;
136+
};
137+
using t1 = foo<int, short>::bind<char, float>;
138+
// CHECK: TemplateSpecializationType 0x{{[^ ]*}} 'Y<char, float, int, short>' sugar Y
139+
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename depth 0 index 0 ... Bs pack_index 3
140+
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
141+
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... Bs pack_index 2
142+
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
143+
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... Bs pack_index 1
144+
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
145+
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename depth 0 index 0 ... Bs pack_index 0
146+
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
147+
130148
template <typename... T> struct D {
131-
template <typename... U> struct bind {
132-
using bound_type = int(int (*...p)(T, U));
133-
};
149+
template <typename... U> using B = int(int (*...p)(T, U));
134150
};
135-
template struct D<float, char>::bind<int, short>;
136-
// CHECK: TypeAliasDecl 0x{{[^ ]*}} <line:{{[1-9]+}}:5, col:45> col:11 bound_type 'int (int (*)(float, int), int (*)(char, short))'
151+
using t2 = D<float, char>::B<int, short>;
152+
// CHECK: TemplateSpecializationType 0x{{[^ ]*}} 'B<int, short>' sugar alias B
137153
// CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (int (*)(float, int), int (*)(char, short))' cdecl
138154
// CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (float, int)' cdecl
139155
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... T pack_index 1
140156
// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'D'
141157
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... U pack_index 1
142-
// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'bind'
158+
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'B'
143159
// CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (char, short)' cdecl
144160
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename depth 0 index 0 ... T pack_index 0
145161
// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'D'
146162
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename depth 0 index 0 ... U pack_index 0
147-
// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'bind'
163+
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'B'
148164
} // namespace PR56099
149165

150166
namespace subst_default_argument {
@@ -155,8 +171,10 @@ template<class E1, class E2> class E {};
155171
using test1 = D<E, int>;
156172
// CHECK: TypeAliasDecl 0x{{[^ ]*}} <line:{{[1-9]+}}:1, col:23> col:7 test1 'D<subst_default_argument::E, int>':'subst_default_argument::E<int, subst_default_argument::A<int>>'
157173
// CHECK: TemplateSpecializationType 0x{{[^ ]*}} 'A<int>' sugar A
158-
// CHECK-NEXT: |-TemplateArgument type 'int'
159-
// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
174+
// CHECK-NEXT: |-TemplateArgument type 'int':'int'
175+
// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 1 D2
176+
// CHECK-NEXT: | |-TypeAliasTemplate 0x{{[^ ]*}} 'D'
177+
// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
160178
// CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A<int>'
161179
// CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'
162180
} // namespace subst_default_argument

clang/test/CXX/temp/temp.deduct.guide/p3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ template<template<typename> typename TT> struct E { // expected-note 2{{template
3333
};
3434

3535
A(int) -> int; // expected-error {{deduced type 'int' of deduction guide is not a specialization of template 'A'}}
36-
template <typename T> A(T)->B<T>; // expected-error {{deduced type 'B<T>' (aka 'A<T>') of deduction guide is not written as a specialization of template 'A'}}
36+
template<typename T> A(T) -> B<T>; // expected-error {{deduced type 'B<T>' (aka 'A<type-parameter-0-0>') of deduction guide is not written as a specialization of template 'A'}}
3737
template<typename T> A(T*) -> const A<T>; // expected-error {{deduced type 'const A<T>' of deduction guide is not a specialization of template 'A'}}
3838

3939
// A deduction-guide shall be declared in the same scope as the corresponding

clang/test/Misc/diag-template-diffing.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,22 +257,25 @@ int f9(S9<int, char, U9<const double>>);
257257
int k9 = f9(V9<double>());
258258

259259
// CHECK-ELIDE-NOTREE: no matching function for call to 'f9'
260-
// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'S9<[2 * ...], U9<double>>' to 'S9<[2 * ...], U9<const double>>' for 1st argument
260+
// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'S9<[2 * ...], S9<[2 * ...], double>>' to 'S9<[2 * ...], S9<[2 * ...], const double>>' for 1st argument
261261
// CHECK-NOELIDE-NOTREE: no matching function for call to 'f9'
262-
// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'S9<int, char, U9<double>>' to 'S9<int, char, U9<const double>>' for 1st argument
262+
// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'S9<int, char, S9<int, char, double>>' to 'S9<int, char, S9<int, char, const double>>' for 1st argument
263263
// CHECK-ELIDE-TREE: no matching function for call to 'f9'
264264
// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
265265
// CHECK-ELIDE-TREE: S9<
266-
// CHECK-ELIDE-TREE: [2 * ...],
267-
// CHECK-ELIDE-TREE: U9<
268-
// CHECK-ELIDE-TREE: [(no qualifiers) != const] double>>
266+
// CHECK-ELIDE-TREE: [2 * ...],
267+
// CHECK-ELIDE-TREE: S9<
268+
// CHECK-ELIDE-TREE: [2 * ...],
269+
// CHECK-ELIDE-TREE: [double != const double]>>
269270
// CHECK-NOELIDE-TREE: no matching function for call to 'f9'
270271
// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
271272
// CHECK-NOELIDE-TREE: S9<
272-
// CHECK-NOELIDE-TREE: int,
273-
// CHECK-NOELIDE-TREE: char,
274-
// CHECK-NOELIDE-TREE: U9<
275-
// CHECK-NOELIDE-TREE: [(no qualifiers) != const] double>>
273+
// CHECK-NOELIDE-TREE: int,
274+
// CHECK-NOELIDE-TREE: char,
275+
// CHECK-NOELIDE-TREE: S9<
276+
// CHECK-NOELIDE-TREE: int,
277+
// CHECK-NOELIDE-TREE: char,
278+
// CHECK-NOELIDE-TREE: [double != const double]>>
276279

277280
template<typename ...A> class class_types {};
278281
void set10(class_types<int, int>) {}

clang/test/SemaCXX/sizeless-1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void template_fn_rvalue_ref(T &&) {}
325325

326326
#if __cplusplus >= 201103L
327327
template <typename T>
328-
using array_alias = T[1]; // expected-error {{array has sizeless element type 'svint8_t' (aka '__SVInt8_t')}}
328+
using array_alias = T[1]; // expected-error {{array has sizeless element type '__SVInt8_t'}}
329329
extern array_alias<int> *array_alias_int_ptr;
330330
extern array_alias<svint8_t> *array_alias_int8_ptr; // expected-note {{in instantiation of template type alias 'array_alias' requested here}}
331331
#endif

clang/test/SemaTemplate/make_integer_seq.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,31 @@ using test2 = B<int, 1>;
3737
// CHECK-NEXT: `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, int, 1>' sugar
3838
// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, int, 1>' sugar alias __make_integer_seq
3939
// CHECK-NEXT: |-TemplateArgument template A
40-
// CHECK-NEXT: |-TemplateArgument type 'int'
41-
// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
40+
// CHECK-NEXT: |-TemplateArgument type 'int':'int'
41+
// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar class depth 0 index 0 B1
42+
// CHECK-NEXT: | |-TypeAliasTemplate 0x{{[0-9A-Fa-f]+}} 'B'
43+
// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
4244
// CHECK-NEXT: |-TemplateArgument expr
4345
// CHECK-NEXT: | `-ConstantExpr 0x{{[0-9A-Fa-f]+}} <line:26:64> 'int'
4446
// CHECK-NEXT: | |-value: Int 1
4547
// CHECK-NEXT: | `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}} <col:64> 'int'
4648
// CHECK-NEXT: | |-NonTypeTemplateParmDecl 0x{{[0-9A-Fa-f]+}} <col:21, col:24> col:24 referenced 'B1' depth 0 index 1 B2
4749
// CHECK-NEXT: | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}} <col:64> 'int' 1
4850
// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A<int, 0>' sugar A
49-
// CHECK-NEXT: |-TemplateArgument type 'int'
50-
// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
51+
// CHECK-NEXT: |-TemplateArgument type 'int':'int'
52+
// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar class depth 0 index 0 B1
53+
// CHECK-NEXT: | |-TypeAliasTemplate 0x{{[0-9A-Fa-f]+}} 'B'
54+
// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
5155
// CHECK-NEXT: |-TemplateArgument expr
5256
// CHECK-NEXT: | `-ConstantExpr 0x{{[0-9A-Fa-f]+}} <col:64> 'int'
5357
// CHECK-NEXT: | |-value: Int 0
54-
// CHECK-NEXT: | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}} <col:64> 'int' 0
58+
// CHECK-NEXT: | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}} <col:64> 'int':'int' 0
5559
// CHECK-NEXT: `-RecordType 0x{{[0-9A-Fa-f]+}} 'A<int, 0>'
5660
// CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
5761

5862
template <template <class T, T...> class S, class T, int N> struct C {
5963
using test3 = __make_integer_seq<S, T, N>;
60-
// CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:59:3, col:43> col:9 test3 '__make_integer_seq<S, T, N>':'__make_integer_seq<type-parameter-0-1, N>'
64+
// CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:63:3, col:43> col:9 test3 '__make_integer_seq<S, T, N>':'__make_integer_seq<type-parameter-0-1, N>'
6165
// CHECK-NEXT: `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<S, T, N>' sugar dependent
6266
// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<S, T, N>' sugar dependent alias __make_integer_seq
6367
// CHECK-NEXT: |-TemplateArgument template S
@@ -76,7 +80,7 @@ template <template <class T, T...> class S, class T, int N> struct C {
7680
// CHECK-NEXT: `-DeclRefExpr 0x{{[0-9A-Fa-f]+}} <col:42> 'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
7781

7882
using test4 = __make_integer_seq<A, T, 1>;
79-
// CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:78:3, col:43> col:9 test4 '__make_integer_seq<A, T, 1>':'__make_integer_seq<A, type-parameter-0-1, 1>'
83+
// CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:82:3, col:43> col:9 test4 '__make_integer_seq<A, T, 1>':'__make_integer_seq<A, type-parameter-0-1, 1>'
8084
// CHECK-NEXT: `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, T, 1>' sugar dependent
8185
// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, T, 1>' sugar dependent alias __make_integer_seq
8286
// CHECK-NEXT: |-TemplateArgument template A
@@ -95,7 +99,7 @@ template <template <class T, T...> class S, class T, int N> struct C {
9599
// CHECK-NEXT: `-IntegerLiteral 0x{{[0-9A-Fa-f]+}} <col:42> 'int' 1
96100

97101
using test5 = __make_integer_seq<A, int, N>;
98-
// CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:97:3, col:45> col:9 test5 '__make_integer_seq<A, int, N>':'__make_integer_seq<A, int, N>'
102+
// CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:101:3, col:45> col:9 test5 '__make_integer_seq<A, int, N>':'__make_integer_seq<A, int, N>'
99103
// CHECK-NEXT: `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, int, N>' sugar dependent
100104
// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, int, N>' sugar dependent alias __make_integer_seq
101105
// CHECK-NEXT: |-TemplateArgument template A

clang/test/SemaTemplate/temp_arg_nontype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ namespace dependent_nested_partial_specialization {
437437

438438
template<template<typename> class X> struct A {
439439
template<typename T, X<T> N> struct B; // expected-note 2{{here}}
440-
template <typename T> struct B<T, 0> {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y<T>' (aka 'T *')}}
440+
template<typename T> struct B<T, 0> {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y<T>' (aka 'type-parameter-0-0 *')}}
441441
};
442442
A<X>::B<int, 0> ax;
443443
A<Y>::B<int, &n> ay; // expected-error {{undefined}} expected-note {{instantiation of}}

lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def test(self):
2424
result_type="std::shared_ptr<int>",
2525
result_summary="3 strong=1 weak=1",
2626
result_children=[ValueCheck(name="__ptr_")])
27-
self.expect_expr("*s", result_type="element_type", result_value="3")
28-
self.expect_expr("*s = 5", result_type="element_type", result_value="5")
29-
self.expect_expr("*s", result_type="element_type", result_value="5")
27+
self.expect_expr("*s", result_type="int", result_value="3")
28+
self.expect_expr("*s = 5", result_type="int", result_value="5")
29+
self.expect_expr("*s", result_type="int", result_value="5")
3030
self.expect_expr("(bool)s", result_type="bool", result_value="true")
3131
self.expect("expr s.reset()")
3232
self.expect_expr("(bool)s", result_type="bool", result_value="false")

lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test(self):
2323
self.expect_expr("w",
2424
result_type="std::weak_ptr<Foo>",
2525
result_children=[ValueCheck(name="__ptr_")])
26-
self.expect_expr("*w.lock()", result_type="element_type")
26+
self.expect_expr("*w.lock()", result_type="Foo")
2727
self.expect_expr("w.lock()->a", result_type="int", result_value="3")
2828
self.expect_expr("w.lock()->a = 5",
2929
result_type="int",

0 commit comments

Comments
 (0)