Skip to content

Conversation

@xedin
Copy link
Contributor

@xedin xedin commented Jan 6, 2026

The functionally is hidden behind a constraint system flag - EnableTransitiveInference at the moment
and can only be enabled for unit tests.

The constraint graph now tracks subtype/supertype chains established by introduction of Subtype.
When new exact/supertype binding for a type variable becomes available, it gets propagated up
the chain to all of the current supertypes of this type variable. Such "transitive" bindings get retracted
when a type variable gets bound or originator constraint gets retracted.

This is a replacement for the logic that currently lives in determineBestBindings and isn't currently in
100% correct because it relies on the type variable ordering (i.e. it's wrong when a type variable with
a higher ID is a subtype of a type variable is a lower ID).

xedin added 11 commits January 15, 2026 15:49
There are two variants of `introduceToInference` now, one for a fixed
type binding and the other is for a new constraint added to the node.

This wasn't necessary before since it was a simple `infer` call on
`PotentialBindings` but the plan is to expand this into performing
the transitive inference through subtype chains as well.
This could be used by the constraint graph to propagate transtiive
bindings through subtype chains.
…ariables

This is important to perform actions and propagate bindings and
and down subtype/supertype chains.
…type bindings

A constraint graph node can now receive and propagate subtype bindings
up its supertype chain. At the same time, given a set of constraints a
constraint graph node can recursively, starting from itself, delete all
the transitive bindings associated with them.
…erence`

The `mergeNodesPre` effectively means the type variable that about
to merged into an equivalence class should be removed from inference.
The functinality is enabled by `EnableTransitiveInference` flag.

Instead of transferring supertype bindings up the chain during
`determineBestBindings`, do it when new bindings become available.

This avoids all of the ordering issues that plague the current
approach and helps with the performance.
…ing transitive bindings

This change enables the use of these methods for both subtype and
supertype transitive bindings.
…upertypes

If there are any loops in the graph current recursive approach cannot
discover them because it only seems direct subtypes/supertypes but
BFS algorithm that walks the whole chain starting for the given node
can.
@xedin xedin force-pushed the lazy-transitive-inference branch from 0cbd3d7 to 3bd6da1 Compare January 16, 2026 00:55
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.

1 participant