|
2 | 2 |
|
3 | 3 | // REQUIRES: swift_feature_BorrowAndMutateAccessors
|
4 | 4 |
|
5 |
| -public class Klass {} |
| 5 | +public class Klass { |
| 6 | + var id: Int = 0 |
| 7 | +} |
6 | 8 |
|
7 | 9 | func getKlass() -> Klass {
|
8 | 10 | return Klass()
|
@@ -90,6 +92,18 @@ public struct Wrapper {
|
90 | 92 | }
|
91 | 93 | }
|
92 | 94 |
|
| 95 | + var nested_get3: Int { |
| 96 | + borrow { |
| 97 | + return _s.getKlass.id |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + var nested_get4: Int { |
| 102 | + borrow { |
| 103 | + return s_get.borrowKlass.id |
| 104 | + } |
| 105 | + } |
| 106 | + |
93 | 107 | var nested_read1: Klass {
|
94 | 108 | borrow {
|
95 | 109 | return _s.readKlass // expected-error{{invalid return value from borrow accessor}} // expected-note{{borrow accessors can return either literals, stored properties or computed properties that have borrow accessors}}
|
@@ -461,6 +475,41 @@ func nctest() {
|
461 | 475 | // CHECK: return [[REG4]]
|
462 | 476 | // CHECK: }
|
463 | 477 |
|
| 478 | +// CHECK: sil hidden [ossa] @$s15borrow_accessor7WrapperV11nested_get3Sivb : $@convention(method) (@guaranteed Wrapper) -> Int { |
| 479 | +// CHECK: bb0([[REG0:%.*]] : @guaranteed $Wrapper): |
| 480 | +// CHECK: [[REG2:%.*]] = struct_extract [[REG0]], #Wrapper._s |
| 481 | +// CHECK: [[REG3:%.*]] = copy_value [[REG2]] |
| 482 | +// CHECK: [[REG4:%.*]] = begin_borrow [[REG3]] |
| 483 | +// CHECK: [[REG5:%.*]] = function_ref @$s15borrow_accessor1SV8getKlassAA0D0Cvg : $@convention(method) (@guaranteed S) -> @owned Klass |
| 484 | +// CHECK: [[REG6:%.*]] = apply [[REG5]]([[REG4]]) : $@convention(method) (@guaranteed S) -> @owned Klass |
| 485 | +// CHECK: end_borrow [[REG4]] |
| 486 | +// CHECK: destroy_value [[REG3]] |
| 487 | +// CHECK: [[REG9:%.*]] = begin_borrow [[REG6]] |
| 488 | +// CHECK: [[REG10:%.*]] = class_method [[REG9]], #Klass.id!getter : (Klass) -> () -> Int, $@convention(method) (@guaranteed Klass) -> Int |
| 489 | +// CHECK: [[REG11:%.*]] = apply [[REG10]]([[REG9]]) : $@convention(method) (@guaranteed Klass) -> Int |
| 490 | +// CHECK: end_borrow [[REG9]] |
| 491 | +// CHECK: destroy_value [[REG6]] |
| 492 | +// CHECK: return [[REG11]] |
| 493 | +// CHECK: } |
| 494 | + |
| 495 | +// CHECK: sil hidden [ossa] @$s15borrow_accessor7WrapperV11nested_get4Sivb : $@convention(method) (@guaranteed Wrapper) -> Int { |
| 496 | +// CHECK: bb0([[REG0:%.*]] : @guaranteed $Wrapper): |
| 497 | +// CHECK: [[REG2:%.*]] = function_ref @$s15borrow_accessor7WrapperV5s_getAA1SVvg : $@convention(method) (@guaranteed Wrapper) -> @owned S |
| 498 | +// CHECK: [[REG3:%.*]] = apply [[REG2]]([[REG0]]) : $@convention(method) (@guaranteed Wrapper) -> @owned S |
| 499 | +// CHECK: [[REG4:%.*]] = begin_borrow [[REG3]] |
| 500 | +// CHECK: [[REG5:%.*]] = function_ref @$s15borrow_accessor1SV0A5KlassAA0C0Cvb : $@convention(method) (@guaranteed S) -> @guaranteed Klass |
| 501 | +// CHECK: [[REG6:%.*]] = apply [[REG5]]([[REG4]]) : $@convention(method) (@guaranteed S) -> @guaranteed Klass |
| 502 | +// CHECK: [[REG7:%.*]] = copy_value [[REG6]] |
| 503 | +// CHECK: end_borrow [[REG4]] |
| 504 | +// CHECK: destroy_value [[REG3]] |
| 505 | +// CHECK: [[REG10:%.*]] = begin_borrow [[REG7]] |
| 506 | +// CHECK: [[REG11:%.*]] = class_method [[REG10]], #Klass.id!getter : (Klass) -> () -> Int, $@convention(method) (@guaranteed Klass) -> Int |
| 507 | +// CHECK: [[REG12:%.*]] = apply [[REG11]]([[REG10]]) : $@convention(method) (@guaranteed Klass) -> Int |
| 508 | +// CHECK: end_borrow [[REG10]] |
| 509 | +// CHECK: destroy_value [[REG7]] |
| 510 | +// CHECK: return [[REG12]] |
| 511 | +// CHECK: } |
| 512 | + |
464 | 513 | // CHECK: sil hidden [ossa] @$s15borrow_accessor7WrapperV6nestedAA5KlassCvb : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass {
|
465 | 514 | // CHECK: bb0([[REG0:%.*]] : @guaranteed $Wrapper):
|
466 | 515 | // CHECK: [[REG2:%.*]] = function_ref @$s15borrow_accessor7WrapperV1kAA5KlassCvb : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass
|
|
0 commit comments