Skip to content

Commit 1f1603c

Browse files
authored
Merge pull request #29072 from gottesmm/pr-4fc3226fa119351bf363a50e981847403a32369a
[silgen] Change silgen destructor to access ref_element_addr through begin_access [deinit].
2 parents 1aa9508 + 9b9760e commit 1f1603c

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

lib/SILGen/SILGenDestructor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ void SILGenFunction::emitClassMemberDestruction(ManagedValue selfValue,
186186
SILValue addr =
187187
B.createRefElementAddr(cleanupLoc, selfValue.getValue(), vd,
188188
ti.getLoweredType().getAddressType());
189+
addr = B.createBeginAccess(
190+
cleanupLoc, addr, SILAccessKind::Deinit, SILAccessEnforcement::Static,
191+
false /*noNestedConflict*/, false /*fromBuiltin*/);
189192
B.createDestroyAddr(cleanupLoc, addr);
193+
B.createEndAccess(cleanupLoc, addr, false /*is aborting*/);
190194
}
191195
}
192196
}

test/SILGen/ivar_destroyer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ class DerivedClassWithNonTrivialProperties : RootClassWithoutProperties {
2929
// CHECK: bb0(%0 : @guaranteed $DerivedClassWithNonTrivialProperties):
3030
// CHECK-NEXT: debug_value %0
3131
// CHECK-NEXT: [[Z_ADDR:%.*]] = ref_element_addr %0
32-
// CHECK-NEXT: destroy_addr [[Z_ADDR]]
32+
// CHECK-NEXT: [[Z_ADDR_DEINIT_ACCESS:%.*]] = begin_access [deinit] [static] [[Z_ADDR]]
33+
// CHECK-NEXT: destroy_addr [[Z_ADDR_DEINIT_ACCESS]]
34+
// CHECK-NEXT: end_access [[Z_ADDR_DEINIT_ACCESS]]
3335
// CHECK-NEXT: [[RESULT:%.*]] = tuple ()
3436
// CHECK-NEXT: return [[RESULT]]
3537

test/SILGen/lifetime.swift

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ struct Daleth {
263263
}
264264

265265
class He {
266-
266+
267267
// -- default allocator:
268268
// CHECK-LABEL: sil hidden [exact_self_class] [ossa] @$s8lifetime2HeC{{[_0-9a-zA-Z]*}}fC : $@convention(method) (@thick He.Type) -> @owned He {
269269
// CHECK: bb0({{%.*}} : $@thick He.Type):
@@ -292,7 +292,7 @@ struct Waw {
292292
var b:Val
293293

294294
// -- loadable value initializer with tuple destructuring:
295-
// CHECK-LABEL: sil hidden [ossa] @$s8lifetime3WawV{{[_0-9a-zA-Z]*}}fC : $@convention(method) (@owned Ref, Val, Val, @thin Waw.Type) -> @owned Waw
295+
// CHECK-LABEL: sil hidden [ossa] @$s8lifetime3WawV{{[_0-9a-zA-Z]*}}fC : $@convention(method) (@owned Ref, Val, Val, @thin Waw.Type) -> @owned Waw
296296
// CHECK: bb0([[A0:%.*]] : @owned $Ref, [[A1:%.*]] : $Val, [[B:%.*]] : $Val, {{%.*}} : $@thin Waw.Type):
297297
// CHECK-NEXT: [[A:%.*]] = tuple ([[A0]] : {{.*}}, [[A1]] : {{.*}})
298298
// CHECK-NEXT: [[RET:%.*]] = struct $Waw ([[A]] : {{.*}}, [[B]] : {{.*}})
@@ -513,7 +513,7 @@ class Foo<T> {
513513

514514
x = chi.intify()
515515
}
516-
516+
517517
// CHECK-LABEL: sil hidden [ossa] @$s8lifetime3FooCfd : $@convention(method) <T> (@guaranteed Foo<T>) -> @owned Builtin.NativeObject
518518

519519
deinit {
@@ -526,13 +526,19 @@ class Foo<T> {
526526
// CHECK-NOT: ref_element_addr [[THIS]] : {{.*}}, #Foo.x
527527
// -- destroy_value y
528528
// CHECK: [[YADDR:%[0-9]+]] = ref_element_addr [[THIS]] : {{.*}}, #Foo.y
529-
// CHECK: destroy_addr [[YADDR]]
529+
// CHECK: [[YADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[YADDR]]
530+
// CHECK: destroy_addr [[YADDR_ACCESS]]
531+
// CHECK: end_access [[YADDR_ACCESS]]
530532
// -- destroy_value z
531533
// CHECK: [[ZADDR:%[0-9]+]] = ref_element_addr [[THIS]] : {{.*}}, #Foo.z
532-
// CHECK: destroy_addr [[ZADDR]]
534+
// CHECK: [[ZADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[ZADDR]]
535+
// CHECK: destroy_addr [[ZADDR_ACCESS]]
536+
// CHECK: end_access [[ZADDR_ACCESS]]
533537
// -- destroy_value w
534538
// CHECK: [[WADDR:%[0-9]+]] = ref_element_addr [[THIS]] : {{.*}}, #Foo.w
535-
// CHECK: destroy_addr [[WADDR]]
539+
// CHECK: [[WADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[WADDR]]
540+
// CHECK: destroy_addr [[WADDR_ACCESS]]
541+
// CHECK: end_access [[WADDR_ACCESS]]
536542
// -- return back this
537543
// CHECK: [[PTR:%.*]] = unchecked_ref_cast [[THIS]] : $Foo<T> to $Builtin.NativeObject
538544
// CHECK: [[PTR_OWNED:%.*]] = unchecked_ownership_conversion [[PTR]] : $Builtin.NativeObject, @guaranteed to @owned
@@ -567,7 +573,7 @@ class FooSubclass<T> : Foo<T> {
567573
// CHECK: [[BORROWED_PTR:%.*]] = begin_borrow [[PTR]]
568574
// CHECK: end_borrow [[BORROWED_PTR]]
569575
// CHECK: return [[PTR]]
570-
576+
571577

572578
deinit {
573579
bar()
@@ -586,18 +592,22 @@ class ImplicitDtor {
586592
// CHECK-NOT: ref_element_addr [[THIS]] : {{.*}}, #ImplicitDtor.x
587593
// -- destroy_value y
588594
// CHECK: [[YADDR:%[0-9]+]] = ref_element_addr [[THIS]] : {{.*}}, #ImplicitDtor.y
589-
// CHECK: destroy_addr [[YADDR]]
595+
// CHECK: [[YADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[YADDR]]
596+
// CHECK: destroy_addr [[YADDR_ACCESS]]
597+
// CHECK: end_access [[YADDR_ACCESS]]
590598
// -- destroy_value w
591599
// CHECK: [[WADDR:%[0-9]+]] = ref_element_addr [[THIS]] : {{.*}}, #ImplicitDtor.w
592-
// CHECK: destroy_addr [[WADDR]]
600+
// CHECK: [[WADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[WADDR]]
601+
// CHECK: destroy_addr [[WADDR_ACCESS]]
602+
// CHECK: end_access [[WADDR_ACCESS]]
593603
// CHECK: return
594604
}
595605

596606
class ImplicitDtorDerived<T> : ImplicitDtor {
597607
var z:T
598608

599-
init(z : T) {
600-
super.init()
609+
init(z : T) {
610+
super.init()
601611
self.z = z
602612
}
603613

@@ -611,7 +621,9 @@ class ImplicitDtorDerived<T> : ImplicitDtor {
611621
// CHECK: [[BORROWED_PTR:%.*]] = begin_borrow [[PTR]]
612622
// CHECK: [[CAST_BORROWED_PTR:%.*]] = unchecked_ref_cast [[BORROWED_PTR]] : $Builtin.NativeObject to $ImplicitDtorDerived<T>
613623
// CHECK: [[ZADDR:%[0-9]+]] = ref_element_addr [[CAST_BORROWED_PTR]] : {{.*}}, #ImplicitDtorDerived.z
614-
// CHECK: destroy_addr [[ZADDR]]
624+
// CHECK: [[ZADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[ZADDR]]
625+
// CHECK: destroy_addr [[ZADDR_ACCESS]]
626+
// CHECK: end_access [[ZADDR_ACCESS]]
615627
// CHECK: end_borrow [[BORROWED_PTR]]
616628
// -- epilog
617629
// CHECK-NOT: unchecked_ref_cast

test/SILGen/objc_dealloc.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ class SwiftGizmo : Gizmo {
8282
// CHECK-NEXT: debug_value [[SELF]] : $SwiftGizmo, let, name "self"
8383
// CHECK-NEXT: [[SELF_BORROW:%.*]] = begin_borrow [[SELF]]
8484
// CHECK-NEXT: [[X:%[0-9]+]] = ref_element_addr [[SELF_BORROW]] : $SwiftGizmo, #SwiftGizmo.x
85-
// CHECK-NEXT: destroy_addr [[X]] : $*X
85+
// CHECK-NEXT: [[X_ACCESS:%.*]] = begin_access [deinit] [static] [[X]]
86+
// CHECK-NEXT: destroy_addr [[X_ACCESS]]
87+
// CHECK-NEXT: end_access [[X_ACCESS]]
8688
// CHECK-NEXT: end_borrow [[SELF_BORROW]]
8789
// CHECK-NEXT: [[RESULT:%[0-9]+]] = tuple ()
8890
// CHECK-NEXT: return [[RESULT]] : $()

0 commit comments

Comments
 (0)