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-11714] Compiler crash when generic class is passed as a parameter to a function accepting a generic class composition type #54123

Open
zoecarver opened this issue Nov 5, 2019 · 3 comments
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 optimized only Flag: An issue whose reproduction requires optimized compilation SILOptimizer Area → compiler: SIL optimization passes

Comments

@zoecarver
Copy link
Collaborator

Previous ID SR-11714
Radar rdar://problem/56923071
Original Reporter @zoecarver
Type Bug
Environment

link title

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

md5: 85d7362c02354745e1c97f009f986a30

Issue Description:

This crash is similar to SR-11624 but, it happens when the argument of both functions are generic.

Example crash from master (built in the last 24 hours) invoked with: swiftc run.swift -O -wmo -emit-sil

public class ClassA<T> { }


protocol ProtocolA {
  func foo() -> Int
}


public class ClassB<T>: ClassA<T> {
  func foo() -> Int {
    return 10
  }
}


extension ClassB: ProtocolA { }


func shouldOptimize1<T>(_ x: ClassA<T> & ProtocolA) -> Int {
  return x.foo()
}


public func entryPoint1<T>(c: ClassB<T>) -> Int {
  return shouldOptimize1(c)
}
@beccadax
Copy link
Contributor

beccadax commented Nov 5, 2019

Reproduced in 11/1 master snapshot toolchain. (Guru meditation: swift_2019-11-05-145206.)

Assertion failed: (Val && "isa<> used on a null pointer"), function doit, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/llvm/include/llvm/Support/Casting.h, line 105.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-11-01-a.xctoolchain/usr/bin/swift -frontend -emit-sil - -target x86_64-apple-darwin19.0.0 -enable-objc-interop -color-diagnostics -O -module-name main -o - 
1.  Apple Swift version 5.1.1-dev (Swift 74328cdda2)
2.  While running pass #&#8203;418 SILFunctionTransform "SILCombine" on SILFunction "@$s4main11entryPoint11cSiAA6ClassBCyxG_tlF".
 for 'entryPoint1(c:)' (at <stdin>:24:8)
0  swift                    0x00000001072f6c35 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001072f5ee5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001072f7218 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff624abb1d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000004c30 _sigtramp + 2645922096
5  libsystem_c.dylib        0x00007fff62381a08 abort + 120
6  libsystem_c.dylib        0x00007fff62380cc2 err + 0
7  swift                    0x00000001074a3ee1 swift::SILCombiner::buildConcreteOpenedExistentialInfoFromSoleConformingType(swift::Operand&) (.cold.4) + 33
8  swift                    0x0000000103cb6c44 swift::SILCombiner::buildConcreteOpenedExistentialInfoFromSoleConformingType(swift::Operand&) + 1524
9  swift                    0x0000000103cb6e31 swift::SILCombiner::buildConcreteOpenedExistentialInfos(swift::FullApplySite, llvm::SmallDenseMap<unsigned int, swift::ConcreteOpenedExistentialInfo, 4u, llvm::DenseMapInfo<unsigned int>, llvm::detail::DenseMapPair<unsigned int, swift::ConcreteOpenedExistentialInfo> >&, swift::SILBuilderContext&, swift::SILOpenedArchetypesTracker&) + 257
10 swift                    0x0000000103cb8b6a swift::SILCombiner::propagateConcreteTypeOfInitExistential(swift::FullApplySite) + 282
11 swift                    0x0000000103cb9a90 swift::SILCombiner::visitApplyInst(swift::ApplyInst*) + 816
12 swift                    0x0000000103cad99b swift::SILCombiner::doOneIteration(swift::SILFunction&, unsigned int) + 1259
13 swift                    0x0000000103caf74f (anonymous namespace)::SILCombine::run() + 623
14 swift                    0x0000000103c9a0ef swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) + 1711
15 swift                    0x0000000103c9ad4f swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 1055
16 swift                    0x0000000103c9bdee swift::SILPassManager::execute() + 606
17 swift                    0x000000010384f88b swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 187
18 swift                    0x0000000103ca3425 swift::runSILOptimizationPasses(swift::SILModule&) + 117
19 swift                    0x00000001039136f5 swift::CompilerInstance::performSILProcessing(swift::SILModule*, swift::UnifiedStatsReporter*) + 981
20 swift                    0x0000000103704fbf 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*) + 1391
21 swift                    0x00000001036faa1e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 7118
22 swift                    0x00000001036f7ed6 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3046
23 swift                    0x000000010369d2d9 main + 729
24 libdyld.dylib            0x00007fff622aa325 start + 1
25 libdyld.dylib            0x000000000000000d start + 2648005865

