Skip to content

Conversation

@dianne
Copy link
Contributor

@dianne dianne commented Nov 8, 2025

Based on #148658; only the last commit is new.

This accomplishes two things:

  • Makes the THIR slightly smaller by not attaching a full TempLifetime to every expression.
  • Reduces the number of traversals of the ScopeTree by only calling ScopeTree::temporary_scope when building MIR for something that needs to be dropped in a temporary scope.

This removes some unneeded indirection and consolidates the logic for
scope resolution.
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 8, 2025
@dianne
Copy link
Contributor Author

dianne commented Nov 8, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Nov 8, 2025
…try>

compute temporary scopes when building MIR, not THIR
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 8, 2025
@rust-bors
Copy link

rust-bors bot commented Nov 8, 2025

☀️ Try build successful (CI)
Build commit: 9de26a5 (9de26a5918b5655a37eefd1b02cdb1ff0cdcdc74, parent: 87f9dcd5e28a301fce81515bd4bea792444dcf29)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9de26a5): comparison URL.

Overall result: ✅ improvements - 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

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

mean range count
Regressions ❌
(primary)
1.2% [1.2%, 1.2%] 1
Regressions ❌
(secondary)
0.7% [0.2%, 1.2%] 2
Improvements ✅
(primary)
-0.4% [-2.0%, -0.1%] 56
Improvements ✅
(secondary)
-0.9% [-2.5%, -0.0%] 81
All ❌✅ (primary) -0.4% [-2.0%, 1.2%] 57

Max RSS (memory usage)

Results (primary -0.5%, secondary -2.8%)

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

mean range count
Regressions ❌
(primary)
1.4% [1.4%, 1.4%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.5% [-1.9%, -1.2%] 2
Improvements ✅
(secondary)
-2.8% [-4.8%, -1.3%] 28
All ❌✅ (primary) -0.5% [-1.9%, 1.4%] 3

Cycles

Results (primary -2.3%, secondary -4.0%)

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)
4.9% [4.2%, 5.5%] 2
Improvements ✅
(primary)
-2.3% [-2.4%, -2.2%] 3
Improvements ✅
(secondary)
-4.6% [-8.7%, -2.3%] 29
All ❌✅ (primary) -2.3% [-2.4%, -2.2%] 3

Binary size

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

Bootstrap: 475.809s -> 473.629s (-0.46%)
Artifact size: 390.93 MiB -> 390.83 MiB (-0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 8, 2025
Comment on lines -259 to +262
/// The lifetime of this expression if it should be spilled into a
/// temporary
pub temp_lifetime: TempLifetime,
/// The id of the HIR expression whose [temporary scope] should be used for this expression.
///
/// [temporary scope]: https://doc.rust-lang.org/reference/destructors.html#temporary-scopes
pub temp_scope_id: hir::ItemLocalId,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be removed entirely from thir::Expr, and we could use thir::ExprKind::Scopes to set up temporary scopes, but it's a little subtle/inconvenient for certain THIR lowerings (looking at &pin mut here) so for now I've opted to keep it simple.

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

3 participants