Skip to content
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

[SR-14140] Segmentation Fault. Protocol specializing function to @differentiable #55965

Open
swift-ci opened this issue Sep 9, 2020 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 9, 2020

Previous ID SR-14140
Radar rdar://problem/73833011
Original Reporter chip1967 (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @rxwei
Priority Medium

md5: 6f862fc922cf78c8f0dc37cfff9052fb

duplicates:

  • SR-13229 Derivative function protocol witness SILGen verification failure

Issue Description:

The following code causes the compiler to segmentation fault.

I am compiling with XCode 12 beta - development snapshot 2020-09-03.

public protocol Distribution {
  associatedtype Value
  func logProbability(of value: Value) -> Self
}


public protocol DifferentiableDistribution: Differentiable, Distribution
where Value: Differentiable {
  @differentiable(wrt: (self, value))
  func logProbability(of value: Value) -> Self
}


struct Foo<Value>: Distribution {
  func logProbability(of value: Value) -> Self {
    self
  }
}


extension Foo : Differentiable, DifferentiableDistribution
where Value: Differentiable
{
    
}
CompileSwift normal x86_64 /Users/chris/tmp/BugBug/Sources/BugBug/BugBug.swift (in target 'BugBug' from project 'BugBug')
    cd /Users/chris/tmp/BugBug
    /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2020-09-03-a.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/chris/tmp/BugBug/Sources/BugBug/Bug.swift -primary-file /Users/chris/tmp/BugBug/Sources/BugBug/BugBug.swift -emit-module-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug\~partial.swiftmodule -emit-module-doc-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug\~partial.swiftdoc -emit-module-source-info-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug\~partial.swiftsourceinfo -serialize-diagnostics-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug.dia -emit-dependencies-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug.d -emit-reference-dependencies-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug.swiftdeps -target x86_64-apple-macos10.15 -enable-objc-interop -sdk /Users/chris/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -I /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Products/Debug -I /Users/chris/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Products/Debug -F /Users/chris/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/chris/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity\=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -enable-anonymous-context-mangled-names -Xcc -I/Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/swift-overrides.hmap -Xcc -I/Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Products/Debug/include -Xcc -I/Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/DerivedSources-normal/x86_64 -Xcc -I/Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/DerivedSources/x86_64 -Xcc -I/Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG\=1 -Xcc -working-directory/Users/chris/tmp/BugBug -target-sdk-version 11.0 -module-name BugBug -o /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug.o -index-store-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Index/DataStore -index-system-modules

Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2020-09-03-a.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/chris/tmp/BugBug/Sources/BugBug/Bug.swift -primary-file /Users/chris/tmp/BugBug/Sources/BugBug/BugBug.swift -emit-module-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug~partial.swiftmodule -emit-module-doc-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug~partial.swiftdoc -emit-module-source-info-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug~partial.swiftsourceinfo -serialize-diagnostics-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug.dia -emit-dependencies-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug.d -emit-reference-dependencies-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug.swiftdeps -target x86_64-apple-macos10.15 -enable-objc-interop -sdk /Users/chris/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -I /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Products/Debug -I /Users/chris/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Products/Debug -F /Users/chris/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/chris/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -enable-anonymous-context-mangled-names -Xcc -I/Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/swift-overrides.hmap -Xcc -I/Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Products/Debug/include -Xcc -I/Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/DerivedSources-normal/x86_64 -Xcc -I/Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/DerivedSources/x86_64 -Xcc -I/Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -Xcc -working-directory/Users/chris/tmp/BugBug -target-sdk-version 11.0 -module-name BugBug -o /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Build/Intermediates.noindex/BugBug.build/Debug/BugBug.build/Objects-normal/x86_64/BugBug.o -index-store-path /Users/chris/Library/Developer/Xcode/DerivedData/Bug-gzpyqxezwciizkfaqugrjrxyribl/Index/DataStore -index-system-modules 
1.  Swift version 5.3-dev (LLVM 14a10d635b229fb, Swift 39c6ee112f95980)
2.  While evaluating request IRGenRequest(IR Generation for file "/Users/chris/tmp/BugBug/Sources/BugBug/BugBug.swift")
3.  While emitting IR SIL function "@AD__$s03BugA03FooV14logProbability2ofACyxGx_tF__vjp_src_0_wrt_0_1_l".
 for 'logProbability(of:)' (at /Users/chris/tmp/BugBug/Sources/BugBug/BugBug.swift:18:3)
0  swift-frontend           0x0000000110b460f5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift-frontend           0x0000000110b45365 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x0000000110b466c6 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff67c085fd _sigtramp + 29
4  libsystem_platform.dylib 0x00007f9d7e20e200 _sigtramp + 18446743653178170400
5  swift-frontend           0x000000010cc1fe9d void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::PolymorphicConvention::enumerateUnfulfilledRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&)::$_11>(long, swift::irgen::GenericRequirement) + 205
6  swift-frontend           0x000000010cc1b844 (anonymous namespace)::PolymorphicConvention::enumerateUnfulfilledRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 180
7  swift-frontend           0x000000010cc1b642 swift::irgen::NecessaryBindings::computeBindings(swift::irgen::IRGenModule&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap, bool, bool) + 354
8  swift-frontend           0x000000010cc1b777 swift::irgen::NecessaryBindings::forPartialApplyForwarder(swift::irgen::IRGenModule&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap, bool) + 23
9  swift-frontend           0x000000010cbcbf68 swift::irgen::emitFunctionPartialApplication(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::FunctionPointer const&, llvm::Value*, swift::irgen::Explosion&, llvm::ArrayRef<swift::SILParameterInfo>, swift::SubstitutionMap, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::irgen::Explosion&, bool) + 680
10 swift-frontend           0x000000010cc97626 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 78150
11 swift-frontend           0x000000010cc80dc9 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 6825
12 swift-frontend           0x000000010cb7eea1 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) + 753
13 swift-frontend           0x000000010cc56b60 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 880
14 swift-frontend           0x000000010cc7f2e5 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 37
15 swift-frontend           0x000000010cc5c7bc llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 492
16 swift-frontend           0x000000010cc5921b swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 347
17 swift-frontend           0x000000010c9f0b96 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*) + 2182
18 swift-frontend           0x000000010c9efffc performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 332
19 swift-frontend           0x000000010c9e8682 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4658
20 swift-frontend           0x000000010c987683 main + 835
21 libdyld.dylib            0x00007fff67a0fcc9 start + 1
error: Segmentation fault: 11 (in target 'BugBug' from project 'BugBug')
@rxwei
Copy link
Member

rxwei commented Feb 1, 2021

@swift-ci create

@rxwei
Copy link
Member

rxwei commented Feb 1, 2021

The original reproducer no longer causes a crash. However the following slightly modified example (added where Value: Differentiable in the @differentiable attribute on Foo) causes a crash on the latest compiler:

import _Differentiation

public protocol Distribution {
  associatedtype Value
  func logProbability(of value: Value) -> Self
}


public protocol DifferentiableDistribution: Differentiable, Distribution
where Value: Differentiable {
  @differentiable(wrt: (self, value))
  func logProbability(of value: Value) -> Self
}


struct Foo<Value>: Distribution {
  @differentiable(wrt: (self, value) where Value: Differentiable)
  func logProbability(of value: Value) -> Self {
    self
  }
}


extension Foo : Differentiable, DifferentiableDistribution
where Value: Differentiable
{
}

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

3 participants