Skip to content

Comments

[red-knot] support empty TypeInference with fallback type#16510

Merged
carljm merged 3 commits intomainfrom
cjm/fallbackty
Mar 5, 2025
Merged

[red-knot] support empty TypeInference with fallback type#16510
carljm merged 3 commits intomainfrom
cjm/fallbackty

Conversation

@carljm
Copy link
Contributor

@carljm carljm commented Mar 5, 2025

This is split out of #14029, to reduce the size of that PR, and to validate that this "fallback type" support in TypeInference doesn't come with a performance cost. It also improves the reliability and debuggability of our current (temporary) cycle handling.

In order to recover from a cycle, we have to be able to construct a "default" TypeInference where all expressions and definitions have some "default" type. In our current cycle handling, this "default" type is just unknown or a todo type. With fixpoint iteration, the "default" type will be Type::Never, which is the "bottom" type that fixpoint iteration starts from.

Since it would be costly (both in space and time) to actually enumerate all expressions and definitions in a scope, just to insert the same default type for all of them, instead we add an optional "missing type" fallback to TypeInference, which (if set) is the fallback type for any expression or definition which doesn't have an explicit type set.

With this change, cycles can no longer result in the dreaded "Missing key" errors looking up the type of some expression.

@carljm carljm marked this pull request as ready for review March 5, 2025 00:33
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Mar 5, 2025
@carljm carljm merged commit 114abc7 into main Mar 5, 2025
21 checks passed
@carljm carljm deleted the cjm/fallbackty branch March 5, 2025 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants