swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.06k stars 10.33k forks source link

AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift run with sil-verify-all fails verification after SILCombine #73435

Closed nate-chandler closed 3 weeks ago

nate-chandler commented 2 months ago

Description

A run of the test after applying the following diff

diff --git a/test/AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift b/test/AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift
index df0e35d0e12..f6498c0b008 100644
--- a/test/AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift
+++ b/test/AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-sil -O -g %s | %FileCheck %s
+// RUN: %target-swift-frontend -sil-verify-all -emit-sil -O -g %s | %FileCheck %s

 // REQUIRES: swift_in_compiler

results in

SIL verification failed: Operand of release must have reference semantics: value->getType().isReferenceCounted(F.getModule()) || value->getType().isForeignReferenceType()
Verifying instruction:
   %1 = argument of bb0 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // users: %6, %10, %15, %5, %13, %14, %3
->   strong_release %1 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // id: %6
In function:
// specialized valueWithPullback<A>(at:of:)
sil shared @$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlFSd_Tg5 : $@convention(thin) (Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> @owned @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> {
// %0 "x"                                         // users: %8, %2
// %1 "f"                                         // users: %6, %10, %15, %5, %13, %14, %3
bb0(%0 : $Double, %1 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>):
  debug_value %0 : $Double, let, name "x", argno 1 // id: %2
  debug_value %1 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>, let, name "f", argno 2 // id: %3
  // function_ref specialized reverse-mode derivative of nonInoutWrappingFunction #1 <A>(_:) in valueWithPullback<A>(at:of:)
  %4 = function_ref @$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlF24nonInoutWrappingFunctionL_yxxAiJRzlFAiJRzlTJrSUpSrSd_TG5 : $@convention(thin) (@in_guaranteed Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // user: %10
  retain_value %1 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // id: %5
  strong_release %1 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // id: %6
  %7 = alloc_stack $Double                        // users: %10, %12, %8
  store %0 to %7 : $*Double                       // id: %8
  %9 = alloc_stack $Double                        // users: %10, %11
  %10 = apply %4(%9, %7, %1) : $@convention(thin) (@in_guaranteed Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // users: %16, %18
  dealloc_stack %9 : $*Double                     // id: %11
  dealloc_stack %7 : $*Double                     // id: %12
  strong_release %1 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // id: %13
  strong_release %1 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // id: %14
  strong_release %1 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // id: %15
  debug_value %10 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>, let, name "nonInoutPullback" // id: %16
  // function_ref specialized closure #1 in valueWithPullback<A>(at:of:)
  %17 = function_ref @$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlFyAGzcfU_Sd_Tg5 : $@convention(thin) (@inout Double, @guaranteed @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) -> () // user: %18
  %18 = partial_apply [callee_guaranteed] %17(%10) : $@convention(thin) (@inout Double, @guaranteed @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) -> () // user: %19
  %19 = convert_function %18 : $@callee_guaranteed (@inout Double) -> () to $@callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // user: %20
  return %19 : $@callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // id: %20
} // end sil function '$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlFSd_Tg5'

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: 
1.      Swift version 6.0-dev (LLVM 43f499658077b0d, Swift 6fdaea514fd621f)
2.      Compiling with effective version 4.1.50
3.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for main)
4.      While running pass #9595 SILFunctionTransform "SILCombine" on SILFunction "@$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlFSd_Tg5".
 for 'valueWithPullback(at:of:)' (at /Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/swift/test/AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift:19:8)
5.      While verifying SIL function "@$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlFSd_Tg5".
 for 'valueWithPullback(at:of:)' (at /Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/swift/test/AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift:19:8)
 #0 0x0000000106017a40 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x105a0ba40)
 #1 0x0000000106015df8 llvm::sys::RunSignalHandlers() (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x105a09df8)
 #2 0x00000001060180d4 SignalHandler(int) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x105a0c0d4)
 #3 0x0000000188f86a24 (/usr/lib/system/libsystem_platform.dylib+0x18042ea24)
 #4 0x0000000188f57c28 (/usr/lib/system/libsystem_pthread.dylib+0x1803ffc28)
 #5 0x0000000188e65ae8 (/usr/lib/system/libsystem_c.dylib+0x18030dae8)
 #6 0x0000000101718164 swift::SILModule::print(llvm::raw_ostream&, swift::ModuleDecl*, swift::SILOptions const&, bool) const (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x10110c164)
 #7 0x0000000101736c58 (anonymous namespace)::SILVerifier::requireReferenceValue(swift::SILValue, llvm::Twine const&) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x10112ac58)
 #8 0x000000010171fd88 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x101113d88)
 #9 0x000000010171c200 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x101110200)
#10 0x000000010171ace0 (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x10110ece0)
#11 0x00000001017146e4 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x1011086e4)
#12 0x00000001011c6e18 swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100bbae18)
#13 0x00000001011c7808 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100bbb808)
#14 0x00000001011c48cc swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100bb88cc)
#15 0x00000001011c4868 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100bb8868)
#16 0x00000001011ff4f4 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100bf34f4)
#17 0x00000001011df890 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100bd3890)
#18 0x00000001011c4aa8 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100bb8aa8)
#19 0x00000001011e1f44 swift::runSILOptimizationPasses(swift::SILModule&) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100bd5f44)
#20 0x0000000100a54180 swift::CompilerInstance::performSILProcessing(swift::SILModule*) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100448180)
#21 0x0000000100812758 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100206758)
#22 0x00000001008120d4 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x1002060d4)
#23 0x0000000100822e08 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100216e08)
#24 0x0000000100814430 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100208430)
#25 0x0000000100813414 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x100207414)
#26 0x00000001006451e0 swift::mainEntry(int, char const**) (/Volumes/ams1_ext3/Source/Open/Apple/swift/maintain_5/build/silopt-stdlib/swift-macosx-arm64/bin/swift-frontend+0x1000391e0)
#27 0x0000000188bfff28

Reproduction

Enable sil-verify-all in the test via, for example

diff --git a/test/AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift b/test/AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift
index df0e35d0e12..f6498c0b008 100644
--- a/test/AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift
+++ b/test/AutoDiff/compiler_crashers_fixed/issue-62608-conflicting-debug-info.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-sil -O -g %s | %FileCheck %s
+// RUN: %target-swift-frontend -sil-verify-all -emit-sil -O -g %s | %FileCheck %s

 // REQUIRES: swift_in_compiler

Expected behavior

Valid SIL out of SILCombine

Environment

Recent main. Specifically 6fdaea514fd621f62a56afb4ff1ce39f8bf77b31.

Additional information

No response

asl commented 1 month ago

So, apparently the following function type is considered as non-refcounted:

$@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>

Still, we're doing retains / release on values of this type.

asl commented 1 month ago

So, things are interesting. Here is the code at some point of sil-combine:

sil shared @$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlFSd_Tg5 : $@convention(thin) (Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> @owned @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> {
// %0 "x"                                         // users: %15, %2
// %1 "f"                                         // users: %10, %8, %5, %3
bb0(%0 : $Double, %1 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>):
  debug_value %0 : $Double, let, name "x", argno 1 // id: %2
  debug_value %1 : $@differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>, let, name "f", argno 2 // id: %3
  // function_ref specialized nonInoutWrappingFunction #1 <A>(_:) in valueWithPullback<A>(at:of:)
  %4 = function_ref @$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlF24nonInoutWrappingFunctionL_yxxAiJRzlFSd_TG5 : $@convention(thin) (@in_guaranteed Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> @out Double // user: %5
  %5 = partial_apply [callee_guaranteed] %4(%1) : $@convention(thin) (@in_guaranteed Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> @out Double // user: %6
  %6 = convert_function %5 : $@callee_guaranteed (@in_guaranteed Double) -> @out Double to $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double> // users: %22, %11
  // function_ref specialized forward-mode derivative of nonInoutWrappingFunction #1 <A>(_:) in valueWithPullback<A>(at:of:)
  %7 = function_ref @$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlF24nonInoutWrappingFunctionL_yxxAiJRzlFAiJRzlTJfSUpSrSd_TG5 : $@convention(thin) (@in_guaranteed Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // user: %8
  %8 = partial_apply [callee_guaranteed] %7(%1) : $@convention(thin) (@in_guaranteed Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // users: %12, %23
  // function_ref specialized reverse-mode derivative of nonInoutWrappingFunction #1 <A>(_:) in valueWithPullback<A>(at:of:)
  %9 = function_ref @$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlF24nonInoutWrappingFunctionL_yxxAiJRzlFAiJRzlTJrSUpSrSd_TG5 : $@convention(thin) (@in_guaranteed Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // user: %10
  %10 = partial_apply [callee_guaranteed] %9(%1) : $@convention(thin) (@in_guaranteed Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // users: %13, %24
  %11 = convert_escape_to_noescape %6 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double> to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double> // user: %16
  %12 = convert_escape_to_noescape %8 : $@callee_guaranteed (@in_guaranteed Double) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) to $@noescape @callee_guaranteed (@in_guaranteed Double) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // user: %17
  %13 = convert_escape_to_noescape %10 : $@callee_guaranteed (@in_guaranteed Double) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) to $@noescape @callee_guaranteed (@in_guaranteed Double) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // user: %19
  %14 = alloc_stack $Double                       // users: %21, %19, %15
  store %0 to %14 : $*Double                      // id: %15
  %16 = convert_function %11 : $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double> to $@noescape @callee_guaranteed (@in_guaranteed Double) -> @out Double
  %17 = convert_function %12 : $@noescape @callee_guaranteed (@in_guaranteed Double) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) to $@noescape @callee_guaranteed (@in_guaranteed Double) -> (@out Double, @owned @callee_guaranteed (@in_guaranteed Double) -> @out Double)
  %18 = alloc_stack $Double                       // users: %20, %19
  %19 = apply %13(%18, %14) : $@noescape @callee_guaranteed (@in_guaranteed Double) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // users: %27, %25
  dealloc_stack %18 : $*Double                    // id: %20
  dealloc_stack %14 : $*Double                    // id: %21
  strong_release %6 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double> // id: %22
  strong_release %8 : $@callee_guaranteed (@in_guaranteed Double) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // id: %23
  strong_release %10 : $@callee_guaranteed (@in_guaranteed Double) -> (@out Double, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) // id: %24
  debug_value %19 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>, let, name "nonInoutPullback" // id: %25
  // function_ref specialized closure #1 in valueWithPullback<A>(at:of:)
  %26 = function_ref @$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlFyAGzcfU_Sd_Tg5 : $@convention(thin) (@inout Double, @guaranteed @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) -> () // user: %27
  %27 = partial_apply [callee_guaranteed] %26(%19) : $@convention(thin) (@inout Double, @guaranteed @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Double, Double>) -> () // user: %28
  %28 = convert_function %27 : $@callee_guaranteed (@inout Double) -> () to $@callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // user: %29
  return %28 : $@callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double> // id: %29
} // end sil function '$s4main17valueWithPullback2at2ofyt0B0_y13TangentVectorQzzc8pullbacktx_yxzYjrXEt16_Differentiation14DifferentiableRzlFSd_Tg5'

Now, notice that %5 = partial_apply [callee_guaranteed] %4(%1) : $@convention(thin) (@in_guaranteed Double, @guaranteed @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0> (@inout τ_0_0) -> () for <Double>) -> @out Double // user: %6 has essentially only refcounting users. We capture %1 into closure %5 and then release this closure in the end.

Then sil-combine goes via tryDeleteDeadClosure that in turn calls keepArgsOfPartialApplyAlive. Here in the end we're calling swift::emitDestroyOperation on the argument of a partial_apply.

Here strong_release is emitted if type is know to have reference semantics (i.e. hasReferenceSemantics returns true). SIL verifier checks is argument is reference counted. (i.e. isReferenceCounted returns true). differentiable functions are modelled as non-trivial aggregates, so they are not reference-counted scalars. Still hasReferenceSemantics returns true for them as they are function types at AST level.

To me it seems that SIL verifier is correct and swift::emitDestroyOperation is not. But maybe I'm missing something? It seems very strange that such issue was not found previously. But maybe it's just because differentiable functions are so special?

Tagging @rxwei