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
|
// RUN: %target-sil-opt -transfer-non-sendable -strict-concurrency=complete %s -verify -o /dev/null
// REQUIRES: concurrency
// REQUIRES: asserts
// REQUIRES: differentiable_programming
sil_stage raw
import Swift
import Builtin
import _Differentiation
////////////////////////
// MARK: Declarations //
////////////////////////
class NonSendableKlass {}
sil @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
sil @useNonSendableKlass : $@convention(thin) (@guaranteed NonSendableKlass) -> ()
sil @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
final class SendableKlass : Sendable {}
sil @transferSendableKlass : $@convention(thin) @async (@guaranteed SendableKlass) -> ()
sil @constructSendableKlass : $@convention(thin) () -> @owned SendableKlass
final class KlassContainingKlasses {
let nsImmutable : NonSendableKlass
var nsMutable : NonSendableKlass
let sImmutable : SendableKlass
var sMutable : SendableKlass
}
sil @transferKlassContainingKlasses : $@convention(thin) @async (@guaranteed KlassContainingKlasses) -> ()
sil @useKlassContainingKlasses : $@convention(thin) (@guaranteed KlassContainingKlasses) -> ()
sil @constructKlassContainingKlasses : $@convention(thin) () -> @owned KlassContainingKlasses
@_moveOnly
struct NonSendableMoveOnlyStruct {
var ns: NonSendableKlass
deinit
}
sil @constructMoveOnlyStruct : $@convention(thin) () -> @owned NonSendableMoveOnlyStruct
sil @transferMoveOnlyStruct : $@convention(thin) @async (@guaranteed NonSendableMoveOnlyStruct) -> ()
struct NonSendableStruct {
var ns: NonSendableKlass
}
sil @constructStruct : $@convention(thin) () -> @owned NonSendableStruct
sil @transferStruct : $@convention(thin) @async (@guaranteed NonSendableStruct) -> ()
sil @transferRawPointer : $@convention(thin) @async (Builtin.RawPointer) -> ()
sil @useRawPointer : $@convention(thin) (Builtin.RawPointer) -> ()
sil @initRawPointer : $@convention(thin) () -> Builtin.RawPointer
sil @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
sil @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
sil @initIndirect : $@convention(thin) <T> () -> @out T
enum FakeOptional<T> {
case none
case some(T)
}
sil @getLinearFunction : $@convention(thin) () -> @owned @differentiable(_linear) @callee_guaranteed (Float) -> Float
sil @transferLinearFunction : $@async @convention(thin) (@guaranteed @differentiable(_linear) @callee_guaranteed (Float) -> Float) -> ()
sil @getDifferentiableFunction : $@convention(thin) () -> @owned @differentiable(reverse) @callee_guaranteed (Float) -> Float
sil @transferDifferentiableFunction : $@async @convention(thin) (@guaranteed @differentiable(reverse) @callee_guaranteed (Float) -> Float) -> ()
sil @getFunction : $@convention(thin) () -> @owned @callee_guaranteed (Float) -> Float
sil @useFunction : $@convention(thin) (@guaranteed @callee_guaranteed (Float) -> Float) -> ()
sil @transferFunction : $@async @convention(thin) (@guaranteed @callee_guaranteed (Float) -> Float) -> ()
/////////////////
// MARK: Tests //
/////////////////
sil [ossa] @linear_function_extract_test : $@async @convention(thin) () -> () {
bb0:
%init = function_ref @getLinearFunction : $@convention(thin) () -> @owned @differentiable(_linear) @callee_guaranteed (Float) -> Float
%0 = apply %init() : $@convention(thin) () -> @owned @differentiable(_linear) @callee_guaranteed (Float) -> Float
%transfer = function_ref @transferLinearFunction : $@async @convention(thin) (@guaranteed @differentiable(_linear) @callee_guaranteed (Float) -> Float) -> ()
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transfer(%0) : $@async @convention(thin) (@guaranteed @differentiable(_linear) @callee_guaranteed (Float) -> Float) -> () // expected-warning {{}}
// No error since this is just look through.
%1 = begin_borrow %0 : $@differentiable(_linear) @callee_guaranteed (Float) -> Float
%2 = linear_function_extract [original] %1 : $@differentiable(_linear) @callee_guaranteed (Float) -> Float
%f = function_ref @useFunction : $@convention(thin) (@guaranteed @callee_guaranteed (Float) -> Float) -> ()
apply %f(%2) : $@convention(thin) (@guaranteed @callee_guaranteed (Float) -> Float) -> () // expected-note {{access can happen concurrently}}
end_borrow %1 : $@differentiable(_linear) @callee_guaranteed (Float) -> Float
destroy_value %0 : $@differentiable(_linear) @callee_guaranteed (Float) -> Float
%9999 = tuple ()
return %9999 : $()
}
sil [ossa] @differentiable_function_extract_test : $@async @convention(thin) () -> () {
bb0:
%init = function_ref @getDifferentiableFunction : $@convention(thin) () -> @owned @differentiable(reverse) @callee_guaranteed (Float) -> Float
%0 = apply %init() : $@convention(thin) () -> @owned @differentiable(reverse) @callee_guaranteed (Float) -> Float
%transfer = function_ref @transferDifferentiableFunction : $@async @convention(thin) (@guaranteed @differentiable(reverse) @callee_guaranteed (Float) -> Float) -> ()
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transfer(%0) : $@async @convention(thin) (@guaranteed @differentiable(reverse) @callee_guaranteed (Float) -> Float) -> () // expected-warning {{}}
// No error since this is just look through.
%1 = begin_borrow %0 : $@differentiable(reverse) @callee_guaranteed (Float) -> Float
%2 = differentiable_function_extract [original] %1 : $@differentiable(reverse) @callee_guaranteed (Float) -> Float
%f = function_ref @useFunction : $@convention(thin) (@guaranteed @callee_guaranteed (Float) -> Float) -> ()
apply %f(%2) : $@convention(thin) (@guaranteed @callee_guaranteed (Float) -> Float) -> () // expected-note {{access can happen concurrently}}
end_borrow %1 : $@differentiable(reverse) @callee_guaranteed (Float) -> Float
destroy_value %0 : $@differentiable(reverse) @callee_guaranteed (Float) -> Float
%9999 = tuple ()
return %9999 : $()
}
sil [ossa] @linear_function_test : $@async @convention(thin) () -> () {
bb0:
%0 = function_ref @getFunction : $@convention(thin) () -> @owned @callee_guaranteed (Float) -> Float
%1 = apply %0() : $@convention(thin) () -> @owned @callee_guaranteed (Float) -> Float
%transfer = function_ref @transferFunction : $@async @convention(thin) (@guaranteed @callee_guaranteed (Float) -> Float) -> ()
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transfer(%1) : $@async @convention(thin) (@guaranteed @callee_guaranteed (Float) -> Float) -> () // expected-warning {{}}
%2 = begin_borrow %1 : $@callee_guaranteed (Float) -> Float
%3 = linear_function [parameters 0] %2 : $@callee_guaranteed (Float) -> Float // expected-note {{access can happen concurrently}}
end_borrow %2 : $@callee_guaranteed (Float) -> Float
destroy_value %1 : $@callee_guaranteed (Float) -> Float
%9999 = tuple ()
return %9999 : $()
}
sil @derivative : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
sil @vjp : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
// differentiable_function [parameters 0] [results 0] [[ORIG_FN]] : $@convention(thin) (Float) -> Float with_derivative {undef : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float), [[VJP_FN]] : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)}
sil [ossa] @differentiable_function_test : $@async @convention(thin) () -> () {
bb0:
%0 = function_ref @getFunction : $@convention(thin) () -> @owned @callee_guaranteed (Float) -> Float
%1 = apply %0() : $@convention(thin) () -> @owned @callee_guaranteed (Float) -> Float
%transfer = function_ref @transferFunction : $@async @convention(thin) (@guaranteed @callee_guaranteed (Float) -> Float) -> ()
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transfer(%1) : $@async @convention(thin) (@guaranteed @callee_guaranteed (Float) -> Float) -> () // expected-warning {{}}
%derivative = function_ref @derivative : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
%vjp = function_ref @vjp : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
%2 = begin_borrow %1 : $@callee_guaranteed (Float) -> Float
%3 = differentiable_function [parameters 0] [results 0] %2 : $@callee_guaranteed (Float) -> Float with_derivative {%derivative : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float), %vjp : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)} // expected-note {{access can happen concurrently}}
end_borrow %2 : $@callee_guaranteed (Float) -> Float
destroy_value %1 : $@callee_guaranteed (Float) -> Float
%9999 = tuple ()
return %9999 : $()
}
|