swiftlang / swift

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

Combination of sending generic + isolated(any) results in demangling failure #75523

Open mattmassicotte opened 3 months ago

mattmassicotte commented 3 months ago

Description

Got this one reduced quite bit, but I'm not sure I got it all the way. Something about the combination of the isolated(any) closure and the sending genertic param results in a crash. But, to trigger the crash, you have to also call the function.

Seems like the most relevant bit is:

Can't demangle: $s4test7MyClassC9withBlockyxxyYaKYAYTcYaKlF

Reproduction

public final class MyClass {
    public init() {
    }

    public func withBlock<T>(
        _ block: @isolated(any) @escaping () async throws -> sending T
    ) async rethrows -> T {
    }
}

let value = MyClass()

await value.withBlock {
}

Stack dump

Can't demangle: $s4test7MyClassC9withBlockyxxyYaKYAYTcYaKlF
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-26-a.xctoolchain/usr/bin/swift-frontend -frontend -interpret test.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -color-diagnostics -swift-version 6 -empty-abi-descriptor -resource-dir /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-26-a.xctoolchain/usr/lib/swift -module-name test -plugin-path /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-26-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-26-a.xctoolchain/usr/local/lib/swift/host/plugins -target-sdk-version 14.5 -target-sdk-name macosx14.5 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server
1.  Apple Swift version 6.0-dev (LLVM 961ea4ef750ef11, Swift dc553031a742cd6)
2.  Compiling with the current language version
3.  While evaluating request ASTLoweringRequest(Lowering AST to SIL for module test)
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           0x000000010970acb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109709484 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010970b300 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x00000001965eb584 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001965bac20 pthread_kill + 288
5  libsystem_c.dylib        0x00000001964c7a30 abort + 180
6  swift-frontend           0x0000000109cbae30 swift::Mangle::Mangler::verify(llvm::StringRef) (.cold.2) + 0
7  swift-frontend           0x0000000105bc4828 swift::Mangle::Mangler::verify(llvm::StringRef) + 744
8  swift-frontend           0x0000000105872344 swift::Mangle::ASTMangler::mangleEntity(swift::ValueDecl const*, swift::Mangle::ASTMangler::SymbolKind) + 172
9  swift-frontend           0x00000001050a2158 swift::SILDeclRef::mangle(swift::SILDeclRef::ManglingKind) const + 2512
10 swift-frontend           0x00000001050c034c swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, llvm::function_ref<swift::SILFunction* (swift::SILLocation, swift::SILDeclRef)>, swift::ProfileCounter) + 96
11 swift-frontend           0x0000000104876918 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 340
12 swift-frontend           0x00000001049826a0 swift::Lowering::SILGenFunction::emitGlobalFunctionRef(swift::SILLocation, swift::SILDeclRef, swift::Lowering::SILConstantInfo, bool) + 608
13 swift-frontend           0x000000010488db64 (anonymous namespace)::Callee::getFnValue(swift::Lowering::SILGenFunction&, std::__1::optional<swift::Lowering::ManagedValue>) const & + 408
14 swift-frontend           0x000000010488c458 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1936
15 swift-frontend           0x000000010488aa64 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2028
16 swift-frontend           0x00000001048e6dd8 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 912
17 swift-frontend           0x0000000104989510 swift::Lowering::SILGenTopLevel::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 236
18 swift-frontend           0x0000000104987cc4 swift::Lowering::SILGenTopLevel::visitSourceFile(swift::SourceFile*) + 100
19 swift-frontend           0x0000000104987560 swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*, swift::SILFunction*) + 780
20 swift-frontend           0x0000000104988e98 swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*) + 228
21 swift-frontend           0x000000010487c4fc swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1360
22 swift-frontend           0x0000000104979f78 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&) + 148
23 swift-frontend           0x0000000104881bf8 swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 340
24 swift-frontend           0x000000010487c950 swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 144
25 swift-frontend           0x000000010425f054 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1176
26 swift-frontend           0x000000010426ab48 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
27 swift-frontend           0x0000000104260d24 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
28 swift-frontend           0x00000001042603f8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2344
29 swift-frontend           0x000000010407576c swift::mainEntry(int, char const**) + 3096
30 dyld                     0x00000001962320e0 start + 2360

Expected behavior

I'd expect this to produce an error about the lack of return within the withBlock function.

Environment

Apple Swift version 6.0-dev (LLVM 961ea4ef750ef11, Swift dc553031a742cd6) Target: arm64-apple-macosx14.0

Additional information

No response

hborla commented 3 months ago

This looks similar to another demangling issue with sending I've seen... there may be a related issue floating around.