[red-knot] support empty TypeInference with fallback type#16510
Merged
Conversation
MichaReiser
approved these changes
Mar 5, 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 is split out of #14029, to reduce the size of that PR, and to validate that this "fallback type" support in
TypeInferencedoesn'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"
TypeInferencewhere 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 beType::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.