swift
swift copied to clipboard
[SR-15985] [AutoDiff] Specific custom VJP triggers assertion "internal/private function cannot be serialized"
Previous ID | SR-15985 |
Radar | None |
Original Reporter | @BradLarson |
Type | Bug |
Additional Detail from JIRA
Votes | 0 |
Component/s | |
Labels | Bug, AutoDiff |
Assignee | None |
Priority | Medium |
md5: fda31536276ac9af6789e3146d3c3482
Issue Description:
Starting with the 2022-03-13 nightly toolchain snapshot, the following simple custom VJP:
import _Differentiation
public extension SIMD
where
Self: Differentiable,
Scalar: BinaryFloatingPoint & Differentiable,
Scalar.TangentVector: BinaryFloatingPoint,
TangentVector == Self
{
@inlinable
@derivative(of: sum)
func _vjpSum() -> (
value: Scalar, pullback: (Scalar.TangentVector) -> TangentVector
) {
return (sum(), { v in Self(repeating: Scalar(v)) })
}
}
when placed in a file and built with `swiftc file.swift` causes an assertion failure of "SIL verification failed: internal/private function cannot be serialized or serializable: !F->isSerialized()". This was not present in the 2022-03-09 nightly snapshot toolchain, and seems to be a fairly recent regression.
The full assertion is as follows:
SIL verification failed: internal/private function cannot be serialized or serializable: !F->isSerialized()
In function:
// reverse-mode derivative of SIMD<>.sum()
sil hidden [serialized] [thunk] [always_inline] [ossa] @$ss4SIMDPsSF6ScalarRpzrlE3sumADyFsAARz16_Differentiation14DifferentiableRz13TangentVectorAfGPQzRszSBACs11SIMDStoragePRpzAfgMRQSBAcL_AhIRPzlTJrSpSr : $@convention(method) <τ_0_0 where τ_0_0 : SIMD, τ_0_0 : Differentiable, τ_0_0 == τ_0_0.TangentVector, τ_0_0.Scalar : BinaryFloatingPoint, τ_0_0.Scalar : Differentiable, τ_0_0.Scalar.TangentVector : BinaryFloatingPoint> (@in_guaranteed τ_0_0) -> (@out τ_0_0.Scalar, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <τ_0_0.Scalar.TangentVector, τ_0_0.TangentVector>) {
// %0 // user: %3
// %1 // user: %3
bb0(%0 : $*τ_0_0.Scalar, %1 : $*τ_0_0):
// function_ref SIMD<>._vjpSum()
%2 = function_ref @$ss4SIMDP4main16_Differentiation14DifferentiableRz13TangentVectorAdEPQzRszSB6Scalars11SIMDStoragePRpzAdeLRQSBAiK_AfGRPzrlE7_vjpSumAL5value_xAMc8pullbacktyF : $@convention(method) <τ_0_0 where τ_0_0 : SIMD, τ_0_0 : Differentiable, τ_0_0 == τ_0_0.TangentVector, τ_0_0.Scalar : BinaryFloatingPoint, τ_0_0.Scalar : Differentiable, τ_0_0.Scalar.TangentVector : BinaryFloatingPoint> (@in_guaranteed τ_0_0) -> (@out τ_0_0.Scalar, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <τ_0_0.Scalar.TangentVector, τ_0_0>) // user: %3
%3 = apply %2<τ_0_0>(%0, %1) : $@convention(method) <τ_0_0 where τ_0_0 : SIMD, τ_0_0 : Differentiable, τ_0_0 == τ_0_0.TangentVector, τ_0_0.Scalar : BinaryFloatingPoint, τ_0_0.Scalar : Differentiable, τ_0_0.Scalar.TangentVector : BinaryFloatingPoint> (@in_guaranteed τ_0_0) -> (@out τ_0_0.Scalar, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <τ_0_0.Scalar.TangentVector, τ_0_0>) // user: %4
return %3 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <τ_0_0.Scalar.TangentVector, τ_0_0> // id: %4
} // end sil function '$ss4SIMDPsSF6ScalarRpzrlE3sumADyFsAARz16_Differentiation14DifferentiableRz13TangentVectorAfGPQzRszSBACs11SIMDStoragePRpzAfgMRQSBAcL_AhIRPzlTJrSpSr'
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0. Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-03-13-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file main.swift -target x86_64-apple-macosx11.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -color-diagnostics -new-driver-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-03-13-a.xctoolchain/usr/bin/swift-driver -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-03-13-a.xctoolchain/usr/lib/swift -module-name main -target-sdk-version 11.3 -o /var/folders/1s/z_s04yq55wq2jvgqghm8zm7w0000gp/T/TemporaryDirectory.h0jeC4/main-1.o
1. Apple Swift version 5.7-dev (LLVM 974d1cdad71ae84, Swift e737770cdb5fcb5)
2. Compiling with the current language version
3. While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "main.swift")
4. While verifying SIL function "@$ss4SIMDPsSF6ScalarRpzrlE3sumADyFsAARz16_Differentiation14DifferentiableRz13TangentVectorAfGPQzRszSBACs11SIMDStoragePRpzAfgMRQSBAcL_AhIRPzlTJrSpSr".
for '_vjpSum()' (at main.swift:12:5)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 swift-frontend 0x00000001089360c7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1 swift-frontend 0x00000001089352e5 llvm::sys::RunSignalHandlers() + 85
2 swift-frontend 0x0000000108936700 SignalHandler(int) + 288
3 libsystem_platform.dylib 0x00007fff20536d7d _sigtramp + 29
4 libsystem_platform.dylib 0x00007ffeec3885d8 _sigtramp + 18446744072835373176
5 libsystem_c.dylib 0x00007fff20446406 abort + 125
6 swift-frontend 0x0000000103b62fce (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) + 1374
7 swift-frontend 0x0000000103b63afa (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 1002
8 swift-frontend 0x0000000103b62393 swift::SILModule::verify() const + 275
9 swift-frontend 0x0000000103f58aa5 swift::Lowering::SILGenModule::~SILGenModule() + 149
10 swift-frontend 0x0000000103f638cf swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 6367
11 swift-frontend 0x00000001040324e6 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 134
12 swift-frontend 0x0000000103f6767d llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 413
13 swift-frontend 0x0000000103f63bb4 swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&) + 116
14 swift-frontend 0x000000010399183a swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 618
15 swift-frontend 0x0000000103993c79 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3801
16 swift-frontend 0x0000000103894434 swift::mainEntry(int, char const**) + 3220
17 libdyld.dylib 0x00007fff2050cf3d start + 1