Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wit-parser): improve checking for stable feature gates #1689

Conversation

vados-cosmonic
Copy link
Contributor

@vados-cosmonic vados-cosmonic commented Jul 18, 2024

This commit introduces some extra checking (and panicking) for feature gates that are stable (i.e. Stability::Stable) AKA @since with a version and/or features specified.

There are two primary changes:

  • Make referring to a future version of the package an error (for now)
  • Ensure that if a feature is specified that it is checked before inclusion

In the past Stability::Stable feature gates were simply treated as Unknown, which hides the information necessary for downstream crates/consumers to use (and created the question around whether referring to future package versions is valid).

See also the relevant Zulip discussion

@vados-cosmonic vados-cosmonic force-pushed the fix(wit-parser)=check-features-for-stable-feature-gates branch 3 times, most recently from 7f9c1b4 to c267ab5 Compare July 18, 2024 18:01
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Could you be sure to add a test for this too? Something in tests/cli/* should suffice with a // FAIL: ... header

crates/wit-parser/src/resolve.rs Outdated Show resolved Hide resolved
crates/wit-parser/src/resolve.rs Outdated Show resolved Hide resolved
crates/wit-parser/src/resolve.rs Outdated Show resolved Hide resolved
@vados-cosmonic vados-cosmonic force-pushed the fix(wit-parser)=check-features-for-stable-feature-gates branch 4 times, most recently from cf7d65b to cbf9bbd Compare July 19, 2024 09:11
crates/wit-parser/src/resolve.rs Outdated Show resolved Hide resolved
crates/wit-parser/src/resolve.rs Outdated Show resolved Hide resolved
crates/wit-parser/src/resolve.rs Outdated Show resolved Hide resolved
crates/wit-parser/src/resolve.rs Outdated Show resolved Hide resolved
crates/wit-parser/src/resolve.rs Outdated Show resolved Hide resolved
crates/wit-parser/src/resolve.rs Outdated Show resolved Hide resolved
@vados-cosmonic vados-cosmonic force-pushed the fix(wit-parser)=check-features-for-stable-feature-gates branch from b92523d to 8425d91 Compare July 23, 2024 05:40
@vados-cosmonic
Copy link
Contributor Author

vados-cosmonic commented Jul 23, 2024

Hey @alexcrichton so looking back at the WIT design doc (while I was trying to change it):

To enable a smooth transition (during which producer toolchains are targeting a version earlier than the @since-specified version), the @SInCE gate contains an optional feature field that, when present, says to enable the feature when either the target version is greator-or-equal or the feature name is explicitly enabled by the developer. Thus, c is enabled if the version is 0.2.2 or newer or the fancy-foo feature is explicitly enabled by the developer. The feature field can be removed once producer toolchains have updated their default version to enable the feature by default.

It looks like there is an expectation for feature to be used along with version to decide when to process a gated item...

Maybe this PR should reflect that, rather than changing it and then updating the docs upstream?

@vados-cosmonic vados-cosmonic force-pushed the fix(wit-parser)=check-features-for-stable-feature-gates branch 2 times, most recently from e099e8b to 8a0eaf8 Compare July 23, 2024 16:34
@alexcrichton
Copy link
Member

Ah I had missed that as well, good catch! That seems reasonable to me to implement yeah, want to do so as part of this PR?

@vados-cosmonic vados-cosmonic force-pushed the fix(wit-parser)=check-features-for-stable-feature-gates branch 3 times, most recently from 7d76c66 to fe67930 Compare July 24, 2024 15:12
@vados-cosmonic
Copy link
Contributor Author

Done!

I needed to add some changes (and update some tests), would appreciate some extra close eyes on this change set (and of course the rest of the PR).

Requiring the feature be specified is making a bunch of interfaces be missing, along with the deprecated flag (which wasn't being taken into account before), just want to make sure I'm reading the test output right and it passes a human spot check that isn't mine.

@vados-cosmonic
Copy link
Contributor Author

Actually, some more thinking here @alexcrichton ... The way that the note is phrased, we actually must allow @since with versions in the future right?

Thus, c is enabled if the version is 0.2.2 or newer or the fancy-foo feature is explicitly enabled by the developer. The feature field can be removed once producer toolchains have updated their default version to enable the feature by default.

Given this sentence it assumes it is possible for c to be at a version that is after the package version -- otherwise it's just a feature check (because right now we consider future versions a bug).

I think to match this expected functionality we have to allow @since(version = x) where x is a future version.

I'm updating the code now to match

@vados-cosmonic vados-cosmonic force-pushed the fix(wit-parser)=check-features-for-stable-feature-gates branch 2 times, most recently from f1e8d12 to 99bbd65 Compare July 24, 2024 17:04
@alexcrichton
Copy link
Member

Hm I think you're right on your interpretation of the text, but now I'm having second thoughts about supporting it exactly as-is. How about reverting back to:

  • With @since the feature is ignored and is purely informational in the WIT itself
  • The @since version must be <= the current package version
  • Using @since requires the package to have a version
  • Mixing @deprecated with @since has no effect on whether it's included or not

That to me feels like a more straightforward way to interpret these attributes and if you agree I can work on sending a PR upstream as well.

@vados-cosmonic
Copy link
Contributor Author

Hey so after some discussion at the JS meeting with @guybedford we actually realized another issue -- the AND vs OR combination of version and feature makes a bunch of things easier w/ respect to figuring out dependencies (i.e. if you know some world imports a, and a has @since(version = v.v.v, feature = f) you can intuit the required package and enabled features of the relevant package).

There's also the benefit (possibly anti-benefit?) of being able to span a feature over multiple versions (changing how a certain item works over two different versions). An example of this that might make sense is something like:

@since(0.2.0, feature = async)
@since(0.3.0, feature = async)

I'm I think there might be a bunch of surprise at the ORing of those, does it make sense to actually hammer this out/give everyone a chance to chat about it in an issue on component-model?

@alexcrichton
Copy link
Member

I'm not sure I quite follow what you mean by AND vs OR? But regardless it seems fine to discuss some more of the finer details on the component-model repository as well.

@vados-cosmonic
Copy link
Contributor Author

vados-cosmonic commented Jul 24, 2024

Ah so before I make the other issue -- basically the idea of whether version and feature should be AND or OR'd --

The logic right now in the WIT design describes an OR (valid version or feature enabled), but it might make sense/be unsurprising to have an AND -- i.e. valid version and feature enabled to see the import at all.

So there are 3 options:

  • OR (current WIT design description)
  • AND (new)
  • Strictly @unstable -> @since with ignored feature

@alexcrichton
Copy link
Member

Ah ok I see. Personally I don't think an AND is viable given how features/since/unstable are planned to be used in WASI. I also don't think that the OR requirement as stated in WIT.md necessarily makes sense because it doesn't really make sense for since to list a version in the future, but if it's always <= the current package version then the OR-ness is like it's OR-ing with true which doesn't affect too much.

In any case I agree with your 3 options, and probably good to discuss upstream!

@vados-cosmonic vados-cosmonic force-pushed the fix(wit-parser)=check-features-for-stable-feature-gates branch 6 times, most recently from 417399c to d7982b3 Compare July 29, 2024 17:43
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! One last comment here and I think this is good to go

crates/wit-parser/src/resolve.rs Outdated Show resolved Hide resolved
@vados-cosmonic vados-cosmonic force-pushed the fix(wit-parser)=check-features-for-stable-feature-gates branch from d7982b3 to 6cbb4a1 Compare July 30, 2024 01:33
@vados-cosmonic vados-cosmonic force-pushed the fix(wit-parser)=check-features-for-stable-feature-gates branch from 6cbb4a1 to c50260a Compare July 30, 2024 02:19
@vados-cosmonic
Copy link
Contributor Author

vados-cosmonic commented Jul 30, 2024

Seems like actions/upload-artifact is having a bit of an outage, hopefully this that step can just be re-run and pass soon!

[EDIT] Rebasing one more time just to try and re-trigger CI

This commit introduces some extra checking for stabilized feature
gates (i.e. `@since` & in-code `Stability::Stable`) with a version
and/or feature specified.

There are two primary changes:
- Ensure that packages containing a `@since` annotation must have a
version specified
- Referring to a future unreleased package version in a `@since`
annotation is an error

In the past `Stability::Stable` feature gates were simply treated as
`Unknown`, which hides the information necessary for downstream
crates/consumers to use (and created the question around whether
referring to future package versions is valid).

Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
@vados-cosmonic vados-cosmonic force-pushed the fix(wit-parser)=check-features-for-stable-feature-gates branch from c50260a to 7ee44d9 Compare July 30, 2024 10:02
@alexcrichton alexcrichton added this pull request to the merge queue Jul 30, 2024
Merged via the queue into bytecodealliance:main with commit 4818141 Jul 30, 2024
28 checks passed
@vados-cosmonic vados-cosmonic deleted the fix(wit-parser)=check-features-for-stable-feature-gates branch July 30, 2024 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants