Skip to content

Commit 07dfa49

Browse files
committed
IRGen: Skip lowering unavailable opaque type descriptors.
Part of rdar://107425181
1 parent 8e1ec85 commit 07dfa49

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

lib/AST/Availability.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ AvailabilityInference::parentDeclForInferredAvailability(const Decl *D) {
184184
if (auto *PBD = dyn_cast<PatternBindingDecl>(D))
185185
return PBD->getAnchoringVarDecl(0);
186186

187+
if (auto *OTD = dyn_cast<OpaqueTypeDecl>(D))
188+
return OTD->getNamingDecl();
189+
187190
// Clang decls may be inaccurately parented rdar://53956555
188191
if (D->hasClangNode())
189192
return nullptr;

lib/AST/Decl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,8 @@ AvailabilityContext Decl::getAvailabilityForLinkage() const {
10981098
return *containingContext;
10991099
}
11001100

1101+
// FIXME: Adopt AvailabilityInference::parentDeclForInferredAvailability()
1102+
// here instead of duplicating the logic.
11011103
if (auto *accessor = dyn_cast<AccessorDecl>(this))
11021104
return accessor->getStorage()->getAvailabilityForLinkage();
11031105

lib/IRGen/GenStruct.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,9 @@ void IRGenModule::emitStructDecl(StructDecl *st) {
15721572
}
15731573

15741574
void IRGenModule::maybeEmitOpaqueTypeDecl(OpaqueTypeDecl *opaque) {
1575+
if (Lowering::shouldSkipLowering(opaque))
1576+
return;
1577+
15751578
if (IRGen.Opts.EnableAnonymousContextMangledNames) {
15761579
// If we're emitting anonymous context mangled names for debuggability,
15771580
// then emit all opaque type descriptors and make them runtime-discoverable
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-frontend -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 -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+
// CHECK-NO-STRIP: s4Test1SV31unavailableFuncWithOpaqueReturnQryFQOMQ
6+
// CHECK-STRIP-NOT: s4Test1SV31unavailableFuncWithOpaqueReturnQryFQOMQ
7+
8+
// CHECK-NO-STRIP: s4Test1SV30unavailableVarWithOpaqueReturnQrvpQOMQ
9+
// CHECK-STRIP-NOT: s4Test1SV30unavailableVarWithOpaqueReturnQrvpQOMQ
10+
11+
public protocol P {}
12+
13+
public struct S: P {
14+
// CHECK-NO-STRIP: s4Test1SV31unavailableFuncWithOpaqueReturnQryF
15+
// CHECK-STRIP-NOT: s4Test1SV31unavailableFuncWithOpaqueReturnQryF
16+
@available(*, unavailable)
17+
public func unavailableFuncWithOpaqueReturn() -> some P {
18+
return self
19+
}
20+
21+
// CHECK-NO-STRIP: s4Test1SV30unavailableVarWithOpaqueReturnQrvg
22+
// CHECK-STRIP-NOT: s4Test1SV30unavailableVarWithOpaqueReturnQrvg
23+
@available(*, unavailable)
24+
public var unavailableVarWithOpaqueReturn: some P {
25+
return self
26+
}
27+
}

0 commit comments

Comments
 (0)