Created
September 8, 2016 13:12
-
-
Save ole/f33d64c06ca4517261c3fdab67830b4e to your computer and use it in GitHub Desktop.
Compiler segmentation fault in Xcode 8 GM using ExpressibleByArrayLiteral
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save this to stack.swift, then run | |
// | |
// $ xcrun swift stack.swift | |
// | |
// Does it compile or does the compiler segfault? | |
struct Stack<Element> { | |
var elements: [Element] = [] | |
} | |
extension Stack: ExpressibleByArrayLiteral { | |
init(arrayLiteral elements: Element...) { | |
self.elements = elements | |
} | |
} |
Same here:
→ xcrun swift stack.swift
0 swift 0x0000000109cb8b6d PrintStackTraceSignalHandler(void*) + 45
1 swift 0x0000000109cb85b6 SignalHandler(int) + 470
2 libsystem_platform.dylib 0x00007fffa3b15bba _sigtramp + 26
3 libsystem_platform.dylib 0x00007fff58ba1320 _sigtramp + 3037247360
4 swift 0x00000001071968b9 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 73
5 swift 0x00000001071d407d void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::EmitPolymorphicArguments::emit(swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::Substitution>, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&)::$_14>(long, swift::irgen::GenericRequirement) + 861
6 swift 0x00000001071c99e1 (anonymous namespace)::PolymorphicConvention::enumerateRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 129
7 swift 0x00000001071d3bdb swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::Substitution>, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) + 459
8 swift 0x00000001072304f5 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 2997
9 swift 0x000000010721b268 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9080
10 swift 0x00000001071414d0 swift::irgen::IRGenerator::emitLazyDefinitions() + 5216
11 swift 0x000000010720119b performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1723
12 swift 0x00000001071ff507 swift::performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&) + 1527
13 swift 0x00000001070e3a7b swift::RunImmediately(swift::CompilerInstance&, 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&, swift::IRGenOptions&, swift::SILOptions const&) + 187
14 swift 0x00000001070cf07e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23358
15 swift 0x00000001070c7265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
16 swift 0x000000010708482d main + 8685
17 libdyld.dylib 0x00007fffa3909255 start + 1
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret stack.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name stack
1. While emitting IR SIL function @_TFV5stack5StackCft12arrayLiteralGSax__GS0_x_ for 'init' at stack.swift:12:7
Segmentation fault: 11
→ swift --version
Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)
Target: x86_64-apple-macosx10.9
If you need a workaround for the time being, this seems to compile fine:
struct Stack<Element> {
var elements: [Element]
init(elements: [Element]) {
self.elements = elements
}
}
extension Stack: ExpressibleByArrayLiteral {
init(arrayLiteral elements: Element...) {
self.elements = elements
}
}
The problem seems to be related to the inline instantiation of the elements array.
@chrisfsampaio Ah, that's interesting, thanks. Another workaround is to explicitly call self.init
from the extension:
struct Stack<Element> {
var elements: [Element] = []
}
extension Stack: ExpressibleByArrayLiteral {
init(arrayLiteral elements: Element...) {
self.init(elements: elements)
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am seeing this with Xcode 8 GM seed:
Using
DEVELOPMENT-SNAPSHOT-2016-09-07-a
, it compiles fine:It also compiles fine with older snapshots, such as
DEVELOPMENT-SNAPSHOT-2016-08-07-a
, which is the oldest one I still have installed.