Skip to content
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

Merged
merged 2 commits into from
Jun 29, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jun 28, 2024

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):

self.place_ty(place).needs_drop(self.tcx(), self.elaborator.param_env())

However, since we don't keep the param-env of the instance we resolved the item for, we use the wrong param-env:

let param_env = tcx.param_env_reveal_all_normalized(def_id);

(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).

@rustbot
Copy link
Collaborator

rustbot commented Jun 28, 2024

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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 Jun 28, 2024
@compiler-errors
Copy link
Member Author

r? @BoxyUwU

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 28, 2024
@compiler-errors compiler-errors added beta-nominated Nominated for backporting to the compiler in the beta channel. T-types Relevant to the types team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 28, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 28, 2024
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.
@bors
Copy link
Contributor

bors commented Jun 28, 2024

⌛ Trying commit d62c70c with merge e495e73...

@compiler-errors compiler-errors changed the title Stall dropaStall computing instance for drop shim until it has no unsubstituted const params Stall computing instance for drop shim until it has no unsubstituted const params Jun 28, 2024
@@ -53,6 +53,15 @@ fn resolve_instance<'tcx>(
_ => return Ok(None),
}

// FIXME(#127030): `ConstParamHasTy` has bad interactions with
Copy link
Member Author

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(

Copy link
Member Author

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.

Copy link
Member Author

@compiler-errors compiler-errors Jun 28, 2024

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.

@bors
Copy link
Contributor

bors commented Jun 28, 2024

☀️ Try build successful - checks-actions
Build commit: e495e73 (e495e734d5a543e0b2dbc28c0ea2a733b80fb50c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e495e73): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking 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
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

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

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.

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

Cycles

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

Binary size

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

Bootstrap: 697.882s -> 696.928s (-0.14%)
Artifact size: 326.66 MiB -> 326.72 MiB (0.02%)

@rustbot
Copy link
Collaborator

rustbot commented Jun 28, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 28, 2024

@bors r+ rollup

thank you errs

@bors
Copy link
Contributor

bors commented Jun 28, 2024

📌 Commit f17b27b has been approved by BoxyUwU

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 28, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 28, 2024
…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
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 29, 2024
…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
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 29, 2024
…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
@bors bors merged commit 5afb4c2 into rust-lang:master Jun 29, 2024
6 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jun 29, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 29, 2024
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).
@apiraino
Copy link
Contributor

apiraino commented Jul 4, 2024

Beta backport accepted as per compiler team on Zulip. A backport PR will be authored by the release team at the end of the current development cycle.

@rustbot label +beta-accepted

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jul 4, 2024
@cuviper cuviper mentioned this pull request Jul 5, 2024
@cuviper cuviper modified the milestones: 1.81.0, 1.80.0 Jul 5, 2024
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 5, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 6, 2024
[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
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 6, 2024
[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
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 6, 2024
[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
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 6, 2024
[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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-types Relevant to the types 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