Skip to content

Commit b60c885

Browse files
committed
Fix serialization for structural opaque result types
1 parent 96d486a commit b60c885

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,8 +2719,8 @@ class OpaqueTypeDecl final :
27192719
/// abstracted underlying types.
27202720
GenericSignature OpaqueInterfaceGenericSignature;
27212721

2722-
/// The generic parameter that represents the underlying type.
2723-
GenericTypeParamType *UnderlyingInterfaceType;
2722+
/// The underlying type, which will involve the opaque generic parameters.
2723+
Type UnderlyingInterfaceType;
27242724

27252725
/// If known, the underlying type and conformances of the opaque type,
27262726
/// expressed as a SubstitutionMap for the opaque interface generic signature.
@@ -2734,7 +2734,7 @@ class OpaqueTypeDecl final :
27342734
DeclContext *DC,
27352735
GenericSignature OpaqueInterfaceGenericSignature,
27362736
ArrayRef<OpaqueReturnTypeRepr *> OpaqueReturnTypeReprs,
2737-
GenericTypeParamType *UnderlyingInterfaceType);
2737+
Type UnderlyingInterfaceType);
27382738

27392739
unsigned getNumOpaqueReturnTypeReprs() const {
27402740
return NamingDeclAndHasOpaqueReturnTypeRepr.getInt()
@@ -2752,7 +2752,7 @@ class OpaqueTypeDecl final :
27522752
DeclContext *DC,
27532753
GenericSignature OpaqueInterfaceGenericSignature,
27542754
ArrayRef<OpaqueReturnTypeRepr *> OpaqueReturnTypeReprs,
2755-
GenericTypeParamType *UnderlyingInterfaceType);
2755+
Type UnderlyingInterfaceType);
27562756

27572757
ValueDecl *getNamingDecl() const {
27582758
return NamingDeclAndHasOpaqueReturnTypeRepr.getPointer();
@@ -2794,10 +2794,7 @@ class OpaqueTypeDecl final :
27942794
}
27952795

27962796
/// The underlying interface type describing the whole opaque type.
2797-
///
2798-
/// FIXME: Structured opaque types will generalize this to an
2799-
/// arbitrary type.
2800-
GenericTypeParamType *getUnderlyingInterfaceType() const {
2797+
Type getUnderlyingInterfaceType() const {
28012798
return UnderlyingInterfaceType;
28022799
}
28032800

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ SwiftDeclCollector::constructTypeNode(Type T, TypeInitInfo Info) {
15181518
if (auto OTA = T->getAs<OpaqueTypeArchetypeType>()) {
15191519
if (auto *D = OTA->getDecl()) {
15201520
if (auto SubMap = D->getUnderlyingTypeSubstitutions()) {
1521-
T = Type(D->getUnderlyingInterfaceType()).
1521+
T = D->getUnderlyingInterfaceType().
15221522
subst(*SubMap)->getCanonicalType();
15231523
}
15241524
}

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ namespace {
567567
OS << " naming_decl=";
568568
printDeclName(OTD->getNamingDecl());
569569
PrintWithColorRAII(OS, TypeColor) << " opaque_interface="
570-
<< Type(OTD->getUnderlyingInterfaceType()).getString();
570+
<< OTD->getUnderlyingInterfaceType().getString();
571571
OS << " in "
572572
<< OTD->getOpaqueInterfaceGenericSignature()->getAsString();
573573
if (auto underlyingSubs = OTD->getUnderlyingTypeSubstitutions()) {

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7782,7 +7782,7 @@ OpaqueTypeDecl::OpaqueTypeDecl(ValueDecl *NamingDecl,
77827782
GenericSignature OpaqueInterfaceGenericSignature,
77837783
ArrayRef<OpaqueReturnTypeRepr *>
77847784
OpaqueReturnTypeReprs,
7785-
GenericTypeParamType *UnderlyingInterfaceType)
7785+
Type UnderlyingInterfaceType)
77867786
: GenericTypeDecl(DeclKind::OpaqueType, DC, Identifier(), SourceLoc(), {},
77877787
GenericParams),
77887788
NamingDeclAndHasOpaqueReturnTypeRepr(
@@ -7807,7 +7807,7 @@ OpaqueTypeDecl *OpaqueTypeDecl::get(
78077807
DeclContext *DC,
78087808
GenericSignature OpaqueInterfaceGenericSignature,
78097809
ArrayRef<OpaqueReturnTypeRepr *> OpaqueReturnTypeReprs,
7810-
GenericTypeParamType *UnderlyingInterfaceType) {
7810+
Type UnderlyingInterfaceType) {
78117811
ASTContext &ctx = DC->getASTContext();
78127812
auto size = totalSizeToAlloc<OpaqueReturnTypeRepr *>(
78137813
OpaqueReturnTypeReprs.size());

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,7 +3458,7 @@ class DeclDeserializer {
34583458
auto declContext = MF.getDeclContext(contextID);
34593459
auto interfaceSig = MF.getGenericSignature(interfaceSigID);
34603460
auto interfaceType = MF.getType(interfaceTypeID);
3461-
3461+
34623462
// Check for reentrancy.
34633463
if (declOrOffset.isComplete())
34643464
return cast<OpaqueTypeDecl>(declOrOffset.get());
@@ -3469,7 +3469,7 @@ class DeclDeserializer {
34693469
auto opaqueDecl = OpaqueTypeDecl::get(
34703470
/*NamingDecl=*/ nullptr, genericParams, declContext,
34713471
interfaceSig, /*OpaqueReturnTypeReprs*/ { },
3472-
interfaceType->castTo<GenericTypeParamType>());
3472+
interfaceType);
34733473
declOrOffset = opaqueDecl;
34743474

34753475
auto namingDecl = cast<ValueDecl>(MF.getDecl(namingDeclID));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public protocol P { }
2+
public protocol Q { }
3+
4+
extension Int: P { }
5+
extension Double: Q { }
6+
7+
public protocol R {
8+
associatedtype A
9+
func f() -> A
10+
}
11+
12+
public struct X: R {
13+
public func f() -> (some P, [some Q]) {
14+
return (1, [3.14159, 2.71828])
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t -enable-library-evolution %S/Inputs/OpaqueTypeStructured.swift
3+
// RUN: %target-swift-frontend -emit-sil -I %t %s | %FileCheck -check-prefix=SIL %s
4+
// RUN: %target-swift-ide-test -print-module -source-filename %s -module-to-print OpaqueTypeStructured -I %t | %FileCheck -check-prefix=AST %s
5+
import OpaqueTypeStructured
6+
7+
func acceptR<T: R>(_: T) { }
8+
9+
// AST: func f() -> (some P, [some Q])
10+
11+
func passAnX(x: X) {
12+
// SIL: $@convention(method) (@in_guaranteed X) -> (@out @_opaqueReturnTypeOf("$s20OpaqueTypeStructured1XV1fQr_SayQrGtyF", 0) __, @owned Array<@_opaqueReturnTypeOf("$s20OpaqueTypeStructured1XV1fQr_SayQrGtyF", 1) __>)
13+
acceptR(x)
14+
let _: X.A = x.f()
15+
}
16+

0 commit comments

Comments
 (0)