Skip to content

Commit f42b107

Browse files
committed
Unbreak tests after read / modify accessors added
1 parent c49c3d9 commit f42b107

14 files changed

+59
-54
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,14 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
11101110

11111111
SmallVector<AnyFunctionType::Yield, 4> buffer;
11121112
auto TheFunc = AnyFunctionRef::fromDeclContext(DC);
1113-
auto yieldResults = TheFunc->getBodyYieldResults(buffer);
1113+
// Checking yields requires proper interface type. If decl is invalid, then
1114+
// we already emitted diagnostics elsewhere.
1115+
if (auto *AFD = TheFunc->getAbstractFunctionDecl()) {
1116+
if (AFD->isInvalid())
1117+
return YS;
1118+
}
11141119

1120+
auto yieldResults = TheFunc->getBodyYieldResults(buffer);
11151121
auto yieldExprs = YS->getMutableYields();
11161122
if (yieldExprs.size() != yieldResults.size()) {
11171123
getASTContext().Diags.diagnose(YS->getYieldLoc(), diag::bad_yield_count,

lib/Sema/TypeCheckStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,7 @@ createCoroutineAccessorPrototype(AbstractStorageDecl *storage,
24922492

24932493
// Coroutine accessors yields storage value types
24942494
const Type retTy = YieldResultType::get(storage->getValueInterfaceType(),
2495-
kind == AccessorKind::Modify);
2495+
isYieldingMutableAccessor(kind));
24962496

24972497
auto *accessor = AccessorDecl::create(
24982498
ctx, loc, /*AccessorKeywordLoc=*/SourceLoc(), kind, storage,

test/IRGen/default_override.sil

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ sil @B_i_modify : $@yield_once @convention(method) (@guaranteed B) -> @yields @i
2828
sil @B_i_modify2 : $@yield_once_2 @convention(method) (@guaranteed B) -> @yields @inout Int
2929

3030
sil_vtable B {
31-
#B.i!read: (B) -> () -> () : @B_i_read
32-
#B.i!read2: (B) -> () -> () : @B_i_read2
31+
#B.i!read: (B) -> @yield_once () -> @yields Int : @B_i_read
32+
#B.i!read2: (B) -> @yield_once () -> @yields Int : @B_i_read2
3333
#B.i!setter: (B) -> (Int) -> () : @B_i_set
34-
#B.i!modify: (B) -> () -> () : @B_i_modify
35-
#B.i!modify2: (B) -> () -> () : @B_i_modify2
34+
#B.i!modify: (B) -> @yield_once () -> inout @yields Int : @B_i_modify
35+
#B.i!modify2: (B) -> @yield_once () -> inout @yields Int : @B_i_modify2
3636
}
3737

3838
sil @B_i_read2_default_override : $@yield_once_2 @convention(method) (@guaranteed B) -> @yields Int
3939
sil @B_i_modify2_default_override : $@yield_once_2 @convention(method) (@guaranteed B) -> @yields @inout Int
4040

4141
sil_default_override_table B {
42-
#B.i!read2: #B.i!read: (B) -> () -> () : @B_i_read2_default_override
43-
#B.i!modify2: #B.i!modify: (B) -> () -> () : @B_i_modify2_default_override
42+
#B.i!read2: #B.i!read: (B) -> @yield_once () -> @yields Int : @B_i_read2_default_override
43+
#B.i!modify2: #B.i!modify: (B) -> @yield_once () -> inout @yields Int : @B_i_modify2_default_override
4444
}
4545

4646
// CHECK: %swift.method_default_override_descriptor = type { i32, i32, i32 }

test/Parse/coroutine_accessors_ambiguity.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ func read<T>(_ c : () -> T) -> T { c() }
1717
// disabled: ok!
1818
var im : Int {
1919
modify { // expected-enabled-error{{variable with a 'modify' accessor must also have a getter, addressor, or 'read' accessor}}
20-
1 // expected-enabled-warning{{integer literal is unused}}
20+
1 // expected-enabled-error{{unexpected non-void return value in void function}}
2121
}
2222
}
2323

2424
// enabled: ok
2525
// disabled: ok!
2626
var ir : Int {
2727
read {
28-
1 // expected-enabled-warning{{integer literal is unused}}
28+
1 // expected-enabled-error{{unexpected non-void return value in void function}}
2929
}
3030
}

test/SIL/Parser/default_override.sil

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ sil @B_i_modify : $@yield_once @convention(method) (@guaranteed B) -> @yields @i
2424
sil @B_i_modify2 : $@yield_once_2 @convention(method) (@guaranteed B) -> @yields @inout Int
2525

2626
sil_vtable B {
27-
#B.i!read: (B) -> () -> () : @B_i_read
28-
#B.i!read2: (B) -> () -> () : @B_i_read2
27+
#B.i!read: (B) -> @yield_once () -> @yields Int : @B_i_read
28+
#B.i!read2: (B) -> @yield_once () -> @yields Int : @B_i_read2
2929
#B.i!setter: (B) -> (Int) -> () : @B_i_set
30-
#B.i!modify: (B) -> () -> () : @B_i_modify
31-
#B.i!modify2: (B) -> () -> () : @B_i_modify2
30+
#B.i!modify: (B) -> @yield_once () -> inout @yields Int : @B_i_modify
31+
#B.i!modify2: (B) -> @yield_once () -> inout @yields Int : @B_i_modify2
3232
}
3333

3434
sil @B_i_read2_default_override : $@yield_once_2 @convention(method) (@guaranteed B) -> @yields Int
3535
sil @B_i_modify2_default_override : $@yield_once_2 @convention(method) (@guaranteed B) -> @yields @inout Int
3636

3737
// CHECK-LABEL: sil_default_override_table B {
38-
// CHECK-NEXT: #B.i!read2: #B.i!read: (B) -> () -> () : @B_i_read2_default_override
39-
// CHECK-NEXT: #B.i!modify2: #B.i!modify: (B) -> () -> () : @B_i_modify2_default_override
38+
// CHECK-NEXT: #B.i!read2: #B.i!read: (B) -> @yield_once () -> @yields Int : @B_i_read2_default_override
39+
// CHECK-NEXT: #B.i!modify2: #B.i!modify: (B) -> @yield_once () -> inout @yields Int : @B_i_modify2_default_override
4040
// CHECK-NEXT: }
4141
sil_default_override_table B {
42-
#B.i!read2: #B.i!read: (B) -> () -> () : @B_i_read2_default_override
43-
#B.i!modify2: #B.i!modify: (B) -> () -> () : @B_i_modify2_default_override
42+
#B.i!read2: #B.i!read: (B) -> @yield_once () -> @yields Int : @B_i_read2_default_override
43+
#B.i!modify2: #B.i!modify: (B) -> @yield_once () -> inout @yields Int : @B_i_modify2_default_override
4444
}

test/SIL/Serialization/default_override.sil

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ sil @B_i_modify : $@yield_once @convention(method) (@guaranteed B) -> @yields @i
2626
sil @B_i_modify2 : $@yield_once_2 @convention(method) (@guaranteed B) -> @yields @inout Int
2727

2828
sil_vtable B {
29-
#B.i!read: (B) -> () -> () : @B_i_read
30-
#B.i!read2: (B) -> () -> () : @B_i_read2
29+
#B.i!read: (B) -> @yield_once () -> @yields Int : @B_i_read
30+
#B.i!read2: (B) -> @yield_once () -> @yields Int : @B_i_read2
3131
#B.i!setter: (B) -> (Int) -> () : @B_i_set
32-
#B.i!modify: (B) -> () -> () : @B_i_modify
33-
#B.i!modify2: (B) -> () -> () : @B_i_modify2
32+
#B.i!modify: (B) -> @yield_once () -> inout @yields Int : @B_i_modify
33+
#B.i!modify2: (B) -> @yield_once () -> inout @yields Int : @B_i_modify2
3434
}
3535

3636
sil @B_i_read2_default_override : $@yield_once_2 @convention(method) (@guaranteed B) -> @yields Int
3737
sil @B_i_modify2_default_override : $@yield_once_2 @convention(method) (@guaranteed B) -> @yields @inout Int
3838

3939
// CHECK-LABEL: sil_default_override_table B {
40-
// CHECK-NEXT: #B.i!read2: #B.i!read: (B) -> () -> () : @B_i_read2_default_override
41-
// CHECK-NEXT: #B.i!modify2: #B.i!modify: (B) -> () -> () : @B_i_modify2_default_override
40+
// CHECK-NEXT: #B.i!read2: #B.i!read: (B) -> @yield_once () -> @yields Int : @B_i_read2_default_override
41+
// CHECK-NEXT: #B.i!modify2: #B.i!modify: (B) -> @yield_once () -> inout @yields Int : @B_i_modify2_default_override
4242
// CHECK-NEXT: }
4343
sil_default_override_table B {
44-
#B.i!read2: #B.i!read: (B) -> () -> () : @B_i_read2_default_override
45-
#B.i!modify2: #B.i!modify: (B) -> () -> () : @B_i_modify2_default_override
44+
#B.i!read2: #B.i!read: (B) -> @yield_once () -> @yields Int : @B_i_read2_default_override
45+
#B.i!modify2: #B.i!modify: (B) -> @yield_once () -> inout @yields Int : @B_i_modify2_default_override
4646
}

test/SILGen/default_override.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ open class OpenBase<T> {
3838
// CHECK-SAME: [[SELF:%[^,]+]] :
3939
// CHECK-SAME: ):
4040
// CHECK: [[ORIGINAL:%[^,]+]] = class_method [[SELF]], #OpenBase.openField!read
41-
// CHECK-SAME: <T> (OpenBase<T>) -> () -> ()
41+
// CHECK-SAME: <T> (OpenBase<T>) -> @yield_once () -> @yields T
4242
// CHECK-SAME: $@yield_once @convention(method) <τ_0_0> (@guaranteed OpenBase<τ_0_0>) -> @yields @in_guaranteed τ_0_0
4343
// CHECK: ([[ADDR:%[^,]+]], [[TOKEN:%[^,]+]]) = begin_apply [[ORIGINAL]]<τ_0_0>([[SELF]])
4444
// CHECK: yield [[ADDR]]
@@ -69,7 +69,7 @@ open class OpenBase<T> {
6969
// CHECK-SAME: [[SELF:%[^,]+]] :
7070
// CHECK-SAME: ):
7171
// CHECK: [[ORIGINAL:%[^,]+]] = class_method [[SELF]], #OpenBase.openField!modify
72-
// CHECK: <T> (OpenBase<T>) -> () -> ()
72+
// CHECK: <T> (OpenBase<T>) -> @yield_once () -> inout @yields T
7373
// CHECK: $@yield_once @convention(method) <τ_0_0> (@guaranteed OpenBase<τ_0_0>) -> @yields @inout τ_0_0
7474
// CHECK: ([[ADDR:%[^,]+]], [[TOKEN:%[^,]+]]) = begin_apply [[ORIGINAL]]<τ_0_0>([[SELF]])
7575
// CHECK: yield [[ADDR]]
@@ -107,7 +107,7 @@ open class OpenBase<T> {
107107
// CHECK-SAME: ):
108108
// CHECK: [[ORIGINAL:%[^,]+]] = class_method [[SELF]]
109109
// CHECK: #OpenBase.subscript!read
110-
// CHECK: <T><U> (OpenBase<T>) -> (U, Open.Type) -> ()
110+
// CHECK: <T><U> (OpenBase<T>) -> @yield_once (U, Open.Type) -> @yields T
111111
// CHECK: $@yield_once @convention(method) <τ_0_0><τ_1_0> (@in_guaranteed τ_1_0, @thin Open.Type, @guaranteed OpenBase<τ_0_0>) -> @yields @in_guaranteed τ_0_0
112112
// CHECK: ([[ADDR:%[^,]+]], [[TOKEN:%[^,]+]]) = begin_apply [[ORIGINAL]]<τ_0_0, τ_1_0>([[KEY]], [[OPEN_TY]], [[SELF]])
113113
// CHECK: yield [[ADDR]]
@@ -143,7 +143,7 @@ open class OpenBase<T> {
143143
// CHECK-SAME: ):
144144
// CHECK: [[ORIGINAL:%[^,]+]] = class_method [[SELF]]
145145
// CHECK-SAME: #OpenBase.subscript!modify
146-
// CHECK-SAME: <T><U> (OpenBase<T>) -> (U, Open.Type) -> ()
146+
// CHECK-SAME: <T><U> (OpenBase<T>) -> @yield_once (U, Open.Type) -> inout @yields T
147147
// CHECK-SAME: $@yield_once @convention(method) <τ_0_0><τ_1_0> (@in_guaranteed τ_1_0, @thin Open.Type, @guaranteed OpenBase<τ_0_0>) -> @yields @inout τ_0_0
148148
// CHECK: ([[ADDR:%[^,]+]], [[TOKEN:%[^,]+]]) = begin_apply [[ORIGINAL]]<τ_0_0, τ_1_0>([[KEY]], [[OPEN_TY]], [[SELF]])
149149
// CHECK: yield [[ADDR]]
@@ -300,24 +300,24 @@ class InternalBase<T> {
300300
// CHECK-LABEL: sil_default_override_table OpenBase {
301301
// CHECK-NEXT: #OpenBase.openField!read2
302302
// CHECK-SAME: #OpenBase.openField!read
303-
// CHECK-SAME: <T> (OpenBase<T>) -> () -> ()
303+
// CHECK-SAME: <T> (OpenBase<T>) -> @yield_once () -> @yields T
304304
// CHECK-SAME: @$s16default_override8OpenBaseC9openFieldxvyTwd
305305
// CHECK-NEXT: #OpenBase.openField!modify2
306306
// CHECK-SAME: #OpenBase.openField!modify
307-
// CHECK-SAME: <T> (OpenBase<T>) -> () -> ()
307+
// CHECK-SAME: <T> (OpenBase<T>) -> @yield_once () -> inout @yields T
308308
// CHECK-SAME: @$s16default_override8OpenBaseC9openFieldxvxTwd
309309
// CHECK-NEXT: #OpenBase.subscript!read2
310310
// CHECK-SAME: #OpenBase.subscript!read
311-
// CHECK-SAME: <T><U> (OpenBase<T>) -> (U, Open.Type) -> ()
311+
// CHECK-SAME: <T><U> (OpenBase<T>) -> @yield_once (U, Open.Type) -> @yields T
312312
// CHECK-SAME: @$s16default_override8OpenBaseCyxqd___AA0C0OmtcluiyTwd
313313
// CHECK-NEXT: #OpenBase.subscript!modify2
314314
// CHECK-SAME: #OpenBase.subscript!modify
315-
// CHECK-SAME: <T><U> (OpenBase<T>) -> (U, Open.Type) -> ()
315+
// CHECK-SAME: <T><U> (OpenBase<T>) -> @yield_once (U, Open.Type) -> inout @yields T
316316
// CHECK-SAME: @$s16default_override8OpenBaseCyxqd___AA0C0OmtcluixTwd
317317
// CHECK-NOT: #OpenBase.publicField!read2
318318
// CHECK-NOT: #OpenBase.publicField!modify2
319-
// CHECK-NOT: #OpenBase.subscript!read2: #OpenBase.subscript!read: <T><U> (OpenBase<T>) -> (U, Public.Type) -> ()
320-
// CHECK-NOT: #OpenBase.subscript!modify2: #OpenBase.subscript!modify: <T><U> (OpenBase<T>) -> (U, Public.Type) -> ()
319+
// CHECK-NOT: #OpenBase.subscript!read2: #OpenBase.subscript!read: <T><U> (OpenBase<T>) -> @yield_once (U, Public.Type) -> @yields T
320+
// CHECK-NOT: #OpenBase.subscript!modify2: #OpenBase.subscript!modify: <T><U> (OpenBase<T>) -> @yield_once (U, Public.Type) -> inout @yields T
321321
// CHECK-NEXT: }
322322

323323
// CHECK-NOT: sil_default_override_table PublicBase {

test/SILGen/sendable_to_any_for_generic_arguments.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ func test_subscript_computed_property_and_mutating_access(u: User) {
207207
// CHECK-NEXT: {{.*}} = apply [[SUBSCRIPT_GETTER]]<String, Any, String>({{.*}}, [[BORROWED_COPY]])
208208
_ = u.dict[entry: ""]
209209

210-
// CHECK: [[DICT_GETTER:%.*]] = class_method %0, #User.dict!modify : (User) -> () -> (), $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
211-
// CHECK-NEXT: ([[DICT_ADDR:%.*]], {{.*}}) = begin_apply [[DICT_GETTER]]({{.*}}) : $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
210+
// CHECK: [[DICT_MODIFY:%.*]] = class_method %0, #User.dict!modify : (User) -> @yield_once () -> inout @yields [String : any Sendable], $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
211+
// CHECK-NEXT: ([[DICT_ADDR:%.*]], {{.*}}) = begin_apply [[DICT_MODIFY]]({{.*}}) : $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
212212
// CHECK-NEXT: [[ANY_DICT:%.*]] = alloc_stack $Dictionary<String, Any>
213213
// CHECK-NEXT: [[LOADED_DICT:%.*]] = load [copy] [[DICT_ADDR]]
214214
// CHECK-NEXT: [[ANY_LOADED_DICT:%.*]] = unchecked_bitwise_cast [[LOADED_DICT]] to $Dictionary<String, Any>
@@ -231,8 +231,8 @@ func test_subscript_computed_property_and_mutating_access(u: User) {
231231
// CHECK-NEXT: {{.*}} = apply [[GETTER]]([[ANY_DICT]]) : $@convention(method) (@guaranteed Dictionary<String, Any>) -> Optional<Int>
232232
_ = u.dict.test
233233

234-
// CHECK: [[DICT_GETTER:%.*]] = class_method %0, #User.dict!modify : (User) -> () -> (), $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
235-
// CHECK-NEXT: ([[DICT:%.*]], {{.*}}) = begin_apply [[DICT_GETTER]]({{.*}}) : $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
234+
// CHECK: [[DICT_MODIFY:%.*]] = class_method %0, #User.dict!modify : (User) -> @yield_once () -> inout @yields [String : any Sendable], $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
235+
// CHECK-NEXT: ([[DICT:%.*]], {{.*}}) = begin_apply [[DICT_MODIFY]]({{.*}}) : $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
236236
// CHECK-NEXT: [[ANY_DICT:%.*]] = alloc_stack $Dictionary<String, Any>
237237
// CHECK-NEXT: [[LOADED_DICT:%.*]] = load [copy] [[DICT]]
238238
// CHECK-NEXT: [[CASTED_DICT:%.*]] = unchecked_bitwise_cast [[LOADED_DICT]] to $Dictionary<String, Any>
@@ -246,8 +246,8 @@ func test_subscript_computed_property_and_mutating_access(u: User) {
246246
// CHECK-NEXT: assign [[COPIED_SENDABLE_DICT]] to [[DICT]]
247247
u.dict.test = 42
248248

249-
// CHECK: [[DICT_GETTER:%.*]] = class_method %0, #User.dict!modify : (User) -> () -> (), $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
250-
// CHECK-NEXT: ([[DICT:%.*]], {{.*}}) = begin_apply [[DICT_GETTER:%.*]](%0) : $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
249+
// CHECK: [[DICT_MODIFY:%.*]] = class_method %0, #User.dict!modify : (User) -> @yield_once () -> inout @yields [String : any Sendable], $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
250+
// CHECK-NEXT: ([[DICT:%.*]], {{.*}}) = begin_apply [[DICT_MODIFY:%.*]](%0) : $@yield_once @convention(method) (@guaranteed User) -> @yields @inout Dictionary<String, any Sendable>
251251
// CHECK-NEXT: [[ANY_DICT:%.*]] = alloc_stack $Dictionary<String, Any>
252252
// CHECK-NEXT: [[LOADED_DICT:%.*]] = load [copy] [[DICT]]
253253
// CHECK-NEXT: [[CASTED_DICT:%.*]] = unchecked_bitwise_cast [[LOADED_DICT]] to $Dictionary<String, Any>

test/SILOptimizer/access_marker_verify.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,7 @@ class C : Abstractable {
791791
// CHECK-NEXT: [[THUNKED_NEW_FN:%.*]] = partial_apply [callee_guaranteed] [[THUNK]]([[NEW_FN_CONV]])
792792
// CHECK-NEXT: store [[THUNKED_NEW_FN]] to [init] [[ADDR]] :
793793
// CHECK-NEXT: dealloc_stack [[TEMP]]
794-
// CHECK-NEXT: end_apply [[TOKEN]]
795-
// CHECK-NEXT: [[TUPLE:%.*]] = tuple ()
794+
// CHECK-NEXT: [[TUPLE:%.*]] = end_apply [[TOKEN]]
796795
// CHECK-NEXT: end_borrow [[SELF]] : $C
797796
// CHECK-NEXT: return [[TUPLE]]
798797

test/SILOptimizer/devirtualize_coroutine_accessors.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sil [ossa] @utilize_begin_apply : $@convention(thin) () -> () {
2929
bb0:
3030
%derived = alloc_ref $Derived
3131
%base = upcast %derived : $Derived to $Base
32-
%reader = class_method %base : $Base, #Base.x!read2 : (Base) -> () -> (), $@yield_once_2 @convention(method) (@guaranteed Base) -> @yields Int
32+
%reader = class_method %base : $Base, #Base.x!read2 : (Base) -> @yield_once () -> @yields Int, $@yield_once_2 @convention(method) (@guaranteed Base) -> @yields Int
3333
(%value, %token, %allocation) = begin_apply %reader(%base) : $@yield_once_2 @convention(method) (@guaranteed Base) -> @yields Int
3434
end_apply %token as $()
3535
dealloc_stack %allocation : $*Builtin.SILToken

0 commit comments

Comments
 (0)