Skip to content

Commit 8af75ea

Browse files
authored
Support Swift 6.1 (#47)
* Update to Swift 6.1 * Bump min SwiftSyntax * More cleanup
1 parent dae9bc0 commit 8af75ea

36 files changed

+64
-288
lines changed

Package.resolved

Lines changed: 26 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:6.0
22

33
import PackageDescription
44
import CompilerPluginSupport
55
import Foundation
66

77
let buildDynamic = ProcessInfo.processInfo.environment["NODE_SWIFT_BUILD_DYNAMIC"] == "1"
88

9-
let baseSwiftSettings: [SwiftSetting] = [
10-
.enableExperimentalFeature("StrictConcurrency"),
11-
]
12-
139
let package = Package(
1410
name: "node-swift",
1511
platforms: [
@@ -31,8 +27,8 @@ let package = Package(
3127
),
3228
],
3329
dependencies: [
34-
.package(url: "https://github.com/apple/swift-syntax.git", "509.0.0"..<"601.0.0"),
35-
.package(url: "https://github.com/pointfreeco/swift-macro-testing.git", .upToNextMinor(from: "0.4.2")),
30+
.package(url: "https://github.com/swiftlang/swift-syntax.git", "600.0.0"..<"602.0.0"),
31+
.package(url: "https://github.com/pointfreeco/swift-macro-testing.git", .upToNextMinor(from: "0.6.2")),
3632
],
3733
targets: [
3834
.systemLibrary(name: "CNodeAPI"),
@@ -55,13 +51,11 @@ let package = Package(
5551
dependencies: [
5652
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
5753
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
58-
],
59-
swiftSettings: baseSwiftSettings
54+
]
6055
),
6156
.target(
6257
name: "NodeAPI",
63-
dependencies: ["CNodeAPI", "CNodeAPISupport", "NodeAPIMacros"],
64-
swiftSettings: baseSwiftSettings
58+
dependencies: ["CNodeAPI", "CNodeAPISupport", "NodeAPIMacros"]
6559
),
6660
.target(
6761
name: "NodeModuleSupport",
@@ -79,5 +73,6 @@ let package = Package(
7973
]
8074
),
8175
],
76+
swiftLanguageModes: [.v5, .v6],
8277
cxxLanguageStandard: .cxx17
8378
)

Package@swift-6.0.swift

Lines changed: 0 additions & 78 deletions
This file was deleted.

Sources/CNodeAPISupport/include/task_reflection.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

Sources/CNodeAPISupport/task_reflection.cpp

Lines changed: 0 additions & 81 deletions
This file was deleted.

Sources/CNodeJSC/js_native_api_javascriptcore.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,7 +2717,10 @@ static napi_status bigint_to_string(napi_env env, napi_value value, std::string
27172717
JSString js_string{ToJSString(env, value, &exception)};
27182718
CHECK_JSC(env, exception);
27192719

2720+
#pragma clang diagnostic push
2721+
#pragma clang diagnostic ignored "-Wvla"
27202722
char buf[js_string.LengthUTF8()];
2723+
#pragma clang diagnostic pop
27212724
js_string.CopyToUTF8(buf, sizeof(buf), nullptr);
27222725
string = std::string { buf };
27232726
return napi_ok;

Sources/NodeAPI/NodeAPIError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@_implementationOnly import CNodeAPI
1+
internal import CNodeAPI
22

33
public struct NodeAPIError: Error {
44
public enum Code: Sendable {

Sources/NodeAPI/NodeActor.swift

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Foundation
2-
import CNodeAPISupport
3-
@_implementationOnly import CNodeAPI
2+
internal import CNodeAPI
43

54
extension NodeContext {
65
// if we're on a node thread, run `action` on it
@@ -10,21 +9,6 @@ extension NodeContext {
109
}
1110
}
1211

13-
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
14-
extension UnownedJob {
15-
func asCurrent<T>(work: () -> T) -> T {
16-
withoutActuallyEscaping(work) { work in
17-
var result: T!
18-
node_swift_as_current_task(unsafeBitCast(self, to: OpaquePointer.self), { ctx in
19-
Unmanaged<Box<() -> Void>>.fromOpaque(ctx).takeRetainedValue().value()
20-
}, Unmanaged.passRetained(Box<() -> Void> {
21-
result = work()
22-
}).toOpaque())
23-
return result
24-
}
25-
}
26-
}
27-
2812
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2913
private final class NodeExecutor: SerialExecutor {
3014
private let schedulerQueue = DispatchQueue(label: "NodeExecutorScheduler")
@@ -46,29 +30,7 @@ private final class NodeExecutor: SerialExecutor {
4630
// NodeExecutor.enqueue is invoked with the same isolation as the caller,
4731
// which means we can simply read out the TaskLocal value to obtain
4832
// this.
49-
let target: NodeAsyncQueue.Handle?
50-
#if compiler(>=6.0)
51-
target = NodeActor.target
52-
#else
53-
// It's a bit trickier in Swift <= 5.10 as Swift first makes a hop to the
54-
// global executor before invoking this method. So instead we have to use
55-
// some runtime spelunking to read the TaskLocal value from `job`.
56-
// To do so, we temporarily swap ResumeTask for our own function.
57-
// Then, swift_job_run is called, which sets the active task to
58-
// the receiver and invokes its ResumeTask. We then execute the
59-
// given closure, allowing us to grab task-local values. Finally,
60-
// we "suspend" the task and return ResumeTask to its old value.
61-
//
62-
// on Darwin we can instead replace the "current task" thread-local
63-
// (key 103) temporarily, but that isn't portable.
64-
//
65-
// This is sort of like inserting a "work(); await Task.yield()" block
66-
// at the top of the task, since when a Task awaits it similarly changes
67-
// the Resume function and suspends. Note that we can assume that this
68-
// is a Task and not a basic Job, because Executor.enqueue is only
69-
// called from swift_task_enqueue.
70-
target = job.asCurrent { NodeActor.target }
71-
#endif
33+
let target = NodeActor.target
7234

7335
guard let q = target?.queue else {
7436
nodeFatalError("There is no target NodeAsyncQueue associated with this Task")

Sources/NodeAPI/NodeArray.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@_implementationOnly import CNodeAPI
1+
internal import CNodeAPI
22

33
public final class NodeArray: NodeObject {
44

Sources/NodeAPI/NodeArrayBuffer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Foundation
2-
@_implementationOnly import CNodeAPI
2+
internal import CNodeAPI
33

44
public struct NodeDataDeallocator: Sendable {
55
let action: @Sendable @NodeActor (UnsafeMutableRawBufferPointer) -> Void

0 commit comments

Comments
 (0)