Skip to content

Serialization: Deserialize opaque type xrefs from the right extension module. #25600

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
Jun 19, 2019
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
5 changes: 5 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,11 @@ class OpaqueTypeDecl : public GenericTypeDecl {

ValueDecl *getNamingDecl() const { return NamingDecl; }

void setNamingDecl(ValueDecl *D) {
assert(!NamingDecl && "already have naming decl");
NamingDecl = D;
}

GenericSignature *getOpaqueInterfaceGenericSignature() const {
return OpaqueInterfaceGenericSignature;
}
Expand Down
13 changes: 8 additions & 5 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1724,9 +1724,10 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {

auto name = getIdentifier(DefiningDeclNameID);
pathTrace.addOpaqueReturnType(name);

if (auto opaqueTy = baseModule->lookupOpaqueResultType(name.str(),
nullptr)) {

auto lookupModule = M ? M : baseModule;
if (auto opaqueTy = lookupModule->lookupOpaqueResultType(name.str(),
nullptr)) {
values.push_back(opaqueTy);
}
break;
Expand Down Expand Up @@ -3134,7 +3135,6 @@ class swift::DeclDeserializer {
interfaceTypeID, genericEnvID,
underlyingTypeID);

auto namingDecl = cast<ValueDecl>(MF.getDecl(namingDeclID));
auto declContext = MF.getDeclContext(contextID);
auto sig = MF.getGenericSignature(interfaceSigID);
auto interfaceType = MF.getType(interfaceTypeID)
Expand All @@ -3146,10 +3146,13 @@ class swift::DeclDeserializer {

// Create the decl.
auto opaqueDecl =
new (ctx) OpaqueTypeDecl(namingDecl, nullptr, declContext,
new (ctx) OpaqueTypeDecl(nullptr, nullptr, declContext,
sig, interfaceType);
declOrOffset = opaqueDecl;

auto namingDecl = cast<ValueDecl>(MF.getDecl(namingDeclID));
opaqueDecl->setNamingDecl(namingDecl);

if (auto genericParams = MF.maybeReadGenericParams(opaqueDecl))
opaqueDecl->setGenericParams(genericParams);

Expand Down
6 changes: 6 additions & 0 deletions test/SIL/Serialization/Inputs/OpaqueReturnTypeExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ public protocol Butt {}
extension Int: Butt {}

public func exportsOpaqueReturn() -> some Butt { return 0 }

extension Int {
public func someButt() -> some Butt {
return self
}
}
13 changes: 11 additions & 2 deletions test/SIL/Serialization/opaque_return_type_serialize.sil
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
// RUN: %target-sil-opt -I %t %s -emit-sib -module-name test -o %t/test.sib
// RUN: %target-swift-frontend -disable-availability-checking -I %t -emit-ir %t/test.sib

import Swift
import OpaqueReturnTypeExporter

typealias SomeButt = @_opaqueReturnTypeOf("$s24OpaqueReturnTypeExporter07exportsaB0QryF", 0) opaque
typealias SomeButt2 = @_opaqueReturnTypeOf("$sSi24OpaqueReturnTypeExporterE8someButtQryF", 0) opaque

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

sil @use_opaque_type : $@convention(thin) () -> () {
entry:
sil @use_opaque_type : $@convention(thin) (Int) -> () {
entry(%a : $Int):
%f = function_ref @$s24OpaqueReturnTypeExporter07exportsaB0QryF : $@convention(thin) () -> @out SomeButt
%x = alloc_stack $SomeButt
apply %f(%x) : $@convention(thin) () -> @out SomeButt
destroy_addr %x : $*SomeButt
dealloc_stack %x : $*SomeButt

%g = function_ref @$sSi24OpaqueReturnTypeExporterE8someButtQryF : $@convention(thin) (Int) -> @out SomeButt2
%y = alloc_stack $SomeButt2
apply %g(%y, %a) : $@convention(thin) (Int) -> @out SomeButt2
destroy_addr %y : $*SomeButt2
dealloc_stack %y : $*SomeButt2
return undef : $()
}