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-12327] Compiler crashes when specializing generic #54758

Closed
swift-ci opened this issue Mar 6, 2020 · 3 comments
Closed

[SR-12327] Compiler crashes when specializing generic #54758

swift-ci opened this issue Mar 6, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances crash Bug: A crash, i.e., an abnormal termination of software generics Feature: generic declarations and types optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Mar 6, 2020

Previous ID SR-12327
Radar rdar://problem/60219705
Original Reporter jacob.weightman (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment
  • Reproducible 100% of the time with Xcode 11.3 and 11.4 beta

  • Optimize for speed

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, OptimizedOnly
Assignee None
Priority Medium

md5: c5609d3eaadeea2e25c7882c96396688

Issue Description:

Here's a minimal example:

protocol A {
    associatedtype Foo // Does not crash if renamed
}

protocol B {
    associatedtype Foo // Does not crash if renamed
    var aFoo: Foo { get }
}

public struct Wrapper<T> {
    let wrapped: T
}

// Removing this extension or combining it with the next one prevents the crash
extension Wrapper: A where T: A {
    typealias Foo = Wrapper<T.Foo>
}

extension Wrapper: B where T: B {
    var aFoo: Wrapper<T.Foo> {
        return .init(wrapped: wrapped.aFoo)
    }
}

public struct Model: B {
    public struct Foo {}

    public var aFoo: Foo {
        return Foo()
    }
}

// Attempting to specialize this method for Wrapper<Model> crashes the compiler
func fooString<Body: B>(body: Body) -> String {
    return "\(body.aFoo)"
}

// This public method causes encode to be specialized for [Model] when compiled with optimizations for speed
public func foo(_ command: Wrapper<Model>) -> String {
    return fooString(body: command)
}

Crash report from Xcode 11.4 beta (illegal instruction):

Unable to find source-code formatter for language: log. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml1. Apple Swift version 5.2 (swiftlang-1103.0.30 clang-1103.0.30)
2.  While running pass #&#8203;10 SILFunctionTransform "AllocStackHoisting" on SILFunction "@$s5crash3fooySSAA7WrapperVyAA5ModelVGF".
 for 'foo(_:)' (at /Users/jacobweightman/Desktop/crash/crash/Crash.swift:39:8)
3.  While converting type 'Wrapper<Model>.Foo'
0  swift                    0x00000001114724ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000111471cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff72a2342d _sigtramp + 29
3  libsystem_platform.dylib 0x0000000000000008 _sigtramp + 2371734520
4  swift                    0x000000010d230139 (anonymous namespace)::AllocStackHoisting::run() + 537
5  swift                    0x000000010d8d06ad swift::SILPassManager::execute() + 6637
6  swift                    0x000000010d3d8228 runIRGenPreparePasses(swift::SILModule&, swift::irgen::IRGenModule&) + 1384
7  swift                    0x000000010d3d8e7f performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1055
8  swift                    0x000000010d1d033f performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 4255
9  swift                    0x000000010d1c5790 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48416
10 swift                    0x000000010d13d4a3 main + 1283
11 libdyld.dylib            0x00007fff7282a7fd start + 1
12 libdyld.dylib            0x0000000000000045 start + 2373802057
error: Illegal instruction: 4 (in target 'crash' from project 'crash')

Crash report from Xcode 11.3 (segfault):

Unable to find source-code formatter for language: log. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml1. While running pass #&#8203;680 SILFunctionTransform "GenericSpecializer" on SILFunction "@$s5crash3fooySSAA7WrapperVyAA5ModelVGF".
 for 'foo(_:)' (at /Users/jacobweightman/Desktop/crash/crash/Crash.swift:39:8)
0  swift                    0x00000001087b1a63 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x00000001087b1236 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff72a2342d _sigtramp + 29
3  libsystem_platform.dylib 0x00007fdb569035b0 _sigtramp + 3824026016
4  swift                    0x0000000104be24b9 swift::TypeSubstCloner<swift::GenericCloner, swift::SILOptFunctionBuilder>::remapType(swift::SILType) + 329
5  swift                    0x0000000104bf23aa swift::SILInstructionVisitor<swift::GenericCloner, void>::visit(swift::SILInstruction*) + 60554
6  swift                    0x0000000104be1893 swift::GenericCloner::populateCloned() + 5907
7  swift                    0x0000000104c51167 swift::GenericFuncSpecializer::tryCreateSpecialization() + 1095
8  swift                    0x0000000104c52f52 swift::trySpecializeApplyOfGeneric(swift::SILOptFunctionBuilder&, swift::ApplySite, llvm::SmallSetVector<swift::SILInstruction*, 8u>&, llvm::SmallVectorImpl<swift::SILFunction*>&, swift::OptRemark::Emitter&) + 2322
9  swift                    0x0000000104b2b7b1 (anonymous namespace)::GenericSpecializer::run() + 2673
10 swift                    0x0000000104aa4fbe swift::SILPassManager::execute() + 4606
11 swift                    0x00000001047039eb swift::CompilerInstance::performSILProcessing(swift::SILModule*, swift::UnifiedStatsReporter*) + 6379
12 swift                    0x00000001043fbf45 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 33925
13 swift                    0x00000001043f02b4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
14 swift                    0x000000010437d7b3 main + 1219
15 libdyld.dylib            0x00007fff7282a7fd start + 1
error: Segmentation fault: 11 (in target 'crash' from project 'crash')
@theblixguy
Copy link
Collaborator

cc @eeckstein

@eeckstein
Copy link
Member

@swift-ci create

@slavapestov
Copy link
Member

#33493

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added crash Bug: A crash, i.e., an abnormal termination of software generics Feature: generic declarations and types conformances Feature → protocol: protocol conformances labels Dec 12, 2022
This issue was closed.
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 conformances Feature → protocol: protocol conformances crash Bug: A crash, i.e., an abnormal termination of software generics Feature: generic declarations and types optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

5 participants