Skip to content

[SR-15566] Differentiable functions with control flow yield an assertion failure: "location is a VarDecl, but SILDebugVariable is empty" #57869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BradLarson opened this issue Dec 6, 2021 · 2 comments
Assignees
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself

Comments

@BradLarson
Copy link
Contributor

Previous ID SR-15566
Radar None
Original Reporter @BradLarson
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff
Assignee @rxwei
Priority Medium

md5: cc857cf6edb138b26261ab8a61df5c82

Issue Description:

Starting with the 2021-12-04 nightly snapshot, certain differentiable functions that involve struct or local `var`s cause an assertion failure of "location is a VarDecl, but SILDebugVariable is empty". A simple reproducer is as follows:

import _Differentiation

public struct Test: Differentiable {
    public var v1: [[Float]]

    @differentiable(reverse)
    public init(v1: [[Float]]) {
        if v1.count != 2 {
            fatalError("Mismatched counts")
        }
        self.v1 = v1
    }
}

Place the above by itself in a file and build with swiftc file.swift to trigger this failure. The full assertion text is as follows:

Assertion failed: ((!dyn_cast_or_null<VarDecl>(Loc.getAsASTNode<Decl>()) || Var) && "location is a VarDecl, but SILDebugVariable is empty"), function createAllocStack, file SILBuilder.h, line 389.
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-2021-12-02-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/bradlarson/Development/DifferentiableSwift/CompilerBugs/VarDeclCrasher/VarDeclCrasher/main.swift -emit-dependencies-path /Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/Objects-normal/x86_64/main.swiftdeps -serialize-diagnostics-path /Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/Objects-normal/x86_64/main.dia -target x86_64-apple-macos11.3 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -I /Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Products/Debug -F /Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Products/Debug -enable-testing -g -module-cache-path /Users/bradlarson/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -new-driver-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-12-02-a.xctoolchain/usr/bin/swift-driver -serialize-debugging-options -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-12-02-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/VarDeclCrasher-generated-files.hmap -Xcc -I/Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/VarDeclCrasher-own-target-headers.hmap -Xcc -I/Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/VarDeclCrasher-all-target-headers.hmap -Xcc -iquote -Xcc /Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/VarDeclCrasher-project-headers.hmap -Xcc -I/Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Products/Debug/include -Xcc -I/Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/DerivedSources-normal/x86_64 -Xcc -I/Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/DerivedSources/x86_64 -Xcc -I/Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/bradlarson/Development/DifferentiableSwift/CompilerBugs/VarDeclCrasher -module-name VarDeclCrasher -target-sdk-version 11.3.0 -o /Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Build/Intermediates.noindex/VarDeclCrasher.build/Debug/VarDeclCrasher.build/Objects-normal/x86_64/main.o -index-store-path /Users/bradlarson/Library/Developer/Xcode/DerivedData/VarDeclCrasher-ahvubcfxipupclheemrxtzypaszf/Index/DataStore -index-system-modules
1.  Apple Swift version 5.6-dev (LLVM 45a3cc180a9a385, Swift 8a7ca32cf0f903f)
2.  Compiling with the current language version
3.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for VarDeclCrasher)
4.  While running pass #&#8203;142 SILModuleTransform "Differentiation".
5.  While processing // differentiability witness for Test.init(v1:)
sil_differentiability_witness [serialized] [reverse] [parameters 0] [results 0] @$s14VarDeclCrasher4TestV2v1ACSaySaySfGG_tcfC : $@convention(method) (@owned Array<Array<Float>>, @thin Test.Type) -> @owned Test {
}

 on SIL function "@$s14VarDeclCrasher4TestV2v1ACSaySaySfGG_tcfC".
 for 'init(v1:)' (at /Users/bradlarson/Development/DifferentiableSwift/CompilerBugs/VarDeclCrasher/VarDeclCrasher/main.swift:7:12)
6.  While generating VJP for SIL function "@$s14VarDeclCrasher4TestV2v1ACSaySaySfGG_tcfC".
 for 'init(v1:)' (at /Users/bradlarson/Development/DifferentiableSwift/CompilerBugs/VarDeclCrasher/VarDeclCrasher/main.swift:7:12)
