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

Remove mir::CastKind::Misc #102675

Merged
merged 1 commit into from
Oct 8, 2022
Merged

Remove mir::CastKind::Misc #102675

merged 1 commit into from
Oct 8, 2022

Conversation

ouz-a
Copy link
Contributor

@ouz-a ouz-a commented Oct 4, 2022

As discussed in #97649 mir::CastKind::Misc is not clear, this PR addresses that by creating a new enum variant for every valid cast.

r? @oli-obk

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 4, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 4, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 4, 2022

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras

@rust-log-analyzer

This comment has been minimized.

compiler/rustc_codegen_ssa/src/mir/rvalue.rs Show resolved Hide resolved
CastKind::PointerFromExposedAddress
| CastKind::PointerExposeAddress
| CastKind::Pointer(_) => {}
_ => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check that the types are as expected here (leaving out CastKind::Pointer(_) might be fine). This will probably need some deduplication with the typeck code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure what to check 😅 , with new function mir_cast_kind we already report a bug with any unexpected cast, and since we built Rvalues with that new function is a check really needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, because MIR validation doesn't just run after MIR is built, but also after transformations that modify it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I modified those too, but it's better to be safe than sorry will add the checks in the next PR.

@@ -42,8 +42,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let res = self.pointer_from_exposed_address_cast(&src, cast_ty)?;
self.write_immediate(res, dest)?;
}

Misc => {
IntToInt | FloatToInt | FloatToFloat | IntToFloat | FnPtrToPtr | PtrToPtr => {
let src = self.read_immediate(src)?;
let res = self.misc_cast(&src, cast_ty)?;
Copy link
Member

Choose a reason for hiding this comment

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

Please add a FIXME here indicating that we shouldn't have a single misc_cast for all of them, but handle them separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that once this get's merged. 👍

Copy link
Member

Choose a reason for hiding this comment

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

Please add the FIXME now, even if you plan to fix it immediately in a follow-up. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I already did :D

Copy link
Member

Choose a reason for hiding this comment

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

Ah good, I misunderstood your comment then. :)

@oli-obk
Copy link
Contributor

oli-obk commented Oct 6, 2022

Please squash the commits. Then we can merge and leave the cleanups to follow up PRs

@ouz-a ouz-a force-pushed the mir-technical-debt branch from db0d68d to d59c7ff Compare October 6, 2022 12:32
@oli-obk
Copy link
Contributor

oli-obk commented Oct 6, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Oct 6, 2022

📌 Commit d59c7ff has been approved by oli-obk

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 Oct 6, 2022
FloatToInt,
FloatToFloat,
IntToFloat,
PtrToPtr,
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking request from the peanut gallery: It's not obvious to me how PtrToPtr differs from things in Pointer(_). Could you please put some doc-comments on the new variants?

Copy link
Contributor

Choose a reason for hiding this comment

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

"FIXME: Pointer(_) is legacy code and should be removed. Please submit a PR if you feel inclined." 🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't investigated the behavior of Pointer(_) but old code did it like the below, and some Ptr to Ptr casts went through CastKind::Misc e.g code in src/test/ui/simd/intrinsic/ptr-cast.rs. However, I could also investigate what Pointer(_) is actually doing in the next PR.

(_, _) => CastKind::Misc,

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 8, 2022
Remove `mir::CastKind::Misc`

As discussed in rust-lang#97649 `mir::CastKind::Misc` is not clear, this PR addresses that by creating a new enum variant for every valid cast.

r? `@oli-obk`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 8, 2022
Remove `mir::CastKind::Misc`

As discussed in rust-lang#97649 `mir::CastKind::Misc` is not clear, this PR addresses that by creating a new enum variant for every valid cast.

r? ``@oli-obk``
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 8, 2022
Remove `mir::CastKind::Misc`

As discussed in rust-lang#97649 `mir::CastKind::Misc` is not clear, this PR addresses that by creating a new enum variant for every valid cast.

r? ```@oli-obk```
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 8, 2022
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#101520 (Allow transmutes between the same types after erasing lifetimes)
 - rust-lang#102675 (Remove `mir::CastKind::Misc`)
 - rust-lang#102778 (Fix MIR inlining of asm_unwind)
 - rust-lang#102785 (Remove `DefId` from some `SelectionCandidate` variants)
 - rust-lang#102788 (Update rustc-dev-guide)
 - rust-lang#102789 (Update browser UI test version)
 - rust-lang#102797 (rustdoc: remove no-op CSS `.rightside { position: initial }`)
 - rust-lang#102798 (rustdoc: add main-heading and example-wrap link CSS to big selector)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c731646 into rust-lang:master Oct 8, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 8, 2022
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 20, 2022
Remove `mir::CastKind::Misc`

As discussed in rust-lang#97649 `mir::CastKind::Misc` is not clear, this PR addresses that by creating a new enum variant for every valid cast.

r? ````@oli-obk````
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 22, 2022
Remove misc_cast and validate types when casting

Continuing our work in rust-lang#102675

r? `@oli-obk`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 24, 2022
Remove misc_cast and validate types when casting

Continuing our work in rust-lang#102675

r? `@oli-obk`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 25, 2022
Remove misc_cast and validate types when casting

Continuing our work in rust-lang#102675

r? ``@oli-obk``
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 25, 2022
Remove misc_cast and validate types when casting

Continuing our work in rust-lang#102675

r? ```@oli-obk```
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 25, 2022
Remove misc_cast and validate types when casting

Continuing our work in rust-lang#102675

r? ````@oli-obk````
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
Remove misc_cast and validate types when casting

Continuing our work in rust-lang#102675

r? ````@oli-obk````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants