1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
|
// RUN: %target-swift-emit-silgen -swift-version 5 -disable-availability-checking -Xllvm -sil-full-demangle -parse-as-library -disable-objc-attr-requires-foundation-module -enable-objc-interop %s | %FileCheck %s
// REQUIRES: concurrency
var zero: Int = 0
func use(_: Int) {}
func takeInt(_ a : Int) {}
public struct DidSetWillSetTests {
// CHECK-LABEL: sil [ossa] @$s9observers010DidSetWillC5TestsV{{[_0-9a-zA-Z]*}}fC
@MainActor public init(x : Int) {
// Accesses to didset/willset variables are direct in init methods and dtors.
a = x
a = x
// CHECK: bb0(%0 : $Int, %1 : $@thin DidSetWillSetTests.Type):
// CHECK: [[SELF:%.*]] = mark_uninitialized [rootself]
// CHECK: [[SELF_LIFETIME:%.*]] = begin_borrow [var_decl] [[SELF]]
// CHECK: [[PB_SELF:%.*]] = project_box [[SELF_LIFETIME]]
// CHECK: [[WRITE:%.*]] = begin_access [modify] [unknown] [[PB_SELF]]
// CHECK: [[P1:%.*]] = struct_element_addr [[WRITE]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
// CHECK-NEXT: assign %0 to [[P1]]
// CHECK: [[WRITE:%.*]] = begin_access [modify] [unknown] [[PB_SELF]]
// CHECK: [[P2:%.*]] = struct_element_addr [[WRITE]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
// CHECK-NEXT: assign %0 to [[P2]]
// In Swift 5 and earlier, the accesses are _not_ direct within a defer that
// appears in an init/deinit for non-actor types.
defer { a = x }
// CHECK-LABEL: sil private [ossa] @$s9observers010DidSetWillC5TestsV1xACSi_tcfc6$deferL_yyF
// CHECK-NOT: assign
// CHECK: [[SETTER:%.*]] = function_ref @$s9observers010DidSetWillC5TestsV1aSivs
// CHECK-NEXT: apply [[SETTER]]
// CHECK-NOT: assign
// CHECK: } // end sil function
}
public var a: Int {
// CHECK-LABEL: sil private [ossa] @$s9observers010DidSetWillC5TestsV1a{{[_0-9a-zA-Z]*}}vw
willSet(newA) {
// CHECK: bb0(%0 : $Int, %1 : $*DidSetWillSetTests):
// CHECK-NEXT: debug_value %0
// CHECK-NEXT: debug_value %1 : $*DidSetWillSetTests, {{.*}} expr op_deref
takeInt(a)
// CHECK: [[READ:%.*]] = begin_access [read] [unknown] %1
// CHECK-NEXT: [[FIELDPTR:%.*]] = struct_element_addr [[READ]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
// CHECK-NEXT: [[A:%.*]] = load [trivial] [[FIELDPTR]] : $*Int
// CHECK-NEXT: end_access [[READ]]
// CHECK: [[TAKEINTFN:%.*]] = function_ref @$s9observers7takeInt{{[_0-9a-zA-Z]*}}F
// CHECK-NEXT: apply [[TAKEINTFN]]([[A]]) : $@convention(thin) (Int) -> ()
takeInt(newA)
// CHECK-NEXT: // function_ref observers.takeInt(Swift.Int) -> ()
// CHECK-NEXT: [[TAKEINTFN:%.*]] = function_ref @$s9observers7takeInt{{[_0-9a-zA-Z]*}}F
// CHECK-NEXT: apply [[TAKEINTFN]](%0) : $@convention(thin) (Int) -> ()
a = zero // reassign, but don't infinite loop.
// CHECK-NEXT: // function_ref observers.zero.unsafeMutableAddressor : Swift.Int
// CHECK-NEXT: [[ZEROFN:%.*]] = function_ref @$s9observers4zero{{[_0-9a-zA-Z]*}}vau
// CHECK-NEXT: [[ZERORAW:%.*]] = apply [[ZEROFN]]() : $@convention(thin) () -> Builtin.RawPointer
// CHECK-NEXT: [[ZEROADDR:%.*]] = pointer_to_address [[ZERORAW]] : $Builtin.RawPointer to [strict] $*Int
// CHECK-NEXT: [[READ:%.*]] = begin_access [read] [dynamic] [[ZEROADDR]] : $*Int
// CHECK-NEXT: [[ZERO:%.*]] = load [trivial] [[READ]]
// CHECK-NEXT: end_access [[READ]] : $*Int
// CHECK-NEXT: [[WRITE:%.*]] = begin_access [modify] [unknown] %1
// CHECK-NEXT: [[AADDR:%.*]] = struct_element_addr [[WRITE]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
// CHECK-NEXT: assign [[ZERO]] to [[AADDR]]
}
// CHECK-LABEL: sil private [ossa] @$s9observers010DidSetWillC5TestsV1a{{[_0-9a-zA-Z]*}}vW
didSet {
// CHECK: bb0(%0 : $*DidSetWillSetTests):
// CHECK-NEXT: debug_value %0 : $*DidSetWillSetTests, {{.*}} expr op_deref
takeInt(a)
// CHECK: [[READ:%.*]] = begin_access [read] [unknown] %0
// CHECK-NEXT: [[AADDR:%.*]] = struct_element_addr [[READ]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
// CHECK-NEXT: [[A:%.*]] = load [trivial] [[AADDR]] : $*Int
// CHECK-NEXT: end_access [[READ]]
// CHECK-NEXT: // function_ref observers.takeInt(Swift.Int) -> ()
// CHECK-NEXT: [[TAKEINTFN:%.*]] = function_ref @$s9observers7takeInt{{[_0-9a-zA-Z]*}}F
// CHECK-NEXT: apply [[TAKEINTFN]]([[A]]) : $@convention(thin) (Int) -> ()
(self).a = zero // reassign, but don't infinite loop.
// CHECK-NEXT: // function_ref observers.zero.unsafeMutableAddressor : Swift.Int
// CHECK-NEXT: [[ZEROFN:%.*]] = function_ref @$s9observers4zero{{[_0-9a-zA-Z]*}}vau
// CHECK-NEXT: [[ZERORAW:%.*]] = apply [[ZEROFN]]() : $@convention(thin) () -> Builtin.RawPointer
// CHECK-NEXT: [[ZEROADDR:%.*]] = pointer_to_address [[ZERORAW]] : $Builtin.RawPointer to [strict] $*Int
// CHECK-NEXT: [[READ:%.*]] = begin_access [read] [dynamic] [[ZEROADDR]] : $*Int
// CHECK-NEXT: [[ZERO:%.*]] = load [trivial] [[READ]]
// CHECK-NEXT: end_access [[READ]] : $*Int
// CHECK-NEXT: [[WRITE:%.*]] = begin_access [modify] [unknown] %0
// CHECK-NEXT: [[AADDR:%.*]] = struct_element_addr [[WRITE]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
// CHECK-NEXT: assign [[ZERO]] to [[AADDR]]
}
// This is the synthesized getter and setter for the willset/didset variable.
// CHECK-LABEL: sil [transparent] [serialized] [ossa] @$s9observers010DidSetWillC5TestsV1aSivg
// CHECK: bb0(%0 : $DidSetWillSetTests):
// CHECK-NEXT: debug_value %0
// CHECK-NEXT: %2 = struct_extract %0 : $DidSetWillSetTests, #DidSetWillSetTests.a
// CHECK-NEXT: return %2 : $Int{{.*}} // id: %3
// CHECK-LABEL: sil [ossa] @$s9observers010DidSetWillC5TestsV1aSivs : $@convention(method) (Int, @inout DidSetWillSetTests) -> () {
// CHECK: bb0([[NEWVALUE:%.*]] : $Int, %1 : $*DidSetWillSetTests):
// CHECK-NEXT: debug_value [[NEWVALUE]] : $Int, let, name "value", argno 1
// CHECK-NEXT: debug_value %1{{.*}} expr op_deref
// CHECK-NEXT: [[MODIFY_ONE:%.*]] = begin_access [modify] [unknown] %1 : $*DidSetWillSetTests
// CHECK-NEXT: // function_ref observers.DidSetWillSetTests.a.willset : Swift.Int
// CHECK-NEXT: [[WILLSETFN:%.*]] = function_ref @$s9observers010DidSetWillC5TestsV1aSivw : $@convention(method) (Int, @inout DidSetWillSetTests) -> ()
// CHECK-NEXT: [[RESULT:%.*]] = apply [[WILLSETFN]]([[NEWVALUE]], [[MODIFY_ONE]]) : $@convention(method) (Int, @inout DidSetWillSetTests) -> ()
// CHECK-NEXT: end_access [[MODIFY_ONE]] : $*DidSetWillSetTests
// CHECK-NEXT: [[MODIFY_TWO:%.*]] = begin_access [modify] [unknown] %1 : $*DidSetWillSetTests
// CHECK-NEXT: [[ADDR:%.*]] = struct_element_addr [[MODIFY_TWO]] : $*DidSetWillSetTests, #DidSetWillSetTests.a
// CHECK-NEXT: assign [[NEWVALUE]] to [[ADDR]] : $*Int
// CHECK-NEXT: end_access [[MODIFY_TWO]] : $*DidSetWillSetTests
// CHECK-NEXT: [[MODIFY_THREE:%.*]] = begin_access [modify] [unknown] %1 : $*DidSetWillSetTests
// CHECK-NEXT: // function_ref observers.DidSetWillSetTests.a.didset : Swift.Int
// CHECK-NEXT: [[DIDSETFN:%.*]] = function_ref @$s9observers010DidSetWillC5TestsV1aSivW : $@convention(method) (@inout DidSetWillSetTests) -> ()
// CHECK-NEXT: [[RESULT:%.*]] = apply [[DIDSETFN]]([[MODIFY_THREE]]) : $@convention(method) (@inout DidSetWillSetTests) -> ()
// CHECK-NEXT: end_access [[MODIFY_THREE]] : $*DidSetWillSetTests
// CHECK-NEXT: [[TUPLE:%.*]] = tuple ()
// CHECK-NEXT: return [[TUPLE]] : $()
}
// CHECK-LABEL: sil hidden [ossa] @$s9observers010DidSetWillC5TestsV8testReadSiyF
// CHECK: [[SELF:%.*]] = begin_access [read] [unknown] %0 : $*DidSetWillSetTests
// CHECK-NEXT: [[PROP:%.*]] = struct_element_addr [[SELF]] : $*DidSetWillSetTests
// CHECK-NEXT: [[LOAD:%.*]] = load [trivial] [[PROP]] : $*Int
// CHECK-NEXT: end_access [[SELF]] : $*DidSetWillSetTests
// CHECK-NEXT: return [[LOAD]] : $Int
mutating func testRead() -> Int {
return a
}
// CHECK-LABEL: sil hidden [ossa] @$s9observers010DidSetWillC5TestsV9testWrite5inputySi_tF
// CHECK: [[SELF:%.*]] = begin_access [modify] [unknown] %1 : $*DidSetWillSetTests
// CHECK-NEXT: // function_ref observers.DidSetWillSetTests.a.setter
// CHECK-NEXT: [[SETTER:%.*]] = function_ref @$s9observers010DidSetWillC5TestsV1aSivs
// CHECK-NEXT: apply [[SETTER]](%0, [[SELF]])
// CHECK-NEXT: end_access [[SELF]] : $*DidSetWillSetTests
// CHECK-NEXT: [[RET:%.*]] = tuple ()
// CHECK-NEXT: return [[RET]] : $()
mutating func testWrite(input: Int) {
a = input
}
// CHECK-LABEL: sil hidden [ossa] @$s9observers010DidSetWillC5TestsV13testReadWrite5inputySi_tF
// CHECK: [[SELF:%.*]] = begin_access [modify] [unknown] %1 : $*DidSetWillSetTests
// CHECK-NEXT: [[TEMP:%.*]] = alloc_stack $Int
// CHECK-NEXT: [[PROP:%.*]] = struct_element_addr [[SELF]] : $*DidSetWillSetTests
// CHECK-NEXT: [[LOAD:%.*]] = load [trivial] [[PROP]] : $*Int
// CHECK-NEXT: store [[LOAD]] to [trivial] [[TEMP]] : $*Int
// (modification goes here)
// CHECK: [[RELOAD:%.*]] = load [trivial] [[TEMP]] : $*Int
// CHECK-NEXT: // function_ref observers.DidSetWillSetTests.a.setter
// CHECK-NEXT: [[SETTER:%.*]] = function_ref @$s9observers010DidSetWillC5TestsV1aSivs
// CHECK-NEXT: apply [[SETTER]]([[RELOAD]], [[SELF]])
// CHECK-NEXT: end_access [[SELF]] : $*DidSetWillSetTests
// CHECK-NEXT: dealloc_stack [[TEMP]] : $*Int
// CHECK-NEXT: [[RET:%.*]] = tuple ()
// CHECK-NEXT: return [[RET]] : $()
mutating func testReadWrite(input: Int) {
a += input
}
}
actor Pop {
var a: Int = 0 {
didSet {}
}
init(input: Int) {
defer { a = input }
}
// In Swift 5, a defer in an actor init or deinit matches its enclosing context,
// which is direct-to-storage.
// CHECK-LABEL: sil private [ossa] @$s9observers3PopC5inputACSi_tcfc6$deferL_yyF
// CHECK-NOT: apply
// CHECK: assign {{%.*}} to {{%.*}} : $*Int
// CHECK-NOT: apply
// CHECK: } // end sil function
deinit {
defer { a = 0 }
}
// CHECK-LABEL: sil private [ossa] @$s9observers3PopCfd6$deferL_yyF
// CHECK: [[INT:%.*]] = apply {{.*}} : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
// CHECK-NOT: apply
// CHECK: assign [[INT]] to {{.*}} : $*Int
// CHECK-NOT: apply
// CHECK: } // end sil function
}
@MainActor
class SaltNVinegar {
var a: Int = 0 {
didSet {}
}
init(regular val: Int) {
defer { a = val }
// In Swift 5, an actor-isolated type has its defers match-up. So, we're
// direct-to-storage here...
// CHECK-LABEL: sil private [ossa] @$s9observers12SaltNVinegarC7regularACSi_tcfc6$deferL_yyF
// CHECK-NOT: apply
// CHECK: assign {{%.*}} to {{%.*}} : $*Int
// CHECK-NOT: apply
// CHECK: } // end sil function
}
}
@MainActor(unsafe)
class BBQ {
var a: Int = 0 {
didSet {}
}
init(regular val: Int) {
defer { a = val }
// ... but if the type is using unsafe global-actor isolation, then we preserve
// the non-direct access in the defer.
// CHECK-LABEL: sil private [ossa] @$s9observers3BBQC7regularACSi_tcfc6$deferL_yyF
// CHECK-NOT: assign
// CHECK: [[SETTER:%.*]] = class_method {{%.*}} : $BBQ, #BBQ.a!setter
// CHECK-NEXT: apply [[SETTER]]
// CHECK-NOT: assign
// CHECK: } // end sil function
}
}
// Test global observing properties.
var global_observing_property : Int = zero {
// The variable is initialized with "zero".
// CHECK-LABEL: sil private [global_init_once_fn] [ossa] @{{.*}}WZ : $@convention(c) (Builtin.RawPointer) -> () {
// CHECK: bb0(%0 : $Builtin.RawPointer):
// CHECK-NEXT: alloc_global @$s9observers25global_observing_propertySiv
// CHECK-NEXT: %2 = global_addr @$s9observers25global_observing_propertySivp : $*Int
// CHECK: observers.zero.unsafeMutableAddressor
// CHECK: return
// global_observing_property's setter needs to call didSet.
// CHECK-LABEL: sil private [ossa] @$s9observers25global_observing_property{{[_0-9a-zA-Z]*}}vW
didSet {
// The didSet implementation needs to call takeInt.
takeInt(global_observing_property)
// CHECK: function_ref observers.takeInt
// CHECK-NEXT: function_ref @$s9observers7takeInt{{[_0-9a-zA-Z]*}}F
// Setting the variable from within its own didSet doesn't recursively call didSet.
global_observing_property = zero
// CHECK: // function_ref observers.global_observing_property.unsafeMutableAddressor : Swift.Int
// CHECK-NEXT: [[ADDRESSOR:%.*]] = function_ref @$s9observers25global_observing_propertySivau : $@convention(thin) () -> Builtin.RawPointer
// CHECK-NEXT: [[ADDRESS:%.*]] = apply [[ADDRESSOR]]() : $@convention(thin) () -> Builtin.RawPointer
// CHECK-NEXT: [[POINTER:%.*]] = pointer_to_address [[ADDRESS]] : $Builtin.RawPointer to [strict] $*Int
// CHECK-NEXT: // function_ref observers.zero.unsafeMutableAddressor : Swift.Int
// CHECK-NEXT: [[ZEROFN:%.*]] = function_ref @$s9observers4zero{{[_0-9a-zA-Z]*}}vau
// CHECK-NEXT: [[ZERORAW:%.*]] = apply [[ZEROFN]]() : $@convention(thin) () -> Builtin.RawPointer
// CHECK-NEXT: [[ZEROADDR:%.*]] = pointer_to_address [[ZERORAW]] : $Builtin.RawPointer to [strict] $*Int
// CHECK-NEXT: [[READ:%.*]] = begin_access [read] [dynamic] [[ZEROADDR]] : $*Int
// CHECK-NEXT: [[ZERO:%.*]] = load [trivial] [[READ]]
// CHECK-NEXT: end_access [[READ]] : $*Int
// CHECK-NEXT: [[WRITE:%.*]] = begin_access [modify] [dynamic] [[POINTER]] : $*Int
// CHECK-NEXT: assign [[ZERO]] to [[WRITE]] : $*Int
// CHECK-NEXT: end_access [[WRITE]] : $*Int
// CHECK-NOT: function_ref @$s9observers25global_observing_property{{[_0-9a-zA-Z]*}}vW
// CHECK: end sil function
}
// CHECK-LABEL: sil hidden [ossa] @$s9observers25global_observing_property{{[_0-9a-zA-Z]*}}vs
// CHECK: function_ref observers.global_observing_property.unsafeMutableAddressor
// CHECK-NEXT: function_ref @$s9observers25global_observing_property{{[_0-9a-zA-Z]*}}vau
// CHECK: function_ref observers.global_observing_property.didset
// CHECK-NEXT: function_ref @$s9observers25global_observing_property{{[_0-9a-zA-Z]*}}vW
}
func force_global_observing_property_setter() {
let x = global_observing_property
global_observing_property = x
}
// Test local observing properties.
// CHECK-LABEL: sil hidden [ossa] @$s9observers24local_observing_property{{[_0-9a-zA-Z]*}}SiF
func local_observing_property(_ arg: Int) {
var localproperty: Int = arg {
didSet {
takeInt(localproperty)
localproperty = zero
}
}
takeInt(localproperty)
localproperty = arg
// Alloc and initialize the property to the argument value.
// CHECK: bb0([[ARG:%[0-9]+]] : $Int)
// CHECK: [[BOX:%[0-9]+]] = alloc_box ${ var Int }
// CHECK: [[L:%.*]] = begin_borrow [var_decl] [[BOX]]
// CHECK: [[PB:%.*]] = project_box [[L]]
// CHECK: store [[ARG]] to [trivial] [[PB]]
}
// didSet of localproperty (above)
// Ensure that setting the variable from within its own didSet doesn't recursively call didSet.
// CHECK-LABEL: sil private [ossa] @$s9observers24local_observing_property{{[_0-9a-zA-Z]*}}SiF13localproperty{{[_0-9a-zA-Z]*}}SivW
// CHECK: bb0(%0 : @closureCapture @guaranteed ${ var Int })
// CHECK: [[POINTER:%.*]] = project_box %0 : ${ var Int }, 0
// CHECK: // function_ref observers.zero.unsafeMutableAddressor : Swift.Int
// CHECK-NEXT: [[ZEROFN:%.*]] = function_ref @$s9observers4zero{{[_0-9a-zA-Z]*}}vau
// CHECK-NEXT: [[ZERORAW:%.*]] = apply [[ZEROFN]]() : $@convention(thin) () -> Builtin.RawPointer
// CHECK-NEXT: [[ZEROADDR:%.*]] = pointer_to_address [[ZERORAW]] : $Builtin.RawPointer to [strict] $*Int
// CHECK-NEXT: [[READ:%.*]] = begin_access [read] [dynamic] [[ZEROADDR]] : $*Int
// CHECK-NEXT: [[ZERO:%.*]] = load [trivial] [[READ]]
// CHECK-NEXT: end_access [[READ]] : $*Int
// CHECK-NEXT: [[WRITE:%.*]] = begin_access [modify] [unknown] [[POINTER]] : $*Int
// CHECK-NEXT: assign [[ZERO]] to [[WRITE]] : $*Int
// CHECK-NEXT: end_access [[WRITE]] : $*Int
// CHECK-NOT: function_ref @$s9observers24local_observing_property{{[_0-9a-zA-Z]*}}SiF13localproperty{{[_0-9a-zA-Z]*}}SivW
// CHECK: end sil function
func local_generic_observing_property<T>(_ arg: Int, _: T) {
var localproperty1: Int = arg {
didSet {
takeInt(localproperty1)
}
}
takeInt(localproperty1)
localproperty1 = arg
var localproperty2: Int = arg {
didSet {
_ = T.self
takeInt(localproperty2)
}
}
takeInt(localproperty2)
localproperty2 = arg
}
// <rdar://problem/16006333> observing properties don't work in @objc classes
@objc
class ObservingPropertyInObjCClass {
var bounds: Int {
willSet {}
didSet {}
}
init(b: Int) { bounds = b }
}
// CHECK-LABEL: sil hidden [ossa] @$s9observers32propertyWithDidSetTakingOldValueyyF : $@convention(thin) () -> () {
func propertyWithDidSetTakingOldValue() {
var p : Int = zero {
didSet(oldValue) {
// access to oldValue
use(oldValue)
// and newValue.
use(p)
}
}
p = zero
}
// CHECK-LABEL: sil private [ossa] @$s9observers32propertyWithDidSetTakingOldValueyyF1pL_Sivs
// CHECK: bb0([[ARG1:%.*]] : $Int, [[ARG2:%.*]] : @closureCapture @guaranteed ${ var Int }):
// CHECK-NEXT: debug_value [[ARG1]] : $Int, let, name "value", argno 1
// CHECK-NEXT: [[ARG2_PB:%.*]] = project_box [[ARG2]]
// CHECK-NEXT: debug_value [[ARG2_PB]] : $*Int, var, name "p", argno 2, expr op_deref
// CHECK-NEXT: [[READ:%.*]] = begin_access [read] [unknown] [[ARG2_PB]]
// CHECK-NEXT: [[ARG2_PB_VAL:%.*]] = load [trivial] [[READ]] : $*Int
// CHECK-NEXT: end_access [[READ]]
// CHECK-NEXT: [[WRITE:%.*]] = begin_access [modify] [unknown] [[ARG2_PB]]
// CHECK-NEXT: assign [[ARG1]] to [[WRITE]] : $*Int
// CHECK-NEXT: end_access [[WRITE]]
// SEMANTIC ARC TODO: Another case where we need to put the mark_function_escape on a new projection after a copy.
// CHECK-NEXT: mark_function_escape [[ARG2_PB]]
// CHECK-NEXT: // function_ref
// CHECK-NEXT: [[FUNC:%.*]] = function_ref @$s9observers32propertyWithDidSetTakingOldValueyyF1pL_SivW : $@convention(thin) (Int, @guaranteed { var Int }) -> ()
// CHECK-NEXT: %{{.*}} = apply [[FUNC]]([[ARG2_PB_VAL]], [[ARG2]]) : $@convention(thin) (Int, @guaranteed { var Int }) -> ()
// CHECK-NEXT: %{{.*}} = tuple ()
// CHECK-NEXT: return %{{.*}} : $()
// CHECK-NEXT:} // end sil function '$s9observers32propertyWithDidSetTakingOldValue{{[_0-9a-zA-Z]*}}'
// <rdar://problem/16406886> Observing properties don't work with ownership types
class Ref {}
struct ObservingPropertiesWithOwnershipTypes {
unowned var alwaysPresent : Ref {
didSet {
}
}
init(res: Ref) {
alwaysPresent = res
}
}
// CHECK-LABEL: sil private [ossa] @$s9observers37ObservingPropertiesWithOwnershipTypesV13alwaysPresentAA3RefCvW : $@convention(method) (@inout ObservingPropertiesWithOwnershipTypes) -> () {
struct ObservingPropertiesWithOwnershipTypesInferred {
unowned var alwaysPresent = Ref() {
didSet {
}
}
weak var maybePresent = nil as Ref? {
willSet {
}
}
}
// CHECK-LABEL: sil private [ossa] @$s9observers45ObservingPropertiesWithOwnershipTypesInferredV13alwaysPresentAA3RefCvW : $@convention(method) (@inout ObservingPropertiesWithOwnershipTypesInferred) -> () {
// CHECK-LABEL: sil private [ossa] @$s9observers45ObservingPropertiesWithOwnershipTypesInferredV12maybePresentAA3RefCSgvw : $@convention(method) (@guaranteed Optional<Ref>, @inout ObservingPropertiesWithOwnershipTypesInferred) -> () {
//<rdar://problem/16620121> Initializing constructor tries to initialize computed property overridden with willSet/didSet
class ObservedBase {
var printInfo: Ref!
}
class ObservedDerived : ObservedBase {
override init() {}
override var printInfo: Ref! {
didSet { }
}
}
// CHECK-LABEL: sil private [ossa] @$s9observers15ObservedDerivedC9printInfoAA3RefCSgvW : $@convention(method) (@guaranteed ObservedDerived) -> () {
/// <rdar://problem/26408353> crash when overriding internal property with
/// public property
public class BaseClassWithInternalProperty {
var x: () = ()
}
public class DerivedClassWithPublicProperty : BaseClassWithInternalProperty {
public override var x: () {
didSet {}
}
}
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s9observers29BaseClassWithInternalPropertyC1xytvg
// CHECK-LABEL: sil [ossa] @$s9observers30DerivedClassWithPublicPropertyC1xytvg
// CHECK: bb0([[SELF:%.*]] : @guaranteed $DerivedClassWithPublicProperty):
// CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]] : $DerivedClassWithPublicProperty
// CHECK-NEXT: [[SUPER:%.*]] = upcast [[SELF_COPY]] : $DerivedClassWithPublicProperty to $BaseClassWithInternalProperty
// CHECK-NEXT: [[BORROWED_SUPER:%.*]] = begin_borrow [[SUPER]]
// CHECK-NEXT: // function_ref observers.BaseClassWithInternalProperty.x.getter : ()
// CHECK-NEXT: [[METHOD:%.*]] = function_ref @$s9observers29BaseClassWithInternalPropertyC1xytvg : $@convention(method) (@guaranteed BaseClassWithInternalProperty) -> ()
// CHECK-NEXT: [[RESULT:%.*]] = apply [[METHOD]]([[BORROWED_SUPER]]) : $@convention(method) (@guaranteed BaseClassWithInternalProperty) -> ()
// CHECK-NEXT: end_borrow [[BORROWED_SUPER]]
// CHECK-NEXT: destroy_value [[SUPER]] : $BaseClassWithInternalProperty
// CHECK: } // end sil function '$s9observers30DerivedClassWithPublicPropertyC1xytvg'
// Make sure we use the correct substitutions when referencing a property in a
// generic base class
public class GenericBase<T> {
var storage: T? = nil
}
public class ConcreteDerived : GenericBase<Int> {
override var storage: Int? {
didSet {}
}
}
// CHECK-LABEL: sil private [ossa] @$s9observers15ConcreteDerivedC7storageSiSgvW : $@convention(method) (@guaranteed ConcreteDerived) -> () {
// Make sure we upcast properly when the overridden property is in an ancestor
// of our superclass
public class BaseObserved {
var x: Int = 0
}
public class MiddleObserved : BaseObserved {}
public class DerivedObserved : MiddleObserved {
override var x: Int {
didSet {}
}
}
// CHECK-LABEL: sil private [ossa] @$s9observers15DerivedObservedC1xSivW : $@convention(method) (@guaranteed DerivedObserved) -> () {
|