-
Notifications
You must be signed in to change notification settings - Fork 1k
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] Eagerly validate search paths before constructing Program
s
#12684
Conversation
|
It seems to me that a lot of the pain here arises from the fact that |
That sounds reasonable to me, but I'll defer to @MichaReiser on this :-) |
aa6d0a2
to
7fb0168
Compare
I don't think this will work because the module resolver depends on I haven't looked at the specific implementation here and it may be worth thinking this through more carefully and re-reading through #12318. To me, the most natural place for
|
6c9d976
to
9d483c4
Compare
9d483c4
to
c5581f9
Compare
I plan to look at this once I start working on validation. Sorry for the delay. Let me know if you want feedback earlier |
No worries; I don't see that as urgent. It's a pain that it touches so many files as merge conflicts keep cropping up, but it is what it is 😄 Please take your time! |
I thought more about this and I'm leaning towards merging @AlexWaygood what do you think of unifying the two crates? |
Yeah I think combining the two crates could definitely make sense. I wasn't 100% sure it made sense for them to be separate crates to begin with. In theory it's nice to have a clean separation of concerns between the semantic-model crate and the module resolver but in practice it doesn't really work:
|
Summary
This is a prototype for a way by which we could move settings resolution for search paths out of the module resolver. It may not be the best way; I'm not wedded to it necessarily!
Moving settings resolution for search paths out of the module resolver enables us to validate that these settings are correct before constructing
Program
instances, which is desirable becauseProgram
instances should ideally store validated, normalized settings on them rather than unvalidated, unnormalized settings.The way this PR works is that in
crates/ruff_db/src/program.rs
, newSearchPathInner
andSearchPath
types are added. These are extremely minimal, but in terms of the data they hold they have 1:1 correspondence with theSearchPathInner
andSearchPath
types incrates/red_knot_module_resolver/path.rs
. Having public types inruff_db
that can be cheaply and easily converted to and from the private types inred_knot_module_resolver
means that theProgram
struct can use aSearchPath
type in its fields (representing a validated, normalized search path) without depending on anything from the module-resolver crate.The module resolver, meanwhile, exposes a new public function for creating a
Program
instance from the raw, unvalidated search-path settings. This function uses internals of the module resolver to attempt to construct validatedred_knot_module_resolver::SearchPath
s, and then cheaply converts those search paths toruff_db::SearchPath
s in order to construct aProgram
instance.I initially experimented with simply moving the
SearchPathInner
andSearchPath
types out of the module resolver crate entirely and intoruff_db
. While this is doable, it is quite painful, because validating search paths requires knowledge of the internals of the module resolver. For example: one of the validation steps we need to perform is to check that the file atstdlib/VERSIONS
parses as a validVERSIONS
file if the user has given us a custom typeshed directory. Attempting to parseVERSIONS
requires knowledge of the structure of theVERSIONS
file, which in turn requires knowledge of theModuleName
type, etc. etc.Guide to reviewing
I would recommend looking at the changes to
ruff_db
first, then the changes tored_knot_module_resolver
, and everything else after that.Test Plan
cargo test