swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.29k stars 10.33k forks source link

Swift 5.8 compiler crash in `swift::GenericSignatureImpl::getDependentUpperBounds` mixing Objective-C generics with Swift generics #65331

Open darronschall opened 1 year ago

darronschall commented 1 year ago

Description

I have some code that compiled and ran OK in Xcode 14.2 / Swift 5.7.

After upgrading to Xcode 14.3 / Swift 5.8, my project no longer compiles. Instead, it triggers a compiler crash with stack trace.

I've attached a minimal reproducer project. This project compiles with Swift 5.7 but crashes the Swift 5.8 compiler. SwiftCrash.zip

Steps to reproduce

  1. Open reproducer project
  2. Notice the following crash on compile:
1.  Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
2.  Compiling with the current language version
3.  While evaluating request IRGenRequest(IR Generation for file "/Users/darron/Desktop/SwiftCrash/SwiftCrash/SwiftCrash/CFlowExt.swift")
4.  While emitting IR SIL function "@$sxSgIegg_AAIeyBy_RlzC5InputQy_Rsz7Combine10SubscriberR_s5NeverO7FailureRt_r0_lTR".
 for <<debugloc at "<compiler-generated>":0:0>>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           0x000000010595f300 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010595e2e4 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010595f910 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x00000001815e82a4 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001815b9cec pthread_kill + 288
5  libsystem_c.dylib        0x00000001814f22c8 abort + 180
6  swift-frontend           0x0000000101f8b24c swift::GenericSignatureImpl::getDependentUpperBounds(swift::Type) const + 1392
7  swift-frontend           0x0000000102091afc swift::ArchetypeType::getExistentialType() const + 192
8  swift-frontend           0x0000000100d041a8 void llvm::function_ref<void (swift::GenericRequirement)>::callback_fn<(anonymous namespace)::PolymorphicConvention::addPseudogenericFulfillments()::$_11>(long, swift::GenericRequirement) + 304
9  swift-frontend           0x0000000100d08544 void llvm::function_ref<void (swift::GenericTypeParamType*, bool)>::callback_fn<swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::GenericRequirement)> const&)::$_0>(long, swift::GenericTypeParamType*, bool) + 44
10 swift-frontend           0x0000000101f884bc swift::GenericSignatureImpl::forEachParam(llvm::function_ref<void (swift::GenericTypeParamType*, bool)>) const + 756
11 swift-frontend           0x0000000100cfa8c4 swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::GenericRequirement)> const&) + 1044
12 swift-frontend           0x0000000100d034c0 (anonymous namespace)::PolymorphicConvention::PolymorphicConvention(swift::irgen::IRGenModule&, swift::CanTypeWrapper<swift::SILFunctionType>, bool) + 188
13 swift-frontend           0x0000000100d0078c swift::irgen::emitPolymorphicParameters(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::EntryPointArgumentEmission&, swift::irgen::WitnessMetadata*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 76
14 swift-frontend           0x0000000100da0da0 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 5996
15 swift-frontend           0x0000000100c2e048 swift::irgen::IRGenerator::emitLazyDefinitions() + 2664
16 swift-frontend           0x0000000100d56824 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 11448
17 swift-frontend           0x0000000100d9f368 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 188
18 swift-frontend           0x0000000100d67ca0 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 832
19 swift-frontend           0x0000000100d599b0 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           0x0000000100852f30 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >) + 228
21 swift-frontend           0x000000010084d7a0 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*) + 1684
22 swift-frontend           0x0000000100850520 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1856
23 swift-frontend           0x000000010084e944 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4308
24 swift-frontend           0x000000010081368c swift::mainEntry(int, char const**) + 4116
25 dyld                     0x000000018128fe50 start + 2544
zsh: abort       -c -primary-file    -emit-dependencies-path    -serialize-diagnostics-path
xedin commented 1 year ago

cc @angela-laar

angela-laar commented 1 year ago

seems like a dupe of an existing issue, looking to confirm

darronschall commented 1 year ago

I'm sorry if this is a duplicate. I really did search before I logged it, but I couldn't find any existing issues with a stack trace including getDependentUpperBounds.

AnthonyLatsis commented 1 year ago

More minimal:

@import Foundation;

@interface ObjCClass<T>: NSObject
- (void)crash:(void (^)(T _Nonnull))block __attribute__((swift_name("crash(block:)")));
@end
protocol P<A, B> {
  associatedtype A
  associatedtype B
}

func test<T1: AnyObject, T2: P>(
  obj: ObjCClass<T1>, _: T2
) where T2.B == Never {
  obj.crash { _ in }
}
Not all primary associated types constrained?
Interface type: τ_0_1
<τ_0_0, τ_0_1 where τ_0_0 : AnyObject, τ_0_1 : P, τ_0_1.B == Never>
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.  Program arguments: bin/swift-frontend -primary-file /Users/mac/Desktop/test.swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -import-objc-header /Users/mac/Downloads/SwiftCrash/SwiftCrash/CFlow.h -emit-irgen
1.  Swift version 5.9-dev (LLVM 91080e65df791d6, Swift c1d5118c21da49a)
...