7.  While generating pullback for SIL function "@$s14VarDeclCrasher4TestV2v1ACSaySaySfGG_tcfC".
 for 'init(v1:)' (at /Users/bradlarson/Development/DifferentiableSwift/CompilerBugs/VarDeclCrasher/VarDeclCrasher/main.swift:7:12)
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           0x000000010b058967 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x000000010b057b85 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x000000010b058fa0 SignalHandler(int) + 288
3  libsystem_platform.dylib 0x00007fff20367d7d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000000089 _sigtramp + 18446603339975721769
5  libsystem_c.dylib        0x00007fff20277406 abort + 125
6  libsystem_c.dylib        0x00007fff202767d8 err + 0
7  swift-frontend           0x000000010b0bb493 swift::SILBuilder::createAllocStack(swift::SILLocation, swift::SILType, llvm::Optional<swift::SILDebugVariable>, bool, bool) (.cold.2) + 35
8  swift-frontend           0x000000010647c2c1 swift::SILBuilder::createAllocStack(swift::SILLocation, swift::SILType, llvm::Optional<swift::SILDebugVariable>, bool, bool) + 673
9  swift-frontend           0x0000000106aabe04 swift::autodiff::TangentBuilder::emitAdd(swift::SILLocation, swift::SILValue, swift::SILValue) + 468
10 swift-frontend           0x0000000106aa03f6 swift::autodiff::PullbackCloner::Implementation::accumulateAdjointsDirect(swift::autodiff::AdjointValue, swift::autodiff::AdjointValue, swift::SILLocation) + 438
11 swift-frontend           0x0000000106a99216 swift::autodiff::PullbackCloner::Implementation::addAdjointValue(swift::SILBasicBlock*, swift::SILValue, swift::autodiff::AdjointValue, swift::SILLocation) + 1286
12 swift-frontend           0x0000000106a9d607 swift::autodiff::PullbackCloner::Implementation::visit(swift::SILInstruction*) + 167
13 swift-frontend           0x0000000106a996bb swift::autodiff::PullbackCloner::Implementation::visitSILBasicBlock(swift::SILBasicBlock*) + 811
14 swift-frontend           0x0000000106a96aa7 swift::autodiff::PullbackCloner::Implementation::run() + 6967
15 swift-frontend           0x0000000106a94f42 swift::autodiff::PullbackCloner::run() + 18
16 swift-frontend           0x0000000106ab6308 swift::autodiff::VJPCloner::Implementation::run() + 1528
17 swift-frontend           0x0000000106ab69c2 swift::autodiff::VJPCloner::run() + 18
18 swift-frontend           0x0000000106bdc2b2 (anonymous namespace)::DifferentiationTransformer::canonicalizeDifferentiabilityWitness(swift::SILDifferentiabilityWitness*, swift::autodiff::DifferentiationInvoker, swift::IsSerialized_t) + 6882
19 swift-frontend           0x0000000106bd9dc8 (anonymous namespace)::Differentiation::run() + 1432
20 swift-frontend           0x0000000106c35581 swift::SILPassManager::runModulePass(unsigned int) + 689
21 swift-frontend           0x0000000106c3a57a swift::SILPassManager::execute() + 634
22 swift-frontend           0x0000000106c32168 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
23 swift-frontend           0x0000000106c320f1 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 65
24 swift-frontend           0x0000000106c52c7d swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 29
25 swift-frontend           0x0000000106c3d121 llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) + 241
26 swift-frontend           0x0000000106c323a2 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 82
27 swift-frontend           0x0000000106c401b7 swift::runSILDiagnosticPasses(swift::SILModule&) + 87
28 swift-frontend           0x00000001063f731c swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 60
29 swift-frontend           0x00000001062955f1 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*) + 625
30 swift-frontend           0x0000000106294c15 performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 693
31 swift-frontend           0x000000010628a265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3845
32 swift-frontend           0x000000010623c0a9 swift::mainEntry(int, char const**) + 553
33 libdyld.dylib            0x00007fff2033df3d start + 1
34 libdyld.dylib            0x0000000000000047 start + 18446603339975893259
error: Abort trap: 6 (in target 'VarDeclCrasher' from project 'VarDeclCrasher')
@rxwei
Copy link
Contributor

rxwei commented Dec 10, 2021

Accidental fix #40503

@astrotuna201
Copy link
Contributor

Unfortunately it seems this bug cropped up again in recent release (5.6, 2022-03-08) for the same tests as above:

% xcrun /Library/Developer/Toolchains/swift-5.6-RELEASE.xctoolchain/usr/bin/swift --version                

Apple Swift version 5.6 (swift-5.6-RELEASE)

Target: arm64-apple-macosx12.0

% xcrun /Library/Developer/Toolchains/swift-5.6-RELEASE.xctoolchain/usr/bin/swiftc crasher.swift -o crasher

error: compile command failed due to signal 6 (use -v to see invocation)

Assertion failed: ((!dyn_cast_or_null<VarDecl>(Loc.getAsASTNode<Decl>()) || Var) && "location is a VarDecl, but SILDebugVariable is empty"), function createAllocStack, file SILBuilder.h, line 389.

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-5.6-RELEASE.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file crasher.swift -target arm64-apple-macosx12.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -color-diagnostics -new-driver-path /Library/Developer/Toolchains/swift-5.6-RELEASE.xctoolchain/usr/bin/swift-driver -resource-dir /Library/Developer/Toolchains/swift-5.6-RELEASE.xctoolchain/usr/lib/swift -module-name crasher -target-sdk-version 12.3 -o /var/folders/hq/bm2zh17n5gq1xbhtvm30rj7r0000gn/T/TemporaryDirectory.XXxuRK/crasher-1.o

1. Apple Swift version 5.6 (swift-5.6-RELEASE)

2. Compiling with the current language version

3. While evaluating request ExecuteSILPipelineRequest(Run pipelines \{ Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for crasher)

4. While running pass #&#8203;142 SILModuleTransform "Differentiation".

5. While processing // differentiability witness for Test.init(v1:)

sil_differentiability_witness [serialized] [reverse] [parameters 0] [results 0] @$s7crasher4TestV2v1ACSaySaySfGG_tcfC : $@convention(method) (@owned Array<Array<Float>>, @thin Test.Type) -> @owned Test {

}

 

 on SIL function "@$s7crasher4TestV2v1ACSaySaySfGG_tcfC".

 for 'init(v1:)' (at crasher.swift:7:12)

6. While generating VJP for SIL function "@$s7crasher4TestV2v1ACSaySaySfGG_tcfC".

 for 'init(v1:)' (at crasher.swift:7:12)

7. While generating pullback for SIL function "@$s7crasher4TestV2v1ACSaySaySfGG_tcfC".

 for 'init(v1:)' (at crasher.swift:7:12)

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           0x0000000106b3c9a4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56

1  swift-frontend           0x0000000106b3bc04 llvm::sys::RunSignalHandlers() + 128

2  swift-frontend           0x0000000106b3d008 SignalHandler(int) + 304

3  libsystem_platform.dylib 0x000000019d5bd4c4 _sigtramp + 56

4  libsystem_pthread.dylib  0x000000019d5a5ee0 pthread_kill + 288

5  libsystem_c.dylib        0x000000019d4e0340 abort + 168

6  libsystem_c.dylib        0x000000019d4df754 err + 0

7  swift-frontend           0x0000000106b880e8 swift::SILCloner<(anonymous namespace)::TrivialCloner>::getOpType(swift::SILType) (.cold.1) + 0

8  swift-frontend           0x00000001029d8640 swift::SILBuilder::createAllocStack(swift::SILLocation, swift::SILType, llvm::Optional<swift::SILDebugVariable>, bool, bool) + 668

9  swift-frontend           0x0000000102f50ce8 swift::autodiff::TangentBuilder::emitAdd(swift::SILLocation, swift::SILValue, swift::SILValue) + 464

10 swift-frontend           0x0000000102f46cc4 swift::autodiff::PullbackCloner::Implementation::accumulateAdjointsDirect(swift::autodiff::AdjointValue, swift::autodiff::AdjointValue, swift::SILLocation) + 424

11 swift-frontend           0x0000000102f40b98 swift::autodiff::PullbackCloner::Implementation::addAdjointValue(swift::SILBasicBlock*, swift::SILValue, swift::autodiff::AdjointValue, swift::SILLocation) + 1172

12 swift-frontend           0x0000000102f4452c swift::autodiff::PullbackCloner::Implementation::visit(swift::SILInstruction*) + 200

13 swift-frontend           0x0000000102f40fbc swift::autodiff::PullbackCloner::Implementation::visitSILBasicBlock(swift::SILBasicBlock*) + 688

14 swift-frontend           0x0000000102f3e710 swift::autodiff::PullbackCloner::Implementation::run() + 5064

15 swift-frontend           0x0000000102f3d31c swift::autodiff::PullbackCloner::run() + 24

16 swift-frontend           0x0000000102f58ea8 swift::autodiff::VJPCloner::Implementation::run() + 1368

17 swift-frontend           0x0000000102f594c4 swift::autodiff::VJPCloner::run() + 24

18 swift-frontend           0x000000010304eeec (anonymous namespace)::DifferentiationTransformer::canonicalizeDifferentiabilityWitness(swift::SILDifferentiabilityWitness*, swift::autodiff::DifferentiationInvoker, swift::IsSerialized_t) + 5272

19 swift-frontend           0x000000010304d048 (anonymous namespace)::Differentiation::run() + 924

20 swift-frontend           0x00000001030a4eb4 swift::SILPassManager::runModulePass(unsigned int) + 632

21 swift-frontend           0x00000001030aa268 swift::SILPassManager::execute() + 628

22 swift-frontend           0x00000001030a1fe4 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 68

23 swift-frontend           0x00000001030a1f6c swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68

24 swift-frontend           0x00000001030bfc40 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28

25 swift-frontend           0x00000001030ac544 llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) + 252

26 swift-frontend           0x00000001030a21e0 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 84

27 swift-frontend           0x00000001030aebb4 swift::runSILDiagnosticPasses(swift::SILModule&) + 92

28 swift-frontend           0x0000000102967d34 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 68

29 swift-frontend           0x000000010282c608 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*) + 620

30 swift-frontend           0x000000010282be3c bool llvm::function_ref<bool (swift::CompilerInstance&)>::callback_fn<performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_19>(long, swift::CompilerInstance&) + 572

31 swift-frontend           0x0000000102822a8c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2960

32 swift-frontend           0x00000001027e1104 swift::mainEntry(int, char const**) + 524

33 dyld                     0x000000010f121088 start + 516

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself
Projects
None yet
Development

No branches or pull requests

3 participants