Stream: jco

Topic: support for @since/@after/@unstable


view this post on Zulip Victor Adossi (Jul 01 2024 at 14:17):

Hey all, been working on support for the new WIT feature gating functionality -- it's required a bunch of updates (even further than what was added just last week), and I'm trying to add a test, etc.

Would love anyone with opinions/comments to take a look at the draft PR:

https://github.com/bytecodealliance/jco/pull/459

This PR updates jco to support the @since, @after and @unstable annotations as implemented by the upstream Rust tooling. Currently there are a few issues left to address: We likely need an upstre...

view this post on Zulip Guy Bedford (Jul 02 2024 at 17:16):

Thanks for working on this! I've left some comments in the PR.

view this post on Zulip Victor Adossi (Jul 09 2024 at 15:35):

Hey all -- made some progress here, but I think I'm stuck.

I have two tests that do what they're supposed to, and one that doesn't -- in particular @since(0.2.2) is not being removed from a package that is at @0.2.1 -- and the Stability values I'm getting from the functions are all actually Unknown when I'd expect them to be marked with versions

view this post on Zulip Victor Adossi (Jul 09 2024 at 15:39):

The PR is updated (it seems to be steadily growing...) but the relevant wit is:

package test:feature-gates@0.2.1;

interface foo {
  a: func();

  @since(version = 0.2.1)
  b: func();

  @since(version = 0.2.2)
  c: func();

  @unstable(feature = fancier-foo)
  d: func();
}

world import-and-export {
  import foo;
  export foo;
}

I've also added printlns so if you comment out the tests that aren't witTest you'll see output coming from ts_bindgen.rs that looks like this:

> @bytecodealliance/jco@1.3.1 test                                                                                                                                                                                                           
> node --stack-trace-limit=100 node_modules/mocha/bin/mocha.js -u tdd test/test.js --timeout 30000                                                                                                                                           
                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                             
  WIT                                                                                                                                                                                                                                        
[TS_BINDGEN] generating TS func: [a] (stability: Unknown)                                                                                                                                                                                    
[TS_BINDGEN] generating TS func: [b] (stability: Unknown)                                                                                                                                                                                    
[TS_BINDGEN] generating TS func: [c] (stability: Unknown)                                                                                                                                                                                    
                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                             
[TEST] interfaces file content? export namespace TestFeatureGatesFoo {                                                                                                                                                                       
  export function a(): void;                                                                                                                                                                                                                 
  export function b(): void;                                                                                                                                                                                                                 
  export function c(): void;                                                                                                                                                                                                                 
}                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                             
    1) feature-gates: since should exclude future versions                                                                                                                                                                                   
[TS_BINDGEN] generating TS func: [a] (stability: Unknown)                                                                                                                                                                                    
[TS_BINDGEN] generating TS func: [b] (stability: Unknown)                                                                                                                                                                                    
[TS_BINDGEN] generating TS func: [c] (stability: Unknown)                                                                                                                                                                                    
[TS_BINDGEN] generating TS func: [d] (stability: Unknown)                                                                                                                                                                                    
     feature-gates: unstable should be present with all features enabled                                                                                                                                                                    
[TS_BINDGEN] generating TS func: [a] (stability: Unknown)                                                                                                                                                                                    
[TS_BINDGEN] generating TS func: [b] (stability: Unknown)                                                                                                                                                                                    
[TS_BINDGEN] generating TS func: [c] (stability: Unknown)                                                                                                                                                                                    
     feature-gates: unstable should not be present without all features enabled

view this post on Zulip Victor Adossi (Jul 09 2024 at 15:41):

Just want to make sure I'm not misunderstanding the feature, but I'd expect to not see c() because it's @since(0.2.2) and the package is @0.2.1.

I also tried with 0.3.0 just to be sure I wasn't running into a semver compat smoothing thing.

Weirdly enough, unstable works just fine w/ all features specified (those are the passing tests)

view this post on Zulip Guy Bedford (Jul 09 2024 at 18:06):

@Victor Adossi this looks amazing. Given you're seeing information being lost, I'm wondering if the issue here is just lower-level then? There seems to have been a bit of movement in this code in wasm-tools. Perhaps this is an issue in the Wasmtime machinery itself? I wonder if the unreleased wasm-tools code here will fix it?

view this post on Zulip Victor Adossi (Jul 10 2024 at 01:52):

Appreciate all the help so far :bow:

I think you're right, I'm going to take a look at the lower level wasm-tools again -- I'm already on 0.212.0, but it really feels like they shouldn't all be Unknown, there may have been some movement there I haven't pulled down... Looking at the upstream code I'm also fairly certain I shouldn't even see the import on the to begin with (like how unstable worked)...

view this post on Zulip Christof Petig (Jul 10 2024 at 05:06):

Yesterday I encountered a panic in wit-parser because Wasi-cli's since isn't merged, yet. This was due to a mismatching since and unknown on the same interface.

Perhaps upgrading cli to Joel's version already fixes things.

view this post on Zulip Victor Adossi (Jul 10 2024 at 13:03):

mismatching since & unknown on the same interface is a use case I don't even have in the test yet -- I should add it.

Would you mind sharing a snippet of the WIT, @Christof Petig ?

view this post on Zulip Christof Petig (Jul 10 2024 at 13:23):

I will need to gather the details, just combining Wasi-cli main with main on the other Wasi dependencies (io, fs, clocks) using wit-deps created the problem for us.

view this post on Zulip Victor Adossi (Jul 10 2024 at 15:29):

Ahh thanks, let me take a look and see those changes, maybe no need to waste cycles gathering the details just yet, though I'm going to add that test

view this post on Zulip Christof Petig (Jul 10 2024 at 20:27):

:thinking: it was far more difficult to reproduce than I thought. Here it is: take this wit/deps.toml and wit/test.wit combo, run wit-deps update and then wit-bindgen markdown wit.

It crashes with

thread 'main' panicked at /.cargo/registry/src/index.crates.io-6f17d22bba15001f/wit-parser-0.212.0/src/resolve.rs:2350:21:
assertion `left == right` failed
  left: Interface { id: Id { idx: 1 }, stability: Unknown }
 right: Interface { id: Id { idx: 1 }, stability: Stable { since: Version { major: 0, minor: 2, patch: 0 }, feature: None } }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

If you replace either clocks with v0.2.0 or cli with the version by JoelYoshua the crash is gone.
wasi-problem.tgz

view this post on Zulip Christof Petig (Jul 10 2024 at 20:29):

Version by Yoshua at https://github.com/WebAssembly/wasi-cli/pull/43

Depends on WebAssembly/component-model#332 to be merged first. This documents the stability of all items using the @since gate notation, enabling WIT documents to be updated over time without major...

view this post on Zulip Christof Petig (Jul 10 2024 at 20:32):

But to be honest I haven't yet figured out which interface is referenced both with and without since.

view this post on Zulip Christof Petig (Jul 10 2024 at 20:35):

Here is the full version (no wit-deps update required to retrieve the deps)
wasi-problem.full.tgz

view this post on Zulip Victor Adossi (Jul 11 2024 at 08:08):

Thanks for providing the tarballs -- I'm not sure I'm completely right (maybe you could confirm) but the line that is being pointed to seems to be this one:

https://github.com/bytecodealliance/wasm-tools/blob/v1.212.0/crates/wit-parser/src/resolve.rs#L2350

CLI and Rust libraries for low-level manipulation of WebAssembly modules - bytecodealliance/wasm-tools

view this post on Zulip Victor Adossi (Jul 11 2024 at 08:09):

It looks like wit parser expects stabilities to never change, and we're getting the interface in there as Unknown at one poitn then the newer version actually has it specified?

view this post on Zulip Victor Adossi (Jul 11 2024 at 08:10):

Wonder if that assert_eq! should be a bail! with a more descriptive error message

view this post on Zulip Christof Petig (Jul 11 2024 at 11:06):

Ideally it would output the name of the interface which got redefined, but due to rearranging of the structure during the merge this is a far from easy to get information. Another solution would be to ignore unknown in the comparison.

view this post on Zulip Christof Petig (Jul 11 2024 at 11:07):

And yes this assert_eq is exactly the panicking line.

view this post on Zulip Christof Petig (Jul 11 2024 at 11:12):

I feel filling a bug report on wit-parser would be adequate.

view this post on Zulip Victor Adossi (Jul 12 2024 at 14:15):

Filed an issue:
https://github.com/bytecodealliance/wasm-tools/issues/1666

@Yoshua Wuyts would you mind taking a look if you find some time? The thing is that the check makes sense -- the same item shouldn't have it's Stability essentially discovered twice (and be different)... so the assert makes sense, and however we're getting the Unknown in there in the first place is probably what's jamming me up on thejco impl

In attempting to implement @since and related feature gates in jco I ran into an issue that may be long here. First, all the Stability values in functions on the Resolve seem to be Unknown. Secondl...

view this post on Zulip Victor Adossi (Jul 17 2024 at 16:38):

Hmnnn, so I've updated to 0.214.0 and relevant packages but still see the issue -- all stabilities are still coming in as Unknown.

Still looking into why this could be, maybe the right annotation is ending up in the wrong place possibly

view this post on Zulip Victor Adossi (Jul 17 2024 at 18:52):

OK so I think I've found where the issue might be -- it seems that update_stability is not called when moving worlds, and in particular moving interfaces...

CLI and Rust libraries for low-level manipulation of WebAssembly modules - bytecodealliance/wasm-tools

view this post on Zulip Victor Adossi (Jul 17 2024 at 18:53):

I'm wondering if there's not enough copying/moving done there -- when I print out the stabilities for the items as they pass through, they're correct (non-Unknown)

view this post on Zulip Victor Adossi (Jul 18 2024 at 14:44):

Ah some interesting discussion on how the feature gating should work in the first place:

https://bytecodealliance.zulipchat.com/#narrow/stream/223391-wasm/topic/Missing.20impl.20for.20.40since.20in.20.60Resolve.3A.3Ainclude_stability.28.29.60/near/452175637

Found the bit that was missing -- but maybe it should be missing


Last updated: Dec 23 2024 at 12:05 UTC