Skip to content

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Aug 10, 2024

The MIR inliner could already inline drop_in_place, but not TerminatorKind::Drop. This change lets it turn drop(place) into drop_in_place(&place), so it can inline them too.

For now it's intentionally set to only allow inlining relatively small things, because allowing more results in every Box inlining a ton of stuff. But it's nice to see newtype drops getting elided.

Hopefully perf will be happy too...

@rustbot
Copy link
Collaborator

rustbot commented Aug 10, 2024

r? @fmease

rustbot has assigned @fmease.
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 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 Aug 10, 2024
@scottmcm
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 10, 2024
@bors
Copy link
Collaborator

bors commented Aug 10, 2024

⌛ Trying commit d5a03e8 with merge 884b395...

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 10, 2024
Allow inlining drop glue more generally

The MIR inliner could already inline `drop_in_place`, but not `TerminatorKind::Drop`.  This change lets it inline `drop_in_place` too.

For now it's intentionally set to only allow inlining relatively small things, because allowing more results in every `Box` inlining a ton of stuff.  But it's nice to see newtype drops getting elided.

Hopefully perf will be happy too...
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Aug 10, 2024

💔 Test failed - checks-actions

@bors bors 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 Aug 10, 2024
@scottmcm scottmcm force-pushed the nuke-runtime-drops branch from d5a03e8 to e08aae3 Compare August 10, 2024 19:04
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
------
 > importing cache manifest from ghcr.io/rust-lang/rust-ci-cache:3aacb9c90579defe09351ac5e8ee504359f8054da6326ff19038f1b7c90e3cb2aafe33685c6d9b76ee8d2ccbd187ca80c46ab5380485abdd8c0ce7d69cd8d8fd:
------
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
---- [ui] tests/ui/mir/issue-107691.rs stdout ----

error: test compilation failed although it shouldn't!
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/ui/mir/issue-107691.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" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/mir/issue-107691" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/mir/issue-107691/auxiliary" "-C" "opt-level=3"
--- stderr -------------------------------
--- stderr -------------------------------
##[error]error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:169:90: Failed to normalize Alias(Projection, AliasTy { args: [&'{erased} [u8]], def_id: DefId(0:5 ~ issue_107691[b1ee]::Archive::Resolver), .. }), maybe try to call `try_normalize_erasing_regions` instead
thread 'rustc' panicked at compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:169:90:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: <rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
   7: <rustc_middle::ty::context::TyCtxt>::normalize_erasing_regions::<rustc_middle::ty::Ty>
   7: <rustc_middle::ty::context::TyCtxt>::normalize_erasing_regions::<rustc_middle::ty::Ty>
   8: <core::iter::adapters::map::Map<core::iter::adapters::enumerate::Enumerate<core::slice::iter::Iter<rustc_middle::ty::FieldDef>>, <rustc_mir_dataflow::elaborate_drops::DropCtxt<rustc_mir_transform::shim::DropShimElaborator>>::move_paths_for_fields::{closure#0}> as core::iter::traits::iterator::Iterator>::fold::<(), core::iter::traits::iterator::Iterator::for_each::call<(rustc_middle::mir::syntax::Place, core::option::Option<()>), <alloc::vec::Vec<(rustc_middle::mir::syntax::Place, core::option::Option<()>)>>::extend_trusted<core::iter::adapters::map::Map<core::iter::adapters::enumerate::Enumerate<core::slice::iter::Iter<rustc_middle::ty::FieldDef>>, <rustc_mir_dataflow::elaborate_drops::DropCtxt<rustc_mir_transform::shim::DropShimElaborator>>::move_paths_for_fields::{closure#0}>>::{closure#0}>::{closure#0}>
   9: <alloc::vec::Vec<(rustc_middle::mir::syntax::Place, core::option::Option<()>)> as alloc::vec::spec_from_iter::SpecFromIter<(rustc_middle::mir::syntax::Place, core::option::Option<()>), core::iter::adapters::map::Map<core::iter::adapters::enumerate::Enumerate<core::slice::iter::Iter<rustc_middle::ty::FieldDef>>, <rustc_mir_dataflow::elaborate_drops::DropCtxt<rustc_mir_transform::shim::DropShimElaborator>>::move_paths_for_fields::{closure#0}>>>::from_iter
  10: <rustc_mir_dataflow::elaborate_drops::DropCtxt<rustc_mir_transform::shim::DropShimElaborator>>::elaborate_drop
  11: rustc_mir_transform::shim::make_shim
      [... omitted 2 frames ...]
  13: <rustc_mir_transform::inline::Inliner>::try_inlining
  14: <rustc_mir_transform::inline::Inliner>::process_blocks
  15: <rustc_mir_transform::inline::Inline as rustc_middle::mir::MirPass>::run_pass
  16: rustc_mir_transform::pass_manager::run_passes_inner
  16: rustc_mir_transform::pass_manager::run_passes_inner
  17: rustc_mir_transform::optimized_mir
      [... omitted 2 frames ...]
  18: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  19: rustc_mir_transform::cross_crate_inline::cross_crate_inlinable
      [... omitted 2 frames ...]
  21: rustc_passes::reachable::reachable_set
  21: rustc_passes::reachable::reachable_set
      [... omitted 2 frames ...]
  22: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  23: rustc_metadata::rmeta::encoder::encode_metadata
  24: rustc_metadata::fs::encode_and_write_metadata
  26: <rustc_interface::queries::Linker>::codegen_and_build_linker
  27: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#6}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
  28: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#6}>
  29: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#0}::{closure#1}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
---
note: please make sure that you have updated to the latest nightly

note: rustc 1.82.0-nightly (6174f6dce 2024-08-10) 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 -C codegen-units=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z write-long-types-to-disk=no -C strip=debuginfo -C prefer-dynamic -C rpath -C debuginfo=0 -C opt-level=3
query stack during panic:
query stack during panic:
#0 [mir_shims] generating MIR shim for `core::ptr::drop_in_place`
#1 [optimized_mir] optimizing MIR for `<impl at /checkout/tests/ui/mir/issue-107691.rs:34:1: 36:23>::resolve`
#2 [cross_crate_inlinable] whether the item should be made inlinable across crates
#3 [reachable_set] reachability
error: aborting due to 1 previous error
------------------------------------------


@cjgillot
Copy link
Contributor

2 ideas:

  • move the drop -> drop_in_place transform to LowerIntrinsics or InstSimplify?
  • reuse drop elaboration to do this in some cases?

The former should resolve your cycle issue out of the box.

@bors
Copy link
Collaborator

bors commented Aug 20, 2024

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

@Dylan-DPC Dylan-DPC removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 7, 2024
@fmease fmease removed their assignment Jul 30, 2025
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.

8 participants