Skip to content

Commit 2079419

Browse files
Merge pull request #40 from ordo-one/repro-rt-crash
[sc-22398] reproduce swift rt crash
1 parent bdf9a78 commit 2079419

4 files changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// swift-tools-version: 6.2
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "swift-62-runtime-crash",
8+
platforms: [
9+
.macOS(.v26)
10+
],
11+
targets: [
12+
// Targets are the basic building blocks of a package, defining a module or a test suite.
13+
// Targets can depend on other targets in this package and products from dependencies.
14+
.target(
15+
name: "base"
16+
),
17+
.target(
18+
name: "impl",
19+
dependencies: ["base"]
20+
),
21+
.executableTarget(
22+
name: "swift-62-runtime-crash",
23+
dependencies: ["base", "impl"]
24+
)
25+
]
26+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Foundation
2+
3+
public protocol Marker1: Sendable {}
4+
public protocol Marker2: Sendable {}
5+
6+
public protocol Base<Object, ObjectEntry>: Sendable {
7+
associatedtype Object: Marker1 & Marker2 & Identifiable
8+
associatedtype ObjectEntry: Identifiable<Object.ID>
9+
10+
var predicate: Predicate<Self.Object> { get }
11+
}
12+
13+
public protocol Proto1<Object>: Base where Object == ObjectEntry {
14+
}
15+
16+
public struct TestIdentifiable: Identifiable, Marker2, Marker1, Sendable {
17+
public let id: String
18+
19+
init(id: String) {
20+
self.id = id
21+
}
22+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import base
2+
import Foundation
3+
import Synchronization
4+
5+
private class CacheInstanceBase<Object: Identifiable>: @unchecked Sendable {
6+
let predicate: Predicate<Object>?
7+
8+
init(predicate: Predicate<Object>) {
9+
self.predicate = predicate
10+
}
11+
}
12+
13+
private final class Impl<Object: Marker1 & Marker2 & Identifiable & Sendable>: Proto1 where Object.ID: Sendable & Hashable {
14+
typealias ObjectEntry = Object
15+
private struct State: Sendable {
16+
var predicate: Predicate<Object>?
17+
var instance: CacheInstanceBase<Object>?
18+
var array: [Object.ID: Object] = [:]
19+
}
20+
21+
private let state: Mutex<State>
22+
23+
init(predicate: Predicate<Object>) {
24+
state = .init(.init(predicate: predicate, instance: .init(predicate: predicate)))
25+
}
26+
27+
var predicate: Predicate<Object> { state.withLock { $0.instance?.predicate ?? $0.predicate ?? .true } }
28+
}
29+
30+
public func make<Object: Marker1 & Marker2 & Identifiable & Sendable>(predicate: Predicate<Object>) -> any Proto1<Object> where Object.ID: Sendable & Hashable {
31+
return Impl<Object>(predicate: predicate)
32+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Foundation
2+
import Synchronization
3+
import base
4+
import impl
5+
6+
7+
let predicate = #Predicate<TestIdentifiable> {
8+
$0.id == "test"
9+
}
10+
11+
let cache = make(predicate: predicate)
12+
13+
print(cache.predicate)
14+

0 commit comments

Comments
 (0)