Skip to content

assert more in release in rustc_ast_lowering #142267

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

workingjubilee
Copy link
Member

@workingjubilee workingjubilee commented Jun 9, 2025

My understanding of the compiler's architecture is that in the ast_lowering crate, we are constructing the HIR as a one-time thing per crate. This is after tokenizing, parsing, resolution, expansion, possible reparsing, reresolution, reexpansion, and so on. In other words, there are many reasons that perf-focused PRs spend a lot of time touching rustc_parse, rustc_expand, rustc_ast, and then rustc_hir and "onwards", but ast_lowering is a little bit of an odd duck.

In this crate, we have a number of debug assertions. Some are clearly expensive checks that seem like they are prohibitive to run in actual optimized compiler builds, but then there are a number that are simple asserts on integer equalities, is_empty, or the like. I believe we should do some of them even in release builds, because the correctness gain is worth the performance cost: almost zero.

@workingjubilee workingjubilee added the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label Jun 9, 2025
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 9, 2025
@workingjubilee
Copy link
Member Author

@bors2 try
@rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jun 9, 2025

⌛ Trying commit c62171a with merge d4e2ead

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 9, 2025
…ing, r=<try>

[EXPERIMENTAL] assert in release builds in `rustc_ast_lowering`

My understanding of the compiler's architecture is that in the `ast_lowering` crate, we are constructing the HIR as a one-time thing per crate. This is after tokenizing, parsing, resolution, expansion, possible reparsing, reresolution, reexpansion, and so on. In other words, there are many reasons that perf-focused PRs spend a lot of time touching `rustc_parse`, `rustc_expand`, `rustc_ast`, and then `rustc_hir` and "onwards", but `ast_lowering` is a little bit of an odd duck.

In this crate, we have a number of debug assertions. Some are clearly expensive checks that seem like they are prohibitive to run in actual optimized compiler builds, but then there are simple integer equalities. I am curious if the latter introduce a serious problem if we simply *do* them.

r? `@ghost`
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 9, 2025
@rust-bors
Copy link

rust-bors bot commented Jun 9, 2025

☀️ Try build successful (CI)
Build commit: d4e2ead (d4e2ead1d10ad3fc360e74bb08414c0476225305)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d4e2ead): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +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.2% [0.1%, 0.3%] 9
Regressions ❌
(secondary)
0.3% [0.2%, 0.4%] 10
Improvements ✅
(primary)
-1.2% [-1.2%, -1.2%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-1.2%, 0.3%] 10

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 754.885s -> 754.261s (-0.08%)
Artifact size: 372.30 MiB -> 372.35 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 10, 2025
@workingjubilee
Copy link
Member Author

hm. I suspect the index functions might be hot enough I need to back their diff out.

@workingjubilee workingjubilee force-pushed the debug-assert-less-in-ast-lowering branch from c62171a to dd78c95 Compare June 10, 2025 18:21
@workingjubilee
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 10, 2025
bors added a commit that referenced this pull request Jun 10, 2025
…ing, r=<try>

[EXPERIMENTAL] assert in release builds in `rustc_ast_lowering`

My understanding of the compiler's architecture is that in the `ast_lowering` crate, we are constructing the HIR as a one-time thing per crate. This is after tokenizing, parsing, resolution, expansion, possible reparsing, reresolution, reexpansion, and so on. In other words, there are many reasons that perf-focused PRs spend a lot of time touching `rustc_parse`, `rustc_expand`, `rustc_ast`, and then `rustc_hir` and "onwards", but `ast_lowering` is a little bit of an odd duck.

In this crate, we have a number of debug assertions. Some are clearly expensive checks that seem like they are prohibitive to run in actual optimized compiler builds, but then there are simple integer equalities. I am curious if the latter introduce a serious problem if we simply *do* them.

r? `@ghost`
@bors
Copy link
Collaborator

bors commented Jun 10, 2025

⌛ Trying commit dd78c95 with merge a729c24...

@bors
Copy link
Collaborator

bors commented Jun 10, 2025

☀️ Try build successful - checks-actions
Build commit: a729c24 (a729c24463fb0fe8f3af7881cfd00143616f9bfd)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a729c24): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -3.5%, secondary -1.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
8.5% [8.5%, 8.5%] 1
Improvements ✅
(primary)
-3.5% [-4.0%, -3.0%] 3
Improvements ✅
(secondary)
-2.5% [-3.7%, -1.1%] 18
All ❌✅ (primary) -3.5% [-4.0%, -3.0%] 3

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 754.321s -> 755.264s (0.13%)
Artifact size: 372.15 MiB -> 372.18 MiB (0.01%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Jun 11, 2025
@workingjubilee workingjubilee changed the title [EXPERIMENTAL] assert in release builds in rustc_ast_lowering assert more in release in rustc_ast_lowering Jun 11, 2025
@workingjubilee workingjubilee marked this pull request as ready for review June 11, 2025 08:43
@rustbot
Copy link
Collaborator

rustbot commented Jun 11, 2025

r? @compiler-errors

rustbot has assigned @compiler-errors.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 11, 2025
@workingjubilee
Copy link
Member Author

@rustbot label: -S-experimental

@rustbot rustbot removed the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label Jun 11, 2025
@oli-obk
Copy link
Contributor

oli-obk commented Jun 11, 2025

r? @oli-obk

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 11, 2025

📌 Commit dd78c95 has been approved by oli-obk

It is now in the queue for this repository.

@rustbot rustbot assigned oli-obk and unassigned compiler-errors Jun 11, 2025
@bors bors 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-review Status: Awaiting review from the assignee but also interested parties. labels Jun 11, 2025
@oli-obk
Copy link
Contributor

oli-obk commented Jun 11, 2025

@bors rollup

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 12, 2025
…n-ast-lowering, r=oli-obk

assert more in release in `rustc_ast_lowering`

My understanding of the compiler's architecture is that in the `ast_lowering` crate, we are constructing the HIR as a one-time thing per crate. This is after tokenizing, parsing, resolution, expansion, possible reparsing, reresolution, reexpansion, and so on. In other words, there are many reasons that perf-focused PRs spend a lot of time touching `rustc_parse`, `rustc_expand`, `rustc_ast`, and then `rustc_hir` and "onwards", but `ast_lowering` is a little bit of an odd duck.

In this crate, we have a number of debug assertions. Some are clearly expensive checks that seem like they are prohibitive to run in actual optimized compiler builds, but then there are a number that are simple asserts on integer equalities, `is_empty`, or the like. I believe we should do some of them even in release builds, because the correctness gain is worth the performance cost: almost zero.
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 12, 2025
…n-ast-lowering, r=oli-obk

assert more in release in `rustc_ast_lowering`

My understanding of the compiler's architecture is that in the `ast_lowering` crate, we are constructing the HIR as a one-time thing per crate. This is after tokenizing, parsing, resolution, expansion, possible reparsing, reresolution, reexpansion, and so on. In other words, there are many reasons that perf-focused PRs spend a lot of time touching `rustc_parse`, `rustc_expand`, `rustc_ast`, and then `rustc_hir` and "onwards", but `ast_lowering` is a little bit of an odd duck.

In this crate, we have a number of debug assertions. Some are clearly expensive checks that seem like they are prohibitive to run in actual optimized compiler builds, but then there are a number that are simple asserts on integer equalities, `is_empty`, or the like. I believe we should do some of them even in release builds, because the correctness gain is worth the performance cost: almost zero.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants