Skip to content

[silgen] Change silgen destructor to access ref_element_addr through begin_access [deinit]. #29072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/SILGen/SILGenDestructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ void SILGenFunction::emitClassMemberDestruction(ManagedValue selfValue,
SILValue addr =
B.createRefElementAddr(cleanupLoc, selfValue.getValue(), vd,
ti.getLoweredType().getAddressType());
addr = B.createBeginAccess(
cleanupLoc, addr, SILAccessKind::Deinit, SILAccessEnforcement::Static,
false /*noNestedConflict*/, false /*fromBuiltin*/);
B.createDestroyAddr(cleanupLoc, addr);
B.createEndAccess(cleanupLoc, addr, false /*is aborting*/);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/SILGen/ivar_destroyer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class DerivedClassWithNonTrivialProperties : RootClassWithoutProperties {
// CHECK: bb0(%0 : @guaranteed $DerivedClassWithNonTrivialProperties):
// CHECK-NEXT: debug_value %0
// CHECK-NEXT: [[Z_ADDR:%.*]] = ref_element_addr %0
// CHECK-NEXT: destroy_addr [[Z_ADDR]]
// CHECK-NEXT: [[Z_ADDR_DEINIT_ACCESS:%.*]] = begin_access [deinit] [static] [[Z_ADDR]]
// CHECK-NEXT: destroy_addr [[Z_ADDR_DEINIT_ACCESS]]
// CHECK-NEXT: end_access [[Z_ADDR_DEINIT_ACCESS]]
// CHECK-NEXT: [[RESULT:%.*]] = tuple ()
// CHECK-NEXT: return [[RESULT]]

Expand Down
36 changes: 24 additions & 12 deletions test/SILGen/lifetime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ struct Daleth {
}

class He {

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

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

x = chi.intify()
}

// CHECK-LABEL: sil hidden [ossa] @$s8lifetime3FooCfd : $@convention(method) <T> (@guaranteed Foo<T>) -> @owned Builtin.NativeObject

deinit {
Expand All @@ -526,13 +526,19 @@ class Foo<T> {
// CHECK-NOT: ref_element_addr [[THIS]] : {{.*}}, #Foo.x
// -- destroy_value y
// CHECK: [[YADDR:%[0-9]+]] = ref_element_addr [[THIS]] : {{.*}}, #Foo.y
// CHECK: destroy_addr [[YADDR]]
// CHECK: [[YADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[YADDR]]
// CHECK: destroy_addr [[YADDR_ACCESS]]
// CHECK: end_access [[YADDR_ACCESS]]
// -- destroy_value z
// CHECK: [[ZADDR:%[0-9]+]] = ref_element_addr [[THIS]] : {{.*}}, #Foo.z
// CHECK: destroy_addr [[ZADDR]]
// CHECK: [[ZADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[ZADDR]]
// CHECK: destroy_addr [[ZADDR_ACCESS]]
// CHECK: end_access [[ZADDR_ACCESS]]
// -- destroy_value w
// CHECK: [[WADDR:%[0-9]+]] = ref_element_addr [[THIS]] : {{.*}}, #Foo.w
// CHECK: destroy_addr [[WADDR]]
// CHECK: [[WADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[WADDR]]
// CHECK: destroy_addr [[WADDR_ACCESS]]
// CHECK: end_access [[WADDR_ACCESS]]
// -- return back this
// CHECK: [[PTR:%.*]] = unchecked_ref_cast [[THIS]] : $Foo<T> to $Builtin.NativeObject
// CHECK: [[PTR_OWNED:%.*]] = unchecked_ownership_conversion [[PTR]] : $Builtin.NativeObject, @guaranteed to @owned
Expand Down Expand Up @@ -567,7 +573,7 @@ class FooSubclass<T> : Foo<T> {
// CHECK: [[BORROWED_PTR:%.*]] = begin_borrow [[PTR]]
// CHECK: end_borrow [[BORROWED_PTR]]
// CHECK: return [[PTR]]


deinit {
bar()
Expand All @@ -586,18 +592,22 @@ class ImplicitDtor {
// CHECK-NOT: ref_element_addr [[THIS]] : {{.*}}, #ImplicitDtor.x
// -- destroy_value y
// CHECK: [[YADDR:%[0-9]+]] = ref_element_addr [[THIS]] : {{.*}}, #ImplicitDtor.y
// CHECK: destroy_addr [[YADDR]]
// CHECK: [[YADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[YADDR]]
// CHECK: destroy_addr [[YADDR_ACCESS]]
// CHECK: end_access [[YADDR_ACCESS]]
// -- destroy_value w
// CHECK: [[WADDR:%[0-9]+]] = ref_element_addr [[THIS]] : {{.*}}, #ImplicitDtor.w
// CHECK: destroy_addr [[WADDR]]
// CHECK: [[WADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[WADDR]]
// CHECK: destroy_addr [[WADDR_ACCESS]]
// CHECK: end_access [[WADDR_ACCESS]]
// CHECK: return
}

class ImplicitDtorDerived<T> : ImplicitDtor {
var z:T

init(z : T) {
super.init()
init(z : T) {
super.init()
self.z = z
}

Expand All @@ -611,7 +621,9 @@ class ImplicitDtorDerived<T> : ImplicitDtor {
// CHECK: [[BORROWED_PTR:%.*]] = begin_borrow [[PTR]]
// CHECK: [[CAST_BORROWED_PTR:%.*]] = unchecked_ref_cast [[BORROWED_PTR]] : $Builtin.NativeObject to $ImplicitDtorDerived<T>
// CHECK: [[ZADDR:%[0-9]+]] = ref_element_addr [[CAST_BORROWED_PTR]] : {{.*}}, #ImplicitDtorDerived.z
// CHECK: destroy_addr [[ZADDR]]
// CHECK: [[ZADDR_ACCESS:%.*]] = begin_access [deinit] [static] [[ZADDR]]
// CHECK: destroy_addr [[ZADDR_ACCESS]]
// CHECK: end_access [[ZADDR_ACCESS]]
// CHECK: end_borrow [[BORROWED_PTR]]
// -- epilog
// CHECK-NOT: unchecked_ref_cast
Expand Down
4 changes: 3 additions & 1 deletion test/SILGen/objc_dealloc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ class SwiftGizmo : Gizmo {
// CHECK-NEXT: debug_value [[SELF]] : $SwiftGizmo, let, name "self"
// CHECK-NEXT: [[SELF_BORROW:%.*]] = begin_borrow [[SELF]]
// CHECK-NEXT: [[X:%[0-9]+]] = ref_element_addr [[SELF_BORROW]] : $SwiftGizmo, #SwiftGizmo.x
// CHECK-NEXT: destroy_addr [[X]] : $*X
// CHECK-NEXT: [[X_ACCESS:%.*]] = begin_access [deinit] [static] [[X]]
// CHECK-NEXT: destroy_addr [[X_ACCESS]]
// CHECK-NEXT: end_access [[X_ACCESS]]
// CHECK-NEXT: end_borrow [[SELF_BORROW]]
// CHECK-NEXT: [[RESULT:%[0-9]+]] = tuple ()
// CHECK-NEXT: return [[RESULT]] : $()
Expand Down