swift
swift copied to clipboard
[SR-14227] [AutoDiff] SIL verification failed: method does not appear in the class's vtable
Previous ID | SR-14227 |
Radar | None |
Original Reporter | @dan-zheng |
Type | Bug |
Status | In Progress |
Resolution |
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, AutoDiff |
Assignee | @dan-zheng |
Priority | Medium |
md5: 6fcf38e9571d104b4dea6dc6c60f31ae
Issue Description:
public protocol TensorView {
associatedtype Element
}
public protocol DifferentiableTensorView: TensorView & Differentiable where Self == TangentVector {}
public protocol PlatformAPI {
@differentiable
func abs<T>(_ x: T) -> T where T: DifferentiableTensorView, T.Element: Numeric
}
public class CpuService: PlatformAPI {
@differentiable
public func abs<T>(_ x: T) -> T where T: DifferentiableTensorView, T.Element: Numeric { x }
}
public final class Platform {
public static var service: PlatformAPI = CpuService()
}
@differentiable(where T: DifferentiableTensorView)
public func abs<T: DifferentiableTensorView>(_ x: T) -> T where T.Element: Numeric {
Platform.service.abs(x)
}
SIL verification failed: method does not appear in the class's vtable: VerifyClassMethodVisitor(member).Seen
Verifying instruction:
%3 = load_borrow %2 : $*CpuService // users: %6, %5, %4
-> %4 = class_method %3 : $CpuService, #CpuService.abs!1.jvp.SU.<Self, T where Self : PlatformAPI, T : DifferentiableTensorView, T.Element : Numeric> : <T where T : DifferentiableTensorView, T.Element : Numeric> (CpuService) -> (T) -> T, $@convention(method) <τ_0_0 where τ_0_0 : DifferentiableTensorView, τ_0_0.Element : Numeric> (@in_guaranteed τ_0_0, @guaranteed CpuService) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0) // user: %5
%5 = apply %4<τ_0_0>(%0, %1, %3) : $@convention(method) <τ_0_0 where τ_0_0 : DifferentiableTensorView, τ_0_0.Element : Numeric> (@in_guaranteed τ_0_0, @guaranteed CpuService) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0) // user: %7
In function:
// AD__$s3abs10CpuServiceCAA11PlatformAPIA2aDPAAyqd__qd__AA24DifferentiableTensorViewRd__Sj7ElementAA0gH0PRpd__lFTW_jvp_SU
sil shared [transparent] [serialized] [thunk] [ossa] @AD__$s3abs10CpuServiceCAA11PlatformAPIA2aDPAAyqd__qd__AA24DifferentiableTensorViewRd__Sj7ElementAA0gH0PRpd__lFTW_jvp_SU : $@convention(witness_method: PlatformAPI) <τ_0_0 where τ_0_0 : DifferentiableTensorView, τ_0_0.Element : Numeric> (@in_guaranteed τ_0_0, @in_guaranteed CpuService) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0) {
// %0 // user: %5
// %1 // user: %5
// %2 // user: %3
bb0(%0 : $*τ_0_0, %1 : $*τ_0_0, %2 : $*CpuService):
%3 = load_borrow %2 : $*CpuService // users: %6, %5, %4
%4 = class_method %3 : $CpuService, #CpuService.abs!1.jvp.SU.<Self, T where Self : PlatformAPI, T : DifferentiableTensorView, T.Element : Numeric> : <T where T : DifferentiableTensorView, T.Element : Numeric> (CpuService) -> (T) -> T, $@convention(method) <τ_0_0 where τ_0_0 : DifferentiableTensorView, τ_0_0.Element : Numeric> (@in_guaranteed τ_0_0, @guaranteed CpuService) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0) // user: %5
%5 = apply %4<τ_0_0>(%0, %1, %3) : $@convention(method) <τ_0_0 where τ_0_0 : DifferentiableTensorView, τ_0_0.Element : Numeric> (@in_guaranteed τ_0_0, @guaranteed CpuService) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0) // user: %7
end_borrow %3 : $CpuService // id: %6
return %5 : $@callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0 // id: %7
} // end sil function 'AD__$s3abs10CpuServiceCAA11PlatformAPIA2aDPAAyqd__qd__AA24DifferentiableTensorViewRd__Sj7ElementAA0gH0PRpd__lFTW_jvp_SU'
A minimized reproducer (thanks to Shadaj):
import _Differentiation
protocol DifferentiableBase {
@differentiable func myFunc(_ input: Float) -> Float
}
class MyClass: DifferentiableBase {
@differentiable
public func myFunc(_ input: Float) -> Float {
return input
}
}
SIL verification failed: method does not appear in the class's vtable: VerifyClassMethodVisitor(member).Seen
Verifying instruction:
%2 = load_borrow %1 : $*MyClass // users: %8, %4, %3
-> %3 = class_method %2 : $MyClass, #MyClass.myFunc!jvp.SU.<Self where Self : DifferentiableBase> : (MyClass) -> (Float) -> Float, $@convention(method) (Float, @guaranteed MyClass) -> (Float, @owned @callee_guaranteed (Float) -> Float) // user: %4
%4 = apply %3(%0, %2) : $@convention(method) (Float, @guaranteed MyClass) -> (Float, @owned @callee_guaranteed (Float) -> Float) // user: %5
In function:
// AD__$s4main7MyClassCAA18DifferentiableBaseA2aDP6myFuncyS2fFTW_jvp_SU
sil private [transparent] [thunk] [ossa] @AD__$s4main7MyClassCAA18DifferentiableBaseA2aDP6myFuncyS2fFTW_jvp_SU : $@convention(witness_method: DifferentiableBase) (Float, @in_guaranteed MyClass) -> (Float, @owned @callee_guaranteed (Float) -> Float) {
// %0 // user: %4
// %1 // user: %2
bb0(%0 : $Float, %1 : $*MyClass):
%2 = load_borrow %1 : $*MyClass // users: %8, %4, %3
%3 = class_method %2 : $MyClass, #MyClass.myFunc!jvp.SU.<Self where Self : DifferentiableBase> : (MyClass) -> (Float) -> Float, $@convention(method) (Float, @guaranteed MyClass) -> (Float, @owned @callee_guaranteed (Float) -> Float) // user: %4
%4 = apply %3(%0, %2) : $@convention(method) (Float, @guaranteed MyClass) -> (Float, @owned @callee_guaranteed (Float) -> Float) // user: %5
(%5, %6) = destructure_tuple %4 : $(Float, @callee_guaranteed (Float) -> Float) // users: %7, %7
%7 = tuple (%5 : $Float, %6 : $@callee_guaranteed (Float) -> Float) // user: %9
end_borrow %2 : $MyClass // id: %8
return %7 : $(Float, @callee_guaranteed (Float) -> Float) // id: %9
} // end sil function 'AD__$s4main7MyClassCAA18DifferentiableBaseA2aDP6myFuncyS2fFTW_jvp_SU'
Second minimal reproducer does not crash on 05/24 toolchain. First one still does but with a different stack dump.
Assertion failed: (!type.hasArchetype()), function mapTypeIntoContext, file SILFunction.cpp, line 505.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/kshitij/workspace/scratch/test.swift -target arm64-apple-macosx13.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -color-diagnostics -O -empty-abi-descriptor -Xcc -working-directory -Xcc /Users/kshitij/workspace/scratch -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a.xctoolchain/usr/lib/swift -module-name test -target-sdk-version 14.2 -target-sdk-name macosx14.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a.xctoolchain/usr/local/lib/swift/host/plugins -enable-default-cmo -o /var/folders/5h/9l25ljkd47qct1zm4g4_dxz00000gq/T/TemporaryDirectory.jOqdA6/test-1.o
1. Apple Swift version 6.0-dev (LLVM b66077aefd3be08, Swift 84d36181a762913)
2. Compiling with effective version 5.10
3. While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for test)
4. While running pass #299 SILModuleTransform "Differentiation".
5. While processing // differentiability witness for abs<A>(_:)
sil_differentiability_witness [serialized] [reverse] [parameters 0] [results 0] <T where T : DifferentiableTensorView, T.Element : Numeric> @$s4test3absyxxAA24DifferentiableTensorViewRzSj7ElementAA0dE0PRpzlF : $@convention(thin) <T where T : DifferentiableTensorView, T.Element : Numeric> (@in_guaranteed T) -> @out T {
}
on SIL function "@$s4test3absyxxAA24DifferentiableTensorViewRzSj7ElementAA0dE0PRpzlF".
for 'abs(_:)' (at /Users/kshitij/workspace/scratch/test.swift:22:8)
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 0x0000000107d29600 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000107d27dcc llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000107d29c48 SignalHandler(int) + 304
3 libsystem_platform.dylib 0x00000001a3286a24 _sigtramp + 56
4 libsystem_pthread.dylib 0x00000001a3257c28 pthread_kill + 288
5 libsystem_c.dylib 0x00000001a3165ae8 abort + 180
6 libsystem_c.dylib 0x00000001a3164e44 err + 0
7 swift-frontend 0x00000001080510cc swift::SILFunction::isNoReturnFunction(swift::TypeExpansionContext) const (.cold.1) + 0
8 swift-frontend 0x00000001036d722c swift::GenericEnvironment::mapTypeIntoContext(swift::SILModule&, swift::SILType) const + 288
9 swift-frontend 0x0000000103082f80 swift::autodiff::LinearMapInfo::remapTypeInDerivative(swift::SILType) + 128
10 swift-frontend 0x0000000103083cec swift::autodiff::LinearMapInfo::getLinearMapType(swift::autodiff::ADContext&, swift::FullApplySite) + 560
11 swift-frontend 0x0000000103082770 swift::autodiff::LinearMapInfo::generateDifferentiationDataStructures(swift::autodiff::ADContext&, swift::SILFunction*) + 1008
12 swift-frontend 0x0000000103082eec swift::autodiff::LinearMapInfo::LinearMapInfo(swift::autodiff::ADContext&, swift::AutoDiffLinearMapKind, swift::SILFunction*, swift::SILFunction*, swift::AutoDiffConfig const&, swift::DifferentiableActivityInfo const&, swift::SILLoopInfo*) + 148
13 swift-frontend 0x00000001030a3de4 swift::autodiff::VJPCloner::Implementation::Implementation(swift::autodiff::VJPCloner&, swift::autodiff::ADContext&, swift::SILDifferentiabilityWitness*, swift::SILFunction*, swift::autodiff::DifferentiationInvoker) + 616
14 swift-frontend 0x00000001030a4ea0 swift::autodiff::VJPCloner::VJPCloner(swift::autodiff::ADContext&, swift::SILDifferentiabilityWitness*, swift::SILFunction*, swift::autodiff::DifferentiationInvoker) + 92
15 swift-frontend 0x00000001032012a4 (anonymous namespace)::DifferentiationTransformer::canonicalizeDifferentiabilityWitness(swift::SILDifferentiabilityWitness*, swift::autodiff::DifferentiationInvoker, swift::IsSerialized_t) + 6020
16 swift-frontend 0x00000001031ff130 (anonymous namespace)::Differentiation::run() + 1060
17 swift-frontend 0x00000001032a2a80 swift::SILPassManager::runModulePass(unsigned int) + 856
18 swift-frontend 0x00000001032a4e40 swift::SILPassManager::execute() + 624
19 swift-frontend 0x000000010329f6f8 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
20 swift-frontend 0x000000010329f678 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
21 swift-frontend 0x00000001032db07c swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
22 swift-frontend 0x00000001032bb2e4 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'()) + 204
23 swift-frontend 0x000000010329f8d4 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
24 swift-frontend 0x00000001032bd86c swift::runSILDiagnosticPasses(swift::SILModule&) + 192
25 swift-frontend 0x0000000102afffa8 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 68
26 swift-frontend 0x00000001028c4b44 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*) + 796
27 swift-frontend 0x00000001028c4258 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 612
28 swift-frontend 0x00000001028d54cc withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
29 swift-frontend 0x00000001028c6868 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
30 swift-frontend 0x00000001028c57d4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2368
31 swift-frontend 0x00000001026e09cc swift::mainEntry(int, char const**) + 3096
32 dyld 0x00000001a2efff28 start + 2236