Last active
August 7, 2021 11:04
-
-
Save GreatApe/a6e29441fd4c377dd7bc1c22a3706a86 to your computer and use it in GitHub Desktop.
Generic segmentation fault
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
// TestType - constrained to built-in protocol, uses conditional conformance (a) | |
struct TestType<T: Error> { } | |
// Conditional conformance (b) | |
extension Array: Error where Element: Error { } | |
struct GenericType<G> { | |
// FAILS: These both segmentation fault (c) | |
func test<T>(_ value: TestType<[T]>) { } | |
// static func test<T>(_ value: TestType<[T]>) { } | |
// FAILS: It doesn't help to ensure the compiler that T is Error, which it knows means that [T] also is | |
// func test<T>(_ value: TestType<[T]>) where T: Error { } | |
// But if TestType<[T]> is in the return type, it works (d) | |
func test<T>() -> TestType<[T]> { fatalError() } | |
// This is also ok, without the array, so it's related to conditional conformance (b) | |
func test<T>(_ value: TestType<T>) { } | |
// Also fine, where we use the generic parameter of the type (c) | |
func test(_ value: TestType<[G]>) where G: Error { } | |
} | |
struct NonGEnericType { | |
// And this, where the only difference is that the outer type is no longer generic (c) | |
func test<T>(_ value: TestType<[T]>) { } | |
} | |
// PestType - constrained to our own protocol, uses conditional conformance (a) | |
protocol Terror { } | |
struct PestType<T: Terror> { } | |
extension Array: Terror where Element: Terror { } | |
// This works, using PestType which is completely analogous to TestType, | |
// except that its constraint is to a homemade protocol | |
struct Pest<G> { | |
func test<T>(_ value: PestType<[T]>) { } | |
} | |
/* So the following are needed to cause the segfault: | |
- Using a built-in protocol (a) | |
- Conditional conformance (with the conditional protocol either the same or different) (b) | |
- The test type must be generic, with a different parameter than the test function (c) | |
- The conditionally conformed type must be an input parameter, not return (d) | |
(b) | |
// Conditional conformance - this also segfaults | |
extension Array: Error where Element: RawRepresentable { } | |
// Without conditional conformance - but this works | |
extension Array: Error { } | |
*/ | |
/* | |
1. Apple Swift version 5.5 (swiftlang-1300.0.27.6 clang-1300.0.27.2) | |
2. | |
3. While evaluating request IRGenRequest(IR Generation for file "Bug.swift") | |
4. While emitting IR SIL function "@$s7asfsadf4TestV4testyyAA9RawValuedVySayqd__GAGSYAAqd__SYHD1__HCg_GSYRd__lF". | |
for 'test(_:)' (at Bug.swift:53:5) | |
5. While mangling type for debugger type 'RawValued<Array<T>>' (declared at [Bug.swift:12:1 - line:12:41] RangeText="struct RawValued<T: RawRepresentable> { ") | |
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 0x000000010868cd18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56 | |
1 swift-frontend 0x000000010868be20 llvm::sys::RunSignalHandlers() + 128 | |
2 swift-frontend 0x000000010868d358 SignalHandler(int) + 292 | |
3 libsystem_platform.dylib 0x00000001a0912c44 _sigtramp + 56 | |
4 swift-frontend 0x000000010542a5ac swift::GenericSignatureImpl::getConformanceAccessPath(swift::Type, swift::ProtocolDecl*) const + 68 | |
5 swift-frontend 0x00000001052dbb08 swift::Mangle::ASTMangler::appendAnyProtocolConformance(swift::CanGenericSignature, swift::CanType, swift::ProtocolConformanceRef) + 64 | |
6 swift-frontend 0x00000001052d9728 swift::Mangle::ASTMangler::appendConcreteProtocolConformance(swift::ProtocolConformance const*) + 1688 | |
7 swift-frontend 0x00000001052d80f4 swift::Mangle::ASTMangler::appendRetroactiveConformances(swift::SubstitutionMap, swift::ModuleDecl*) + 184 | |
8 swift-frontend 0x00000001052d7b94 swift::Mangle::ASTMangler::appendRetroactiveConformances(swift::Type) + 468 | |
9 swift-frontend 0x00000001052d07f0 swift::Mangle::ASTMangler::appendType(swift::Type, swift::ValueDecl const*) + 2836 | |
10 swift-frontend 0x00000001052d51fc swift::Mangle::ASTMangler::mangleTypeForDebugger(swift::Type, swift::GenericSignature) + 540 | |
11 swift-frontend 0x000000010486fda0 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) + 1304 | |
12 swift-frontend 0x000000010486ba20 (anonymous namespace)::IRGenDebugInfoImpl::emitVariableDeclaration(swift::irgen::IRBuilder&, llvm::ArrayRef<llvm::Value*>, swift::irgen::DebugTypeInfo, swift::SILDebugScope const*, swift::ValueDecl*, swift::SILDebugVariable, swift::irgen::IndirectionKind, swift::irgen::ArtificialKind) + 560 | |
13 swift-frontend 0x000000010489c134 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 70916 | |
14 swift-frontend 0x00000001048861bc swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 7732 | |
15 swift-frontend 0x0000000104760a08 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&) + 1332 | |
16 swift-frontend 0x000000010485a19c swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 7572 | |
17 swift-frontend 0x00000001048840b0 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 188 | |
18 swift-frontend 0x0000000104864618 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 752 | |
19 swift-frontend 0x000000010485de3c 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**) + 236 | |
20 swift-frontend 0x0000000104428f20 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*) + 2540 | |
21 swift-frontend 0x000000010441c1dc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6428 | |
22 swift-frontend 0x0000000104376bc0 main + 932 | |
23 libdyld.dylib 0x00000001a08e5450 start + 4 | |
error: Segmentation fault: 11 (in target 'asfsadf' from project 'asfsadf') | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment