Skip to content
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

Introduce HirId, a replacement for ast::NodeId after lowering to HIR #40518

Merged
merged 4 commits into from
Mar 23, 2017

Conversation

michaelwoerister
Copy link
Member

This is the first step towards implementing #40303. This PR introduces the HirId type and generates a HirId for everything that would be assigned one (i.e. stuff in the HIR), but the HIR data types still use NodeId for now. Changing that is a big refactoring that I want to do in a separate PR.

A HirId uniquely identifies a node in the HIR of the current crate. It is composed of the owner, which is the DefIndex of the directly enclosing hir::Item, hir::TraitItem, or hir::ImplItem (i.e. the closest "item-like"), and the local_id which is unique within the given owner.

This PR is also running a number of consistency checks for the generated HirIds:

  • Does NodeId in the HIR have a corresponding HirId?
  • Is the owner part of each HirId consistent with its position in the HIR?
  • Do the numerical values of the local_id part all lie within a dense range of integers?

cc @rust-lang/compiler

r? @eddyb or @nikomatsakis

@michaelwoerister
Copy link
Member Author

Alright, this passes make check now...

@michaelwoerister
Copy link
Member Author

Just pushed another commit that prepares some things for using HirIds as keys in the HIR map.

@@ -18,7 +18,7 @@ trait SomeTrait { }

// Bounds on object types:

struct Foo<'a,'b,'c> { //~ ERROR parameter `'b` is never used
struct Foo<'a,'b,'c> { //~ ERROR parameter `'c` is never used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahahaha I think I remember when this changed due to syntactical elision.

@eddyb
Copy link
Member

eddyb commented Mar 17, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Mar 17, 2017

📌 Commit 2536302 has been approved by eddyb

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Mar 20, 2017
Introduce HirId, a replacement for ast::NodeId after lowering to HIR

This is the first step towards implementing rust-lang#40303. This PR introduces the `HirId` type and generates a `HirId` for everything that would be assigned one (i.e. stuff in the HIR), but the HIR data types still use `NodeId` for now. Changing that is a big refactoring that I want to do in a separate PR.

A `HirId` uniquely identifies a node in the HIR of the current crate. It is composed of the `owner`, which is the `DefIndex` of the directly enclosing `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e. the closest "item-like"), and the `local_id` which is unique within the given owner.

This PR is also running a number of consistency checks for the generated `HirId`s:
- Does `NodeId` in the HIR have a corresponding `HirId`?
- Is the `owner` part of each `HirId` consistent with its position in the HIR?
- Do the numerical values of the `local_id` part all lie within a dense range of integers?

cc @rust-lang/compiler

r? @eddyb or @nikomatsakis
@bors
Copy link
Contributor

bors commented Mar 21, 2017

🔒 Merge conflict

@bors
Copy link
Contributor

bors commented Mar 21, 2017

☔ The latest upstream changes (presumably #40693) made this pull request unmergeable. Please resolve the merge conflicts.

HirId has a more stable representation than NodeId, meaning that
modifications to one item don't influence (part of) the IDs within
other items. The other part is a DefIndex for which there already
is a way of stable hashing and persistence.

This commit introduces the HirId type and generates a HirId for
every NodeId during HIR lowering, but the resulting values are
not yet used anywhere, except in consistency checks.
This way we can have all item-likes occupy a dense range of
DefIndexes, which is good for making fast, array-based
dictionaries.
@michaelwoerister
Copy link
Member Author

@bors r=eddyb

Rebased.

@bors
Copy link
Contributor

bors commented Mar 22, 2017

📌 Commit 090767b has been approved by eddyb

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Mar 23, 2017
Introduce HirId, a replacement for ast::NodeId after lowering to HIR

This is the first step towards implementing rust-lang#40303. This PR introduces the `HirId` type and generates a `HirId` for everything that would be assigned one (i.e. stuff in the HIR), but the HIR data types still use `NodeId` for now. Changing that is a big refactoring that I want to do in a separate PR.

A `HirId` uniquely identifies a node in the HIR of the current crate. It is composed of the `owner`, which is the `DefIndex` of the directly enclosing `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e. the closest "item-like"), and the `local_id` which is unique within the given owner.

This PR is also running a number of consistency checks for the generated `HirId`s:
- Does `NodeId` in the HIR have a corresponding `HirId`?
- Is the `owner` part of each `HirId` consistent with its position in the HIR?
- Do the numerical values of the `local_id` part all lie within a dense range of integers?

cc @rust-lang/compiler

r? @eddyb or @nikomatsakis
bors added a commit that referenced this pull request Mar 23, 2017
Rollup of 6 pull requests

- Successful merges: #39891, #40518, #40542, #40617, #40678, #40696
- Failed merges:
@bors bors merged commit 090767b into rust-lang:master Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants