Skip to content

Commit

Permalink
Follow-up Wasm CI integration (#193)
Browse files Browse the repository at this point in the history
* Skip several deprecated tests on WebAssembly

* Use the official compiler and Swift SDK for WebAssembly

* Grant access to the current directory to the XCTest harness
  • Loading branch information
kateinoigakukun authored Aug 29, 2024
1 parent e443048 commit 857ba4e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 36 deletions.
27 changes: 15 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,26 @@ jobs:
OMIT_MACRO_TESTS: 1
strategy:
matrix:
toolchain:
- wasm-DEVELOPMENT-SNAPSHOT-2024-08-26-a
include:
- toolchain: swift-DEVELOPMENT-SNAPSHOT-2024-07-08-a
swift-sdk: swift-wasm-DEVELOPMENT-SNAPSHOT-2024-07-09-a
steps:
- name: Cache toolchains
uses: actions/cache@v3
with:
path: ~/Library/Developer/Toolchains
key: ${{ matrix.toolchain }}
- uses: actions/checkout@v4
- uses: bytecodealliance/actions/wasmtime/setup@v1
- uses: swiftwasm/setup-swiftwasm@v1
with:
swift-version: ${{ matrix.toolchain }}
- name: Install Swift and Swift SDK for WebAssembly
run: |
PREFIX=/opt/swift
SWIFT_TOOLCHAIN_TAG="${{ matrix.toolchain }}"
SWIFT_SDK_TAG="${{ matrix.swift-sdk }}"
set -ex
curl -f -o /tmp/swift.tar.gz "https://download.swift.org/development/ubuntu2204/$SWIFT_TOOLCHAIN_TAG/$SWIFT_TOOLCHAIN_TAG-ubuntu22.04.tar.gz"
sudo mkdir -p $PREFIX; sudo tar -xzf /tmp/swift.tar.gz -C $PREFIX --strip-component 1
$PREFIX/usr/bin/swift experimental-sdk install "https://github.com/swiftwasm/swift/releases/download/$SWIFT_SDK_TAG/$SWIFT_SDK_TAG-wasm32-unknown-wasi.artifactbundle.zip"
echo "$PREFIX/usr/bin" >> $GITHUB_PATH
- name: Build tests
run: swift build --static-swift-stdlib --triple wasm32-unknown-wasi --build-tests -Xlinker -z -Xlinker stack-size=$((1024 * 1024))
run: swift build --swift-sdk wasm32-unknown-wasi --build-tests -Xlinker -z -Xlinker stack-size=$((1024 * 1024))
- name: Run tests
run: wasmtime .build/debug/swift-case-pathsPackageTests.wasm
run: wasmtime --dir . .build/debug/swift-case-pathsPackageTests.wasm

# windows:
# name: Windows (Swift ${{ matrix.swift }}, ${{ matrix.config }})
Expand Down
71 changes: 47 additions & 24 deletions Tests/CasePathsTests/DeprecatedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,37 @@ final class DeprecatedTests: XCTestCase {
XCTAssertNil(AnyCasePath(Enum.uninhabited).extract(from: .value))
}

func testClosurePayload() throws {
enum Enum { case closure(() -> Void) }
let path = /Enum.closure
for _ in 1...2 {
// Dynamic closure payload extraction is not supported on WebAssembly
//
// Discussion:
// Closure payloads `() -> Void` are extracted via generic abstraction
// `Value` in `extractHelp`, and the extracted closure is called as
// `() -> @out τ_0_0 where τ_0_0 == Void`.
// However, the closure value is stored without generic abstraction
// in the enum payload storage, and not wrapped by abstraction thunk.
// This abstraction mismatch causes signature mismatch between the
// call-site and the actual callee. On most platforms, this mismatch
// is luckily not a problem, but WebAssembly enforces the signature
// match and causes a runtime crash.
// Ideally, `extractHelp` should insert an abstraction thunk when
// extracting a closure payload, but it cannot be done without
// JIT code generation (and WebAssembly does not support JIT...)
#if !arch(wasm32)
func testClosurePayload() throws {
enum Enum { case closure(() -> Void) }
let path = /Enum.closure
for _ in 1...2 {
var invoked = false
let closure = try unwrap(path.extract(from: .closure { invoked = true }))
closure()
XCTAssertTrue(invoked)
}
var invoked = false
let closure = try unwrap(path.extract(from: .closure { invoked = true }))
let closure = try unwrap(AnyCasePath(Enum.closure).extract(from: .closure { invoked = true }))
closure()
XCTAssertTrue(invoked)
}
var invoked = false
let closure = try unwrap(AnyCasePath(Enum.closure).extract(from: .closure { invoked = true }))
closure()
XCTAssertTrue(invoked)
}
#endif

func testRecursivePayload() {
indirect enum Enum: Equatable {
Expand Down Expand Up @@ -891,21 +908,25 @@ final class DeprecatedTests: XCTestCase {
)
}

func testEnumsWithClosures() {
enum Foo {
case bar(() -> Void)
}
// Dynamic closure payload extraction is not supported on WebAssembly
// See testClosurePayload for more details
#if !arch(wasm32)
func testEnumsWithClosures() {
enum Foo {
case bar(() -> Void)
}

var didRun = false
let fooBar = /Foo.bar
guard let bar = fooBar.extract(from: .bar { didRun = true })
else {
XCTFail()
return
var didRun = false
let fooBar = /Foo.bar
guard let bar = fooBar.extract(from: .bar { didRun = true })
else {
XCTFail()
return
}
bar()
XCTAssertTrue(didRun)
}
bar()
XCTAssertTrue(didRun)
}
#endif

func testRecursive() {
indirect enum Foo {
Expand Down Expand Up @@ -1202,10 +1223,12 @@ final class DeprecatedTests: XCTestCase {
)
}

#if os(Windows)
#if os(Windows) || arch(wasm32)
// There seems to be some strangeness with the current
// concurrency implmentation on Windows that breaks if
// you have more than 100 tasks here.
// WebAssembly doesn't support tail-call for now, so we
// have smaller limit as well.
let maxIterations = 100
#else
let maxIterations = 100_000
Expand Down

0 comments on commit 857ba4e

Please sign in to comment.