fix overly-aggressive pruning of types based on features#1958
Merged
dicej merged 1 commit intobytecodealliance:mainfrom Dec 18, 2024
Merged
fix overly-aggressive pruning of types based on features#1958dicej merged 1 commit intobytecodealliance:mainfrom
dicej merged 1 commit intobytecodealliance:mainfrom
Conversation
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 <joel.dice@fermyon.com>
pchickey
approved these changes
Dec 18, 2024
Contributor
pchickey
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously,
ast::Resolvewould sometimes assign aStabilityto 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
&Stabilityparameter fromresolve_paramsandresolve_resultsand instead passing&Stability::Unknowntoresolve_typefrom those functions. Additionally, I've added a newfind_stabilityfunction which recursively inspects a&TypeDefKind, looking for a non-unknown stability. If it finds one, it will use that; otherwise, it will default toStability::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 ifThas a stability (directly or transitively) and use that if so. Things get interesting in the case of e.g.tuple<T, U, V>, whereT,U, andVeach have their own stability. Currently we just use the first known stability we find, but perhaps there's a better approach to consider?