Skip to content

[SR-8643] Crash in mapReplacementTypesOutOfContext() #51158

@rjmccall

Description

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

md5: 884b307466166683e6b62e14403a9882

Issue Description:

harza:/tmp$ cat other.swift
public protocol P {}
public protocol Q {}

public class A : P {}
public class B : A {}

public struct D<T: P> {}

public struct C<T: P> {
  public var x: D<T> { fatalError("death") }
}

harza:/tmp$ swiftc -frontend -enable-key-path-resilience -emit-module other.swift -o other.swiftmodule
harza:/tmp$ cat test.swift 
import other

class M<T: P> : P {}
func foo<T3: B, T4: M<T3>>(t: T3, u: T4) {
  let _ = \C<T4>.x
}
harza:/tmp$swiftc -frontend -enable-key-path-resilience test.swift -emit-silgen -I .
Assertion failed: (nominalDecl && "expected nominal type here"), function getSuperclassForDecl, file /Volumes/Data/swift/tools/swift/lib/AST/Type.cpp, line 3185.
Stack dump:
0.  Program arguments: swiftc -frontend -enable-key-path-resilience test.swift -emit-silgen -I . 
1.  While emitting SIL for 'foo(t:u:)' at test.swift:4:1
2.  While silgen emitFunction SIL function "@$S4test3foo1t1uyx_q_t5other1BCRbzAA1MCyxGRb_r0_lF".
 for 'foo(t:u:)' at test.swift:4:1
0  swiftc                   0x000000010e65050c llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  swiftc                   0x000000010e650ad9 PrintStackTraceSignalHandler(void*) + 25
2  swiftc                   0x000000010e64d2ee llvm::sys::RunSignalHandlers() + 990
3  swiftc                   0x000000010e651725 SignalHandler(int) + 485
4  libsystem_platform.dylib 0x00007fff62c14f5a _sigtramp + 26
5  swiftc                   0x0000000108baf59a llvm::IntrusiveRefCntPtr<swift::AnyRequest::HolderBase>::retain() + 42
6  libsystem_c.dylib        0x00007fff629b21ae abort + 127
7  libsystem_c.dylib        0x00007fff6297a1ac basename_r + 0
8  swiftc                   0x0000000108ddb1e0 swift::TypeBase::getSuperclassForDecl(swift::ClassDecl const*, bool) + 176
9  swiftc                   0x0000000108dad4ce swift::ProtocolConformance::subst(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>) const + 1054
10 swiftc                   0x0000000108dacf4d swift::ProtocolConformanceRef::subst(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>) const + 509
11 swiftc                   0x0000000108dc85ab swift::SubstitutionMap::subst(llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>) const::$_3::operator()(swift::CanType, swift::Type, swift::ProtocolDecl*) const + 347
12 swiftc                   0x0000000108dc840c llvm::Optional<swift::ProtocolConformanceRef> llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>::callback_fn<swift::SubstitutionMap::subst(llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>) const::$_3>(long, swift::CanType, swift::Type, swift::ProtocolDecl*) + 108
13 swiftc                   0x0000000108de446e llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>::operator()(swift::CanType, swift::Type, swift::ProtocolDecl*) const + 126
14 swiftc                   0x0000000108dc60db swift::SubstitutionMap::get(swift::GenericSignature*, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>) + 1115
15 swiftc                   0x0000000108dc6f44 swift::SubstitutionMap::subst(llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>) const + 212
16 swiftc                   0x0000000108dc6e62 swift::SubstitutionMap::mapReplacementTypesOutOfContext() const + 82
17 swiftc                   0x00000001071cbebb swift::Lowering::SILGenModule::emitKeyPathComponentForDecl(swift::SILLocation, swift::GenericEnvironment*, unsigned int&, bool&, swift::SubstitutionMap, swift::AbstractStorageDecl*, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::CanType, bool) + 427
18 swiftc                   0x00000001071f6af3 (anonymous namespace)::RValueEmitter::visitKeyPathExpr(swift::KeyPathExpr*, swift::Lowering::SGFContext) + 1283
19 swiftc                   0x00000001071d9b2a swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 7226
20 swiftc                   0x00000001071c3416 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 198
21 swiftc                   0x00000001071c3164 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 356
22 swiftc                   0x000000010719e94e swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 590
23 swiftc                   0x000000010719ec6f swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*) + 159
24 swiftc                   0x00000001070f836e swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 1534
25 swiftc                   0x00000001072b6764 (anonymous namespace)::StmtEmitter::visitBraceStmt(swift::BraceStmt*) + 1236
26 swiftc                   0x00000001072b2e7c swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 92
27 swiftc                   0x00000001072b2de0 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 48
28 swiftc                   0x000000010721aea5 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 517
29 swiftc                   0x0000000107108e89 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 489
30 swiftc                   0x00000001070f14fa void emitOrDelayFunction<swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1>(swift::Lowering::SILGenModule&, swift::SILDeclRef, swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1&&, bool) + 922
31 swiftc                   0x00000001070efdd2 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 738
32 swiftc                   0x00000001070efadd swift::Lowering::SILGenModule::visitFuncDecl(swift::FuncDecl*) + 29
33 swiftc                   0x00000001070f9570 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 1072
34 swiftc                   0x00000001070f8f17 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 263
35 swiftc                   0x00000001070f9f70 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) + 1328
36 swiftc                   0x00000001070fab05 swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&, bool) + 101
37 swiftc                   0x0000000105ea1729 generateSILModules(swift::CompilerInvocation&, swift::CompilerInstance&) + 1609
38 swiftc                   0x0000000105e96454 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 3396
39 swiftc                   0x0000000105e93882 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5058
40 swiftc                   0x0000000105db97d5 run_driver(llvm::StringRef, llvm::ArrayRef<char const*>) + 917
41 swiftc                   0x0000000105db8095 main + 4005
42 libdyld.dylib            0x00007fff62906015 start + 1
43 libdyld.dylib            0x0000000000000007 start + 2641338355
Abort trap: 6

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions