Skip to content

Commit af742ad

Browse files
authored
[TBDGen] Ensure classes that emit ObjC MetaClass also emit (#62283)
matching ObjC Class symbols This is to account for swift class definitions that have objc class ancestory. resolves: rdar://102525824
1 parent b79bef9 commit af742ad

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

include/swift/SIL/SILSymbolVisitor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ class SILSymbolVisitor {
109109
virtual void addMethodLookupFunction(ClassDecl *CD) {}
110110
virtual void addNominalTypeDescriptor(NominalTypeDecl *NTD) {}
111111
virtual void addObjCInterface(ClassDecl *CD) {}
112-
virtual void addObjCMetaclass(ClassDecl *CD) {}
113112
virtual void addObjCMethod(AbstractFunctionDecl *AFD) {}
114113
virtual void addObjCResilientClassStub(ClassDecl *CD) {}
115114
virtual void addOpaqueTypeDescriptor(OpaqueTypeDecl *OTD) {}

lib/IRGen/IRSymbolVisitor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ class IRSymbolVisitorImpl : public SILSymbolVisitor {
162162
Visitor.addObjCInterface(CD);
163163
}
164164

165-
void addObjCMetaclass(ClassDecl *CD) override {
166-
addLinkEntity(LinkEntity::forObjCMetaclass(CD));
167-
}
168-
169165
void addObjCMethod(AbstractFunctionDecl *AFD) override {
170166
// Pass through; Obj-C methods don't have linkable symbols.
171167
Visitor.addObjCMethod(AFD);

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,9 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
320320
// Metaclasses and ObjC classes (duh) are an ObjC thing, and so are not
321321
// needed in build artifacts/for classes which can't touch ObjC.
322322
if (objCCompatible) {
323-
if (isObjC)
323+
if (isObjC || CD->getMetaclassKind() == ClassDecl::MetaclassKind::ObjC)
324324
Visitor.addObjCInterface(CD);
325-
326-
if (CD->getMetaclassKind() == ClassDecl::MetaclassKind::ObjC) {
327-
// If an ObjCInterface was not added, ObjC Metaclass may still need to
328-
// be included.
329-
if (!isObjC)
330-
Visitor.addObjCMetaclass(CD);
331-
} else
325+
else
332326
Visitor.addSwiftMetaclassStub(CD);
333327
}
334328

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// REQUIRES: VENDOR=apple
2+
// RUN: %empty-directory(%t)
3+
// RUN: %empty-directory(%t/cache)
4+
// RUN: split-file %s %t
5+
6+
/// Create Swift modules to import.
7+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
8+
// RUN: -module-name IndirectMixedDependency -I %t \
9+
// RUN: -enable-library-evolution -swift-version 5 \
10+
// RUN: -emit-module %t/IndirectMixedDependency.swift \
11+
// RUN: -emit-module-path %t/IndirectMixedDependency.swiftmodule
12+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
13+
// RUN: -enable-library-evolution -swift-version 5 \
14+
// RUN: -emit-module %t/SwiftDependency.swift \
15+
// RUN: -module-name SwiftDependency -I %t\
16+
// RUN: -emit-module-path %t/SwiftDependency.swiftmodule
17+
18+
// Generate TBD file.
19+
// RUN: %target-swift-frontend -I %t -module-cache-path %t/cache \
20+
// RUN: %t/Client.swift -emit-ir -o/dev/null -parse-as-library \
21+
// RUN: -module-name client -validate-tbd-against-ir=missing \
22+
// RUN: -emit-tbd -emit-tbd-path %t/client.tbd
23+
24+
// RUN: %FileCheck %s < %t/client.tbd
25+
// CHECK: objc-classes: [ _TtCO6client11extendedAPI6Square ]
26+
// CHECK-NOT: _OBJC_CLASS_$
27+
// CHECK-NOT: _OBJC_METACLASS_$
28+
29+
//--- module.modulemap
30+
module IndirectMixedDependency {
31+
header "IndirectMixedDependency.h"
32+
}
33+
34+
//--- IndirectMixedDependency.h
35+
@import Foundation;
36+
@interface Shape : NSObject
37+
@end
38+
39+
//--- IndirectMixedDependency.swift
40+
@_exported import IndirectMixedDependency
41+
42+
//--- SwiftDependency.swift
43+
import IndirectMixedDependency
44+
open class Rectangle : IndirectMixedDependency.Shape {}
45+
46+
47+
//--- Client.swift
48+
import SwiftDependency
49+
50+
public enum extendedAPI {}
51+
extension extendedAPI {
52+
public class Square : SwiftDependency.Rectangle {}
53+
}

0 commit comments

Comments
 (0)