explain why Rvalue::Len still exists by RalfJung · Pull Request #129939 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation8 Commits1 Checks6 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

RalfJung

I just spent a bit of time trying to remove this until I realized why that's non-trivial. Let's document that for the next person. :)

@RalfJung

@rustbot

r? @cjgillot

rustbot has assigned @cjgillot.
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 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

Sep 3, 2024

@compiler-errors

@bors

📌 Commit 98f74b4 has been approved by compiler-errors

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

Sep 3, 2024

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request

Sep 3, 2024

@GuillaumeGomez

…rors

explain why Rvalue::Len still exists

I just spent a bit of time trying to remove this until I realized why that's non-trivial. Let's document that for the next person. :)

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 3, 2024

@bors

…llaumeGomez

Rollup of 7 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

tgross35 added a commit to tgross35/rust that referenced this pull request

Sep 4, 2024

@tgross35

…rors

explain why Rvalue::Len still exists

I just spent a bit of time trying to remove this until I realized why that's non-trivial. Let's document that for the next person. :)

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 4, 2024

@bors

Rollup of 8 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 4, 2024

@bors

Rollup of 8 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 4, 2024

@bors

Rollup of 8 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 5, 2024

@bors

Rollup of 8 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Sep 5, 2024

@matthiaskrgr

…rors

explain why Rvalue::Len still exists

I just spent a bit of time trying to remove this until I realized why that's non-trivial. Let's document that for the next person. :)

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Sep 5, 2024

@matthiaskrgr

…rors

explain why Rvalue::Len still exists

I just spent a bit of time trying to remove this until I realized why that's non-trivial. Let's document that for the next person. :)

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 5, 2024

@bors

@scottmcm

I have a branch somewhere that removes it -- it's not that hard to change the emitting code to just do PtrMetadata -- but the bigger problem I hit was things like the dataflow framework. #126541 made some progress there by making GVN handle it, but as you found out, it doesn't seem trivial to nuke it.

(MIR building has enough types that when it needs a length for indexing it could emit the size directly for arrays or the right PtrMetadata for slices without much trouble.)

@RalfJung

(MIR building has enough types that when it needs a length for indexing it could emit the size directly for arrays or the right PtrMetadata for slices without much trouble.)

That's what I tired, but it would have to add a temporary to hold a pointer to the place, to pass it to PtrMetadata -- and that seemed like a non-trivial-enough change that I stopped there.

scottmcm

@@ -1307,6 +1307,9 @@ pub enum Rvalue<'tcx> {
/// If the type of the place is an array, this is the array length. For slices (`[T]`, not
/// `&[T]`) this accesses the place's metadata to determine the length. This rvalue is
/// ill-formed for places of other types.
///
/// This cannot be a `UnOp(PtrMetadata, _)` because that expects a value, and we only
/// have a place, and `UnOp(PtrMetadata, RawPtr(place))` is not a thing.

Choose a reason for hiding this comment

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

The other complication here, dunno whether it's worth mentioning, is that PtrMetadata needs a wide pointer, so if the place is an array you also need to unsize it to slice.

BTW, are there [ST]B issues with adding a short-lived raw-ref to use PtrMetadata if the place is something like (*_2).1? Or is it just that it's a bit annoying to make the temporary?

Choose a reason for hiding this comment

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

The other complication here, dunno whether it's worth mentioning, is that PtrMetadata needs a wide pointer, so if the place is an array you also need to unsize it to slice.

Not really, as you said above -- if the place is an array we can just emit a constant instead.

BTW, are there [ST]B issues with adding a short-lived raw-ref to use PtrMetadata if the place is something like (*_2).1? Or is it just that it's a bit annoying to make the temporary?

There also shouldn't be any -- creating a raw pointer you never use should be effectively a NOP.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 5, 2024

@bors

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Sep 5, 2024

@matthiaskrgr

…rors

explain why Rvalue::Len still exists

I just spent a bit of time trying to remove this until I realized why that's non-trivial. Let's document that for the next person. :)

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 5, 2024

@bors

…iaskrgr

Rollup of 12 pull requests

Successful merges:

Failed merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 5, 2024

@bors

…iaskrgr

Rollup of 12 pull requests

Successful merges:

Failed merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 5, 2024

@bors

…iaskrgr

Rollup of 12 pull requests

Successful merges:

Failed merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 5, 2024

@bors

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 5, 2024

@bors

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request

Sep 6, 2024

@workingjubilee

…rors

explain why Rvalue::Len still exists

I just spent a bit of time trying to remove this until I realized why that's non-trivial. Let's document that for the next person. :)

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request

Sep 6, 2024

@workingjubilee

…rors

explain why Rvalue::Len still exists

I just spent a bit of time trying to remove this until I realized why that's non-trivial. Let's document that for the next person. :)

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 6, 2024

@bors

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 6, 2024

@bors

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Sep 6, 2024

@rust-timer

Rollup merge of rust-lang#129939 - RalfJung:rvalue-len, r=compiler-errors

explain why Rvalue::Len still exists

I just spent a bit of time trying to remove this until I realized why that's non-trivial. Let's document that for the next person. :)

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.