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

Compiler crash when declaring async function in an extension of a generic ObjC class that uses the generic parameter as a return type #63741

Open
TadeasKriz opened this issue Feb 17, 2023 · 0 comments
Labels
async & await Feature → concurrency: asynchronous function aka the async/await pattern bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself concurrency Feature: umbrella label for concurrency language features crash Bug: A crash, i.e., an abnormal termination of software generics Feature: generic declarations and types objective-c interop Feature: Interoperability with Objective-C swift 5.7

Comments

@TadeasKriz
Copy link

Description

Declaring an async function in an extension of a generic Objective-C class, results in a compiler crash with the following stack-trace when the generic parameter is used as a return type of the function.

Stack dump:
0.	Program arguments: /Applications/Xcode-14.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/tadeaskriz/Developer/Sandbox/FoundationBug/KotlinIsh/A_sealed.swift /Users/tadeaskriz/Developer/Sandbox/FoundationBug/KotlinIsh/A_A_sealed.swift -emit-module-path /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/KotlinIsh.swiftmodule -emit-module-doc-path /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/KotlinIsh.swiftdoc -emit-module-source-info-path /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/KotlinIsh.swiftsourceinfo -emit-dependencies-path /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/KotlinIsh-master.d -serialize-diagnostics-path /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/KotlinIsh-master.dia -emit-objc-header-path /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/KotlinIsh-Swift.h -emit-abi-descriptor-path /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/KotlinIsh.abi.json -emit-localized-strings -emit-localized-strings-path /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64 -target arm64-apple-macos12.3 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-14.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -I /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Products/Release -F /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Products/Release -no-color-diagnostics -g -import-underlying-module -module-cache-path /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -O -serialize-debugging-options -enable-bare-slash-regex -empty-abi-descriptor -Xcc -working-directory -Xcc /Users/tadeaskriz/Developer/Sandbox/FoundationBug -resource-dir /Applications/Xcode-14.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -Xcc -I/Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/KotlinIsh-generated-files.hmap -Xcc -I/Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/KotlinIsh-own-target-headers.hmap -Xcc -I/Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/KotlinIsh-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/KotlinIsh-project-headers.hmap -Xcc -I/Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Products/Release/include -Xcc -I/Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/DerivedSources-normal/arm64 -Xcc -I/Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/DerivedSources/arm64 -Xcc -I/Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/DerivedSources -Xcc -ivfsoverlay -Xcc /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/unextended-module-overlay.yaml -module-name KotlinIsh -frontend-parseable-output -disable-clang-spi -target-sdk-version 13.1 -num-threads 10 -o /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/A_sealed.o -o /Users/tadeaskriz/Library/Developer/Xcode/DerivedData/FoundationBug-bwyaiwmgiyrjdshkyygmdyykykjr/Build/Intermediates.noindex/FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/A_A_sealed.o -index-unit-output-path /FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/A_sealed.o -index-unit-output-path /FoundationBug.build/Release/KotlinIsh.build/Objects-normal/arm64/A_A_sealed.o
1.	Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module KotlinIsh)
4.	While silgen emitNativeToForeignThunk SIL function "@$sSo11GenericTestC9KotlinIshE10asyncCrash1axyp_tYaFTo".
 for 'asyncCrash(a:)' (at /Users/tadeaskriz/Developer/Sandbox/FoundationBug/KotlinIsh/A_sealed.swift:14:5)
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           0x0000000104dab5b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000104daa5b4 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000104dabc34 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x00000001af5432a4 _sigtramp + 56
4  swift-frontend           0x000000010053f808 (anonymous namespace)::TypeClassifierBase<(anonymous namespace)::LowerType, swift::Lowering::TypeLowering*>::visitAbstractTypeParamType(swift::CanType, swift::Lowering::AbstractionPattern, swift::Lowering::IsTypeExpansionSensitive_t) + 124
5  swift-frontend           0x000000010053f808 (anonymous namespace)::TypeClassifierBase<(anonymous namespace)::LowerType, swift::Lowering::TypeLowering*>::visitAbstractTypeParamType(swift::CanType, swift::Lowering::AbstractionPattern, swift::Lowering::IsTypeExpansionSensitive_t) + 124
6  swift-frontend           0x00000001005353dc swift::CanTypeVisitor<(anonymous namespace)::LowerType, swift::Lowering::TypeLowering*, swift::Lowering::AbstractionPattern, swift::Lowering::IsTypeExpansionSensitive_t>::visit(swift::CanType, swift::Lowering::AbstractionPattern, swift::Lowering::IsTypeExpansionSensitive_t) + 248
7  swift-frontend           0x0000000100535f0c swift::Lowering::TypeConverter::getTypeLoweringForLoweredType(swift::Lowering::AbstractionPattern, swift::CanType, swift::TypeExpansionContext, swift::Lowering::IsTypeExpansionSensitive_t) + 388
8  swift-frontend           0x0000000100a1734c swift::Lowering::SILGenFunction::emitManagedRValueWithCleanup(swift::SILValue) + 156
9  swift-frontend           0x00000001009e28fc swift::Lowering::SILGenFunction::emitNativeToForeignThunk(swift::SILDeclRef)::$_3::operator()(swift::SILValue) const + 128
10 swift-frontend           0x00000001009e1550 swift::Lowering::SILGenFunction::emitNativeToForeignThunk(swift::SILDeclRef) + 6820
11 swift-frontend           0x00000001009ad204 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 2600
12 swift-frontend           0x0000000100a935a4 SILGenExtension::visitFuncDecl(swift::FuncDecl*) + 488
13 swift-frontend           0x0000000100a8f44c SILGenExtension::emitExtension(swift::ExtensionDecl*) + 164
14 swift-frontend           0x00000001009b5b10 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 1176
15 swift-frontend           0x00000001009b3ee4 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 3356
16 swift-frontend           0x0000000100a80f10 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 216
17 swift-frontend           0x00000001009b76e4 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 628
18 swift-frontend           0x00000001003f8c9c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7208
19 swift-frontend           0x0000000100399294 swift::mainEntry(int, char const**) + 3940
20 dyld                     0x00000001af1ebe50 start + 2544

