Skip to content

Conversation

@RalfJung
Copy link
Member

@RalfJung RalfJung commented Dec 12, 2025

Perf experiment exploring alternatives to #148967.

This is the maximally naive version that just always does full typed copies. It may be possible to skip some of the validation work if all we care about is resetting padding -- though it's not obvious to me how to do that in a way that actually helps with performance. Also, typed copies at integer type technically do not preserve provenance, which could become relevant in const-eval for the same reason as provenance in padding (see #148470) -- so it's not like we can just skip all types without padding.

@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 Dec 12, 2025
@RalfJung
Copy link
Member Author

@bors try
@rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Dec 12, 2025
const-eval: always do full typed copies
@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 12, 2025
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-gcc failed! Check out the build log: (web) (plain enhanced) (plain)

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

---- [mir-opt] tests/mir-opt/pattern_types.rs stdout ----
------rustc stdout------------------------------

------rustc stderr------------------------------
warning: unused variable: `x`
##[warning] --> /checkout/tests/mir-opt/pattern_types.rs:9:9
  |
9 |     let x: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(2) };
  |         ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

warning: unused variable: `y`
##[warning]  --> /checkout/tests/mir-opt/pattern_types.rs:11:9
   |
11 |     let y: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) };
   |         ^ help: if this is intentional, prefix it with an underscore: `_y`

warning: function `main` is never used
##[warning] --> /checkout/tests/mir-opt/pattern_types.rs:7:4
  |
7 | fn main() {
  |    ^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default


thread 'rustc' (30735) panicked at compiler/rustc_const_eval/src/util/check_validity_requirement.rs:192:41:
called `Result::unwrap()` on an `Err` value: InterpErrorInfo(InterpErrorInfoInner { kind: UndefinedBehavior(ValidationError(ValidationErrorInfo { path: None, kind: OutOfRange { value: "0", range: 1..=4294967295, max_value: 4294967295 } })), backtrace: InterpErrorBacktrace { backtrace: None } })
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: rustc_const_eval::util::check_validity_requirement::validate_scalar_in_layout
   4: <rustc_const_eval::provide::{closure#3} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::consts::int::ScalarInt, rustc_middle::ty::Ty)>>::call_once
   5: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_const_scalar_int
   6: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_const_scalar
   7: rustc_middle::mir::pretty::pretty_print_const_value_tcx
   8: <rustc_middle::mir::consts::Const as core::fmt::Display>::fmt
   9: core::fmt::write
  10: <rustc_middle::mir::VarDebugInfoContents as core::fmt::Debug>::fmt
  11: core::fmt::write
  12: <rustc_middle::mir::VarDebugInfo as core::fmt::Debug>::fmt
  13: core::fmt::write
  14: alloc::fmt::format::format_inner
  15: rustc_middle::mir::pretty::write_scope_tree
  16: rustc_middle::mir::pretty::write_scope_tree
  17: rustc_middle::mir::pretty::write_scope_tree
  18: <rustc_middle::mir::pretty::MirWriter>::write_mir_fn
  19: <rustc_middle::mir::pretty::MirDumper>::dump_mir_to_writer
  20: <rustc_middle::mir::pretty::MirDumper>::dump_mir
  21: rustc_mir_transform::pass_manager::run_passes_inner
  22: rustc_mir_transform::run_optimization_passes
  23: rustc_mir_transform::optimized_mir
      [... omitted 2 frames ...]
  24: <rustc_middle::ty::context::TyCtxt>::instance_mir
  25: rustc_data_structures::sync::parallel::par_for_each_in::<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners<rustc_interface::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>
  26: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#1}>
  27: rustc_interface::passes::analysis
      [... omitted 2 frames ...]
  28: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
  29: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}>
  30: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  31: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  32: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  33: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: rustc 1.94.0-nightly (3fc493712 2025-12-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z threads=1 -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=/cargo -Z ignore-directory-in-diagnostics-source-blocks=/checkout/vendor -Z codegen-backend=gcc -C opt-level=1 -Z dump-mir=PreCodegen -Z validate-mir -Z lint-mir -Z dump-mir-exclude-pass-number -Z mir-include-spans=false --crate-type rlib -Z mir-opt-level=4 -Z mir-enable-passes=+ReorderBasicBlocks,+ReorderLocals -Z dump-mir-dir=/checkout/obj/build/x86_64-unknown-linux-gnu/test/mir-opt/pattern_types -C prefer-dynamic -C rpath -C debuginfo=0

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [analysis] running analysis passes on crate `pattern_types`
end of query stack
warning: 3 warnings emitted


------------------------------------------

error: compilation failed!
status: exit status: 101
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/mir-opt/pattern_types.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "-Zcodegen-backend=gcc" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "-O" "-Copt-level=1" "-Zdump-mir=PreCodegen" "-Zvalidate-mir" "-Zlint-mir" "-Zdump-mir-exclude-pass-number" "-Zmir-include-spans=false" "--crate-type=rlib" "-Zmir-opt-level=4" "-Zmir-enable-passes=+ReorderBasicBlocks,+ReorderLocals" "-Zdump-mir-dir=/checkout/obj/build/x86_64-unknown-linux-gnu/test/mir-opt/pattern_types" "--emit" "mir" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/mir-opt/pattern_types" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0"
stdout: none
--- stderr -------------------------------
warning: unused variable: `x`
##[warning] --> /checkout/tests/mir-opt/pattern_types.rs:9:9
  |
9 |     let x: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(2) };
  |         ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

warning: unused variable: `y`
##[warning]  --> /checkout/tests/mir-opt/pattern_types.rs:11:9
   |
11 |     let y: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) };
   |         ^ help: if this is intentional, prefix it with an underscore: `_y`

