|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: split-file %s %t |
| 3 | +// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Library.swiftmodule -parse-as-library %t/Library.swift -enable-library-evolution |
| 4 | +// RUN: %target-swift-frontend -emit-silgen %t/Client.swift -I %t -module-name test | %FileCheck %t/Client.swift |
| 5 | + |
| 6 | +// REQUIRES: VENDOR=apple |
| 7 | + |
| 8 | +//--- Library.swift |
| 9 | + |
| 10 | +import _Differentiation |
| 11 | + |
| 12 | +@differentiable(reverse) |
| 13 | +public func foo(_ x: Float) -> Float { x } |
| 14 | + |
| 15 | +@derivative(of: foo) |
| 16 | +public func bar(_ x: Float) -> (value: Float, pullback: (Float) -> Float) { |
| 17 | + fatalError() |
| 18 | +} |
| 19 | + |
| 20 | +//--- Client.swift |
| 21 | + |
| 22 | +@_weakLinked import Library |
| 23 | + |
| 24 | +// CHECK: sil hidden [ossa] @$s4test0A15GlobalFunctionsyyF : $@convention(thin) () -> () |
| 25 | +func testGlobalFunctions() { |
| 26 | + // CHECK: [[QUERY:%[0-9]+]] = function_ref @$s7Library3fooyS2fFTwS : $@convention(thin) () -> Builtin.Int1 |
| 27 | + // CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1 |
| 28 | + // CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}} |
| 29 | + if #_hasSymbol(foo(_:)) {} |
| 30 | + |
| 31 | + // CHECK: [[QUERY:%[0-9]+]] = function_ref @$s7Library3barySf5value_S2fc8pullbacktSfFTwS : $@convention(thin) () -> Builtin.Int1 |
| 32 | + // CHECK: [[RES:%[0-9]+]] = apply [[QUERY]]() : $@convention(thin) () -> Builtin.Int1 |
| 33 | + // CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}} |
| 34 | + if #_hasSymbol(bar(_:)) {} |
| 35 | +} |
| 36 | + |
| 37 | +// --- foo(_:) --- |
| 38 | +// CHECK: sil @$s7Library3fooyS2fF : $@convention(thin) (Float) -> Float |
| 39 | +// CHECK: sil @$s7Library3fooyS2fFTJfSpSr : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) |
| 40 | +// CHECK: sil @$s7Library3fooyS2fFTJrSpSr : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) |
| 41 | +// FIXME: missing reverse-mode differentiability witness for foo(_:) |
| 42 | + |
| 43 | +// --- bar(_:) --- |
| 44 | +// CHECK: sil hidden_external @$s7Library3barySf5value_S2fc8pullbacktSfFTwS : $@convention(thin) () -> Builtin.Int1 |
| 45 | +// CHECK: sil @$s7Library3barySf5value_S2fc8pullbacktSfF : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) |
| 46 | +// FIXME: missing reverse-mode differentiability witness for foo(_:) |
0 commit comments