Steps to reproduce

@interface GenericTest<T>: NSObject
@end
extension GenericTest {
  @objc
  func asyncCrash() async -> T {
    fatalError()
  }
}

Expected behavior

Code compiles successfully similar to:

  • regular sync function with the same signature compiles
  • async function returning a specific type instead of the T parameter compiles
  • async function that's also throws returning T also compiles

Or if it's not possible to compile, then it should report an error instead of the crash.

Environment

  • Swift compiler version info swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
  • Xcode version info Xcode 14.2 Build version 14C18
  • Deployment target: macOS 12.3

NOTE: The "similar to" points only work when building in release mode (more specifically just setting the Optimization Level to -O is enough). I'll be submitting a separate issue report for a compiler crash that happens when the Optimization Level is set to -Onone and the type parameter is used anywhere in the function signature (except when used as a generic argument of a different class that's used in the signature instead).

@TadeasKriz TadeasKriz added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Feb 17, 2023
@AnthonyLatsis AnthonyLatsis added concurrency Feature: umbrella label for concurrency language features generics Feature: generic declarations and types async & await Feature → concurrency: asynchronous function aka the async/await pattern objective-c interop Feature: Interoperability with Objective-C compiler The Swift compiler itself compiler crash crash Bug: A crash, i.e., an abnormal termination of software swift 5.7 and removed triage needed This issue needs more specific labels labels Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async & await Feature → concurrency: asynchronous function aka the async/await pattern bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself concurrency Feature: umbrella label for concurrency language features crash Bug: A crash, i.e., an abnormal termination of software generics Feature: generic declarations and types objective-c interop Feature: Interoperability with Objective-C swift 5.7
Projects
None yet
Development

No branches or pull requests

2 participants