Skip to content

Commit 0640fef

Browse files
author
Harlan Haskins
authored
Merge pull request swiftlang#27119 from harlanhaskins/xref-vision-5.1
[5.1] [Serialization] Teach serialization to get a generic signature from opaque types
2 parents 9acad62 + b59a33e commit 0640fef

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 501; // SIL function availability
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 502; // generic opaque return type xref
5656

5757
using DeclIDField = BCFixed<31>;
5858

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,8 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
17941794
currentSig = fn->getGenericSignature();
17951795
} else if (auto subscript = dyn_cast<SubscriptDecl>(base)) {
17961796
currentSig = subscript->getGenericSignature();
1797+
} else if (auto opaque = dyn_cast<OpaqueTypeDecl>(base)) {
1798+
currentSig = opaque->getGenericSignature();
17971799
}
17981800

17991801
if (!currentSig) {

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,8 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
19471947
case DeclContextKind::GenericTypeDecl: {
19481948
auto generic = cast<GenericTypeDecl>(DC);
19491949

1950+
writeCrossReference(DC->getParent(), pathLen + 1);
1951+
19501952
// Opaque return types are unnamed and need a special xref.
19511953
if (auto opaque = dyn_cast<OpaqueTypeDecl>(generic)) {
19521954
if (!opaque->hasName()) {
@@ -1960,8 +1962,6 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
19601962
}
19611963

19621964
assert(generic->hasName());
1963-
1964-
writeCrossReference(DC->getParent(), pathLen + 1);
19651965

19661966
abbrCode = DeclTypeAbbrCodes[XRefTypePathPieceLayout::Code];
19671967

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public protocol BestProtocol {}
2+
public protocol GoodProtocol {
3+
associatedtype A
4+
}
5+
6+
public struct BestStruct: BestProtocol {
7+
public init() {}
8+
}
9+
10+
extension BestProtocol {
11+
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
12+
public func _bestValue<X: GoodProtocol>(_ x: X.Type, _ a: X.A) -> some BestProtocol {
13+
return BestStruct()
14+
}
15+
}
16+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"./best-protocol.swift": {
3+
"swiftmodule": "./best-protocol.swiftmodule"
4+
},
5+
"./xref-opaque-generic-type.swift": {
6+
"swiftmodule": "./xref-opaque-generic-type.swiftmodule"
7+
}
8+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp -r %S/Inputs/xref-opaque-generic-type/* %t/.
3+
// RUN: cp %s %t/xref-generic-opaque-type.swift
4+
// RUN: cd %t
5+
// RUN: %target-swiftc_driver -emit-module -incremental %t/best-protocol.swift %t/xref-generic-opaque-type.swift -module-name A -output-file-map %t/output.json
6+
7+
@usableFromInline
8+
struct GoodStruct: GoodProtocol {
9+
@usableFromInline
10+
typealias A = Int
11+
}
12+
13+
extension BestProtocol {
14+
@inlinable
15+
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
16+
public func bestValue(_ x: Int) -> some BestProtocol {
17+
return _bestValue(GoodStruct.self, x)
18+
}
19+
}

0 commit comments

Comments
 (0)