-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[red-knot] support deferred evaluation of type expressions #13131
Conversation
CodSpeed Performance ReportMerging #13131 will not alter performanceComparing Summary
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks good!
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
I looked into the regression here, and it seems like it's increased Salsa overhead. This is consistent with the regression only showing up in the incremental benchmark, not the cold benchmark. I guess this is because we now double the number of tracked function memos for definitions, which are our highest-cardinality tracked struct. |
I added tracking of whether a given definition has any deferred expressions, which allows us to avoid ever calling |
Yay, CodSpeed agrees! |
Test coverage for #13131 wasn't as good as I thought it was, because although we infer a lot of types in stubs in typeshed, we don't check typeshed, and therefore we don't do scope-level inference and pull all types for a scope. So we didn't really have good test coverage for scope-level inference in a stub. And because of this, I got the code for supporting that wrong, meaning that if we did scope-level inference with deferred types, we'd end up never populating the deferred types in the scope's `TypeInference`, which causes panics like #13160. Here I both add test coverage by running the corpus tests both as `.py` and as `.pyi` (which reveals the panic), and I fix the code to support deferred types in scope inference. This also revealed a problem with deferred types in generic functions, which effectively span two scopes. That problem will require a bit more thought, and I don't want to block this PR on it, so for now I just don't defer annotations on generic functions. Fixes #13160.
Prototype deferred evaluation of type expressions by deferring evaluation of class bases in a stub file. This allows self-referential class definitions, as occur with the definition of
str
in typeshed (which inheritsSequence[str]
).