Skip to content

5.9 Compiler crash on complex protocol-primary associated type-protocol inheritance relationships on Linux and macOS #67602

Open
@smumriak

Description

@smumriak

Description
I'm experiencing Swift 5.9 crashes on Linux and macOS related to somewhat complex protocol-primary associated type-protocol inheritance relationships. The full log with symbolicated stacktrace can be found here. 5.8 and couple of prior minor version that were used on this code had no issues compiling it. I've boiled down the issue to this particular abstraction, particularly when as constraints in this initializer. Brief context:

  • VkEntity is a protocol representing any "entity" that is created by Vulkan graphics API
  • EntityInfo is a protocol representing specific "info" struct that Vulkan API consumes when creating any "entity". For majority of "entities" there is one-to-one relationship between "info" and "entity". For some tho there is many-to-one relationship, i.e. single multiple infos can be used to create same entity. With recent versions of Vulkan there are types that can be created from 4 different infos
  • The goal is to have a compile time convenience and type check when creating these entities from given infos. In order to do so I've made listed earlier EntityInfo abstraction
  • For entities that have this one-to-one relationship there's a protocol called CreateableFromSingleEntityInfo, for two there's CreateableFromTwoEntityInfos and so on
  • The actual crash is happening while compiler is evaluating class abstraction over some Vulkan entity. Because of this the crash is experienced while compiler is type-checking that particular class and since there are lots of them pretty much every time it crashes on different class. But it always falls on While evaluating request ABIMembersRequest

The code is stretching thin Swifts abilities to infer types and associatedtype overrides. Honestly I feel maybe I've gone too far with it. If this is a non-trivial crash I just need a confirmation that basically "I'm doing something wrong and should go different route"

Steps to reproduce

  • Get a fresh installation of Ubuntu 22.04 or newer. Virtual machine or container is totally fine. Actually preferable since you probably don't want to have unused garbage on your system
  • Install Vulkan SDK, "system libraries" and libclang from Getting Started section of the project
    • To install libclang on macOS just install llvm via homebrew and drop contents of this to /opt/homebrew/lib/pkgconfig/clang.pc
  • Get the project from this commit, it's the last one on which the issue is reproducible. I've simplified the code after it
  • Run swift build --target Volcano. You will need to run in a couple of times because of this problem. It goes away after couple of runs tho
  • You'll eventually see the crash

Expected behavior
Compiler should not crash for sure. I would expect a little bit more context from compiler too.

Environment

  • Swift compiler version info
    linux:
    Swift version 5.9-dev (LLVM ea47328e7cf304e, Swift 9c3928cc0c738b5)
    Target: x86_64-unknown-linux-gnu
    
    macOS:
    Apple Swift version 5.9-dev (LLVM ea47328e7cf304e, Swift 9c3928cc0c738b5)
    Target: arm64-apple-macosx13.0
    
  • Deployment target: Ubuntu 22.04 or newer

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaregenericsFeature: generic declarations and types

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions