Skip to content

Commit c3671e8

Browse files
authored
Fix infinite loop when diffing non-equatable recursive objects (#137)
* Fix infinite loop when diffing non-equatable recursive objects Fixes #136. * wip * wip * wip * wip * wip
1 parent 5d132f7 commit c3671e8

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

.github/workflows/ci.yml

+13-10
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,22 @@ jobs:
4343
run: make test-linux SWIFT_VERSION=${{ matrix.swift }}
4444

4545
wasm:
46-
name: SwiftWasm
46+
name: Wasm
4747
runs-on: ubuntu-latest
4848
steps:
4949
- uses: actions/checkout@v4
5050
- uses: bytecodealliance/actions/wasmtime/setup@v1
51-
- uses: swiftwasm/setup-swiftwasm@v1
52-
with:
53-
swift-version: "wasm-5.9.2-RELEASE"
54-
- name: Build tests
55-
# Extend the stack size to avoid stack overflow in the test suites
56-
run: swift build --triple wasm32-unknown-wasi --build-tests -Xlinker -z -Xlinker stack-size=$((1024 * 1024))
57-
- name: Run tests
58-
run: wasmtime .build/debug/swift-custom-dumpPackageTests.wasm
51+
- name: Install Swift and Swift SDK for WebAssembly
52+
run: |
53+
PREFIX=/opt/swift
54+
set -ex
55+
curl -f -o /tmp/swift.tar.gz "https://download.swift.org/swift-6.0.3-release/ubuntu2204/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-ubuntu22.04.tar.gz"
56+
sudo mkdir -p $PREFIX; sudo tar -xzf /tmp/swift.tar.gz -C $PREFIX --strip-component 1
57+
$PREFIX/usr/bin/swift sdk install https://github.com/swiftwasm/swift/releases/download/swift-wasm-6.0.3-RELEASE/swift-wasm-6.0.3-RELEASE-wasm32-unknown-wasi.artifactbundle.zip --checksum 31d3585b06dd92de390bacc18527801480163188cd7473f492956b5e213a8618
58+
echo "$PREFIX/usr/bin" >> $GITHUB_PATH
59+
60+
- name: Build
61+
run: swift build --swift-sdk wasm32-unknown-wasi -Xlinker -z -Xlinker stack-size=$((1024 * 1024))
5962

6063
windows:
6164
name: Windows
@@ -117,4 +120,4 @@ jobs:
117120
with:
118121
api-level: 29
119122
arch: x86_64
120-
script: ~/test-toolchain.sh
123+
script: ~/test-toolchain.sh

Sources/CustomDump/Internal/Mirror.swift

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ extension Mirror {
2828

2929
func isMirrorEqual(_ lhs: Any, _ rhs: Any) -> Bool {
3030
guard let lhs = lhs as? any Equatable else {
31+
let lhsType = type(of: lhs)
32+
if lhsType is AnyClass, lhsType == type(of: rhs), lhs as AnyObject === rhs as AnyObject {
33+
return true
34+
}
3135
let lhsMirror = Mirror(customDumpReflecting: lhs)
3236
let rhsMirror = Mirror(customDumpReflecting: rhs)
3337
guard

Tests/CustomDumpTests/DiffTests.swift

+9
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,15 @@ final class DiffTests: XCTestCase {
12901290
"""
12911291
)
12921292
}
1293+
1294+
func testRecursion() {
1295+
class Object {
1296+
var child: Object?
1297+
}
1298+
let object = Object()
1299+
object.child = object
1300+
XCTAssertNil(diff(object, object))
1301+
}
12931302
}
12941303

12951304
private class Shared: _CustomDiffObject, Equatable {

0 commit comments

Comments
 (0)