Skip to content

Commit 31e9899

Browse files
Make WIT merging commutative (#2451)
* Make WIT merging commutative Signed-off-by: Brian Hardock <brian.hardock@fermyon.com> * Address PR feedback Signed-off-by: Brian Hardock <brian.hardock@fermyon.com> * Re-elaborate worlds after merge Signed-off-by: Brian Hardock <brian.hardock@fermyon.com> --------- Signed-off-by: Brian Hardock <brian.hardock@fermyon.com>
1 parent 3fcabb6 commit 31e9899

38 files changed

Lines changed: 600 additions & 41 deletions

crates/wit-component/tests/merge.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ fn merging() -> Result<()> {
3434
from.assert_valid();
3535
into.assert_valid();
3636

37+
let from_clone = from.clone();
38+
let into_clone = into.clone();
39+
3740
match into.merge(from) {
3841
Ok(_) => {
3942
assert!(
@@ -51,6 +54,13 @@ fn merging() -> Result<()> {
5154
let output = printer.output.to_string();
5255
assert_output(&expected, &output)?;
5356
}
57+
58+
// Also assert merging in the reverse direction succeeds.
59+
let mut reverse = from_clone;
60+
reverse
61+
.merge(into_clone)
62+
.context("merge succeeded in one direction but failed in reverse")?;
63+
reverse.assert_valid();
5464
}
5565
Err(e) => {
5666
assert!(test_case.starts_with("bad-"), "failed to merge with {e:?}");

crates/wit-component/tests/merge/bad-interface1/error.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

crates/wit-component/tests/merge/bad-interface2/error.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package a:b;
2+
3+
interface a {
4+
f1: func();
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package a:b;
2+
3+
interface a {
4+
f2: func();
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package a:b;
2+
3+
interface a {
4+
f2: func();
5+
6+
f1: func();
7+
}
8+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package wasi:io@0.2.0;
2+
3+
interface error {
4+
resource error;
5+
}
6+
7+
interface streams {
8+
use error.{error};
9+
10+
resource output-stream {
11+
check-write: func() -> result<u64, stream-error>;
12+
write: func(contents: list<u8>) -> result<_, stream-error>;
13+
blocking-write-and-flush: func(contents: list<u8>) -> result<_, stream-error>;
14+
blocking-flush: func() -> result<_, stream-error>;
15+
}
16+
17+
variant stream-error {
18+
last-operation-failed(error),
19+
closed,
20+
}
21+
22+
resource input-stream;
23+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package wasi:io@0.2.0;
2+
3+
interface error {
4+
resource error {
5+
to-debug-string: func() -> string;
6+
}
7+
}
8+
9+
interface poll {
10+
resource pollable {
11+
ready: func() -> bool;
12+
block: func();
13+
}
14+
15+
poll: func(in: list<borrow<pollable>>) -> list<u32>;
16+
}
17+
18+
interface streams {
19+
use error.{error};
20+
use poll.{pollable};
21+
22+
variant stream-error {
23+
last-operation-failed(error),
24+
closed,
25+
}
26+
27+
resource input-stream {
28+
read: func(len: u64) -> result<list<u8>, stream-error>;
29+
blocking-read: func(len: u64) -> result<list<u8>, stream-error>;
30+
skip: func(len: u64) -> result<u64, stream-error>;
31+
blocking-skip: func(len: u64) -> result<u64, stream-error>;
32+
subscribe: func() -> pollable;
33+
}
34+
35+
resource output-stream {
36+
check-write: func() -> result<u64, stream-error>;
37+
write: func(contents: list<u8>) -> result<_, stream-error>;
38+
blocking-write-and-flush: func(contents: list<u8>) -> result<_, stream-error>;
39+
flush: func() -> result<_, stream-error>;
40+
blocking-flush: func() -> result<_, stream-error>;
41+
subscribe: func() -> pollable;
42+
write-zeroes: func(len: u64) -> result<_, stream-error>;
43+
blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error>;
44+
splice: func(src: borrow<input-stream>, len: u64) -> result<u64, stream-error>;
45+
blocking-splice: func(src: borrow<input-stream>, len: u64) -> result<u64, stream-error>;
46+
}
47+
}
48+
49+
world imports {
50+
import error;
51+
import poll;
52+
import streams;
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package wasi:io@0.2.0;
2+
3+
interface error {
4+
resource error {
5+
to-debug-string: func() -> string;
6+
}
7+
}
8+
9+
interface poll {
10+
resource pollable {
11+
ready: func() -> bool;
12+
block: func();
13+
}
14+
15+
poll: func(in: list<borrow<pollable>>) -> list<u32>;
16+
}
17+
18+
interface streams {
19+
use error.{error};
20+
use poll.{pollable};
21+
22+
variant stream-error {
23+
last-operation-failed(error),
24+
closed,
25+
}
26+
27+
resource input-stream {
28+
read: func(len: u64) -> result<list<u8>, stream-error>;
29+
blocking-read: func(len: u64) -> result<list<u8>, stream-error>;
30+
skip: func(len: u64) -> result<u64, stream-error>;
31+
blocking-skip: func(len: u64) -> result<u64, stream-error>;
32+
subscribe: func() -> pollable;
33+
}
34+
35+
resource output-stream {
36+
check-write: func() -> result<u64, stream-error>;
37+
write: func(contents: list<u8>) -> result<_, stream-error>;
38+
blocking-write-and-flush: func(contents: list<u8>) -> result<_, stream-error>;
39+
flush: func() -> result<_, stream-error>;
40+
blocking-flush: func() -> result<_, stream-error>;
41+
subscribe: func() -> pollable;
42+
write-zeroes: func(len: u64) -> result<_, stream-error>;
43+
blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error>;
44+
splice: func(src: borrow<input-stream>, len: u64) -> result<u64, stream-error>;
45+
blocking-splice: func(src: borrow<input-stream>, len: u64) -> result<u64, stream-error>;
46+
}
47+
}
48+
49+
world imports {
50+
import error;
51+
import poll;
52+
import streams;
53+
}

crates/wit-component/tests/merge/bad-interface2/from/a.wit renamed to crates/wit-component/tests/merge/disjoint-funcs/from/a.wit

File renamed without changes.

0 commit comments

Comments
 (0)