Skip to content

Remove some boxes from ast::Ty#152798

Draft
camsteffen wants to merge 9 commits intorust-lang:mainfrom
camsteffen:ast-ty-boxes
Draft

Remove some boxes from ast::Ty#152798
camsteffen wants to merge 9 commits intorust-lang:mainfrom
camsteffen:ast-ty-boxes

Conversation

@camsteffen
Copy link
Contributor

@camsteffen camsteffen commented Feb 18, 2026

Let's see if this works.

Draft: Could use some commit cleanup before full review, but ready for perf run.

@rustbot
Copy link
Collaborator

rustbot commented Feb 18, 2026

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred in compiler/rustc_ast/src/expand/autodiff_attrs.rs

cc @ZuseZ4

@rustbot rustbot added F-autodiff `#![feature(autodiff)]` 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. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Feb 18, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 18, 2026

r? @jackh726

rustbot has assigned @jackh726.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 68 candidates
  • Random selection from 15 candidates

@camsteffen camsteffen marked this pull request as draft February 18, 2026 14:12
@rustbot rustbot 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 Feb 18, 2026
@fmease
Copy link
Member

fmease commented Feb 18, 2026

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 18, 2026
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 18, 2026
@rust-log-analyzer
Copy link
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

=> Removing the following docker images:
WARNING: This output is designed for human readability. For machine-readable output, please use --format.
IMAGE                                               ID             DISK USAGE   CONTENT SIZE   EXTRA
ghcr.io/dependabot/dependabot-updater-core:latest   9a6a20114926       1.18GB          310MB        
=> Removing docker images...
Deleted Images:
untagged: ghcr.io/dependabot/dependabot-updater-core:latest
deleted: sha256:9a6a20114926442eeadab0732ddd7264ecafc907389c47974b1825d779571319

Total reclaimed space: 309.7MB

********************************************************************************
---
[RUSTC-TIMING] toml test:false 0.218
error[E0614]: type `rustc_ast::Ty` cannot be dereferenced
    --> src/tools/rustfmt/src/items.rs:1992:58
     |
1992 |     let field_str = rewrite_assign_rhs(context, prefix, &*field.ty, &RhsAssignKind::Ty, shape)?;
     |                                                          ^^^^^^^^^ can't be dereferenced

error[E0614]: type `rustc_ast::Ty` cannot be dereferenced
    --> src/tools/rustfmt/src/items.rs:2338:33
     |
