Closed KeithBauerANZ closed 2 weeks ago
The crash appears to occur when Swift 6 built code is responsible for creating the type metadata (even though it gets it from the type metadata accessor in the framework?!). For example, adding this function to the framework:
public func createReaderWriter() -> ReaderWriter {
ReaderWriter()
}
(and calling it instead of ReaderWriter()
from Swift 6) will still crash, but adding this function to the framework:
public func createReaderWriter() -> any Writer {
ReaderWriter()
}
(And removing all references to ReaderWriter
from the Swift 6-compiled code) will no longer crash.
@hborla not sure why "concurrency"? AFAICT, nothing here is related to concurrency?
Ah sorry, I'm triaging fairly quickly to make progress through the large backlog of untraiged issues. I saw Sendable
and "ABI difference between Swift 5 and Swift 6" and assumed it was because of Sendable
stripping, but I agree that's not the problem here.
Minimal repro:
// lib.swift
public protocol Reader: Sendable {
func read()
}
public protocol Writer: Reader {}
public struct ReaderWriter: Writer {
public init() {}
public func read() {}
}
// use.swift
import lib
let db: any Writer = ReaderWriter()
db.read()
Looks like an unexpected regression from https://github.com/swiftlang/swift/commit/b333fb1683ef20b6dc965b78a743feccaea9fedd. Odd
Haha it was Concurrency after all 😅
Description
Where a library is built with Swift 5, with ABI resilience, and then called from Swift 6, inherited protocols cause a crash at runtime.
Rebuilding the framework with the Swift 6 compiler resolves the problem, but that shouldn't be necessary!
Reproduction
Build this as a dynamic library with ABI resilience and Swift 5,
Then call it from code compile with Swift 6 (Swift 5 language mode):
You'll crash in the call to
read
, because it's on theReader
protocol. Calls towrite
on the childWriter
protocol will work fine:Both projects to reproduce in case the above isn't sufficient: Archive.zip
Expected behavior
No crash!
Environment
Swift 5 (Xcode 15.4) swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4) Target: arm64-apple-macosx14.0
Swift 6 (Xcode 16.0b3) swift-driver version: 1.111.2 Apple Swift version 6.0 (swiftlang-6.0.0.5.15 clang-1600.0.22.6) Target: arm64-apple-macosx14.0
Additional information
If there's any workaround for this, I'd love to hear it.