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 using typed throws of an enum nested within a generic type #73641

Open
TeamPuzel opened this issue May 15, 2024 · 1 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 typed throws Feature → error handling → throws & rethrows: Typed throws

Comments

@TeamPuzel
Copy link

Description

A completely normal class is crashing with @MainActor applied.

Reproduction

@MainActor
public final class DrawObject<V: Vertex> {
    fileprivate let window: Window
    fileprivate let handle: UInt32
    public let texture: Texture
    public var mesh: Mesh<V>
    
    init(_ window: Window, texture: Texture, mesh: Mesh<V>) throws(InitError) {
        precondition(window === texture.window)
        self.texture = texture
        self.mesh = mesh
        
        var handle: UInt32 = 0
        glad_glGenBuffers(1, &handle)
        guard handle != 0 else { throw .creatingBuffer }
        self.handle = handle
    }
    
    public func bind() {
        
    }
    
    public func unbind() {
        
    }
    
    public enum InitError: Error {
        case creatingBuffer
    }
}

Don't know what is causing this exactly but this is the init mentioned in the crash message

Stack dump

warning: prohibited flag(s): -D_THREAD_SAFE
Building for debugging...
error: compile command failed due to signal 6 (use -v to see invocation)
Assertion failed: (destErrorType == SILType::getExceptionType(getASTContext())), function emitThrow, file SILGenStmt.cpp, line 1634.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-14-a.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/teampuzel/Games/Minecraft/src/Core/Graphics/Builtin.swift /Users/teampuzel/Games/Minecraft/src/Core/Graphics/Color.swift /Users/teampuzel/Games/Minecraft/src/Core/Graphics/Drawable.swift /Users/teampuzel/Games/Minecraft/src/Core/Graphics/Image.swift /Users/teampuzel/Games/Minecraft/src/Core/Graphics/Layout.swift /Users/teampuzel/Games/Minecraft/src/Core/Graphics/MutableDrawable.swift /Users/teampuzel/Games/Minecraft/src/Core/Graphics/TGA.swift /Users/teampuzel/Games/Minecraft/src/Core/Math/Matrix.swift /Users/teampuzel/Games/Minecraft/src/Core/Math/Noise.swift /Users/teampuzel/Games/Minecraft/src/Core/Math/Utility.swift /Users/teampuzel/Games/Minecraft/src/Core/Math/Vector.swift /Users/teampuzel/Games/Minecraft/src/Core/Platform/Desktop/Mesh.swift -primary-file /Users/teampuzel/Games/Minecraft/src/Core/Platform/Desktop/OpenGL.swift -primary-file /Users/teampuzel/Games/Minecraft/src/Core/Platform/Input.swift /Users/teampuzel/Games/Minecraft/src/Core/Platform/Timer.swift /Users/teampuzel/Games/Minecraft/src/Game/Block.swift /Users/teampuzel/Games/Minecraft/src/Game/Chunk.swift /Users/teampuzel/Games/Minecraft/src/Game/Entity.swift /Users/teampuzel/Games/Minecraft/src/Game/World.swift /Users/teampuzel/Games/Minecraft/src/Main.swift -emit-dependencies-path /Users/teampuzel/Games/Minecraft/.build/arm64-apple-macosx/debug/Minecraft.build/OpenGL.d -emit-reference-dependencies-path /Users/teampuzel/Games/Minecraft/.build/arm64-apple-macosx/debug/Minecraft.build/OpenGL.swiftdeps -emit-dependencies-path /Users/teampuzel/Games/Minecraft/.build/arm64-apple-macosx/debug/Minecraft.build/Input.d -emit-reference-dependencies-path /Users/teampuzel/Games/Minecraft/.build/arm64-apple-macosx/debug/Minecraft.build/Input.swiftdeps -target arm64-apple-macosx14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -I /Users/teampuzel/Games/Minecraft/.build/arm64-apple-macosx/debug/Modules -I /opt/homebrew/include -I /opt/homebrew/include/SDL2 -I /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/teampuzel/Games/Minecraft/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -entry-point-function-name Minecraft_main -enable-upcoming-feature ExistentialAny -empty-abi-descriptor -Xcc -working-directory -Xcc /Users/teampuzel/Games/Minecraft -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-14-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/teampuzel/Games/Minecraft -Xcc -fmodule-map-file=/Users/teampuzel/Games/Minecraft/.build/arm64-apple-macosx/debug/Assets.build/module.modulemap -Xcc -I -Xcc /Users/teampuzel/Games/Minecraft/assets/module/include -Xcc -fmodule-map-file=/Users/teampuzel/Games/Minecraft/lib/glad/include/module.modulemap -Xcc -I -Xcc /Users/teampuzel/Games/Minecraft/lib/glad/include -Xcc -fmodule-map-file=/Users/teampuzel/Games/Minecraft/sys/module.modulemap -Xcc -isysroot -Xcc /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -Xcc -F -Xcc /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name Minecraft -package-name minecraft -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-14-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-14-a.xctoolchain/usr/local/lib/swift/host/plugins -target-sdk-version 14.4 -target-sdk-name macosx14.4 -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -o /Users/teampuzel/Games/Minecraft/.build/arm64-apple-macosx/debug/Minecraft.build/OpenGL.swift.o -o /Users/teampuzel/Games/Minecraft/.build/arm64-apple-macosx/debug/Minecraft.build/Input.swift.o -index-store-path /Users/teampuzel/Games/Minecraft/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.	Apple Swift version 6.0-dev (LLVM 3417addab6ff197, Swift d677b7c23fd6355)
2.	Compiling with effective version 5.10
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/teampuzel/Games/Minecraft/src/Core/Platform/Desktop/OpenGL.swift")
4.	While silgen constructor initializer SIL function "@$s9Minecraft10DrawObjectC_7texture4meshACyxGAA6WindowC_AA7TextureCAA4MeshVyxGtAC9InitErrorOyx_GYKcfc".
 for 'init(_:texture:mesh:)' (at /Users/teampuzel/Games/Minecraft/src/Core/Platform/Desktop/OpenGL.swift:219: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           0x00000001079c0a8c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001079bf258 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001079c10d4 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000018f0c3584 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018f092c20 pthread_kill + 288
5  libsystem_c.dylib        0x000000018ef9fa30 abort + 180
6  libsystem_c.dylib        0x000000018ef9ed20 err + 0
7  swift-frontend           0x0000000107b02598 swift::Lowering::SILGenFunction::emitThrow(swift::SILLocation, swift::Lowering::ManagedValue, bool) (.cold.16) + 0
8  swift-frontend           0x0000000102c569a4 swift::Lowering::SILGenFunction::emitThrow(swift::SILLocation, swift::Lowering::ManagedValue, bool) + 2380
9  swift-frontend           0x0000000102c53c24 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6128
10 swift-frontend           0x0000000102c535a8 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4468
11 swift-frontend           0x0000000102c528b4 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 1152
12 swift-frontend           0x0000000102c535a8 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4468
13 swift-frontend           0x0000000102c52428 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 24
14 swift-frontend           0x0000000102baf848 swift::Lowering::SILGenFunction::emitClassConstructorInitializer(swift::ConstructorDecl*) + 2488
15 swift-frontend           0x0000000102b64838 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 2912
16 swift-frontend           0x0000000102b663b0 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 252
17 swift-frontend           0x0000000102b67200 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 388
18 swift-frontend           0x0000000102c63f68 (anonymous namespace)::SILGenType::emitType() + 336
19 swift-frontend           0x0000000102c63e0c swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 24
20 swift-frontend           0x0000000102b68cc8 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 880
21 swift-frontend           0x0000000102c51e80 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
22 swift-frontend           0x0000000102b6e5e0 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
23 swift-frontend           0x0000000102b695cc swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 96
24 swift-frontend           0x00000001025517f8 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 580
25 swift-frontend           0x0000000102562ae8 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
26 swift-frontend           0x0000000102553e64 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
27 swift-frontend           0x0000000102552dd0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2384
28 swift-frontend           0x0000000102362ddc swift::mainEntry(int, char const**) + 3096
29 dyld                     0x000000018ed0a0e0 start + 2360

Expected behavior

I was writing a class and the lsp stopped working, I tried building from the command line expecting it to work and it crashed.

Environment

Apple Swift version 6.0-dev (LLVM 3417addab6ff197, Swift d677b7c)
Target: arm64-apple-macosx14.0

Additional information

No response

@TeamPuzel TeamPuzel 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 May 15, 2024
@TeamPuzel
Copy link
Author

TeamPuzel commented May 15, 2024

I tried removing the generics using [any Vertex] for the mesh and then it compiles, but even ignoring the cost this is a buffer I have to pass to OpenGL so it's not a usable workaround

Ok after trying various things it is probably actually unrelated to the MainActor annotation (although it seemed to work without it once?), rather a combination of the generic type with a nested error enum used together with typed throws. Removing the typed throw, moving the enum outside or removing generics all avoid this crash.

@TeamPuzel TeamPuzel changed the title Compiler crash when adding MainActor to a class Compiler crash when using typed throws of an enum nested within a generic type May 15, 2024
@hborla hborla added typed throws Feature → error handling → throws & rethrows: Typed throws and removed triage needed This issue needs more specific labels labels Jul 14, 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 typed throws Feature → error handling → throws & rethrows: Typed throws
Projects
None yet
Development

No branches or pull requests

2 participants