@@ -495,10 +495,26 @@ protocol ForceAccessors {
495
495
}
496
496
497
497
struct DidSetWillSetTests : ForceAccessors {
498
+ // CHECK-LABEL: sil hidden @$S10properties010DidSetWillC5TestsV{{[_0-9a-zA-Z]*}}fC
499
+ init ( x : Int ) {
500
+ // Accesses to didset/willset variables are direct in init methods and dtors.
501
+ a = x
502
+ a = x
503
+
504
+ // CHECK: bb0(%0 : $Int, %1 : $@thin DidSetWillSetTests.Type):
505
+ // CHECK: [[SELF:%.*]] = mark_uninitialized [rootself]
506
+ // CHECK: [[PB_SELF:%.*]] = project_box [[SELF]]
507
+ // CHECK: [[WRITE:%.*]] = begin_access [modify] [unknown] [[PB_SELF]]
508
+ // CHECK: [[P1:%.*]] = struct_element_addr [[WRITE]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
509
+ // CHECK-NEXT: assign %0 to [[P1]]
510
+ // CHECK: [[WRITE:%.*]] = begin_access [modify] [unknown] [[PB_SELF]]
511
+ // CHECK: [[P2:%.*]] = struct_element_addr [[WRITE]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
512
+ // CHECK-NEXT: assign %0 to [[P2]]
513
+ }
514
+
498
515
var a : Int {
516
+ // CHECK-LABEL: sil hidden @$S10properties010DidSetWillC5TestsV1a{{[_0-9a-zA-Z]*}}vw
499
517
willSet( newA) {
500
- // CHECK-LABEL: // {{.*}}.DidSetWillSetTests.a.willset
501
- // CHECK-NEXT: sil hidden @$S10properties010DidSetWillC5TestsV1a{{[_0-9a-zA-Z]*}}vw
502
518
// CHECK: bb0(%0 : $Int, %1 : $*DidSetWillSetTests):
503
519
// CHECK-NEXT: debug_value %0
504
520
// CHECK-NEXT: debug_value_addr %1 : $*DidSetWillSetTests
@@ -517,11 +533,23 @@ struct DidSetWillSetTests: ForceAccessors {
517
533
// CHECK-NEXT: // function_ref properties.takeInt(Swift.Int) -> ()
518
534
// CHECK-NEXT: [[TAKEINTFN:%.*]] = function_ref @$S10properties7takeInt{{[_0-9a-zA-Z]*}}F
519
535
// CHECK-NEXT: apply [[TAKEINTFN]](%0) : $@convention(thin) (Int) -> ()
536
+
537
+ a = zero // reassign, but don't infinite loop.
538
+
539
+ // CHECK-NEXT: // function_ref properties.zero.unsafeMutableAddressor : Swift.Int
540
+ // CHECK-NEXT: [[ZEROFN:%.*]] = function_ref @$S10properties4zero{{[_0-9a-zA-Z]*}}vau
541
+ // CHECK-NEXT: [[ZERORAW:%.*]] = apply [[ZEROFN]]() : $@convention(thin) () -> Builtin.RawPointer
542
+ // CHECK-NEXT: [[ZEROADDR:%.*]] = pointer_to_address [[ZERORAW]] : $Builtin.RawPointer to [strict] $*Int
543
+ // CHECK-NEXT: [[READ:%.*]] = begin_access [read] [dynamic] [[ZEROADDR]] : $*Int
544
+ // CHECK-NEXT: [[ZERO:%.*]] = load [trivial] [[READ]]
545
+ // CHECK-NEXT: end_access [[READ]] : $*Int
546
+ // CHECK-NEXT: [[WRITE:%.*]] = begin_access [modify] [unknown] %1
547
+ // CHECK-NEXT: [[AADDR:%.*]] = struct_element_addr [[WRITE]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
548
+ // CHECK-NEXT: assign [[ZERO]] to [[AADDR]]
520
549
}
521
550
551
+ // CHECK-LABEL: sil hidden @$S10properties010DidSetWillC5TestsV1a{{[_0-9a-zA-Z]*}}vW
522
552
didSet {
523
- // CHECK-LABEL: // {{.*}}.DidSetWillSetTests.a.didset
524
- // CHECK-NEXT: sil hidden @$S10properties010DidSetWillC5TestsV1a{{[_0-9a-zA-Z]*}}vW
525
553
// CHECK: bb0(%0 : $Int, %1 : $*DidSetWillSetTests):
526
554
// CHECK-NEXT: debug
527
555
// CHECK-NEXT: debug_value_addr %1 : $*DidSetWillSetTests
@@ -536,7 +564,7 @@ struct DidSetWillSetTests: ForceAccessors {
536
564
// CHECK-NEXT: [[TAKEINTFN:%.*]] = function_ref @$S10properties7takeInt{{[_0-9a-zA-Z]*}}F
537
565
// CHECK-NEXT: apply [[TAKEINTFN]]([[A]]) : $@convention(thin) (Int) -> ()
538
566
539
- a = zero // reassign, but don't infinite loop.
567
+ ( self ) . a = zero // reassign, but don't infinite loop.
540
568
541
569
// CHECK-NEXT: // function_ref properties.zero.unsafeMutableAddressor : Swift.Int
542
570
// CHECK-NEXT: [[ZEROFN:%.*]] = function_ref @$S10properties4zero{{[_0-9a-zA-Z]*}}vau
@@ -551,23 +579,16 @@ struct DidSetWillSetTests: ForceAccessors {
551
579
}
552
580
}
553
581
554
- init ( x : Int ) {
555
- // Accesses to didset/willset variables are direct in init methods and dtors.
556
- a = x
557
- a = x
558
- }
582
+ // This is the synthesized getter and setter for the willset/didset variable.
559
583
560
- // These are the synthesized getter and setter for the willset/didset variable.
561
-
562
- // CHECK-LABEL: // {{.*}}.DidSetWillSetTests.a.getter
563
- // CHECK-NEXT: sil hidden [transparent] @$S10properties010DidSetWillC5TestsV1aSivg
584
+ // CHECK-LABEL: sil hidden [transparent] @$S10properties010DidSetWillC5TestsV1aSivg
564
585
// CHECK: bb0(%0 : $DidSetWillSetTests):
565
586
// CHECK-NEXT: debug_value %0
566
587
// CHECK-NEXT: %2 = struct_extract %0 : $DidSetWillSetTests, #DidSetWillSetTests.a
567
588
// CHECK-NEXT: return %2 : $Int{{.*}} // id: %3
568
589
569
- // CHECK-LABEL: // {{.*}}.DidSetWillSetTests.a.setter
570
- // CHECK-NEXT : sil hidden @$S10properties010DidSetWillC5TestsV1aSivs
590
+
591
+ // CHECK-LABEL : sil hidden @$S10properties010DidSetWillC5TestsV1aSivs
571
592
// CHECK: bb0(%0 : $Int, %1 : $*DidSetWillSetTests):
572
593
// CHECK-NEXT: debug_value %0
573
594
// CHECK-NEXT: debug_value_addr %1
@@ -591,25 +612,47 @@ struct DidSetWillSetTests: ForceAccessors {
591
612
// CHECK-NEXT: // function_ref {{.*}}.DidSetWillSetTests.a.didset : Swift.Int
592
613
// CHECK-NEXT: [[DIDSETFN:%.*]] = function_ref @$S10properties010DidSetWillC5TestsV1a{{[_0-9a-zA-Z]*}}vW : $@convention(method) (Int, @inout DidSetWillSetTests) -> ()
593
614
// CHECK-NEXT: apply [[DIDSETFN]]([[OLDVAL]], [[WRITE]]) : $@convention(method) (Int, @inout DidSetWillSetTests) -> ()
594
-
595
- // CHECK-LABEL: sil hidden @$S10properties010DidSetWillC5TestsV{{[_0-9a-zA-Z]*}}fC
596
- // CHECK: bb0(%0 : $Int, %1 : $@thin DidSetWillSetTests.Type):
597
- // CHECK: [[SELF:%.*]] = mark_uninitialized [rootself]
598
- // CHECK: [[PB_SELF:%.*]] = project_box [[SELF]]
599
- // CHECK: [[WRITE:%.*]] = begin_access [modify] [unknown] [[PB_SELF]]
600
- // CHECK: [[P1:%.*]] = struct_element_addr [[WRITE]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
601
- // CHECK-NEXT: assign %0 to [[P1]]
602
- // CHECK: [[WRITE:%.*]] = begin_access [modify] [unknown] [[PB_SELF]]
603
- // CHECK: [[P2:%.*]] = struct_element_addr [[WRITE]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
604
- // CHECK-NEXT: assign %0 to [[P2]]
605
615
}
606
616
607
617
608
618
// Test global observing properties.
609
619
610
620
var global_observing_property : Int = zero {
621
+ // The variable is initialized with "zero".
622
+ // CHECK-LABEL: sil private @globalinit_{{.*}}_func1 : $@convention(c) () -> () {
623
+ // CHECK: bb0:
624
+ // CHECK-NEXT: alloc_global @$S10properties25global_observing_propertySiv
625
+ // CHECK-NEXT: %1 = global_addr @$S10properties25global_observing_propertySivp : $*Int
626
+ // CHECK: properties.zero.unsafeMutableAddressor
627
+ // CHECK: return
628
+
629
+ // CHECK-LABEL: sil hidden @$S10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW
611
630
didSet {
631
+ // The didSet implementation needs to call takeInt.
612
632
takeInt ( global_observing_property)
633
+
634
+ // CHECK: function_ref properties.takeInt
635
+ // CHECK-NEXT: function_ref @$S10properties7takeInt{{[_0-9a-zA-Z]*}}F
636
+
637
+ // Setting the variable from within its own didSet doesn't recursively call didSet.
638
+ global_observing_property = zero
639
+
640
+ // CHECK: // function_ref properties.global_observing_property.unsafeMutableAddressor : Swift.Int
641
+ // CHECK-NEXT: [[ADDRESSOR:%.*]] = function_ref @$S10properties25global_observing_propertySivau : $@convention(thin) () -> Builtin.RawPointer
642
+ // CHECK-NEXT: [[ADDRESS:%.*]] = apply [[ADDRESSOR]]() : $@convention(thin) () -> Builtin.RawPointer
643
+ // CHECK-NEXT: [[POINTER:%.*]] = pointer_to_address [[ADDRESS]] : $Builtin.RawPointer to [strict] $*Int
644
+ // CHECK-NEXT: // function_ref properties.zero.unsafeMutableAddressor : Swift.Int
645
+ // CHECK-NEXT: [[ZEROFN:%.*]] = function_ref @$S10properties4zero{{[_0-9a-zA-Z]*}}vau
646
+ // CHECK-NEXT: [[ZERORAW:%.*]] = apply [[ZEROFN]]() : $@convention(thin) () -> Builtin.RawPointer
647
+ // CHECK-NEXT: [[ZEROADDR:%.*]] = pointer_to_address [[ZERORAW]] : $Builtin.RawPointer to [strict] $*Int
648
+ // CHECK-NEXT: [[READ:%.*]] = begin_access [read] [dynamic] [[ZEROADDR]] : $*Int
649
+ // CHECK-NEXT: [[ZERO:%.*]] = load [trivial] [[READ]]
650
+ // CHECK-NEXT: end_access [[READ]] : $*Int
651
+ // CHECK-NEXT: [[WRITE:%.*]] = begin_access [modify] [dynamic] [[POINTER]] : $*Int
652
+ // CHECK-NEXT: assign [[ZERO]] to [[WRITE]] : $*Int
653
+ // CHECK-NEXT: end_access [[WRITE]] : $*Int
654
+ // CHECK-NOT: function_ref @$S10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW
655
+ // CHECK: end sil function
613
656
}
614
657
}
615
658
@@ -618,21 +661,7 @@ func force_global_observing_property_setter() {
618
661
global_observing_property = x
619
662
}
620
663
621
- // The property is initialized with "zero".
622
- // CHECK-LABEL: sil private @globalinit_{{.*}}_func1 : $@convention(c) () -> () {
623
- // CHECK: bb0:
624
- // CHECK-NEXT: alloc_global @$S10properties25global_observing_propertySiv
625
- // CHECK-NEXT: %1 = global_addr @$S10properties25global_observing_propertySivp : $*Int
626
- // CHECK: properties.zero.unsafeMutableAddressor
627
- // CHECK: return
628
-
629
- // The didSet implementation needs to call takeInt.
630
-
631
- // CHECK-LABEL: sil hidden @$S10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW
632
- // CHECK: function_ref properties.takeInt
633
- // CHECK-NEXT: function_ref @$S10properties7takeInt{{[_0-9a-zA-Z]*}}F
634
-
635
- // The setter needs to call didSet implementation.
664
+ // global_observing_property's setter needs to call didSet.
636
665
637
666
// CHECK-LABEL: sil hidden @$S10properties25global_observing_property{{[_0-9a-zA-Z]*}}vs
638
667
// CHECK: function_ref properties.global_observing_property.unsafeMutableAddressor
@@ -643,25 +672,44 @@ func force_global_observing_property_setter() {
643
672
644
673
// Test local observing properties.
645
674
675
+ // CHECK-LABEL: sil hidden @$S10properties24local_observing_property{{[_0-9a-zA-Z]*}}SiF
646
676
func local_observing_property( _ arg: Int ) {
647
677
var localproperty : Int = arg {
648
678
didSet {
649
679
takeInt ( localproperty)
680
+ localproperty = zero
650
681
}
651
682
}
652
-
683
+
653
684
takeInt ( localproperty)
654
685
localproperty = arg
655
- }
656
-
657
- // This is the local_observing_property function itself. First alloc and
658
- // initialize the property to the argument value.
659
686
660
- // CHECK-LABEL: sil hidden @{{.*}}local_observing_property
661
- // CHECK: bb0([[ARG:%[0-9]+]] : $Int)
662
- // CHECK: [[BOX:%[0-9]+]] = alloc_box ${ var Int }
663
- // CHECK: [[PB:%.*]] = project_box [[BOX]]
664
- // CHECK: store [[ARG]] to [trivial] [[PB]]
687
+ // Alloc and initialize the property to the argument value.
688
+ // CHECK: bb0([[ARG:%[0-9]+]] : $Int)
689
+ // CHECK: [[BOX:%[0-9]+]] = alloc_box ${ var Int }
690
+ // CHECK: [[PB:%.*]] = project_box [[BOX]]
691
+ // CHECK: store [[ARG]] to [trivial] [[PB]]
692
+ }
693
+
694
+ // didSet of localproperty (above)
695
+ // Ensure that setting the variable from within its own didSet doesn't recursively call didSet.
696
+
697
+ // CHECK-LABEL: sil private @$S10properties24local_observing_property{{[_0-9a-zA-Z]*}}SiF13localproperty{{[_0-9a-zA-Z]*}}SivW
698
+ // CHECK: bb0(%0 : $Int, %1 : ${ var Int })
699
+ // CHECK: [[POINTER:%.*]] = project_box %1 : ${ var Int }, 0
700
+ // CHECK: // function_ref properties.zero.unsafeMutableAddressor : Swift.Int
701
+ // CHECK-NEXT: [[ZEROFN:%.*]] = function_ref @$S10properties4zero{{[_0-9a-zA-Z]*}}vau
702
+ // CHECK-NEXT: [[ZERORAW:%.*]] = apply [[ZEROFN]]() : $@convention(thin) () -> Builtin.RawPointer
703
+ // CHECK-NEXT: [[ZEROADDR:%.*]] = pointer_to_address [[ZERORAW]] : $Builtin.RawPointer to [strict] $*Int
704
+ // CHECK-NEXT: [[READ:%.*]] = begin_access [read] [dynamic] [[ZEROADDR]] : $*Int
705
+ // CHECK-NEXT: [[ZERO:%.*]] = load [trivial] [[READ]]
706
+ // CHECK-NEXT: end_access [[READ]] : $*Int
707
+
708
+ // CHECK-NEXT: [[WRITE:%.*]] = begin_access [modify] [unknown] [[POINTER]] : $*Int
709
+ // CHECK-NEXT: assign [[ZERO]] to [[WRITE]] : $*Int
710
+ // CHECK-NEXT: end_access [[WRITE]] : $*Int
711
+ // CHECK-NOT: function_ref @$S10properties24local_observing_property{{[_0-9a-zA-Z]*}}SiF13localproperty{{[_0-9a-zA-Z]*}}SivW
712
+ // CHECK: end sil function
665
713
666
714
func local_generic_observing_property< T> ( _ arg: Int , _: T ) {
667
715
var localproperty1 : Int = arg {
0 commit comments