Skip to content

Commit 6adeed1

Browse files
authored
Merge pull request swiftlang#75198 from eeckstein/fix-vtable-specializer
embedded: fix vtable specialization for nested classes
2 parents 7b71100 + 823036d commit 6adeed1

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lib/SILOptimizer/Transforms/VTableSpecializer.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,19 @@ static bool specializeVTablesOfSuperclasses(SILModule &module,
153153
SILVTable *swift::specializeVTableForType(SILType classTy, SILModule &module,
154154
SILTransform *transform) {
155155
CanType astType = classTy.getASTType();
156-
BoundGenericClassType *genClassTy = dyn_cast<BoundGenericClassType>(astType);
157-
if (!genClassTy) return nullptr;
156+
if (!astType->isSpecialized())
157+
return nullptr;
158+
NominalOrBoundGenericNominalType *genClassTy = dyn_cast<NominalOrBoundGenericNominalType>(astType);
159+
ClassDecl *classDecl = astType->getClassOrBoundGenericClass();
160+
if (!classDecl)
161+
return nullptr;
158162

159163
if (module.lookUpSpecializedVTable(classTy)) return nullptr;
160164

161165
LLVM_DEBUG(llvm::errs() << "specializeVTableFor "
162-
<< genClassTy->getDecl()->getName() << ' '
166+
<< classDecl->getName() << ' '
163167
<< genClassTy->getString() << '\n');
164168

165-
ClassDecl *classDecl = genClassTy->getDecl();
166169
SILVTable *origVtable = module.lookUpVTable(classDecl);
167170
if (!origVtable) {
168171
// This cannot occur in regular builds - only if built without wmo, which
@@ -244,8 +247,8 @@ bool swift::specializeClassMethodInst(ClassMethodInst *cm) {
244247
SILValue instance = cm->getOperand();
245248
SILType classTy = instance->getType();
246249
CanType astType = classTy.getASTType();
247-
BoundGenericClassType *genClassTy = dyn_cast<BoundGenericClassType>(astType);
248-
if (!genClassTy) return false;
250+
if (!astType->isSpecialized())
251+
return false;
249252

250253
SubstitutionMap subs = astType->getContextSubstitutionMap();
251254

test/embedded/generic-classes.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ class SubClass2 : SubClass1<Int> {
3434
override func test() { print("SubClass2") }
3535
}
3636

37+
public class Outer<T> {
38+
public class Inner {
39+
func foo() {
40+
print("Inner.foo")
41+
}
42+
}
43+
}
44+
45+
public func makeInner() -> Outer<Int>.Inner {
46+
return Outer<Int>.Inner()
47+
}
48+
3749
@main
3850
struct Main {
3951
static func main() {
@@ -43,10 +55,12 @@ struct Main {
4355
makeItFoo(f: g)
4456
let x = SubClass2()
4557
x.test()
58+
makeInner().foo()
4659
}
4760
}
4861

4962
// CHECK: GenericFooableClass<T>.foo
5063
// CHECK: GenericFooableSubClass<T>.foo
5164
// CHECK: SubClass2
65+
// CHECK: Inner.foo
5266

0 commit comments

Comments
 (0)