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 in Swift 5 language mode, when using generic, convenience init, assumeIsolated #78293

Open
tomlokhorst opened this issue Dec 19, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@tomlokhorst
Copy link

Description

This program crashes the compiler in language mode 5, but works in language mode 6.

Works: swift -swift-version 6 main.swift
Crashes: swift -swift-version 5 main.swift

When removing the generic, the convenience init or the assumeIsolated, it won't crash.

Reproduction

import Foundation

@MainActor
public class Foo<T> {

    public convenience init(t: T) {
        self.init()

        let queue = DispatchQueue.main
        queue.async { [weak self] in
            MainActor.assumeIsolated {
                self?.bar(x: 3)
            }
        }
    }

    func bar(x: Int) {
        print("hello", x)
    }
}

let f = Foo(t: 1)

try await Task.sleep(for: .seconds(1))
print("Done", f)

Stack dump

Stack dump:
0.	Program arguments: /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -interpret main.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -color-diagnostics -swift-version 5 -new-driver-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name main -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins
1.	Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
2.	Compiling with effective version 5.10
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module main)
4.	While silgen emitValueConstructor SIL function "@$s4main3FooC1tACyxGx_tcfC".
 for 'init(t:)' (at main.swift:6:24)
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           0x000000010a8f2a9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a8f0cf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010a8f3068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000019c942e04 _sigtramp + 56
4  swift-frontend           0x0000000106ce3764 swift::InFlightSubstitution::substType(swift::SubstitutableType*, unsigned int) + 48
5  swift-frontend           0x0000000106ce3764 swift::InFlightSubstitution::substType(swift::SubstitutableType*, unsigned int) + 48
6  swift-frontend           0x0000000106ce78d0 std::__1::optional<swift::Type> llvm::function_ref<std::__1::optional<swift::Type> (swift::TypeBase*)>::callback_fn<substType(swift::Type, unsigned int, swift::InFlightSubstitution&)::$_0>(long, swift::TypeBase*) + 868
7  swift-frontend           0x0000000106cc6580 swift::Type::transformWithPosition(swift::TypePosition, llvm::function_ref<std::__1::optional<swift::Type> (swift::TypeBase*, swift::TypePosition)>) const + 92
8  swift-frontend           0x0000000106cc7e3c swift::Type::transformWithPosition(swift::TypePosition, llvm::function_ref<std::__1::optional<swift::Type> (swift::TypeBase*, swift::TypePosition)>) const + 6424
9  swift-frontend           0x0000000106cc6894 swift::Type::transformWithPosition(swift::TypePosition, llvm::function_ref<std::__1::optional<swift::Type> (swift::TypeBase*, swift::TypePosition)>) const + 880
10 swift-frontend           0x0000000106ce3f14 substType(swift::Type, unsigned int, swift::InFlightSubstitution&) + 312
11 swift-frontend           0x0000000106ce36d0 swift::Type::subst(llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::SubstOptions) const + 340
12 swift-frontend           0x0000000105b0ccec getSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, (anonymous namespace)::Conventions const&, swift::ForeignInfo const&, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 5092
13 swift-frontend           0x0000000105b028f0 getNativeSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 596
14 swift-frontend           0x0000000105b062fc getUncachedSILFunctionTypeForConstant(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::SILDeclRef, swift::Lowering::TypeConverter::LoweredFormalTypes) + 1352
15 swift-frontend           0x0000000105b06e84 swift::Lowering::TypeConverter::getConstantInfo(swift::TypeExpansionContext, swift::SILDeclRef) + 192
16 swift-frontend           0x0000000105afc644 swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, llvm::function_ref<swift::SILFunction* (swift::SILLocation, swift::SILDeclRef)>, swift::ProfileCounter) + 132
17 swift-frontend           0x0000000105cb3c94 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 440
18 swift-frontend           0x0000000105cbf6a0 void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_0>(long) + 92
19 swift-frontend           0x0000000105cb8810 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&) + 280
20 swift-frontend           0x0000000105d5fb30 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 2948
21 swift-frontend           0x0000000105d4f5d0 (anonymous namespace)::RValueEmitter::visitCaptureListExpr(swift::CaptureListExpr*, swift::Lowering::SGFContext) + 124
22 swift-frontend           0x0000000105d531c0 (anonymous namespace)::RValueEmitter::visitFunctionConversionExpr(swift::FunctionConversionExpr*, swift::Lowering::SGFContext) + 3528
23 swift-frontend           0x0000000105d3b58c swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
24 swift-frontend           0x0000000105cda068 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 5028
25 swift-frontend           0x0000000105cc80f0 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 216
26 swift-frontend           0x0000000105cd89ac (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 256
27 swift-frontend           0x0000000105ce4878 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && + 664
28 swift-frontend           0x0000000105ce4298 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1000
29 swift-frontend           0x0000000105ccce7c (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2028
30 swift-frontend           0x0000000105ccb408 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3116
31 swift-frontend           0x0000000105d3bc74 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 888
32 swift-frontend           0x0000000105df3274 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 5512
33 swift-frontend           0x0000000105d0d774 swift::Lowering::SILGenFunction::emitValueConstructor(swift::ConstructorDecl*) + 14032
34 swift-frontend           0x0000000105cb67e4 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 7596
35 swift-frontend           0x0000000105cb73bc swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 216
36 swift-frontend           0x0000000105cb8674 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 724
37 swift-frontend           0x0000000105e072c0 (anonymous namespace)::SILGenType::emitType() + 564
38 swift-frontend           0x0000000105cb4624 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 104
39 swift-frontend           0x0000000105cbb038 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1804
40 swift-frontend           0x0000000105df192c 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&) + 196
41 swift-frontend           0x0000000105cbff14 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'()) + 528
42 swift-frontend           0x000000010529a304 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2828
43 swift-frontend           0x000000010529d374 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2944
44 swift-frontend           0x000000010529bbb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
45 swift-frontend           0x0000000105222a5c swift::mainEntry(int, char const**) + 3680
46 dyld                     0x000000019c58c274 start + 2840
Segmentation fault: 11

Expected behavior

I expect the code to compile in language mode 5 as well as 6, it seems like valid code.

Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0

Additional information

No response

@tomlokhorst tomlokhorst added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Dec 19, 2024
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. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant