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
|
// Note: this test is separate from `differentiability_witness_function_inst.sil`
// because `differentiability_witness_function [transpose] [reverse]` instructions do not
// have IRGen support yet.
// Round-trip parsing/printing test.
// RUN: %target-sil-opt %s | %FileCheck %s
// Round-trip serialization-deserialization test.
// RUN: %empty-directory(%t)
// RUN: %target-sil-opt %s -emit-sib -o %t/tmp.sib -module-name main
// RUN: %target-sil-opt %t/tmp.sib -o %t/tmp.sil -module-name main
// https://github.com/apple/swift/issues/54526
// Workaround because import declarations are not preserved in .sib files.
// RUN: sed -e 's/import Swift$/import Swift; import _Differentiation/' %t/tmp.sil > %t/tmp_fixed.sil
// RUN: %target-sil-opt %t/tmp_fixed.sil -module-name main -emit-sorted-sil | %FileCheck %s
// `shell` is required only to run `sed` as a
// https://github.com/apple/swift/issues/54526 workaround.
// REQUIRES: shell
sil_stage raw
import Swift
import Builtin
import _Differentiation
sil_differentiability_witness [reverse] [parameters 0] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float
sil_differentiability_witness [reverse] [parameters 0 1] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float
sil_differentiability_witness [reverse] [parameters 0] [results 0] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)
sil_differentiability_witness [reverse] [parameters 0 1] [results 0 1] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)
sil_differentiability_witness [reverse] [parameters 0] [results 0] <T where T : Differentiable> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T
sil_differentiability_witness [reverse] [parameters 0 1] [results 0] <T where T : Differentiable> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T
sil_differentiability_witness [reverse] [parameters 0 1] [results 0] <T where T : Differentiable, T == T.TangentVector> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T
sil_differentiability_witness [reverse] [parameters 0 1] [results 0] <T where T : Differentiable, T: AdditiveArithmetic> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T
sil @foo : $@convention(thin) (Float, Float, Float) -> Float
sil @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)
sil @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T
sil @genericreq : $@convention(thin) <T : FloatingPoint> (@in_guaranteed T, Float) -> @out T
sil @test_transpose_witnesses : $@convention(thin) () -> () {
bb0:
%foo_t_wrt_0 = differentiability_witness_function [transpose] [reverse] [parameters 0] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float
%foo_t_wrt_0_1 = differentiability_witness_function [transpose] [reverse] [parameters 0 1] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float
// Test multiple results.
%bar_t_wrt_0_results_0 = differentiability_witness_function [transpose] [reverse] [parameters 0] [results 0] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)
%bar_t_wrt_0_1_results_0_1 = differentiability_witness_function [transpose] [reverse] [parameters 0 1] [results 0 1] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)
// Test generic requirements.
%generic_t_wrt_0 = differentiability_witness_function [transpose] [reverse] [parameters 0] [results 0] <T : Differentiable> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T
%generic_t_wrt_0_1 = differentiability_witness_function [transpose] [reverse] [parameters 0 1] [results 0] <T : AdditiveArithmetic & Differentiable> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T
// Test "dependent" generic requirements: `T == T.TangentVector` depends on `T: Differentiable`.
%generic_t_wrt_0_1_dependent_req = differentiability_witness_function [transpose] [reverse] [parameters 0 1] [results 0] <T where T: Differentiable, T == T.TangentVector> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T
return undef : $()
}
// CHECK-LABEL: sil @test_transpose_witnesses : $@convention(thin) () -> () {
// CHECK: bb0:
// CHECK: {{%.*}} = differentiability_witness_function [transpose] [reverse] [parameters 0] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float
// CHECK: {{%.*}} = differentiability_witness_function [transpose] [reverse] [parameters 0 1] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float
// CHECK: {{%.*}} = differentiability_witness_function [transpose] [reverse] [parameters 0] [results 0] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)
// CHECK: {{%.*}} = differentiability_witness_function [transpose] [reverse] [parameters 0 1] [results 0 1] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)
// CHECK: {{%.*}} = differentiability_witness_function [transpose] [reverse] [parameters 0] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0
// CHECK: {{%.*}} = differentiability_witness_function [transpose] [reverse] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 == τ_0_0.TangentVector> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0
// CHECK: return undef : $()
// CHECK: }
|