-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement Entity HIR structure #134
Merged
Merged
Conversation
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
DropDemBits
force-pushed
the
hir-entities
branch
2 times, most recently
from
June 12, 2023 08:11
3816f36
to
9918dc1
Compare
toc-hir rexports toc-source-graph types, so don't need to directly depend on that
BindDecl is just a bundle of BindItems, and it's not really important to know where the original BindDecl is beyond the validation stage.
Only deals with modules right now, since they're the top level item.
`UnstableSemanticLoc` is useful for referring to nodes that aren't in `AstLocations` (e.g. `ast::Expr` and `ast::Stmt`, and `SemanticNodePtr` for just referring to a syntax range in a semantic file)
It's really just a kind of topological ordering, since all of the parents come before all of the children
Will probably be turned into proper lowering structure later
Makes it easier to refer to those locations stably, for better incrementality
While this means that we may drop type-check errors inside of modules, this comes at the advantage of being able to move items while still maintaining id stability
Better to be able to refer to things by just like `hir::Item` instead of `hir::item::Item`
Is atually in normal topological order
For tracking what tracked functions get re-executed. Currently we don't have any tracked functions downstream of item lookup, which matters since initial item lookup is relatively unstable as it's closest to the AST layer. So for now, logging is unused. Also fixed a typo and updated a comment.
Wanting to display what item a body is associated with, and we might as well use the same format.
Safe to send around the location itself, since it only manifests the actual syntax node (which is `!Send + !Sync`) when calling `to_node`
It also impls `Copy`, so we can just do `*self`
We aren't going to be reusing the existing HIR structs and instead have copied the structs into `toc-hir-def`.
- Put stmt - Assign stmt - Name expr - Literal expr
`ast::ConstVarDecl` unfortunately isn't specific enough of an `ast::Item`, since each `ast::ConstVarDeclName` is considered an item in the entity HIR.
Since the underlying erased location doesn't change when going to a more general syntax node repr (e.g. `ast::TypeDecl` into `ast::Item`), it's fine to just change the target wrapper node type. We use associated functions instead of implementing `From` directly since that overlaps the `impl From<T> for T` in `core`.
This points to a specific instance of a `SourceFile` which is part of a given `Package`, as a `SourceFile` may be part of certain packages. This permits parent item lookups since they eventually need to know what package the item is a part of in order to find the starting place to find nodes from.
Allows for fallible projections of syntax nodes, useful for when the target node might not always be present.
Is not what we're looking for when we are considering if another file is reachable
Allows for doing parent lookup stuff
Allows deriving `PartialEq` and `Eq` on `expr::Literal`
Makes tests pass
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Inspired by rust-analyzer's current entity HIR structure and its effort for a HIR 2.0, this reifies HIR items and bodies as distinct entity handles. This leverages salsa-2022's tracked entity infrastructure so that we don't have to intern everything like RA currently does.
The important thing about this implementation is that it prefers to be lazy (i.e. we only do what we need to do right now). While this does negatively affect the one-shot case of compiling straight to bytecode, we're preferentially improving the IDE experience since it's a nice-to-have for one-shot compilation being fast, while the IDE side of things needs to be fast in order to be responsive and have a nice experience.
However, laziness does not necessarily imply dropping all but the most relevant information (i.e. preferentially recomputing), since RA has had issues with biasing towards recomputing instead of recording results (for example, while trying to replace macros with their expansions). We should bias towards recording and memoizing results so that later micro-passes can leverage these results.
Main entry point is via
hir::def::root_module(Package)
, which gives a module to start discovering the rest of the HIR structure.Notes on
salsa::tracked
entities vs. arena allocationsHIR items are tracked entities whilst body expressions and statements are backed by arena allocations as opposed to both being either arena-backed or tracked entities since: