Conversation
|
r? @cjgillot |
|
Could not assign reviewer from: |
This comment has been minimized.
This comment has been minimized.
f7f31d7 to
eaf91bb
Compare
eaf91bb to
7760acf
Compare
This comment has been minimized.
This comment has been minimized.
7760acf to
2b28424
Compare
|
The test's output changed because I rearranged the order of some lowering to avoid duplicate lowering. |
| self.arena.alloc(self.lower_block_noalloc(hir_id, b, targeted_by_break)) | ||
| } | ||
|
|
||
| pub(super) fn lower_block_with_hir_id( |
There was a problem hiding this comment.
Should this be inlined into its single call site?
There was a problem hiding this comment.
Good idea. I didn't notice there's only one call site.
| let if_expr = self.expr(span, if_kind); | ||
| let block = self.block_expr(self.arena.alloc(if_expr)); | ||
| let span = self.lower_span(span.with_hi(cond.span.hi())); | ||
| let opt_label = self.lower_label(opt_label); |
There was a problem hiding this comment.
It's the limitation that the recording of label hir id is coupled with lower_label method.
So I have to lower label outside otherwise I need to introduce node_id and hir_id parameters to lower_expr_while_in_loop_scope.
| let vis_span = self.lower_span(i.vis.span); | ||
| let hir_id = self.lower_node_id(i.id); | ||
| let hir_id = | ||
| hir::HirId { owner: self.current_hir_id_owner, local_id: hir::ItemLocalId::ZERO }; |
There was a problem hiding this comment.
This can use HirId::make_owner.
| /// NodeIds of labelled nodes that are lowered inside the current HIR owner. | ||
| labelled_node_id_to_local_id: NodeMap<hir::ItemLocalId>, | ||
| /// NodeIds of identifier that are lowered inside the current HIR owner. | ||
| ident_to_local_id: NodeMap<hir::ItemLocalId>, |
There was a problem hiding this comment.
Should we have a single map for both cases?
| #[instrument(level = "debug", skip(self), ret)] | ||
| fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId { | ||
| assert_ne!(ast_node_id, DUMMY_NODE_ID); | ||
|
|
There was a problem hiding this comment.
Should we keep a check, gated behind #[cfg(debug_assertions)], that we don't call this twice on the same NodeId?
There was a problem hiding this comment.
Good idea. I didn't keep the check to avoid hashing cost. Thanks for reminding me of conditional compilation!
|
@cjgillot May you have another look? There is no hurry of course. |
| // All identifiers resolves to this canonical identifier share its `HirId`. | ||
| let binding_id = if canonical_id == p.id { | ||
| self.ident_and_label_to_local_id.insert(canonical_id, hir_id.local_id); | ||
| hir_id | ||
| } else { | ||
| hir::HirId { | ||
| owner: self.current_hir_id_owner, | ||
| local_id: self.ident_and_label_to_local_id[&canonical_id], | ||
| } | ||
| }; |
There was a problem hiding this comment.
Could you merge this with the previous match?
|
Sorry for the very slow review. |
This comment has been minimized.
This comment has been minimized.
8ac9b58 to
4db575a
Compare
|
☔ The latest upstream changes (presumably #131985) made this pull request unmergeable. Please resolve the merge conflicts. |
|
r=me after rebase |
4db575a to
e3bf50e
Compare
|
@bors r=cjgillot |
|
@adwinwhite: 🔑 Insufficient privileges: Not in reviewers |
|
@rustbot ready |
|
@bors r+ |
…jgillot Lower AST node id only once Fixes rust-lang#96346. I basically followed the given instructions except the inline part. `lower_jump_destination` can't reuse local existing `HirId` due to unknown name resolution result so I created an additional mapping for labels. r? `@cjgillot`
…jgillot Lower AST node id only once Fixes rust-lang#96346. I basically followed the given instructions except the inline part. `lower_jump_destination` can't reuse local existing `HirId` due to unknown name resolution result so I created an additional mapping for labels. r? ``@cjgillot``
…kingjubilee Rollup of 9 pull requests Successful merges: - rust-lang#130259 (Lower AST node id only once) - rust-lang#131441 (Add a new trait `proc_macro::ToTokens`) - rust-lang#132247 (stable_mir: Directly use types from rustc_abi) - rust-lang#132249 (compiler: Add rustc_abi dependence to the compiler) - rust-lang#132255 (Add `LayoutS::is_uninhabited` and use it) - rust-lang#132258 ([rustdoc] Unify variant struct fields margins with struct fields) - rust-lang#132260 (cg_llvm: Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`) - rust-lang#132261 (refactor: cleaner check to return None) - rust-lang#132271 (Updating Fuchsia platform-support documentation) r? `@ghost` `@rustbot` modify labels: rollup
…jgillot Lower AST node id only once Fixes rust-lang#96346. I basically followed the given instructions except the inline part. `lower_jump_destination` can't reuse local existing `HirId` due to unknown name resolution result so I created an additional mapping for labels. r? ````@cjgillot````
…jgillot Lower AST node id only once Fixes rust-lang#96346. I basically followed the given instructions except the inline part. `lower_jump_destination` can't reuse local existing `HirId` due to unknown name resolution result so I created an additional mapping for labels. r? `````@cjgillot`````
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#130259 (Lower AST node id only once) - rust-lang#131441 (Add a new trait `proc_macro::ToTokens`) - rust-lang#132247 (stable_mir: Directly use types from rustc_abi) - rust-lang#132249 (compiler: Add rustc_abi dependence to the compiler) - rust-lang#132255 (Add `LayoutData::is_uninhabited` and use it) - rust-lang#132258 ([rustdoc] Unify variant struct fields margins with struct fields) - rust-lang#132260 (cg_llvm: Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`) - rust-lang#132261 (refactor: cleaner check to return None) - rust-lang#132271 (Updating Fuchsia platform-support documentation) - rust-lang#132295 (fixed wast version was released, remove randomization exemption) r? `@ghost` `@rustbot` modify labels: rollup
…kingjubilee Rollup of 9 pull requests Successful merges: - rust-lang#130259 (Lower AST node id only once) - rust-lang#131441 (Add a new trait `proc_macro::ToTokens`) - rust-lang#132247 (stable_mir: Directly use types from rustc_abi) - rust-lang#132249 (compiler: Add rustc_abi dependence to the compiler) - rust-lang#132255 (Add `LayoutData::is_uninhabited` and use it) - rust-lang#132258 ([rustdoc] Unify variant struct fields margins with struct fields) - rust-lang#132260 (cg_llvm: Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`) - rust-lang#132261 (refactor: cleaner check to return None) - rust-lang#132271 (Updating Fuchsia platform-support documentation) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#130259 - adwinwhite:lower-node-id-once, r=cjgillot Lower AST node id only once Fixes rust-lang#96346. I basically followed the given instructions except the inline part. `lower_jump_destination` can't reuse local existing `HirId` due to unknown name resolution result so I created an additional mapping for labels. r? ```@cjgillot```
|
Just FYI, this PR had a nice effect on the performance of the compiler :) #132277 (comment) Great work! |
Fixes #96346.
I basically followed the given instructions except the inline part.
lower_jump_destinationcan't reuse local existingHirIddue to unknown name resolution result so I created an additional mapping for labels.r? @cjgillot