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 overly-aggressive pruning of types based on features #1958

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

dicej
Copy link
Collaborator

@dicej dicej commented Dec 18, 2024

Previously, ast::Resolve would sometimes assign a Stability to types according to the first function it found that type in as a parameter or result. That's a problem if such a function is marked @unstable, since it will effectively poison that type and prevent it from being used by any other function -- even if the type itself is ungated.

This fixes the problem by removing the &Stability parameter from resolve_params and resolve_results and instead passing &Stability::Unknown to resolve_type from those functions. Additionally, I've added a new find_stability function which recursively inspects a &TypeDefKind, looking for a non-unknown stability. If it finds one, it will use that; otherwise, it will default to Stability::Unknown.

For example, if option<T> appears as a parameter type in a function, we'll start by assuming that type has unknown stability, then look to see if T has a stability (directly or transitively) and use that if so. Things get interesting in the case of e.g. tuple<T, U, V>, where T, U, and V each have their own stability. Currently we just use the first known stability we find, but perhaps there's a better approach to consider?

Previously, `ast::Resolve` would sometimes assign a `Stability` to types
according to the first function it found that type in as a parameter or result.
That's a problem if such a function is marked `@unstable`, since it will
effectively poison that type and prevent it from being used by any other
function -- even if the type itself is ungated.

This fixes the problem by removing the `&Stability` parameter from
`resolve_params` and `resolve_results` and instead passing `&Stability::Unknown`
to `resolve_type` from those functions.  Additionally, I've added a new
`find_stability` function which recursively inspects a `&TypeDefKind`, looking
for a non-unknown stability.  If it finds one, it will use that; otherwise, it
will default to `Stability::Unknown`.

For example, if `option<T>` appears as a parameter type in a function, we'll
start by assuming that type has unknown stability, then look to see if `T` has a
stability (directly or transitively) and use that if so.  Things get interesting
in the case of e.g. `tuple<T, U, V>`, where `T`, `U`, and `V` each have their
own stability.  Currently we just use the first known stability we find, but
perhaps there's a better approach to consider?

Signed-off-by: Joel Dice <[email protected]>
Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

For the tuple and related cases you'd need to redesign the definition of Stability to have a way to represent a union of multiple features, but I think its fine to fix this without opening up that can of worms.

@dicej dicej added this pull request to the merge queue Dec 18, 2024
Merged via the queue into bytecodealliance:main with commit 3c41360 Dec 18, 2024
30 checks passed
@dicej dicej deleted the unstable-funcs-stable-types branch December 18, 2024 23:05
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