-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[red-knot] Prevent cross-module query dependencies in own_instance_member
#16268
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
Conversation
|
Ha, this actually performs better and it also makes it harder to hold it wrong. I still haven't been able to construct a test case where |
68a1dd2 to
ad6ef57
Compare
ad6ef57 to
a4a3193
Compare
| self.kind(db).category() | ||
| } | ||
|
|
||
| pub(crate) fn is_declaration(self, db: &'db dyn Db) -> bool { |
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.
These accessors are footguns. They make it very easy to introduce dependencies on kind. That's why I removed them.
AlexWaygood
left a comment
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.
I have not reviewed line-by-line in depth but this makes sense to me!
|
|
||
| /// This test verifies that queries | ||
| #[test] | ||
| fn dependency_own_instance_member() -> anyhow::Result<()> { |
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.
the amount of setup required here makes me think that we might want to prioritise adding support for incremental tests to mdtest, similar to mypy's test framework (take a look at https://github.com/python/mypy/blob/master/test-data/unit/check-incremental.test)
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.
Yeah, although copy pasting is fine, considering how few we have but it could be something to consider for a more scalable approach on how to avoid cross-file queries.
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.
yeah, it would only be worth it if we consider that it would be useful to have a lot more tests like this, and we want to make it easier to write those tests.
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.
There was already a design for this in the original mdtest design (and it's in the README as a planned improvement), we just haven't implemented yet. (And the design probably needs to change a bit to avoid using non-rendering tag info strings on code blocks.)
own_instance_member
own_instance_memberown_instance_member
CodSpeed Performance ReportMerging #16268 will improve performances by 5.46%Comparing Summary
Benchmarks breakdown
|
|
Okay, keeping the |
|
@carljm said he liked it overall. So I'll go ahead and merge it. We may want to keep iterating on how we want to enforce cross-module boundaries. E.g. is it okay that |
Summary
This PR fixes #16172 by using
infer_expression_type(which is a salsa query) when evaluating visibility constraints. This should be sufficient to remove any AST reads fromsymbol_from_declarationsandsymbol_from_bindings.I did consider making a more local change in
own_instance_memberbut I think that has two downsides:symbolhas no visibility constraints (probably common for instance members?)symbol_from_declarationsandsymbol_from_bindingsare still cross-module, and it's very easy to forget to put the call behind a query because it isn't obvious that the method does cross-file analysis.Performance
The cold benchmark improves by about 1%, the incremental benchmark by 3%
I first considered removing the
#[salsa::tracked]fromsymbol_by_idbecause it is no longer necessary for cross-module isolation. However, this PR showed that the version wheresymbol_by_idactually performs better #16279 (comment)Test Plan
I added a new test for
own_instance_memberthat assert thatown_instance_memberisn't re-executed if there's a no-op change in the module that declares theClass. All credit for that test goes to @sharkdp because I used his original test as a template and he helped me come up with an example that contains visibility constraints.I verified that the test fails on
main.