Skip to content

Commit 8bb50fa

Browse files
Merge pull request #229 from STREGA/fix-deprecations
Swift 5.9 Changes
2 parents 42f930d + e77144f commit 8bb50fa

File tree

8 files changed

+38
-52
lines changed

8 files changed

+38
-52
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@ jobs:
1010
matrix:
1111
entry:
1212
# Ensure that all host can install toolchain, build project, and run tests
13-
- { os: macos-11, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node, xcode: Xcode_13.2.1.app }
14-
- { os: macos-12, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node, xcode: Xcode_13.4.1.app }
15-
- { os: macos-13, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node, xcode: Xcode_14.3.app }
16-
- { os: ubuntu-22.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node }
13+
- { os: macos-11, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: Node, xcode: Xcode_13.2.1.app }
14+
- { os: macos-12, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: Node, xcode: Xcode_13.4.1.app }
15+
- { os: macos-13, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: Node, xcode: Xcode_14.3.app }
16+
- { os: ubuntu-22.04, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: Node }
1717

1818
# Ensure that test succeeds with all toolchains and wasi backend combinations
19-
- { os: ubuntu-20.04, toolchain: wasm-5.5.0-RELEASE, wasi-backend: Node }
20-
- { os: ubuntu-20.04, toolchain: wasm-5.6.0-RELEASE, wasi-backend: Node }
2119
- { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: Node }
2220
- { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node }
23-
- { os: ubuntu-20.04, toolchain: wasm-5.6.0-RELEASE, wasi-backend: Wasmer }
2421
- { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: Wasmer }
2522
- { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Wasmer }
26-
- { os: ubuntu-20.04, toolchain: wasm-5.6.0-RELEASE, wasi-backend: MicroWASI }
23+
- { os: ubuntu-20.04, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: Wasmer }
2724
- { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: MicroWASI }
2825
- { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: MicroWASI }
26+
- { os: ubuntu-20.04, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: MicroWASI }
2927

3028
runs-on: ${{ matrix.entry.os }}
3129
env:
@@ -45,7 +43,9 @@ jobs:
4543
- run: make bootstrap
4644
- run: make test
4745
- run: make unittest
48-
if: ${{ startsWith(matrix.toolchain, 'wasm-5.7.') }}
46+
# Skip unit tests with uwasi because its proc_exit throws
47+
# unhandled promise rejection.
48+
if: ${{ matrix.entry.wasi-backend != 'MicroWASI' }}
4949
- name: Check if SwiftPM resources are stale
5050
run: |
5151
make regenerate_swiftpm_resources

IntegrationTests/TestSuites/Sources/ConcurrencyTests/UnitTestUtils.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func test(_ name: String, testBlock: () throws -> Void) throws {
1515
print(error)
1616
throw error
1717
}
18+
print("\(name)")
1819
}
1920

2021
func asyncTest(_ name: String, testBlock: () async throws -> Void) async throws -> Void {
@@ -26,6 +27,7 @@ func asyncTest(_ name: String, testBlock: () async throws -> Void) async throws
2627
print(error)
2728
throw error
2829
}
30+
print("\(name)")
2931
}
3032

3133
struct MessageError: Error {

IntegrationTests/TestSuites/Sources/ConcurrencyTests/main.swift

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import WASILibc
66
import Darwin
77
#endif
88

9-
#if compiler(>=5.5)
10-
119
func performanceNow() -> Double {
12-
return JSObject.global.performance.now.function!().number!
10+
return JSObject.global.performance.now().number!
1311
}
1412

1513
func measure(_ block: () async throws -> Void) async rethrows -> Double {
@@ -213,32 +211,6 @@ func entrypoint() async throws {
213211
#endif
214212
}
215213

216-
217-
// Note: Please define `USE_SWIFT_TOOLS_VERSION_NEWER_THAN_5_5` if the swift-tools-version is newer
218-
// than 5.5 to avoid the linking issue.
219-
#if USE_SWIFT_TOOLS_VERSION_NEWER_THAN_5_5
220-
// Workaround: The latest SwiftPM rename main entry point name of executable target
221-
// to avoid conflicting "main" with test target since `swift-tools-version >= 5.5`.
222-
// The main symbol is renamed to "{{module_name}}_main" and it's renamed again to be
223-
// "main" when linking the executable target. The former renaming is done by Swift compiler,
224-
// and the latter is done by linker, so SwiftPM passes some special linker flags for each platform.
225-
// But SwiftPM assumes that wasm-ld supports it by returning an empty array instead of nil even though
226-
// wasm-ld doesn't support it yet.
227-
// ref: https://github.com/apple/swift-package-manager/blob/1be68e811d0d814ba7abbb8effee45f1e8e6ec0d/Sources/Build/BuildPlan.swift#L117-L126
228-
// So define an explicit "main" by @_cdecl
229-
@_cdecl("main")
230-
func main(argc: Int32, argv: Int32) -> Int32 {
231-
JavaScriptEventLoop.installGlobalExecutor()
232-
Task {
233-
do {
234-
try await entrypoint()
235-
} catch {
236-
print(error)
237-
}
238-
}
239-
return 0
240-
}
241-
#else
242214
JavaScriptEventLoop.installGlobalExecutor()
243215
Task {
244216
do {
@@ -247,8 +219,3 @@ Task {
247219
print(error)
248220
}
249221
}
250-
251-
#endif
252-
253-
254-
#endif

IntegrationTests/lib.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const WASI = {
6464
args: [programName],
6565
env: {},
6666
returnOnExit: false,
67+
version: "preview1",
6768
})
6869

6970
return {

IntegrationTests/package-lock.json

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

IntegrationTests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"dependencies": {
44
"@wasmer/wasi": "^0.12.0",
55
"@wasmer/wasmfs": "^0.12.0",
6-
"uwasi": "^1.0.0",
6+
"uwasi": "^1.2.0",
77
"javascript-kit-swift": "file:.."
88
}
99
}

Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,25 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
122122
private func enqueue(_ job: UnownedJob, withDelay nanoseconds: UInt64) {
123123
let milliseconds = nanoseconds / 1_000_000
124124
setTimeout(Double(milliseconds), {
125+
#if compiler(>=5.9)
126+
job.runSynchronously(on: self.asUnownedSerialExecutor())
127+
#else
125128
job._runSynchronously(on: self.asUnownedSerialExecutor())
129+
#endif
126130
})
127131
}
128132

133+
#if compiler(>=5.9)
134+
public func enqueue(_ job: consuming ExecutorJob) {
135+
// NOTE: Converting a `ExecutorJob` to an ``UnownedJob`` and invoking
136+
// ``UnownedJob/runSynchronously(_:)` on it multiple times is undefined behavior.
137+
insertJobQueue(job: UnownedJob(job))
138+
}
139+
#else
129140
public func enqueue(_ job: UnownedJob) {
130141
insertJobQueue(job: job)
131142
}
143+
#endif
132144

133145
public func asUnownedSerialExecutor() -> UnownedSerialExecutor {
134146
return UnownedSerialExecutor(ordinary: self)

Sources/JavaScriptEventLoop/JobQueue.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ extension JavaScriptEventLoop {
4343
assert(queueState.isSpinning)
4444

4545
while let job = self.claimNextFromQueue() {
46+
#if compiler(>=5.9)
47+
job.runSynchronously(on: self.asUnownedSerialExecutor())
48+
#else
4649
job._runSynchronously(on: self.asUnownedSerialExecutor())
50+
#endif
4751
}
4852

4953
queueState.isSpinning = false

0 commit comments

Comments
 (0)