@beccadax
Copy link
Contributor

beccadax commented Nov 5, 2019

@swift-ci create

@zoecarver
Copy link
Collaborator Author

brentdax (JIRA User) that's an older build. That stack trace was resolved with SR-11624. Here's the current stack trace (as of last night):

SIL verification failed: Operand is of an ArchetypeType that does not exist in the Caller's generic param list.: isArchetypeValidInFunction(A, F)
Verifying instruction:
   %0 = argument of bb0 : $τ_1_0                 // user: %1
->   %1 = init_existential_ref %0 : $τ_1_0 : $τ_1_0, $ClassA<T> & ProtocolA // users: %3, %2
     debug_value %1 : $ClassA<T> & ProtocolA, let, name "x", argno 1 // id: %2
     %3 = open_existential_ref %1 : $ClassA<T> & ProtocolA to $@opened("1A205440-FF82-11E9-A915-ACBC329C418B") ClassA<τ_0_0> & ProtocolA // users: %7, %6, %5, %4
In function:
// specialized shouldOptimize1<A>(_:)
sil shared @$s3run15shouldOptimize1ySiAA9ProtocolA_AA6ClassACyxGXclFTf4e_n : $@convention(thin) <τ_0_0><τ_1_0 where τ_1_0 : ClassA<τ_0_0>, τ_1_0 : ProtocolA> (@guaranteed τ_1_0) -> Int {
// %0                                             // user: %1
bb0(%0 : $τ_1_0):
  %1 = init_existential_ref %0 : $τ_1_0 : $τ_1_0, $ClassA<T> & ProtocolA // users: %3, %2
  debug_value %1 : $ClassA<T> & ProtocolA, let, name "x", argno 1 // id: %2
  %3 = open_existential_ref %1 : $ClassA<T> & ProtocolA to $@opened("1A205440-FF82-11E9-A915-ACBC329C418B") ClassA<τ_0_0> & ProtocolA // users: %7, %6, %5, %4
  %4 = alloc_stack $@opened("1A205440-FF82-11E9-A915-ACBC329C418B") ClassA<τ_0_0> & ProtocolA // type-defs: %3; users: %8, %7, %5
  store %3 to %4 : $*@opened("1A205440-FF82-11E9-A915-ACBC329C418B") ClassA<τ_0_0> & ProtocolA // id: %5
  %6 = witness_method $@opened("1A205440-FF82-11E9-A915-ACBC329C418B") ClassA<τ_0_0> & ProtocolA, #ProtocolA.foo!1 : <Self where Self : ProtocolA> (Self) -> () -> Int, %3 : $@opened("1A205440-FF82-11E9-A915-ACBC329C418B") ClassA<τ_0_0> & ProtocolA : $@convention(witness_method: ProtocolA) <τ_0_0 where τ_0_0 : ProtocolA> (@in_guaranteed τ_0_0) -> Int // type-defs: %3; user: %7
  %7 = apply %6<@opened("1A205440-FF82-11E9-A915-ACBC329C418B") ClassA<τ_0_0> & ProtocolA>(%4) : $@convention(witness_method: ProtocolA) <τ_0_0 where τ_0_0 : ProtocolA> (@in_guaranteed τ_0_0) -> Int // type-defs: %3; user: %9
  dealloc_stack %4 : $*@opened("1A205440-FF82-11E9-A915-ACBC329C418B") ClassA<τ_0_0> & ProtocolA // id: %8
  return %7 : $Int                                // id: %9
} // end sil function '$s3run15shouldOptimize1ySiAA9ProtocolA_AA6ClassACyxGXclFTf4e_n'

