-
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: improve internal documentation in module.rs
#11638
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Oops, something went wrong.
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.
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.
Another reason is that it is a specific concept that is worth its own name and it also stores additional data that isn't available on a path (except if you mean
ModulePath
)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.
Right. At first I thought this struct was really a
ModuleID
struct because it seemed to be a thin wrapper around a primitive type. But now I see that the primitive type really is the ID for the module, and that the struct is correctly named. Which means that this comment is not quite accurate!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.
Hmm, but that isn't quite right either, I see? Since the
modules
field on theModuleResolver
struct mapsModule
objects toModuleData
objects, and its theModuleData
objects that seem to hold the interesting information about the module.In general I feel slightly confused about whether this is meant to represent:
Module
to me); or,FileID
elsewhere in redknot, or toBindingID
inruff_python_semantic/binding.rs
).Currently it feels like it maybe sits awkwardly between the two concepts
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 I'll just remove this comment and try to refactor this into something I like more ;)
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 way module is defined is very intentional. Not necessarily the fields it stores and its name but that it is a thin wrapper around a
u32
with methods to query its fields. From an API perspective, this is theModule
and an outside client doesn't need to be concerned about how it stores the data internally.The reason why we shouldn't change this representation significantly is because this exactly maps to Salsa. You can have a look at my PR and you'll find something very similar:
ResolvedModule
is a newtype wrapper around au32
. This is important for fast cache lookups and to avoid awkward lifetimes. It also ensures that we can store aResolvedModule
very cheaply, it's just 4 bytes.db
as an argument and return the field dataWe can't change this without breaking Salsa compatibility. Ideally, you try to keep the API roughly unchanged (or use something similar to the salsa PR). But feel free to restructure the internal data structures however you want.
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.
Thanks. I was confused by the names of variables such as this in
module.rs
, which seemed to imply to me thatModule
instances did not in fact represent modules -- that they only represented module IDs that could be used to lookup modules, and that it was in factModuleData
instances that represented modules. Here theid
variable has typeModule
, and themodule
variable has typeModuleData
:ruff/crates/red_knot/src/module.rs
Lines 491 to 500 in 7ce17b7
I'll create another PR to try to clarify things further in the internal documentation.