-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[cxx-interop] Delay lowering unowned convention until ownership elimination #84612
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// RUN: %target-run-simple-swift(-I %swift_src_root/lib/ClangImporter/SwiftBridging -I %S/Inputs -cxx-interoperability-mode=default -Xfrontend -disable-availability-checking -O) | %FileCheck %s | ||
|
||
// REQUIRES: executable_test | ||
|
||
import LoggingFrts | ||
|
||
@inline(never) | ||
func use(_ x: CInt) { | ||
print("Value is \(x).") | ||
} | ||
|
||
func testRefIssues() { | ||
var a2 = Optional.some(Payload.create(0)); | ||
let b2 = a2!.ptr(); | ||
a2 = Optional.none; | ||
let v2 = b2.value(); | ||
use(v2) | ||
} | ||
testRefIssues() | ||
|
||
// CHECK: RefCount: 1, message: Ctor | ||
// CHECK-NEXT: RefCount: 2, message: retain | ||
// CHECK-NEXT: RefCount: 1, message: release | ||
// CHECK-NEXT: Value is 0. | ||
// CHECK-NEXT: RefCount: 0, message: release | ||
// CHECK-NEXT: RefCount: 0, message: Dtor |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -828,30 +828,6 @@ bb5(%5 : @owned $ThreeDifferingPayloadEnum): | |
return %5 : $ThreeDifferingPayloadEnum | ||
} | ||
|
||
sil [ossa] @enum_cases_with_trivial_unowned_cases_arg_into_phi : $@convention(thin) (Builtin.NativeObject) -> ThreeDifferingPayloadEnum { | ||
bb0(%0 : @unowned $Builtin.NativeObject): | ||
cond_br undef, bb1, bb2 | ||
|
||
bb1: | ||
cond_br undef, bb3, bb4 | ||
|
||
bb2: | ||
%1 = enum $ThreeDifferingPayloadEnum, #ThreeDifferingPayloadEnum.nopayload!enumelt | ||
br bb5(%1 : $ThreeDifferingPayloadEnum) | ||
|
||
bb3: | ||
%2 = enum $ThreeDifferingPayloadEnum, #ThreeDifferingPayloadEnum.nontrivial_payload!enumelt, %0 : $Builtin.NativeObject | ||
br bb5(%2 : $ThreeDifferingPayloadEnum) | ||
|
||
bb4: | ||
%3 = integer_literal $Builtin.Int32, 0 | ||
%4 = enum $ThreeDifferingPayloadEnum, #ThreeDifferingPayloadEnum.trivial_payload!enumelt, %3 : $Builtin.Int32 | ||
br bb5(%4 : $ThreeDifferingPayloadEnum) | ||
|
||
bb5(%5 : @unowned $ThreeDifferingPayloadEnum): | ||
return %5 : $ThreeDifferingPayloadEnum | ||
} | ||
|
||
sil [ossa] @enum_cases_with_trivial_guaranteed_cases_arg_into_phi : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @owned ThreeDifferingPayloadEnum { | ||
bb0(%0 : @guaranteed $Builtin.NativeObject): | ||
cond_br undef, bb1, bb2 | ||
|
@@ -1383,20 +1359,6 @@ bb3(%fUnknown : @owned $@callee_owned () -> ()): | |
return %9999 : $() | ||
} | ||
|
||
sil [ossa] @unowned_to_ref_is_unowned_instant_use : $@convention(thin) (@guaranteed Builtin.NativeObject) -> Builtin.NativeObject { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These specifically testing the unowned return type which is not supported. I think these or OK to remove. |
||
bb0(%0 : @guaranteed $Builtin.NativeObject): | ||
%1 = ref_to_unowned %0 : $Builtin.NativeObject to $@sil_unowned Builtin.NativeObject | ||
%2 = unowned_to_ref %1 : $@sil_unowned Builtin.NativeObject to $Builtin.NativeObject | ||
return %2 : $Builtin.NativeObject | ||
} | ||
|
||
sil [ossa] @unmanaged_to_ref_is_unowned_instant_use : $@convention(thin) (@guaranteed Builtin.NativeObject) -> Builtin.NativeObject { | ||
bb0(%0 : @guaranteed $Builtin.NativeObject): | ||
%1 = ref_to_unmanaged %0 : $Builtin.NativeObject to $@sil_unmanaged Builtin.NativeObject | ||
%2 = unmanaged_to_ref %1 : $@sil_unmanaged Builtin.NativeObject to $Builtin.NativeObject | ||
return %2 : $Builtin.NativeObject | ||
} | ||
|
||
sil [ossa] @nontrivial_enum_unchecked_enum_data_trivial_payload_owned : $@convention(thin) (@owned ThreeDifferingPayloadEnum) -> Builtin.Int32 { | ||
bb0(%0 : @owned $ThreeDifferingPayloadEnum): | ||
// NOTE: It may be surprising that %0 is consumed by this unchecked_enum_data | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1604,18 +1604,6 @@ bb0(%0 : @guaranteed $B): | |
return %3 : $F | ||
} | ||
|
||
// CHECK-LABEL: sil [ossa] @unchecked_ref_cast_formation_unowned : $@convention(thin) (B) -> F { | ||
// CHECK: bb0([[INPUT_REF:%[0-9]+]] : | ||
// CHECK: ref_to_raw_pointer | ||
// CHECK: raw_pointer_to_ref | ||
// CHECK: } // end sil function 'unchecked_ref_cast_formation_unowned' | ||
sil [ossa] @unchecked_ref_cast_formation_unowned : $@convention(thin) (B) -> F { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the ones in this file are OK to go, specifically testing cases that are never generated. |
||
bb0(%0 : @unowned $B): | ||
%1 = ref_to_raw_pointer %0 : $B to $Builtin.RawPointer | ||
%2 = raw_pointer_to_ref %1 : $Builtin.RawPointer to $F | ||
return %2 : $F | ||
} | ||
|
||
// CHECK-LABEL: sil [ossa] @upcast_unchecked_ref_cast_roundtrip : $@convention(thin) (@owned B) -> @owned B { | ||
// CHECK-NOT: unchecked_ref_cast | ||
// CHECK-NOT: upcast | ||
|
@@ -2745,27 +2733,6 @@ class XXImpl : XX { | |
init() | ||
} | ||
|
||
// CHECK-LABEL: sil [ossa] @unowned_round_trips : $@convention(thin) (@guaranteed B, @guaranteed @sil_unowned B, @guaranteed AnyObject, @sil_unmanaged AnyObject) -> (B, @sil_unowned B, AnyObject, @sil_unmanaged AnyObject) { | ||
// CHECK: bb0( | ||
// CHECK-NEXT: tuple | ||
// CHECK-NEXT: return | ||
// CHECK: } // end sil function 'unowned_round_trips' | ||
sil [ossa] @unowned_round_trips : $@convention(thin) (@guaranteed B, @guaranteed @sil_unowned B, @guaranteed AnyObject, @sil_unmanaged AnyObject) -> (B, @sil_unowned B, AnyObject, @sil_unmanaged AnyObject) { | ||
bb0(%0 : @guaranteed $B, %1 : @guaranteed $@sil_unowned B, %2 : @guaranteed $AnyObject, %3 : $@sil_unmanaged AnyObject): | ||
%4 = ref_to_unowned %0 : $B to $@sil_unowned B | ||
%5 = unowned_to_ref %4 : $@sil_unowned B to $B | ||
%6 = unowned_to_ref %1 : $@sil_unowned B to $B | ||
%7 = ref_to_unowned %6 : $B to $@sil_unowned B | ||
|
||
%8 = ref_to_unmanaged %2 : $AnyObject to $@sil_unmanaged AnyObject | ||
%9 = unmanaged_to_ref %8 : $@sil_unmanaged AnyObject to $AnyObject | ||
%10 = unmanaged_to_ref %3 : $@sil_unmanaged AnyObject to $AnyObject | ||
%11 = ref_to_unmanaged %10 : $AnyObject to $@sil_unmanaged AnyObject | ||
|
||
%9999 = tuple(%5 : $B, %7 : $@sil_unowned B, %9 : $AnyObject, %11 : $@sil_unmanaged AnyObject) | ||
return %9999 : $(B, @sil_unowned B, AnyObject, @sil_unmanaged AnyObject) | ||
} | ||
|
||
// CHECK-LABEL: sil [ossa] @collapse_existential_pack_unpack_unchecked_ref_cast : | ||
// CHECK: bb0([[Ref:%.*]] : @guaranteed $MyClass): | ||
// CHECK-NOT: init_existential_ref | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has a version with owned return type so should be OK to remove.