Stack dump:
0.  Program arguments: /Users/zoe/Developer/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swift -frontend -emit-sil -primary-file run.swift -target x86_64-apple-darwin18.6.0 -enable-objc-interop -color-diagnostics -O -module-name run -o -
1.  Swift version 5.1.1-dev (Swift 74328cdda2)
2.  While verifying SIL function "@$s3run15shouldOptimize1ySiAA9ProtocolA_AA6ClassACyxGXclFTf4e_n".
 for 'shouldOptimize1(_:)' (at run.swift:21:1)
0  swift                    0x0000000112e51bfc llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  swift                    0x0000000112e52159 PrintStackTraceSignalHandler(void*) + 25
2  swift                    0x0000000112e4fe16 llvm::sys::RunSignalHandlers() + 118
3  swift                    0x0000000112e55ad2 SignalHandler(int) + 210
4  libsystem_platform.dylib 0x00007fff7a1bfb5d _sigtramp + 29
5  libsystem_platform.dylib 0x000000012d945ee8 _sigtramp + 3011011496
6  libsystem_c.dylib        0x00007fff7a0796a6 abort + 127
7  swift                    0x000000010b33c192 (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) + 386
8  swift                    0x000000010b350d97 (anonymous namespace)::SILVerifier::checkLegalSILType(swift::SILFunction*, swift::CanType, swift::SILInstruction*)::'lambda'(swift::CanType)::operator()(swift::CanType) const + 247
9  swift                    0x000000010b350c98 void llvm::function_ref<void (swift::CanType)>::callback_fn<(anonymous namespace)::SILVerifier::checkLegalSILType(swift::SILFunction*, swift::CanType, swift::SILInstruction*)::'lambda'(swift::CanType)>(long, swift::CanType) + 56
10 swift                    0x000000010b297d64 llvm::function_ref<void (swift::CanType)>::operator()(swift::CanType) const + 68
11 swift                    0x000000010b297d10 swift::CanType::visit(llvm::function_ref<void (swift::CanType)>) const::'lambda'(swift::Type)::operator()(swift::Type) const + 64
12 swift                    0x000000010b297cb8 bool llvm::function_ref<bool (swift::CanType)>::callback_fn<swift::CanType::visit(llvm::function_ref<void (swift::CanType)>) const::'lambda'(swift::Type)>(long, swift::CanType) + 56
13 swift                    0x000000010c574c34 llvm::function_ref<bool (swift::CanType)>::operator()(swift::CanType) const + 68
14 swift                    0x000000010c574bd0 swift::CanType::findIf(llvm::function_ref<bool (swift::CanType)>) const::'lambda'(swift::Type)::operator()(swift::Type) const + 64
15 swift                    0x000000010c574b78 bool llvm::function_ref<bool (swift::Type)>::callback_fn<swift::CanType::findIf(llvm::function_ref<bool (swift::CanType)>) const::'lambda'(swift::Type)>(long, swift::Type) + 56
16 swift                    0x000000010c583244 llvm::function_ref<bool (swift::Type)>::operator()(swift::Type) const + 68
17 swift                    0x000000010c583194 swift::Type::findIf(llvm::function_ref<bool (swift::Type)>) const::Walker::walkToTypePre(swift::Type) + 52
18 swift                    0x000000010c5bee82 (anonymous namespace)::Traversal::doIt(swift::Type) + 50
19 swift                    0x000000010c5c0e5c (anonymous namespace)::Traversal::visitBoundGenericType(swift::BoundGenericType*) + 204
20 swift                    0x000000010c5bfe78 swift::TypeVisitor<(anonymous namespace)::Traversal, bool>::visitBoundGenericClassType(swift::BoundGenericClassType*) + 40
21 swift                    0x000000010c5bf395 swift::TypeVisitor<(anonymous namespace)::Traversal, bool>::visit(swift::Type) + 869
22 swift                    0x000000010c5beeeb (anonymous namespace)::Traversal::doIt(swift::Type) + 155
23 swift                    0x000000010c5c08fc (anonymous namespace)::Traversal::visitProtocolCompositionType(swift::ProtocolCompositionType*) + 124
24 swift                    0x000000010c5bf719 swift::TypeVisitor<(anonymous namespace)::Traversal, bool>::visit(swift::Type) + 1769
25 swift                    0x000000010c5beeeb (anonymous namespace)::Traversal::doIt(swift::Type) + 155
26 swift                    0x000000010c5bee0b swift::Type::walk(swift::TypeWalker&) const + 75
27 swift                    0x000000010c57378d swift::Type::walk(swift::TypeWalker&&) const + 29
28 swift                    0x000000010c55f5e0 swift::Type::findIf(llvm::function_ref<bool (swift::Type)>) const + 80
29 swift                    0x000000010c55ee99 swift::CanType::findIf(llvm::function_ref<bool (swift::CanType)>) const + 73
30 swift                    0x000000010b297bbc swift::CanType::visit(llvm::function_ref<void (swift::CanType)>) const + 76
31 swift                    0x000000010b350bb9 (anonymous namespace)::SILVerifier::checkLegalSILType(swift::SILFunction*, swift::CanType, swift::SILInstruction*) + 953
32 swift                    0x000000010b3507bd (anonymous namespace)::SILVerifier::checkLegalType(swift::SILFunction*, swift::SILType, swift::SILInstruction*) + 77
33 swift                    0x000000010b34fa7a (anonymous namespace)::SILVerifier::checkLegalType(swift::SILFunction*, swift::ValueBase*, swift::SILInstruction*) + 250
34 swift                    0x000000010b355c43 (anonymous namespace)::SILVerifier::visitSILInstruction(swift::SILInstruction*) + 451
35 swift                    0x000000010b355a78 swift::SILInstructionVisitor<(anonymous namespace)::SILVerifier, void>::visitSingleValueInstruction(swift::SingleValueInstruction*) + 40
36 swift                    0x000000010b354677 (anonymous namespace)::SILVerifierBase<(anonymous namespace)::SILVerifier>::visitInitExistentialRefInst(swift::InitExistentialRefInst*) + 39
37 swift                    0x000000010b34e70d swift::SILInstructionVisitor<(anonymous namespace)::SILVerifier, void>::visit(swift::SILInstruction*) + 4269
38 swift                    0x000000010b34c7da swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) + 138
39 swift                    0x000000010b348076 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 710
40 swift                    0x000000010b34001b (anonymous namespace)::SILVerifier::visitSILBasicBlocks(swift::SILFunction*) + 187
41 swift                    0x000000010b33e35a (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 794
42 swift                    0x000000010b337519 (anonymous namespace)::SILVerifier::verify() + 25
43 swift                    0x000000010b3374ab swift::SILFunction::verify(bool) const + 59
44 swift                    0x000000010b33a679 swift::SILModule::verify() const + 441
45 swift                    0x000000010a41f380 swift::CompilerInstance::performSILProcessing(swift::SILModule*, swift::UnifiedStatsReporter*) + 192
46 swift                    0x0000000109eddac0 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*) + 1056
47 swift                    0x0000000109ec44fd performCompileStepsPostSema(swift::CompilerInvocation&, swift::CompilerInstance&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1373
48 swift                    0x0000000109eba1c5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1621
49 swift                    0x0000000109eb8db9 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2121
50 swift                    0x0000000109daa234 run_driver(llvm::StringRef, llvm::ArrayRef<char const*>) + 292
51 swift                    0x0000000109da9543 main + 1875
52 libdyld.dylib            0x00007fff79fd43d5 start + 1
[1]    7971 abort      bin/swiftc run.swift -O -emit-sil

Also, here's a link.

@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 optimized only Flag: An issue whose reproduction requires optimized compilation SILOptimizer Area → compiler: SIL optimization passes
Projects
None yet
Development

No branches or pull requests

3 participants