Skip to content

Commit 764befe

Browse files
committed
---
yaml --- r: 284415 b: refs/heads/swift-5.1-branch c: 6500ef3 h: refs/heads/master i: 284413: a10023a 284411: c9a9f4e 284407: 123d0c5 284399: 0b0e6de 284383: 69150ec 284351: 0773ae6 284287: e3a1c2a 284159: 5d96af4
1 parent 0a47f21 commit 764befe

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ refs/heads/marcrasi-astverifier-disable: 3fac766a23a77ebd0640296bfd7fc116ea60a4e
12421242
refs/heads/revert-22227-a-tall-white-fountain-played: adfce60b2eaa54903ea189bed8a783bca609fa53
12431243
refs/heads/revert-22300-revert-22227-a-tall-white-fountain-played: 5f92040224df7dd4e618fdfb367349df64d8acad
12441244
refs/heads/swift-5.1-old-llvm-branch: 9cef8175146f25b72806154b8a0f4a3f52e3e400
1245-
refs/heads/swift-5.1-branch: dc9b907b4dfa5b634dfaaf73224bcec83b074746
1245+
refs/heads/swift-5.1-branch: 6500ef339208ef007e3aca8e4e79b433e65879c5
12461246
refs/tags/swift-4.2.2-RELEASE: e429d1f1aaf59e69d38207a96e56265c7f6fccec
12471247
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-02-a: 3e5a03d32ff3b1e9af90d6c1198c14f938379a6e
12481248
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-03-a: 4591c933063ddcb0d6cd6d0cdd01086b2f9b244d

branches/swift-5.1-branch/lib/Parse/ParseDecl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5197,12 +5197,22 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
51975197
pattern = patternRes.get();
51985198
}
51995199

5200+
bool hasOpaqueReturnTy = false;
5201+
if (auto typedPattern = dyn_cast<TypedPattern>(pattern)) {
5202+
hasOpaqueReturnTy =
5203+
isa<OpaqueReturnTypeRepr>(typedPattern->getTypeRepr());
5204+
}
5205+
auto sf = CurDeclContext->getParentSourceFile();
5206+
52005207
// Configure all vars with attributes, 'static' and parent pattern.
52015208
pattern->forEachVariable([&](VarDecl *VD) {
52025209
VD->setStatic(StaticLoc.isValid());
52035210
VD->getAttrs() = Attributes;
52045211
setLocalDiscriminator(VD);
52055212
Decls.push_back(VD);
5213+
if (hasOpaqueReturnTy && sf) {
5214+
sf->addUnvalidatedDeclWithOpaqueResultType(VD);
5215+
}
52065216
});
52075217

52085218
// Remember this pattern/init pair for our ultimate PatternBindingDecl. The
@@ -6364,6 +6374,13 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
63646374
CurDeclContext,
63656375
nullptr);
63666376
Subscript->getAttrs() = Attributes;
6377+
6378+
// Let the source file track the opaque return type mapping, if any.
6379+
if (ElementTy.get() && isa<OpaqueReturnTypeRepr>(ElementTy.get())) {
6380+
if (auto sf = CurDeclContext->getParentSourceFile()) {
6381+
sf->addUnvalidatedDeclWithOpaqueResultType(Subscript);
6382+
}
6383+
}
63676384

