Skip to content

Conversation

@dolio
Copy link
Contributor

@dolio dolio commented Oct 31, 2025

This PR makes use of variance information in a couple places that weren't originally.

  1. When solving a variable, we add slack variables to ability lists that occur in strictly positive position. This helps when matching types across branches in an if/match, and similar situations. Two ability sets may not be subsets of one another, but may be subsets of a common set.
  2. When generalizing types, we discard ability variables that only occur in covariant position. This keeps from accumulating these variables into ability lists that confuse the type checker (when multiple occur in the same list, it becomes unclear which one to solve).

Previously, both these steps only applied to arrow types. Now the inferred variances are used as well.

dolio added 2 commits October 31, 2025 13:31
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.
Copy link
Contributor

@ceedubs ceedubs left a comment

Choose a reason for hiding this comment

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

🎉 nice!

@aryairani aryairani merged commit 5af2a54 into trunk Nov 1, 2025
31 checks passed
@aryairani aryairani deleted the topic/variance-improvements branch November 1, 2025 03:06
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.

5 participants