Make more use of inferred variances during type checking#5976
Merged
Make more use of inferred variances during type checking#5976
Conversation
The original variance work only used variances in subtyping. However, there are a couple other places that variance is relevant that this adds support for. - When solving a variable to a type involving abilities, we relax ability lists in strictly positive position with an extra ability variable if they don't have one already. This allows for e.g. types with different concrete ability lists in separate branches of an if/case to resolve to the combined list. - When generalizing, we discard variables that occur only in covariant position. This avoids some cases that build up multiple ability variables in a single list, which confuses the type checker. It also generally produces cleaner looking types. Previously these only applied to arrow types, but now it also works based on inferred variances.
pchiusano
approved these changes
Oct 31, 2025
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.
This PR makes use of variance information in a couple places that weren't originally.
if/match, and similar situations. Two ability sets may not be subsets of one another, but may be subsets of a common set.Previously, both these steps only applied to arrow types. Now the inferred variances are used as well.