Skip to content

Commit 1ee91eb

Browse files
committed
IRGen: Fix linkage of opaque type descriptor with @_alwaysEmitIntoClient owner decl
1 parent 645d24e commit 1ee91eb

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

lib/IRGen/Linking.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -748,16 +748,17 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
748748
case Kind::OpaqueTypeDescriptor: {
749749
auto *opaqueType = cast<OpaqueTypeDecl>(getDecl());
750750

751-
// The opaque result type descriptor with availability conditions
752-
// has to be emitted into a client module when associated with
751+
// With conditionally available substitutions, the opaque result type
752+
// descriptor has to be emitted into a client module when associated with
753753
// `@_alwaysEmitIntoClient` declaration which means it's linkage
754754
// has to be "shared".
755-
if (opaqueType->hasConditionallyAvailableSubstitutions()) {
756-
if (auto *srcDecl = opaqueType->getNamingDecl()) {
757-
if (srcDecl->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>())
758-
return SILLinkage::Shared;
759-
}
760-
}
755+
//
756+
// If we don't have conditionally available substitutions, we won't emit
757+
// the descriptor at all, but still make sure we report "shared" linkage
758+
// so that TBD files don't include a bogus symbol.
759+
auto *srcDecl = opaqueType->getNamingDecl();
760+
if (srcDecl->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>())
761+
return SILLinkage::Shared;
761762

762763
return getSILLinkage(getDeclLinkage(opaqueType), forDefinition);
763764
}

test/TBD/resolve_imports.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -resolve-imports -emit-tbd -emit-tbd-path %t/resolve_imports.tbd %s
3+
// RUN: %FileCheck %s < %t/resolve_imports.tbd
4+
5+
// REQUIRES: OS=macosx
6+
7+
@_alwaysEmitIntoClient public var x: some Any {
8+
get {
9+
if #available(macOS 20, *) {
10+
return 3
11+
} else {
12+
return "hi"
13+
}
14+
}
15+
}
16+
17+
// CHECK: symbols: [ _main ]

0 commit comments

Comments
 (0)