Skip to content

Commit b250ef7

Browse files
authored
Merge pull request #83751 from egorzhdan/egorzhdan/many-specializations
[cxx-interop] Allow many specializations of a class template
2 parents 6b4c7fc + fed7373 commit b250ef7

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,26 +3270,12 @@ namespace {
32703270

32713271
Decl *VisitClassTemplateSpecializationDecl(
32723272
const clang::ClassTemplateSpecializationDecl *decl) {
3273-
bool isPair = decl->getSpecializedTemplate()->isInStdNamespace() &&
3274-
decl->getSpecializedTemplate()->getName() == "pair";
3275-
3276-
// Before we go any further, check if we've already got tens of thousands
3277-
// of specializations. If so, it means we're likely instantiating a very
3278-
// deep/complex template, or we've run into an infinite loop. In either
3279-
// case, its not worth the compile time, so bail.
3280-
// TODO: this could be configurable at some point.
3281-
size_t specializationLimit = !isPair ? 1000 : 10000;
3282-
if (size_t(
3283-
llvm::size(decl->getSpecializedTemplate()->specializations())) >
3284-
specializationLimit) {
3285-
// Note: it would be nice to import a dummy unavailable struct,
3286-
// but we would then need to instantiate the template here,
3287-
// as we cannot import a struct without a definition. That would
3288-
// defeat the purpose. Also, we can't make the dummy
3289-
// struct simply unavailable, as that still makes the
3290-
// typelias that references it available.
3273+
// Importing std::conditional substantially increases compile times when
3274+
// building with libstdc++, i.e. on most Linux distros.
3275+
if (decl->isInStdNamespace() && decl->getIdentifier() &&
3276+
(decl->getName() == "conditional" || decl->getName() == "__or_" ||
3277+
decl->getName() == "_Expr"))
32913278
return nullptr;
3292-
}
32933279

32943280
// `decl->getDefinition()` can return nullptr before the call to sema and
32953281
// return its definition afterwards.

test/Interop/Cxx/templates/many-specializations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
// CHECK-NEXT: struct TemplateStruct<T> {
66
// CHECK-NEXT: }
77

8-
// CHECK-NOT: typealias
8+
// CHECK: typealias T1000

0 commit comments

Comments
 (0)