Skip to content

Commit 583c8de

Browse files
authored
Merge pull request swiftlang#66232 from tshortli/unavailable-objc-override
IRGen: Avoid emitting Obj-C method metadata for unavailable methods
2 parents 97daf4f + 40648b7 commit 583c8de

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

lib/AST/Availability.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,12 @@ AvailabilityInference::parentDeclForInferredAvailability(const Decl *D) {
182182
return NTD;
183183
}
184184

185-
if (auto *PBD = dyn_cast<PatternBindingDecl>(D))
185+
if (auto *PBD = dyn_cast<PatternBindingDecl>(D)) {
186+
if (PBD->getNumPatternEntries() < 1)
187+
return nullptr;
188+
186189
return PBD->getAnchoringVarDecl(0);
190+
}
187191

188192
if (auto *OTD = dyn_cast<OpaqueTypeDecl>(D))
189193
return OTD->getNamingDecl();

lib/IRGen/GenClass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,9 @@ namespace {
18311831

18321832
void buildMethod(ConstantArrayBuilder &descriptors,
18331833
AbstractFunctionDecl *method) {
1834+
if (Lowering::shouldSkipLowering(method))
1835+
return;
1836+
18341837
auto accessor = dyn_cast<AccessorDecl>(method);
18351838
if (!accessor)
18361839
return emitObjCMethodDescriptor(IGM, descriptors, method);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library -module-name Test -validate-tbd-against-ir=missing %s -emit-ir | %FileCheck %s --check-prefixes=CHECK,CHECK-NO-STRIP
2+
3+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library -module-name Test -validate-tbd-against-ir=missing -unavailable-decl-optimization=complete %s -emit-ir | %FileCheck %s --check-prefixes=CHECK,CHECK-STRIP
4+
5+
// REQUIRES: objc_interop
6+
7+
import Foundation
8+
9+
public class Class: NSObject {
10+
// CHECK-NO-STRIP: define {{.*}} @"$s4Test5ClassC3fooyyF"
11+
// CHECK-STRIP-NOT: define {{.*}} @"$s4Test5ClassC3fooyyF"
12+
13+
// CHECK-NO-STRIP: define {{.*}} @"$s4Test5ClassC3fooyyFTo"
14+
// CHECK-STRIP-NOT: define {{.*}} @"$s4Test5ClassC3fooyyFTo"
15+
@available(*, unavailable)
16+
@objc public func foo() {}
17+
}

0 commit comments

Comments
 (0)