Skip to content

Refactor HygieneEncodeContext - #162520

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
aerooneqq:hygiene-perf
Sep 11, 2026
Merged

Refactor HygieneEncodeContext#162520
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
aerooneqq:hygiene-perf

Conversation

@aerooneqq

@aerooneqq aerooneqq commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

View all comments

Some refactorings around HygieneEncodeContext with minor perf improvements, the most notable thing is that Locks were removed.

First part for #161450.

r? @petrochenkov

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 9, 2026
@petrochenkov

petrochenkov commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This is missing some high level description.
What is the logic behind the changes in HygieneEncodeContext::encode?
Is the &'a -> Rc change necessary to get rid of locks, or is just to avoid lifetimes in signatures?
Some fields like latest_ctxts -> queued_ctxts apparently change their meaning but the descriptions are not updated.

Comment thread compiler/rustc_span/src/hygiene.rs Outdated
Comment thread compiler/rustc_span/src/hygiene.rs Outdated
Comment thread compiler/rustc_span/src/hygiene.rs
Comment thread compiler/rustc_span/src/hygiene.rs Outdated
Comment thread compiler/rustc_span/src/hygiene.rs
Comment thread compiler/rustc_span/src/hygiene.rs Outdated
Comment thread compiler/rustc_span/src/hygiene.rs Outdated
Comment thread compiler/rustc_span/src/hygiene.rs
Comment thread compiler/rustc_span/src/hygiene.rs Outdated
Comment thread compiler/rustc_span/src/hygiene.rs Outdated
@petrochenkov

Copy link
Copy Markdown
Contributor

What is the logic behind the changes in HygieneEncodeContext::encode?

So the changes are to 1) reuse the capacity between the loop iterations (#162520 (comment)) and 2) move some map searches under the HygieneData lock (#162520 (comment)).

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 9, 2026
@aerooneqq

Copy link
Copy Markdown
Contributor Author

Some fields like latest_ctxts -> queued_ctxts apparently change their meaning but the descriptions are not updated.

Renamed them back.

Is the &'a -> Rc change necessary to get rid of locks, or is just to avoid lifetimes in signatures?

There were borrowing problems because hygiene context is contained inside the encoder.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 10, 2026
Comment thread compiler/rustc_span/src/hygiene.rs
Comment thread compiler/rustc_span/src/hygiene.rs
@petrochenkov

Copy link
Copy Markdown
Contributor

r=me after addressing the remaining comments and squashing commits.
@bors delegate+
@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 10, 2026
@rust-bors

rust-bors Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

✌️ @aerooneqq, you can now approve this pull request!

If @petrochenkov told you to "r=me" after making some further change, then please make that change and post @bors r=petrochenkov.

View changes since this delegation.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 10, 2026
@rustbot

rustbot commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@aerooneqq

Copy link
Copy Markdown
Contributor Author

@bors squash

@rust-bors

This comment has been minimized.

* Refactor `HygieneEncodeContext`
* Review: remove comment outdated part
* Review: return `raw_encode_syntax_context` as a free function
* Review: small cleanups
* Review: add comment about expansions data `Option`
* Review: don't set explicit capacity
* Review: return `queued` -> `latest`
* Remove not needed changes
* Fix `Rc` cloning
* Return comment
@rust-bors

rust-bors Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

🔨 10 commits were squashed into 69afc99.

@aerooneqq

Copy link
Copy Markdown
Contributor Author

@bors r=petrochenkov

@rust-bors

rust-bors Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 69afc99 has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 11, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

If bors squash is used, then it's better to use @bors squash msg="something" to avoid garbage in commit messages.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 11, 2026
…nkov

Refactor `HygieneEncodeContext`

Some refactorings around `HygieneEncodeContext` with minor perf improvements, the most notable thing is that `Lock`s were removed.

First part for rust-lang#161450.

r? @petrochenkov
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 11, 2026
…nkov

Refactor `HygieneEncodeContext`

Some refactorings around `HygieneEncodeContext` with minor perf improvements, the most notable thing is that `Lock`s were removed.

First part for rust-lang#161450.

r? @petrochenkov
rust-bors Bot pushed a commit that referenced this pull request Sep 11, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #162126 (Rename various resolving functions for consistency, and document them)
 - #162520 (Refactor `HygieneEncodeContext`)
 - #154373 (Skip linting unused braces for FunctionArg and MethodArg context for 2024 later )
 - #160023 (Refactor the way cg_ssa handles indirect returns (returns via `sret`) — Take 2)
 - #161482 (Use attribute parser for `#[non_exhaustive]` attribute check)
 - #161867 (deeper `rustc_builtin_macros` cleanups)
 - #162099 (small refactor of doc attribute arguments warnings)
 - #162541 (split `macroless_generic_const_args` in two)
 - #162549 (The fuchsia team maintains `riscv64gc-unknown-fuchsia`)
 - #162577 (Fix `i686-pc-windows-msvc` platform support docs and target spec metadata)
@rust-bors

rust-bors Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit 69afc99 with merge f3f47c1...

Workflow: https://github.com/rust-lang/rust/actions/runs/34590729157

rust-bors Bot pushed a commit that referenced this pull request Sep 11, 2026
Refactor `HygieneEncodeContext`



Some refactorings around `HygieneEncodeContext` with minor perf improvements, the most notable thing is that `Lock`s were removed.

First part for #161450.

r? @petrochenkov
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 11, 2026
…nkov

Refactor `HygieneEncodeContext`

Some refactorings around `HygieneEncodeContext` with minor perf improvements, the most notable thing is that `Lock`s were removed.

First part for rust-lang#161450.

r? @petrochenkov
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors yield
Yielding to enclosing rollup

@rust-bors

rust-bors Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #162631.

rust-bors Bot pushed a commit that referenced this pull request Sep 11, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #162520 (Refactor `HygieneEncodeContext`)
 - #154373 (Skip linting unused braces for FunctionArg and MethodArg context for 2024 later )
 - #160023 (Refactor the way cg_ssa handles indirect returns (returns via `sret`) — Take 2)
 - #160860 (Implement arbitrary casts in custom mir)
 - #161482 (Use attribute parser for `#[non_exhaustive]` attribute check)
 - #161867 (deeper `rustc_builtin_macros` cleanups)
 - #162099 (small refactor of doc attribute arguments warnings)
 - #162541 (split `macroless_generic_const_args` in two)
 - #162549 (The fuchsia team maintains `riscv64gc-unknown-fuchsia`)
 - #162577 (Fix `i686-pc-windows-msvc` platform support docs and target spec metadata)
 - #162624 (regression test for opaque field projection in closure capture)
@rust-bors
rust-bors Bot merged commit 70410fe into rust-lang:main Sep 11, 2026
13 of 14 checks passed
rust-bors Bot pushed a commit that referenced this pull request Sep 11, 2026
Rollup merge of #162520 - aerooneqq:hygiene-perf, r=petrochenkov

Refactor `HygieneEncodeContext`

Some refactorings around `HygieneEncodeContext` with minor perf improvements, the most notable thing is that `Lock`s were removed.

First part for #161450.

r? @petrochenkov
@rustbot rustbot added this to the 1.100.0 milestone Sep 11, 2026
@rust-timer

Copy link
Copy Markdown
Collaborator

Note

This PR was benchmarked as part of triage of its containing rollup: triage URL.

Finished benchmarking commit (9b2b438): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-0.2%, -0.1%] 2
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.1%] 2
All ❌✅ (primary) -0.2% [-0.2%, -0.1%] 2

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: missing data
Artifact size: 407.63 MiB -> 406.93 MiB (-0.17%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants