Skip to content

[swift][TBDGen] Stop adding redundant ObjC Classes #62068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/swift/SIL/SILSymbolVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class SILSymbolVisitor {
virtual void addMethodDescriptor(SILDeclRef declRef) {}
virtual void addMethodLookupFunction(ClassDecl *CD) {}
virtual void addNominalTypeDescriptor(NominalTypeDecl *NTD) {}
virtual void addObjCClass(ClassDecl *CD) {}
virtual void addObjCInterface(ClassDecl *CD) {}
virtual void addObjCMetaclass(ClassDecl *CD) {}
virtual void addObjCMethod(AbstractFunctionDecl *AFD) {}
Expand Down
5 changes: 0 additions & 5 deletions lib/IRGen/IRSymbolVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,7 @@ class IRSymbolVisitorImpl : public SILSymbolVisitor {
addLinkEntity(LinkEntity::forNominalTypeDescriptor(NTD));
}

void addObjCClass(ClassDecl *CD) override {
addLinkEntity(LinkEntity::forObjCClass(CD));
}

void addObjCInterface(ClassDecl *CD) override {
// Pass through; Obj-C interfaces don't have linkable symbols.
Visitor.addObjCInterface(CD);
}

Expand Down
5 changes: 5 additions & 0 deletions lib/IRGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,11 @@ PublicSymbolsRequest::evaluate(Evaluator &evaluator,
auto addSymbol = [&](StringRef symbol, SymbolKind kind, SymbolSource source) {
if (kind == SymbolKind::GlobalSymbol)
symbols.push_back(symbol.str());
// TextAPI ObjC Class Kinds represents two symbols.
else if (kind == SymbolKind::ObjectiveCClass) {
symbols.push_back((llvm::MachO::ObjC2ClassNamePrefix + symbol).str());
symbols.push_back((llvm::MachO::ObjC2MetaClassNamePrefix + symbol).str());
}
};
SimpleAPIRecorder recorder(addSymbol);
TBDGenVisitor visitor(desc, recorder);
Expand Down
17 changes: 6 additions & 11 deletions lib/SIL/IR/SILSymbolVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,16 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
// Metaclasses and ObjC classes (duh) are an ObjC thing, and so are not
// needed in build artifacts/for classes which can't touch ObjC.
if (objCCompatible) {
bool addObjCClass = false;
if (isObjC) {
addObjCClass = true;
Visitor.addObjCClass(CD);
}
if (isObjC)
Visitor.addObjCInterface(CD);

if (CD->getMetaclassKind() == ClassDecl::MetaclassKind::ObjC) {
addObjCClass = true;
Visitor.addObjCMetaclass(CD);
// If an ObjCInterface was not added, ObjC Metaclass may still need to
// be included.
if (!isObjC)
Visitor.addObjCMetaclass(CD);
} else
Visitor.addSwiftMetaclassStub(CD);

if (addObjCClass) {
Visitor.addObjCInterface(CD);
}
}

// Some members of classes get extra handling, beyond members of
Expand Down
36 changes: 0 additions & 36 deletions test/APIJSON/apigen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,42 +316,6 @@ public func myFunction2() {}
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "name": "_OBJC_CLASS_$__TtC8MyModule4Test",
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "name": "_OBJC_CLASS_$__TtC8MyModule5Test3",
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "name": "_OBJC_CLASS_$__TtC8MyModule7Derived",
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "name": "_OBJC_METACLASS_$__TtC8MyModule4Test",
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "name": "_OBJC_METACLASS_$__TtC8MyModule5Test3",
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "name": "_OBJC_METACLASS_$__TtC8MyModule7Derived",
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported"
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "interfaces": [
Expand Down
36 changes: 0 additions & 36 deletions test/APIJSON/spi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@ public func spiAvailableFunc() {}
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported",
// CHECK-NEXT: "unavailable": true
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "name": "_OBJC_CLASS_$__TtC8MyModule8MyClass2",
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "name": "_OBJC_METACLASS_$__TtC8MyModule8MyClass2",
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported"
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "interfaces": [
Expand Down Expand Up @@ -244,30 +232,6 @@ public func spiAvailableFunc() {}
// CHECK-SPI-NEXT: "introduced": "10.10"
// CHECK-SPI-NEXT: },
// CHECK-SPI-NEXT: {
// CHECK-SPI-NEXT: "name": "_OBJC_CLASS_$__TtC8MyModule7MyClass",
// CHECK-SPI-NEXT: "access": "private",
// CHECK-SPI-NEXT: "file": "/@input/MyModule.swiftmodule",
// CHECK-SPI-NEXT: "linkage": "exported"
// CHECK-SPI-NEXT: },
// CHECK-SPI-NEXT: {
// CHECK-SPI-NEXT: "name": "_OBJC_CLASS_$__TtC8MyModule8MyClass2",
// CHECK-SPI-NEXT: "access": "public",
// CHECK-SPI-NEXT: "file": "/@input/MyModule.swiftmodule",
// CHECK-SPI-NEXT: "linkage": "exported"
// CHECK-SPI-NEXT: },
// CHECK-SPI-NEXT: {
// CHECK-SPI-NEXT: "name": "_OBJC_METACLASS_$__TtC8MyModule7MyClass",
// CHECK-SPI-NEXT: "access": "private",
// CHECK-SPI-NEXT: "file": "/@input/MyModule.swiftmodule",
// CHECK-SPI-NEXT: "linkage": "exported"
// CHECK-SPI-NEXT: },
// CHECK-SPI-NEXT: {
// CHECK-SPI-NEXT: "name": "_OBJC_METACLASS_$__TtC8MyModule8MyClass2",
// CHECK-SPI-NEXT: "access": "public",
// CHECK-SPI-NEXT: "file": "/@input/MyModule.swiftmodule",
// CHECK-SPI-NEXT: "linkage": "exported"
// CHECK-SPI-NEXT: },
// CHECK-SPI-NEXT: {
// CHECK-SPI-NEXT: "name": "_main",
// CHECK-SPI-NEXT: "access": "public",
// CHECK-SPI-NEXT: "file": "/@input/MyModule.swiftmodule",
Expand Down
3 changes: 3 additions & 0 deletions test/TBD/implied_objc_symbols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@

// RUN: %FileCheck %s < %t/main.tbd

// CHECK-NOT: '_OBJC_CLASS_$_CApi'
// CHECK-NOT: '_OBJC_METACLASS_$_CApi'

// CHECK: objc-classes: [ CApi ]