63686385
// Parse a 'where' clause if present, adding it to our GenericParamList.
63696386
if (Tok.is(tok::kw_where)) {

branches/swift-5.1-branch/lib/Sema/TypeCheckDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,12 @@ static bool shouldUseOpaqueReadAccessor(TypeChecker &TC,
19861986

19871987
static void validateAbstractStorageDecl(TypeChecker &TC,
19881988
AbstractStorageDecl *storage) {
1989+
if (storage->getOpaqueResultTypeDecl()) {
1990+
if (auto sf = storage->getInnermostDeclContext()->getParentSourceFile()) {
1991+
sf->markDeclWithOpaqueResultTypeAsValidated(storage);
1992+
}
1993+
}
1994+
19891995
if (shouldUseOpaqueReadAccessor(TC, storage))
19901996
storage->setOpaqueReadOwnership(OpaqueReadOwnership::Borrowed);
19911997

branches/swift-5.1-branch/test/ParseableInterface/Inputs/opaque-result-types-client.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import OpaqueResultTypes
33
func getAssocType<T: AssocTypeInference>(_ x: T) -> T.Assoc {
44
return x.foo(0)
55
}
6+
func getAssocPropType<T: AssocTypeInference>(_ x: T) -> T.AssocProperty {
7+
return x.prop
8+
}
9+
func getAssocSubscriptType<T: AssocTypeInference>(_ x: T) -> T.AssocSubscript {
10+
return x[]
11+
}
612

713
struct MyFoo: Foo {}
814
struct YourFoo: Foo {}
@@ -29,6 +35,18 @@ func someTypeIsTheSame() {
2935
d = barString.foo(0) // expected-error{{cannot assign}}
3036
d = getAssocType(barInt)
3137
d = getAssocType(barString) // expected-error{{cannot assign}}
38+
39+
var d2 = barInt.prop
40+
d2 = barInt.prop
41+
d2 = barString.prop // expected-error{{cannot assign}}
42+
d2 = getAssocPropType(barInt)
43+
d2 = getAssocPropType(barString) // expected-error{{cannot assign}}
44+
45+
var d3 = barInt[]
46+
d3 = barInt[]
47+
d3 = barString[] // expected-error{{cannot assign}}
48+
d3 = getAssocSubscriptType(barInt)
49+
d3 = getAssocSubscriptType(barString) // expected-error{{cannot assign}}
3250

3351
var e = barString.foo(0)
3452
e = barInt.foo(0) // expected-error{{cannot assign}}

branches/swift-5.1-branch/test/ParseableInterface/opaque-result-types.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ public func foo<T: Foo>(_ x: T) -> some Foo {
2323

2424
public protocol AssocTypeInference {
2525
associatedtype Assoc: Foo
26+
associatedtype AssocProperty: Foo
27+
associatedtype AssocSubscript: Foo
2628

2729
func foo(_: Int) -> Assoc
30+
31+
var prop: AssocProperty { get }
32+
subscript() -> AssocSubscript { get }
2833
}
2934

3035
public struct Bar<T>: AssocTypeInference {
@@ -61,7 +66,16 @@ public struct Bar<T>: AssocTypeInference {
6166
return x
6267
}
6368

69+
public var prop: some Foo {
70+
return 123
71+
}
72+
public subscript() -> some Foo {
73+
return 123
74+
}
75+
6476
// CHECK-LABEL: public typealias Assoc = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<T>
77+
// CHECK-LABEL: public typealias AssocProperty = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<T>
78+
// CHECK-LABEL: public typealias AssocSubscript = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<T>
6579
}
6680

6781
public struct Bass<U: Foo>: AssocTypeInference {
@@ -85,11 +99,28 @@ public struct Bar<T>: AssocTypeInference {
8599
public func foo<V: Foo>(_ x: V) -> some Foo {
86100
return x
87101
}
102+
public var prop: some Foo {
103+
return 123
104+
}
105+
public subscript() -> some Foo {
106+
return 123
107+
}
88108

89109
// CHECK-LABEL: public typealias Assoc = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<T, U>
110+
// CHECK-LABEL: public typealias AssocProperty = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<T, U>
111+
// CHECK-LABEL: public typealias AssocSubscript = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<T, U>
112+
}
113+
114+
public var prop: some Foo {
115+
return 123
116+
}
117+
public subscript() -> some Foo {
118+
return 123
90119
}
91120

92121
// CHECK-LABEL: public typealias Assoc = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<T>
122+
// CHECK-LABEL: public typealias AssocProperty = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<T>
123+
// CHECK-LABEL: public typealias AssocSubscript = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<T>
93124
}
94125

95126
public struct Zim: AssocTypeInference {
@@ -123,6 +154,13 @@ public struct Zim: AssocTypeInference {
123154
public func foo<U: Foo>(_ x: U) -> some Foo {
124155
return x
125156
}
157+
158+
public var prop: some Foo {
159+
return 123
160+
}
161+
public subscript() -> some Foo {
162+
return 123
163+
}
126164
}
127165

128166
public struct Zung<U: Foo>: AssocTypeInference {
@@ -146,6 +184,22 @@ public struct Zim: AssocTypeInference {
146184
return x
147185
}
148186

187+
public var prop: some Foo {
188+
return 123
189+
}
190+
public subscript() -> some Foo {
191+
return 123
192+
}
193+
149194
// CHECK-LABEL: public typealias Assoc = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<U>
195+
// CHECK-LABEL: public typealias AssocProperty = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<U>
196+
// CHECK-LABEL: public typealias AssocSubscript = @_opaqueReturnTypeOf("{{.*}}", 0) {{.*}}<U>
197+
}
198+
199+
public var prop: some Foo {
200+
return 123
201+
}
202+
public subscript() -> some Foo {
203+
return 123
150204
}
151205
}

0 commit comments

Comments
 (0)