Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 5.9 Changes #229

Merged
merged 10 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ jobs:
matrix:
entry:
# Ensure that all host can install toolchain, build project, and run tests
- { os: macos-11, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node, xcode: Xcode_13.2.1.app }
- { os: macos-12, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node, xcode: Xcode_13.4.1.app }
- { os: macos-13, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node, xcode: Xcode_14.3.app }
- { os: ubuntu-22.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node }
- { os: macos-11, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: Node, xcode: Xcode_13.2.1.app }
- { os: macos-12, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: Node, xcode: Xcode_13.4.1.app }
- { os: macos-13, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: Node, xcode: Xcode_14.3.app }
- { os: ubuntu-22.04, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: Node }

# Ensure that test succeeds with all toolchains and wasi backend combinations
- { os: ubuntu-20.04, toolchain: wasm-5.5.0-RELEASE, wasi-backend: Node }
- { os: ubuntu-20.04, toolchain: wasm-5.6.0-RELEASE, wasi-backend: Node }
- { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: Node }
- { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node }
- { os: ubuntu-20.04, toolchain: wasm-5.6.0-RELEASE, wasi-backend: Wasmer }
- { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: Wasmer }
- { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Wasmer }
- { os: ubuntu-20.04, toolchain: wasm-5.6.0-RELEASE, wasi-backend: MicroWASI }
- { os: ubuntu-20.04, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: Wasmer }
- { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: MicroWASI }
- { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: MicroWASI }
- { os: ubuntu-20.04, toolchain: wasm-5.9-SNAPSHOT-2024-01-12-a, wasi-backend: MicroWASI }

runs-on: ${{ matrix.entry.os }}
env:
Expand All @@ -45,7 +43,9 @@ jobs:
- run: make bootstrap
- run: make test
- run: make unittest
if: ${{ startsWith(matrix.toolchain, 'wasm-5.7.') }}
# Skip unit tests with uwasi because its proc_exit throws
# unhandled promise rejection.
if: ${{ matrix.entry.wasi-backend != 'MicroWASI' }}
- name: Check if SwiftPM resources are stale
run: |
make regenerate_swiftpm_resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func test(_ name: String, testBlock: () throws -> Void) throws {
print(error)
throw error
}
print("\(name)")
}

func asyncTest(_ name: String, testBlock: () async throws -> Void) async throws -> Void {
Expand All @@ -26,6 +27,7 @@ func asyncTest(_ name: String, testBlock: () async throws -> Void) async throws
print(error)
throw error
}
print("\(name)")
}

struct MessageError: Error {
Expand Down
35 changes: 1 addition & 34 deletions IntegrationTests/TestSuites/Sources/ConcurrencyTests/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import WASILibc
import Darwin
#endif

#if compiler(>=5.5)

func performanceNow() -> Double {
return JSObject.global.performance.now.function!().number!
return JSObject.global.performance.now().number!
}

func measure(_ block: () async throws -> Void) async rethrows -> Double {
Expand Down Expand Up @@ -213,32 +211,6 @@ func entrypoint() async throws {
#endif
}


// Note: Please define `USE_SWIFT_TOOLS_VERSION_NEWER_THAN_5_5` if the swift-tools-version is newer
// than 5.5 to avoid the linking issue.
#if USE_SWIFT_TOOLS_VERSION_NEWER_THAN_5_5
// Workaround: The latest SwiftPM rename main entry point name of executable target
// to avoid conflicting "main" with test target since `swift-tools-version >= 5.5`.
// The main symbol is renamed to "{{module_name}}_main" and it's renamed again to be
// "main" when linking the executable target. The former renaming is done by Swift compiler,
// and the latter is done by linker, so SwiftPM passes some special linker flags for each platform.
// But SwiftPM assumes that wasm-ld supports it by returning an empty array instead of nil even though
// wasm-ld doesn't support it yet.
// ref: https://github.com/apple/swift-package-manager/blob/1be68e811d0d814ba7abbb8effee45f1e8e6ec0d/Sources/Build/BuildPlan.swift#L117-L126
// So define an explicit "main" by @_cdecl
@_cdecl("main")
func main(argc: Int32, argv: Int32) -> Int32 {
JavaScriptEventLoop.installGlobalExecutor()
Task {
do {
try await entrypoint()
} catch {
print(error)
}
}
return 0
}
#else
JavaScriptEventLoop.installGlobalExecutor()
Task {
do {
Expand All @@ -247,8 +219,3 @@ Task {
print(error)
}
}

#endif


#endif
1 change: 1 addition & 0 deletions IntegrationTests/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const WASI = {
args: [programName],
env: {},
returnOnExit: false,
version: "preview1",
})

return {
Expand Down
16 changes: 8 additions & 8 deletions IntegrationTests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion IntegrationTests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dependencies": {
"@wasmer/wasi": "^0.12.0",
"@wasmer/wasmfs": "^0.12.0",
"uwasi": "^1.0.0",
"uwasi": "^1.2.0",
"javascript-kit-swift": "file:.."
}
}
12 changes: 12 additions & 0 deletions Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,25 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
private func enqueue(_ job: UnownedJob, withDelay nanoseconds: UInt64) {
let milliseconds = nanoseconds / 1_000_000
setTimeout(Double(milliseconds), {
#if compiler(>=5.9)
job.runSynchronously(on: self.asUnownedSerialExecutor())
#else
job._runSynchronously(on: self.asUnownedSerialExecutor())
#endif
})
}

#if compiler(>=5.9)
public func enqueue(_ job: consuming ExecutorJob) {
// NOTE: Converting a `ExecutorJob` to an ``UnownedJob`` and invoking
// ``UnownedJob/runSynchronously(_:)` on it multiple times is undefined behavior.
insertJobQueue(job: UnownedJob(job))
}
#else
public func enqueue(_ job: UnownedJob) {
insertJobQueue(job: job)
}
#endif

public func asUnownedSerialExecutor() -> UnownedSerialExecutor {
return UnownedSerialExecutor(ordinary: self)
Expand Down
4 changes: 4 additions & 0 deletions Sources/JavaScriptEventLoop/JobQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ extension JavaScriptEventLoop {
assert(queueState.isSpinning)

while let job = self.claimNextFromQueue() {
#if compiler(>=5.9)
job.runSynchronously(on: self.asUnownedSerialExecutor())
#else
job._runSynchronously(on: self.asUnownedSerialExecutor())
#endif
}

queueState.isSpinning = false
Expand Down
Loading