Fix path canonicalization in witx use statements#434
Conversation
|
|
8d844d3 to
7ac465b
Compare
|
I have updated this branch so that it is based on #395, which I believe is the commit that corresponds with the Unfortunately, this work conflicts with changes that introduced a new So, in order for this work to make its way into a I thank you in advance for your time and assistance 💌 |
|
Thanks for the fix! I agree yeah that we should revert the Are you ok submitting the reverts? I can take a quick look and approve them/this. |
7ac465b to
99d6cde
Compare
|
I've just pushed #435, which should unblock this patch 🙂 I'll note that I've not updated the base branch here, because I'm not sure how well that plays across forks. |
|
I think this may need a rebase now with the recent merge, but tests may also need some updates? |
This test case demonstrates a bug identified with the semantics of `use` statements in witx documents. No fix is provided in this commit, so `cargo test` will fail at this commit.
Because who doesn't love println debugging?
Now, running the (failing) test case added in the previous commit, we'll
see:
```
---- toplevel::test::multi_use_with_layered_dirs stdout ----
parsing file at path='"root.witx"' root='"/"'
canonical-path='"/root.witx"'
found a use statement, parsing file at "subdir/child.witx"
parsing file at path='"subdir/child.witx"' root='"/"'
canonical-path='"/subdir/child.witx"'
found a use statement, parsing file at "sibling.witx"
parsing file at path='"sibling.witx"' root='"/"'
canonical-path='"/sibling.witx"'
thread 'toplevel::test::multi_use_with_layered_dirs' panicked at 'parse: Io("/sibling.witx", Custom { kind: Other, error: "mock fs: file not found" })', src/toplevel.rs:151:10
```
Note that root is always `/` even when we're evaluating the paths found
in a document that lives in a subdirectory! See how the canonical path
in the last block resolves to '/sibling.witx'?
We found you, Mr. Bug 🐛 🔍😃
This reverts commit 07c1ae9.
99d6cde to
acb808e
Compare
Indeed! I've rebased this branch. Thank you for the quick response! I'll fix tests up next 🙂 |
|
The tests have been satiated |
pchickey
left a comment
There was a problem hiding this comment.
This looks great, suggest adding one more check to the tests (which it passes!)
diff --git a/tools/witx/src/toplevel.rs b/tools/witx/src/toplevel.rs
index e415065..94dbd13 100644
--- a/tools/witx/src/toplevel.rs
+++ b/tools/witx/src/toplevel.rs
@@ -150,6 +150,10 @@ mod test {
"(use \"sibling.witx\")\n(typename $b_float f64)",
),
("/subdir/sibling.witx", "(typename $c_int u32)"),
+ // This definition looks just like subdir/sibling.witx but
+ // defines c_int differently - this test shows it does Not get
+ // included by subdir/child.witx's use.
+ ("/sibling.witx", "(typename $c_int u64)"),
]),
)
.expect("parse");
Co-authored-by: Pat Hickey <phickey@fastly.com>
Great idea! I've added that in 5148a1b. ✨ |
|
It looks like the crate was last published at 7ec4b1a (diff from |
Per this discussion from WebAssembly#434: > It looks like the crate was last published at > [7ec4b1a](WebAssembly@7ec4b1a) > ([diff from > `main`](WebAssembly/WASI@ef8c1a5...main)), > and if we'd like to make an 0.9.1 release (ideally just a bugfix > release), I think there's another breaking change we merged in the > meantime, notably the deletion of `tools/witx/src/phases.rs`, which I > think happened as WebAssembly#398. I think we may need to revert that as well > before publishing 0.9.1? - [@alexcrichton](WebAssembly#434 (comment)) This reintroduces 'witx::phases', so that we do not include any breaking changes in what ought to be a pure bug release.
Great catch, thank you. I've just opened #436, which should address this point. |
Per this discussion from #434: > It looks like the crate was last published at > [7ec4b1a](7ec4b1a) > ([diff from > `main`](ef8c1a5...main)), > and if we'd like to make an 0.9.1 release (ideally just a bugfix > release), I think there's another breaking change we merged in the > meantime, notably the deletion of `tools/witx/src/phases.rs`, which I > think happened as #398. I think we may need to revert that as well > before publishing 0.9.1? - [@alexcrichton](#434 (comment)) This reintroduces 'witx::phases', so that we do not include any breaking changes in what ought to be a pure bug release.
The 0.9.1 release of witx most importantly includes WebAssembly/WASI#434, which is a bug-fix affecting transitive imports in witx documents.
This updates the WASI submodule, pulling in changes to the witx crate, now that there is a 0.9.1 version including some bug fixes. See WebAssembly/WASI#434 for more information.
This updates the WASI submodule, pulling in changes to the witx crate, now that there is a 0.9.1 version including some bug fixes. See WebAssembly/WASI#434 for more information.
* wasi-common: update wasi submodule This updates the WASI submodule, pulling in changes to the witx crate, now that there is a 0.9.1 version including some bug fixes. See WebAssembly/WASI#434 for more information. * wiggle: update witx dependencies * publish: verify and vendor witx-cli * adjust root workspace members This commit removes some items from the root manifest's workspace members array, and adds `witx-cli` to the root `workspace.exclude` array. The motivation for this stems from a cargo bug described in rust-lang/cargo#6745: `workspace.exclude` does not work if it is nested under a `workspace.members` path. See WebAssembly/WASI#438 for the underlying change to the WASI submodule which reorganized the `witx-cli` crate, and WebAssembly/WASI#398 for the original PR introducing `witx-cli`. See [this comment](#3025 (comment)) for more details about the compilation errors, and failed alternative approaches that necessitated this change. N.B. This is not a functional change, these crates are still implicitly workspace members as transitive dependencies, but this will allow us to side-step the aforementioned cargo bug. Co-Authored-By: Alex Crichton <alex@alexcrichton.com> Co-authored-by: Alex Crichton <alex@alexcrichton.com>
🦇 ✨ Hello!
This branch fixes a bug I have found in the
witxcrate, involvingusestatements.🐛 The Bug
Paths in ..transitive(?)
usestatements (e.g. document A imports document B, which imports document C) are evaluated relative to the original root document, rather than the import-er document B.This is better understood with an example (see below), or consulting the test case added here,
multi_use_with_layered_dirs. Note that unlike the existingmulti_usetest, these documents do not all live within the same directory in the file system.📜 Example
Today, when
root.witxis loaded, we'll run into an error that/sibling.witxdoes not exist.☭ The Fix
The fix for this turns out to be a single line of code! That can be found in 963c5cf.
It turns out that when we were recursing in
witx::toplevel::parse_fileupon the discovery of ausestatement, we'd pass the originalrootalong, rather than providing the directory of the given document.