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] Resolve and check dependencies #11161
Conversation
// WARNING!: It's important that this method takes `&mut self`. Without, the implementation is prone to race conditions. | ||
// Note: This won't work with salsa because `Path` is not an ingredient. | ||
pub fn path_to_module<Db>(db: &mut Db, path: &Path) -> Option<Module> |
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 think that's actually fine. There's no risk for deadlocks because the function only ever holds on to a single lock (and not multiple ones). Any mutations happen through resolve_module
which must be idempotent. The only overhead here is that we might end up calling resolve_module
unnecessary but that's fine.
we could even consider not making this method a query. Searching the root paths is cheap. I think the only place where we safe some performance is that we avoid the canoncialize
call. So that's why I think it's still worth keeping the cache for now.
8ae5c06
to
5b9d16f
Compare
|
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.
Some comments in here (the __init__.py
thing for relative imports, and the level = Some(0)
thing) that should definitely at least get TODO comments, if not fixed before merge.
aca0d3d
to
636ca68
Compare
5b9d16f
to
88b1a51
Compare
// `from baz import bar` in `foo/__init__.py` should resolve to `foo/baz.py` | ||
assert_eq!( | ||
Some(ModuleName::new("foo.baz")), | ||
foo_module.relative_name(&db, 0, Some("baz")) | ||
); |
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.
This one isn't right, from baz import bar
is not a relative import (no dots), it's an absolute import, so this should resolve to just baz
.
Either relative_import
should error on level = 0
(and we should never call it that way), or it should just resolve it as an absolute import.
// `from baz import test` in `foo/bar.py` resolves to `foo.bar.baz` | ||
assert_eq!( | ||
Some(ModuleName::new("foo.bar.baz")), | ||
bar_module.relative_name(&db, 0, Some("baz")) | ||
); |
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.
this one is also wrong for the same reason mentioned above
Summary
Discover a modules dependencies and schedule them for checking.
This does not yet support native dependencies of which we don't have access to the source.
Test Plan
I created a
test.py
and ranred_knot test.py
. The test.py importsmatch.py
.I can see from the logs that
match.py
is correctly scheduled for checking. Cyclic dependencies work too.Red knot won't emit any diagnostics for
match.py
because it isn't an open file.