-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Stall computing instance for drop shim until it has no unsubstituted const params #127068
Conversation
r? @BoxyUwU @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Stall dropaStall computing instance for drop shim until it has no unsubstituted const params Stall resolving the drop shim instance for types that still have unsubstituted const params. ## Why? rust-lang#127030 ICEs because it tries to inline the drop shim for a type with an unsubstituted const param. In order to generate this shim, this requires calling the drop shim builder, which invokes the trait solver to compute whether constituent types need drop (since we compute if a type is copy to disqualify any `Drop` behavior): https://github.com/rust-lang/rust/blob/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/compiler/rustc_mir_dataflow/src/elaborate_drops.rs#L378 However, since we don't keep the param-env of the instance we resolved the item for, we use the wrong param-env: https://github.com/rust-lang/rust/blob/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/compiler/rustc_mir_transform/src/shim.rs#L278 (which is the param-env of `std::ptr::drop_in_place`) This param-env is notably missing `ConstParamHasTy` predicates, and since we removed the type from consts in rust-lang#125958, we literally cannot prove these predicates in this (relatively) empty param-env. This currently happens in places like the MIR inliner, but may happen elsewhere such as in lints that resolve terminators. ## What? We delay the resolution (`Instance::resolve`) of calls for `drop_in_place` for types that have unsubstituted const params. This should be OK, since all cases that deal with polymorphic code should handle `Instance::resolve` returning `None` gracefully.
@@ -53,6 +53,15 @@ fn resolve_instance<'tcx>( | |||
_ => return Ok(None), | |||
} | |||
|
|||
// FIXME(#127030): `ConstParamHasTy` has bad interactions with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could actually move this change to:
fn check_mir_is_available( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I am kinda worried that there are other calls to Instance::resolve
that may trigger this problem. Not exactly sure why -- I could audit all of the Instance::resolve
calls in the codebase, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I did check all the calls. The only one of note is actually in the inliner. I'm indifferent about where to put this hack, but I guess putting this hack in the inliner is likely to make less of a perf impact and easier to reason about for backports.
Let me move it after the perf run is done. Then I'll edit the description.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (e495e73): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (secondary 5.8%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 697.882s -> 696.928s (-0.14%) |
d62c70c
to
f17b27b
Compare
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
@bors r+ rollup thank you errs |
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#123714 (Add test for fn pointer duplication.) - rust-lang#124091 (Update AST validation module docs) - rust-lang#127015 (Switch back `non_local_definitions` lint to allow-by-default) - rust-lang#127016 (docs: check if the disambiguator matches its suffix) - rust-lang#127029 (Fix Markdown tables in platform-support.md) - rust-lang#127032 (Enable const casting for `f16` and `f128`) - rust-lang#127055 (Mark Hasher::finish as #[must_use]) - rust-lang#127068 (Stall computing instance for drop shim until it has no unsubstituted const params) - rust-lang#127070 (add () to the marker_impls macro for ConstParamTy) - rust-lang#127071 (Remove (deprecated & unstable) {to,from}_bits pointer methods) - rust-lang#127078 (Enable full tools and profiler for LoongArch Linux targets) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#123714 (Add test for fn pointer duplication.) - rust-lang#124091 (Update AST validation module docs) - rust-lang#127015 (Switch back `non_local_definitions` lint to allow-by-default) - rust-lang#127016 (docs: check if the disambiguator matches its suffix) - rust-lang#127029 (Fix Markdown tables in platform-support.md) - rust-lang#127032 (Enable const casting for `f16` and `f128`) - rust-lang#127055 (Mark Hasher::finish as #[must_use]) - rust-lang#127068 (Stall computing instance for drop shim until it has no unsubstituted const params) - rust-lang#127070 (add () to the marker_impls macro for ConstParamTy) - rust-lang#127071 (Remove (deprecated & unstable) {to,from}_bits pointer methods) - rust-lang#127078 (Enable full tools and profiler for LoongArch Linux targets) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#123714 (Add test for fn pointer duplication.) - rust-lang#124091 (Update AST validation module docs) - rust-lang#127015 (Switch back `non_local_definitions` lint to allow-by-default) - rust-lang#127016 (docs: check if the disambiguator matches its suffix) - rust-lang#127029 (Fix Markdown tables in platform-support.md) - rust-lang#127032 (Enable const casting for `f16` and `f128`) - rust-lang#127055 (Mark Hasher::finish as #[must_use]) - rust-lang#127068 (Stall computing instance for drop shim until it has no unsubstituted const params) - rust-lang#127070 (add () to the marker_impls macro for ConstParamTy) - rust-lang#127071 (Remove (deprecated & unstable) {to,from}_bits pointer methods) - rust-lang#127078 (Enable full tools and profiler for LoongArch Linux targets) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#127068 - compiler-errors:stall-drop, r=BoxyUwU Stall computing instance for drop shim until it has no unsubstituted const params Do not inline the drop shim for types that still have unsubstituted const params. ## Why? rust-lang#127030 ICEs because it tries to inline the drop shim for a type with an unsubstituted const param. In order to generate this shim, this requires calling the drop shim builder, which invokes the trait solver to compute whether constituent types need drop (since we compute if a type is copy to disqualify any `Drop` behavior): https://github.com/rust-lang/rust/blob/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/compiler/rustc_mir_dataflow/src/elaborate_drops.rs#L378 However, since we don't keep the param-env of the instance we resolved the item for, we use the wrong param-env: https://github.com/rust-lang/rust/blob/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/compiler/rustc_mir_transform/src/shim.rs#L278 (which is the param-env of `std::ptr::drop_in_place`) This param-env is notably missing `ConstParamHasTy` predicates, and since we removed the type from consts in rust-lang#125958, we literally cannot prove these predicates in this (relatively) empty param-env. This currently happens in places like the MIR inliner, but may happen elsewhere such as in lints that resolve terminators. ## What? We force the inliner to not consider calls for `drop_in_place` for types that have unsubstituted const params. ## So what? This may negatively affect MIR inlining, but I doubt this matters in practice, and fixes a beta regression, so let's fix it. I will look into approaches for fixing this in a more maintainable way, perhaps delaying the creation of drop shim bodies until codegen (like how intrinsics work).
[beta] backports - Properly gate `safe` keyword in pre-expansion rust-lang#126757 - Switch back `non_local_definitions` lint to allow-by-default rust-lang#127015 - Stall computing instance for drop shim until it has no unsubstituted const params rust-lang#127068 - Update LLVM submodule rust-lang#127190 r? cuviper
[beta] backports - Properly gate `safe` keyword in pre-expansion rust-lang#126757 - Switch back `non_local_definitions` lint to allow-by-default rust-lang#127015 - Stall computing instance for drop shim until it has no unsubstituted const params rust-lang#127068 - Update LLVM submodule rust-lang#127190 - Change to the NetBSD archive URL rather than the CDN rust-lang#127232 r? cuviper
[beta] backports - Properly gate `safe` keyword in pre-expansion rust-lang#126757 - Switch back `non_local_definitions` lint to allow-by-default rust-lang#127015 - Stall computing instance for drop shim until it has no unsubstituted const params rust-lang#127068 - Update LLVM submodule rust-lang#127190 - Change to the NetBSD archive URL rather than the CDN rust-lang#127232 r? cuviper
[beta] backports - Properly gate `safe` keyword in pre-expansion rust-lang#126757 - Switch back `non_local_definitions` lint to allow-by-default rust-lang#127015 - Stall computing instance for drop shim until it has no unsubstituted const params rust-lang#127068 - Update LLVM submodule rust-lang#127190 - Change to the NetBSD archive URL rather than the CDN rust-lang#127232 r? cuviper
Do not inline the drop shim for types that still have unsubstituted const params.
Why?
#127030 ICEs because it tries to inline the drop shim for a type with an unsubstituted const param. In order to generate this shim, this requires calling the drop shim builder, which invokes the trait solver to compute whether constituent types need drop (since we compute if a type is copy to disqualify any
Drop
behavior):rust/compiler/rustc_mir_dataflow/src/elaborate_drops.rs
Line 378 in 9c3bc80
However, since we don't keep the param-env of the instance we resolved the item for, we use the wrong param-env:
rust/compiler/rustc_mir_transform/src/shim.rs
Line 278 in 9c3bc80
(which is the param-env of
std::ptr::drop_in_place
)This param-env is notably missing
ConstParamHasTy
predicates, and since we removed the type from consts in #125958, we literally cannot prove these predicates in this (relatively) empty param-env. This currently happens in places like the MIR inliner, but may happen elsewhere such as in lints that resolve terminators.What?
We force the inliner to not consider calls for
drop_in_place
for types that have unsubstituted const params.So what?
This may negatively affect MIR inlining, but I doubt this matters in practice, and fixes a beta regression, so let's fix it. I will look into approaches for fixing this in a more maintainable way, perhaps delaying the creation of drop shim bodies until codegen (like how intrinsics work).