2338 |             if !is_empty_infer(&*self.ty, self.pat.span) {
     |                                 ^^^^^^^^ can't be dereferenced

error[E0308]: mismatched types
  --> src/tools/rustfmt/src/parse/macros/lazy_static.rs:50:10
   |
47 |         result.push((vis, id, ty, expr));
   |         ------      ------------------- this argument has type `(Visibility, rustc_span::Ident, rustc_ast::Ty, std::boxed::Box<rustc_ast::Expr>)`...
   |         |
   |         ... which causes `result` to have type `Vec<(Visibility, rustc_span::Ident, rustc_ast::Ty, std::boxed::Box<rustc_ast::Expr>)>`
...
50 |     Some(result)
   |     ---- ^^^^^^ expected `Vec<(Visibility, Ident, Box<Ty>, ...)>`, found `Vec<(Visibility, Ident, Ty, Box<Expr>)>`
   |     |
   |     arguments to this enum variant are incorrect
   |
   = note: expected struct `Vec<(Visibility, rustc_span::Ident, std::boxed::Box<rustc_ast::Ty>, std::boxed::Box<_>)>`
              found struct `Vec<(Visibility, rustc_span::Ident, rustc_ast::Ty, std::boxed::Box<_>)>`
help: the type constructed contains `Vec<(Visibility, rustc_span::Ident, rustc_ast::Ty, std::boxed::Box<rustc_ast::Expr>)>` due to the type of the argument passed
  --> src/tools/rustfmt/src/parse/macros/lazy_static.rs:50:5
   |
50 |     Some(result)
   |     ^^^^^------^
   |          |
   |          this argument influences the type of `Some`
note: tuple variant defined here
  --> /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/option.rs:608:4

error[E0308]: mismatched types
  --> src/tools/rustfmt/src/parse/macros/mod.rs:36:68
   |
25 | /     macro_rules! parse_macro_arg {
26 | |         ($macro_arg:ident, $nt_kind:expr, $try_parse:expr, $then:expr) => {
27 | |             let mut cloned_parser = (*parser).clone();
28 | |             if Parser::nonterminal_may_begin_with($nt_kind, &cloned_parser.token) {
...  |
36 | |                             return Some(MacroArg::$macro_arg($then(x)?));
   | |                                                                    ^ expected `Box<Ty>`, found `Ty`
...  |
45 | |         };
46 | |     }
   | |_____- in this expansion of `parse_macro_arg!`
...
54 | /     parse_macro_arg!(
55 | |         Ty,
56 | |         NonterminalKind::Ty,
57 | |         |parser: &mut Parser<'b>| parser.parse_ty(),
58 | |         |x: Box<ast::Ty>| Some(x)
   | |         ------------------------- arguments to this function are incorrect
59 | |     );
   | |_____- in this macro invocation
   |
   = note: expected struct `std::boxed::Box<rustc_ast::Ty>`
              found struct `rustc_ast::Ty`
   = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
note: closure parameter defined here
  --> src/tools/rustfmt/src/parse/macros/mod.rs:58:10
   |
58 |         |x: Box<ast::Ty>| Some(x)
   |          ^^^^^^^^^^^^^^^
help: store this in the heap by calling `Box::new`
   |
36 |                             return Some(MacroArg::$macro_arg($then(Box::new(x))?));
   |                                                                    +++++++++ +

Some errors have detailed explanations: E0308, E0614.
For more information about an error, try `rustc --explain E0308`.
[RUSTC-TIMING] rustfmt_nightly test:false 2.500
error: could not compile `rustfmt-nightly` (lib) due to 4 previous errors

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 18, 2026

☀️ Try build successful (CI)
Build commit: 1fb03d7 (1fb03d712405828307c4376130554cfc22346b10, parent: 8387095803f21a256a9a772ac1f9b41ed4d5aa0a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1fb03d7): 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.3% [0.2%, 0.5%] 15
Regressions ❌
(secondary)
0.3% [0.2%, 0.4%] 9
Improvements ✅
(primary)
-1.0% [-1.0%, -0.9%] 2
Improvements ✅
(secondary)
-0.2% [-0.5%, -0.1%] 6
All ❌✅ (primary) 0.2% [-1.0%, 0.5%] 17

Max RSS (memory usage)

Results (primary 0.4%, secondary -5.2%)

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

mean range count
Regressions ❌
(primary)
0.4% [0.4%, 0.4%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.2% [-5.2%, -5.2%] 1
All ❌✅ (primary) 0.4% [0.4%, 0.4%] 1

Cycles

Results (secondary 6.5%)

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)
9.4% [3.9%, 15.4%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 2
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 480.396s -> 481.352s (0.20%)
Artifact size: 397.88 MiB -> 397.88 MiB (-0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 18, 2026
@camsteffen
Copy link
Contributor Author

Cachegrind just points to ./string/../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:__memcpy_avx_unaligned_erms having increased instructions. Ir in rustc source is basically all improvements, but they are outweighed. @nnethercote do you have any tips for that scenario? I don't know how to determine where the increased memmoves happen.

@nnethercote
Copy link
Contributor

DHAT's --mode=copy does memcpy profiling. Are you able to run rustc-perf locally? If so, the dhat-copy mode is what you want. It doesn't diff, alas, so you'll need to look back and forth between two profile outputs.

@nnethercote
Copy link
Contributor

BTW what's the motivation for this change?

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 19, 2026

☔ The latest upstream changes (presumably #152825) made this pull request unmergeable. Please resolve the merge conflicts.

@camsteffen
Copy link
Contributor Author

@nnethercote Nice, thank you so much! dhat-copy did the trick.

I figured it out. Some expansion related types get bigger when AST types get bigger, and that causes bigger copies. Specifically AstFragment and Annotatable. I'm going to put some Boxes back (e.g. Param.ty) to keep those the sizes the same. But I'm thinking it might be better, in a follow-up, to add boxes to those expansion types instead. Those enums could have a narrower spread of sizes between variants.

BTW what's the motivation for this change?

Just casual shopping for perf and simpler types.

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

Labels

F-autodiff `#![feature(autodiff)]` perf-regression Performance regression. 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. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

Comments