Uh oh!
There was an error while loading. Please reload this page.
Use hir::ItemLocalId as keys in TypeckTables. - #43740
Conversation
eddyb
commented
Aug 8, 2017
LGTM. r? @arielb1 |
There was a problem hiding this comment.
I think this should be a FIXME? Shouldn't tables be None when outside of an item?
There was a problem hiding this comment.
The thing with local_id_root being sometimes invalid makes me uncomfortable. Please insert an Optionsomewhere (I think making local_id_root an option would work well).
There was a problem hiding this comment.
When is this function called? It seems to be called on some random HIR id accesses.
There was a problem hiding this comment.
Can't you rather do some sort of merging of this function with validate_hir_id? Unmarked linear searches are dangerous.
There was a problem hiding this comment.
This is in several places initialized with an invalid_def_id. Why can't this be an Option?
arielb1
commented
Aug 9, 2017
I don't like the way pubstructLocalTableInContext<'a,V>{parent_def_id:Option<DefId>,data:&'aLocalItemMap<V>}Which does validation on the accessor methods. Or something. |
michaelwoerister
commented
Aug 10, 2017
OK, I'll change the various visitors to use an I'll also look into a way of handling |
bors
commented
Aug 10, 2017
☔ The latest upstream changes (presumably #43582) made this pull request unmergeable. Please resolve the merge conflicts. |
49abb36 to
75022edComparebors
commented
Aug 11, 2017
☔ The latest upstream changes (presumably #43743) made this pull request unmergeable. Please resolve the merge conflicts. |
91207de to
c078583Compare… binary one. Unfortunately, the NodeId->HirId array is not sorted. Since this search is only done right before calling bug!(), let's not waste time allocating a faster lookup.
c078583 to
a69eaf6Comparemichaelwoerister
commented
Aug 11, 2017
@arielb1 I think I addressed your comments. |
michaelwoerister
commented
Aug 11, 2017
(Note: I've added the last three commits. The others were not touched except for rebasing). |
There was a problem hiding this comment.
nit: stray newlines in program
There was a problem hiding this comment.
I actually like newlines in places like this. Makes the impl line easier to read. But I'll remove it for consistency.
There was a problem hiding this comment.
nit: stray newline in program (I think)
arielb1
commented
Aug 13, 2017
Nice! r=me modulo nits. |
b30f28a to
6fd7d85Comparemichaelwoerister
commented
Aug 14, 2017
@bors r=arielb1 Amended the nit fixes to the last commit. Thanks for the reviews! |
bors
commented
Aug 14, 2017
📌 Commit 6fd7d85 has been approved by |
bors
commented
Aug 14, 2017
⌛ Testing commit 6fd7d85 with merge 52523ded9a2d39d7a76f41a9d373610cdeecf501... |
bors
commented
Aug 14, 2017
💔 Test failed - status-travis |
| /// stored/returned. | ||
| fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>, | ||
| hir_id: hir::HirId, | ||
| mut_access: bool) { |
There was a problem hiding this comment.
[00:10:17] error: unused variable: `local_id_root`
[00:10:17] --> /checkout/src/librustc/ty/context.rs:226:38
[00:10:17] |
[00:10:17] 226 | fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
[00:10:17] | ^^^^^^^^^^^^^
[00:10:17] |
[00:10:17] [00:10:17] error: unused variable: `hir_id`
[00:10:17] --> /checkout/src/librustc/ty/context.rs:227:38
[00:10:17] |
[00:10:17] 227 | hir_id: hir::HirId,
[00:10:17] | ^^^^^^
[00:10:17] [00:10:17] error: unused variable: `mut_access`
[00:10:17] --> /checkout/src/librustc/ty/context.rs:228:38
[00:10:17] |
[00:10:17] 228 | mut_access: bool) {
[00:10:17] | ^^^^^^^^^^
[00:10:17] [00:10:18] error: aborting due to 3 previous errors
[00:10:18] [00:10:18] error: Could not compile `rustc`.
There was a problem hiding this comment.
Thanks, @kennytm! That must be because of the cfg(debug_assertions) switch...
michaelwoerister
commented
Aug 14, 2017
@bors r=arielb1 |
bors
commented
Aug 14, 2017
📌 Commit 3b92b97 has been approved by |
bors
commented
Aug 14, 2017
…rielb1 Use hir::ItemLocalId as keys in TypeckTables. This PR makes `TypeckTables` use `ItemLocalId` instead of `NodeId` as key. This is needed for incremental compilation -- for stable hashing and for being able to persist and reload these tables. The PR implements the most important part of #40303. Some notes on the implementation: * The PR adds the `HirId` to HIR nodes where needed (`Expr`, `Local`, `Block`, `Pat`) which obviates the need to store a `NodeId -> HirId` mapping in crate metadata. Thanks @eddyb for the suggestion! In the future the `HirId` should completely replace the `NodeId` in HIR nodes. * Before something is read or stored in one of the various `TypeckTables` subtables, the entry's key is validated via the new `TypeckTables::validate_hir_id()` method. This makes sure that we are not mixing information from different items in a single table. That last part could be made a bit nicer by either (a) new-typing the table-key and making `validate_hir_id()` the only way to convert a `HirId` to the new-typed key, or (b) just encapsulate sub-table access a little better. This PR, however, contents itself with not making things significantly worse. Also, there's quite a bit of switching around between `NodeId`, `HirId`, and `DefIndex`. These conversions are cheap except for `HirId -> NodeId`, so if the valued reviewer finds such an instance in a performance critical place, please let me know. Ideally we convert more and more code from `NodeId` to `HirId` in the future so that there are no more `NodeId`s after HIR lowering anywhere. Then the amount of switching should be minimal again. r? @eddyb, maybe?
bors
commented
Aug 14, 2017
☀️ Test successful - status-appveyor, status-travis |
This PR makes
TypeckTablesuseItemLocalIdinstead ofNodeIdas key. This is needed for incremental compilation -- for stable hashing and for being able to persist and reload these tables. The PR implements the most important part of #40303.Some notes on the implementation:
HirIdto HIR nodes where needed (Expr,Local,Block,Pat) which obviates the need to store aNodeId -> HirIdmapping in crate metadata. Thanks @eddyb for the suggestion! In the future theHirIdshould completely replace theNodeIdin HIR nodes.TypeckTablessubtables, the entry's key is validated via the newTypeckTables::validate_hir_id()method. This makes sure that we are not mixing information from different items in a single table.That last part could be made a bit nicer by either (a) new-typing the table-key and making
validate_hir_id()the only way to convert aHirIdto the new-typed key, or (b) just encapsulate sub-table access a little better. This PR, however, contents itself with not making things significantly worse.Also, there's quite a bit of switching around between
NodeId,HirId, andDefIndex. These conversions are cheap except forHirId -> NodeId, so if the valued reviewer finds such an instance in a performance critical place, please let me know.Ideally we convert more and more code from
NodeIdtoHirIdin the future so that there are no moreNodeIds after HIR lowering anywhere. Then the amount of switching should be minimal again.r? @eddyb, maybe?