Skip to content

Commit a36801b

Browse files
authored
Merge pull request #25601 from jckarter/opaque-xref-extension-module-5.1
[5.1] Serialization: Deserialize opaque type xrefs from the right extension module.
2 parents b031deb + 5e65e3e commit a36801b

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,11 @@ class OpaqueTypeDecl : public GenericTypeDecl {
28372837

28382838
ValueDecl *getNamingDecl() const { return NamingDecl; }
28392839

2840+
void setNamingDecl(ValueDecl *D) {
2841+
assert(!NamingDecl && "already have naming decl");
2842+
NamingDecl = D;
2843+
}
2844+
28402845
GenericSignature *getOpaqueInterfaceGenericSignature() const {
28412846
return OpaqueInterfaceGenericSignature;
28422847
}

lib/Serialization/Deserialization.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,9 +1729,10 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
17291729

17301730
auto name = getIdentifier(DefiningDeclNameID);
17311731
pathTrace.addOpaqueReturnType(name);
1732-
1733-
if (auto opaqueTy = baseModule->lookupOpaqueResultType(name.str(),
1734-
nullptr)) {
1732+
1733+
auto lookupModule = M ? M : baseModule;
1734+
if (auto opaqueTy = lookupModule->lookupOpaqueResultType(name.str(),
1735+
nullptr)) {
17351736
values.push_back(opaqueTy);
17361737
}
17371738
break;
@@ -3190,7 +3191,6 @@ class swift::DeclDeserializer {
31903191
interfaceTypeID, genericEnvID,
31913192
underlyingTypeID);
31923193

3193-
auto namingDecl = cast<ValueDecl>(MF.getDecl(namingDeclID));
31943194
auto declContext = MF.getDeclContext(contextID);
31953195
auto sig = MF.getGenericSignature(interfaceSigID);
31963196
auto interfaceType = MF.getType(interfaceTypeID)
@@ -3202,10 +3202,13 @@ class swift::DeclDeserializer {
32023202

32033203
// Create the decl.
32043204
auto opaqueDecl =
3205-
new (ctx) OpaqueTypeDecl(namingDecl, nullptr, declContext,
3205+
new (ctx) OpaqueTypeDecl(nullptr, nullptr, declContext,
32063206
sig, interfaceType);
32073207
declOrOffset = opaqueDecl;
32083208

3209+
auto namingDecl = cast<ValueDecl>(MF.getDecl(namingDeclID));
3210+
opaqueDecl->setNamingDecl(namingDecl);
3211+
32093212
if (auto genericParams = MF.maybeReadGenericParams(opaqueDecl))
32103213
opaqueDecl->setGenericParams(genericParams);
32113214

test/SIL/Serialization/Inputs/OpaqueReturnTypeExporter.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ public protocol Butt {}
22
extension Int: Butt {}
33

44
public func exportsOpaqueReturn() -> some Butt { return 0 }
5+
6+
extension Int {
7+
public func someButt() -> some Butt {
8+
return self
9+
}
10+
}

test/SIL/Serialization/opaque_return_type_serialize.sil

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@
33
// RUN: %target-sil-opt -I %t %s -emit-sib -module-name test -o %t/test.sib
44
// RUN: %target-swift-frontend -disable-availability-checking -I %t -emit-ir %t/test.sib
55

6+
import Swift
67
import OpaqueReturnTypeExporter
78

89
typealias SomeButt = @_opaqueReturnTypeOf("$s24OpaqueReturnTypeExporter07exportsaB0QryF", 0) opaque
10+
typealias SomeButt2 = @_opaqueReturnTypeOf("$sSi24OpaqueReturnTypeExporterE8someButtQryF", 0) opaque
911

1012
sil @$s24OpaqueReturnTypeExporter07exportsaB0QryF : $@convention(thin) () -> @out SomeButt
13+
sil @$sSi24OpaqueReturnTypeExporterE8someButtQryF : $@convention(thin) (Int) -> @out SomeButt2
1114

12-
sil @use_opaque_type : $@convention(thin) () -> () {
13-
entry:
15+
sil @use_opaque_type : $@convention(thin) (Int) -> () {
16+
entry(%a : $Int):
1417
%f = function_ref @$s24OpaqueReturnTypeExporter07exportsaB0QryF : $@convention(thin) () -> @out SomeButt
1518
%x = alloc_stack $SomeButt
1619
apply %f(%x) : $@convention(thin) () -> @out SomeButt
1720
destroy_addr %x : $*SomeButt
1821
dealloc_stack %x : $*SomeButt
22+
23+
%g = function_ref @$sSi24OpaqueReturnTypeExporterE8someButtQryF : $@convention(thin) (Int) -> @out SomeButt2
24+
%y = alloc_stack $SomeButt2
25+
apply %g(%y, %a) : $@convention(thin) (Int) -> @out SomeButt2
26+
destroy_addr %y : $*SomeButt2
27+
dealloc_stack %y : $*SomeButt2
1928
return undef : $()
2029
}

0 commit comments

Comments
 (0)