Files
swift-mirror/test/AutoDiff/compiler_crashers_fixed/sr14004-cross-module-differentiation-differentiable-function-extract-inlining.swift
Dan Zheng 126f1ac6fb [AutoDiff] Disable differentiable_function_extract explicit type as… (#35239)
`differentiability_function_extract` instruction has an optional explicit
extractee type. This is currently used by TypeSubstCloner and the
LoadableByAddress transform to rewrite `differentiability_function_extract`
instructions while preserving `@differentiable` function type invariants.

There is an assertion that `differentiability_function_extract` instructions do
not have explicit extractee types outside of canonical/lowered SIL. However,
this does not handle the SIL deserialization case above: when a function
containing a `differentiable_function_extract` instruction with an explicit type
is deserialized into a raw SIL module (which happens when optimizations are
enabled).

Removing the assertion unblocks this encountered use case.

A more robust longer-term solution may be to change SIL `@differentiable`
function types to explicitly store component original/JVP/VJP function types.

Also fix `differentiable_function_extract` extractee type serialization.

Resolves SR-14004.
2021-01-04 18:40:11 -05:00

35 lines
833 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift-dylib(%t/%target-library-name(Library)) -emit-module -emit-module-path %t/Library.swiftmodule -module-name Library -DLIBRARY %s
// RUN: %target-build-swift -I %t -O -emit-module %s
// SR-14004: Assertion failure due to function with `differentiable_function_extract`
// with explicit extractee type being deserialized into a raw SIL module.
#if LIBRARY
import _Differentiation
public struct Struct<Scalar>: Differentiable {}
@differentiable
public func foo<Scalar>(_ x: Struct<Scalar>) -> Struct<Scalar> { x }
@inlinable
@differentiable
public func bar<Scalar>(_ x: Struct<Scalar>) -> Struct<Scalar> {
foo(x)
}
#else
import _Differentiation
import Library
public func foo(
body: @differentiable (Struct<Float>) -> Struct<Float> = bar
) {
fatalError()
}
#endif