warning: function `main` is never used
##[warning] --> /checkout/tests/mir-opt/pattern_types.rs:7:4
  |
7 | fn main() {
  |    ^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default


thread 'rustc' (30735) panicked at compiler/rustc_const_eval/src/util/check_validity_requirement.rs:192:41:
called `Result::unwrap()` on an `Err` value: InterpErrorInfo(InterpErrorInfoInner { kind: UndefinedBehavior(ValidationError(ValidationErrorInfo { path: None, kind: OutOfRange { value: "0", range: 1..=4294967295, max_value: 4294967295 } })), backtrace: InterpErrorBacktrace { backtrace: None } })
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: rustc_const_eval::util::check_validity_requirement::validate_scalar_in_layout
   4: <rustc_const_eval::provide::{closure#3} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::consts::int::ScalarInt, rustc_middle::ty::Ty)>>::call_once
   5: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_const_scalar_int
   6: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_const_scalar
   7: rustc_middle::mir::pretty::pretty_print_const_value_tcx
   8: <rustc_middle::mir::consts::Const as core::fmt::Display>::fmt
   9: core::fmt::write
  10: <rustc_middle::mir::VarDebugInfoContents as core::fmt::Debug>::fmt
  11: core::fmt::write
  12: <rustc_middle::mir::VarDebugInfo as core::fmt::Debug>::fmt
  13: core::fmt::write
  14: alloc::fmt::format::format_inner
  15: rustc_middle::mir::pretty::write_scope_tree
  16: rustc_middle::mir::pretty::write_scope_tree
  17: rustc_middle::mir::pretty::write_scope_tree
  18: <rustc_middle::mir::pretty::MirWriter>::write_mir_fn
  19: <rustc_middle::mir::pretty::MirDumper>::dump_mir_to_writer
  20: <rustc_middle::mir::pretty::MirDumper>::dump_mir
  21: rustc_mir_transform::pass_manager::run_passes_inner
  22: rustc_mir_transform::run_optimization_passes
  23: rustc_mir_transform::optimized_mir
      [... omitted 2 frames ...]
  24: <rustc_middle::ty::context::TyCtxt>::instance_mir
  25: rustc_data_structures::sync::parallel::par_for_each_in::<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners<rustc_interface::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>
  26: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#1}>
  27: rustc_interface::passes::analysis
      [... omitted 2 frames ...]
  28: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
  29: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}>
  30: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  31: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  32: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  33: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: rustc 1.94.0-nightly (3fc493712 2025-12-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z threads=1 -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=/cargo -Z ignore-directory-in-diagnostics-source-blocks=/checkout/vendor -Z codegen-backend=gcc -C opt-level=1 -Z dump-mir=PreCodegen -Z validate-mir -Z lint-mir -Z dump-mir-exclude-pass-number -Z mir-include-spans=false --crate-type rlib -Z mir-opt-level=4 -Z mir-enable-passes=+ReorderBasicBlocks,+ReorderLocals -Z dump-mir-dir=/checkout/obj/build/x86_64-unknown-linux-gnu/test/mir-opt/pattern_types -C prefer-dynamic -C rpath -C debuginfo=0

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [analysis] running analysis passes on crate `pattern_types`
end of query stack

For more information how to resolve CI failures of this job, visit this link.

@traviscross traviscross added the I-lang-radar Items that are on lang's radar and will need eventual work or consideration. label Dec 12, 2025
@rust-bors
Copy link

rust-bors bot commented Dec 12, 2025

☀️ Try build successful (CI)
Build commit: db4e1d2 (db4e1d23234d93b5e96ecc768b35d9090c32cddf, parent: 5b150d238fbd4fe7bc2cd3140d8e6fb4406099fa)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (db4e1d2): 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)
1.5% [0.1%, 13.4%] 58
Regressions ❌
(secondary)
34.5% [0.2%, 320.6%] 82
Improvements ✅
(primary)
-0.4% [-0.6%, -0.2%] 9
Improvements ✅
(secondary)
-0.5% [-1.2%, -0.0%] 30
All ❌✅ (primary) 1.2% [-0.6%, 13.4%] 67

Max RSS (memory usage)

Results (primary -2.9%, secondary -1.4%)

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)
2.9% [1.8%, 6.4%] 5
Improvements ✅
(primary)
-2.9% [-4.1%, -1.7%] 2
Improvements ✅
(secondary)
-4.5% [-6.4%, -2.9%] 7
All ❌✅ (primary) -2.9% [-4.1%, -1.7%] 2

Cycles

Results (primary 4.4%, secondary 261.5%)

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

mean range count
Regressions ❌
(primary)
4.4% [2.3%, 8.2%] 9
Regressions ❌
(secondary)
268.7% [1.8%, 1393.3%] 37
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.3% [-3.3%, -3.3%] 1
All ❌✅ (primary) 4.4% [2.3%, 8.2%] 9

Binary size

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

Bootstrap: 473.727s -> 474.872s (0.24%)
Artifact size: 389.29 MiB -> 386.79 MiB (-0.64%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 12, 2025
@traviscross
Copy link
Contributor

While we're here...

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-149901 created and queued.
🤖 Automatically detected try build db4e1d2
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-lang-radar Items that are on lang's radar and will need eventual work or consideration. perf-regression Performance regression. S-waiting-on-crater Status: Waiting on a crater run to be completed. 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