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

Stop considering moved-out locals when computing auto traits for generators (rebased) #128846

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Aug 8, 2024

This PR revives #112279. I wanted to reopen this to gauge @cjgillot's thoughts about this, since it's been a while since -Zdrop-tracking-mir has landed.

If this PR looks OK, I can flesh it out and write up an FCP report -- I think this is a T-types FCP, since this has to do with the types that are considered live for auto traits, and doesn't otherwise affect the layout of coroutines.

Open questions:

Fixes #128095
Fixes #94067
Fixes #129325

r? @cjgillot

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 8, 2024
@rustbot
Copy link
Collaborator

rustbot commented Aug 8, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 8, 2024
@compiler-errors
Copy link
Member Author

@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 Aug 8, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 8, 2024
Stop considering moved-out locals when computing auto traits for generators (rebased)

This PR revives rust-lang#112279. I wanted to reopen this to gauge `@cjgillot's` thoughts about this, since it's been a while since `-Zdrop-tracking-mir` has landed.

If this PR looks OK, I can flesh it out and write up an FCP report -- I think this is a T-types FCP, since this has to do with the types that are considered live for auto traits, and doesn't otherwise affect the layout of coroutines.

Open questions:
* **"Why do we require storage to be live if the locals is not initialized?"** (rust-lang#112279 (comment))
    * I agree that we should eventually fix the storage analysis for coroutines, but this seems like a problem that can be fixed after we fix witnesses for *the purposes of traits* here.
    * As far as I could tell, fixing the problem of moved locals for *storage* would require insertion of additional `StorageDead` statements, or would require further entangling the type system with the operational semantics in ways that T-opsem seemed uncomfortable with [when I asked](https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Inserting.20.60StorageDrop.60.20after.20unconditional.20moves). cc `@RalfJung`
    * Relevant: rust-lang/unsafe-code-guidelines#188

Fixes rust-lang#128095
Fixes rust-lang#94067

r? `@cjgillot`
@bors
Copy link
Contributor

bors commented Aug 8, 2024

⌛ Trying commit 9c519d5 with merge 7093781...

@bors
Copy link
Contributor

bors commented Aug 8, 2024

☀️ Try build successful - checks-actions
Build commit: 7093781 (709378137e05d0649c71b323e6246f5d48dd8bff)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7093781): comparison URL.

Overall result: ❌ regressions - 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@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.4% [0.4%, 0.5%] 2
Regressions ❌
(secondary)
2.8% [0.8%, 5.6%] 15
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [0.4%, 0.5%] 2

Max RSS (memory usage)

Results (primary 4.2%, secondary -1.0%)

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)
4.2% [3.5%, 4.9%] 2
Regressions ❌
(secondary)
2.6% [2.6%, 2.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.8% [-3.1%, -2.4%] 2
All ❌✅ (primary) 4.2% [3.5%, 4.9%] 2

Cycles

Results (secondary 3.3%)

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)
3.3% [2.0%, 4.2%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 761.822s -> 762.913s (0.14%)
Artifact size: 337.08 MiB -> 337.07 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 Aug 9, 2024
@compiler-errors
Copy link
Member Author

compiler-errors commented Aug 20, 2024

I think we should eat the perf cost of the analysis. I'm happy to write up an FCP report for this if someone would like to actually review the changes.

@cjgillot
Copy link
Contributor

It was initially a design goal to have the witness types and the runtime transform use the same code. To ensure that they don't diverge and that we don't introduce unsoundness.

On this particular change, why can't apply it to the runtime transform too?

@@ -725,6 +727,10 @@ struct LivenessInfo {
/// Which locals are live across any suspension point.
saved_locals: CoroutineSavedLocals,

/// Which locals are live *and* initialized across any suspension point.
/// A local that is live but is not initialized does not need to accounted in auto trait checking.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your friendly neighborhood spell checker 😁

Suggested change
/// A local that is live but is not initialized does not need to accounted in auto trait checking.
/// A local that is live but is not initialized does not need to be accounted for in auto trait checking.

@compiler-errors
Copy link
Member Author

@cjgillot: I'm not totally sure if I'm understanding what you're asking for. 🤔

Are you saying that we shouldn't just be using this for auto trait coroutine witnesses, but also we should use whether a variable is uninitialized to make it so that we don't even store it across await points?

If so, I'm not totally sure that would be sound, given that we don't have a StorageDrop until possibly some other coroutine state... If not, then could you elaborate?

@cjgillot
Copy link
Contributor

What I'm asking is to have the same logic for both the types and runtime.

The core idea behind type witnesses is to list the types which will appear in the runtime representation.

If the types and runtime have the same logic, we can be confident that whatever happens between both analyses, we will have something consistent.

For instance, we could perform the runtime transform after some opts, and be happy with it.

If we have different analyses, I fear we will have to prove each time that we have that consistency, which will be hard.

So my question is: what would it take to make your PR sourd for the runtime transform.

Do I make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. 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.
Projects
None yet
7 participants