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

regression: error[E0512]: cannot transmute between types of different sizes, or dependently-sized types (Thread) #134711

Closed
cuviper opened this issue Dec 23, 2024 · 6 comments
Labels
C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Milestone

Comments

@cuviper
Copy link
Member

cuviper commented Dec 23, 2024

  1. https://crater-reports.s3.amazonaws.com/beta-1.84.0-4-retry2/beta-2024-12-08/gh/DoumanAsh.nng-c/log.txt
  2. https://crater-reports.s3.amazonaws.com/beta-1.84.0-4-retry2/beta-2024-12-08/reg/thread-waker-1.1.0/log.txt
  3. https://crater-reports.s3.amazonaws.com/beta-1.84.0-4-retry2/beta-2024-12-08/reg/utils-atomics-1.1.2/log.txt

They are all variants of transmuting Thread, including the Lock(Thread) in the 3rd one:

[INFO] [stdout] error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
[INFO] [stdout]   --> src/locks.rs:42:33
[INFO] [stdout]    |
[INFO] [stdout] 42 |                 return unsafe { core::mem::transmute(self) }
[INFO] [stdout]    |                                 ^^^^^^^^^^^^^^^^^^^^
[INFO] [stdout]    |
[INFO] [stdout]    = note: source type: `Lock` (128 bits)
[INFO] [stdout]    = note: target type: `*mut ()` (64 bits)
[INFO] [stdout] 
[INFO] [stdout] 
[INFO] [stdout] error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
[INFO] [stdout]   --> src/locks.rs:54:29
[INFO] [stdout]    |
[INFO] [stdout] 54 |                 return Self(core::mem::transmute(raw))
[INFO] [stdout]    |                             ^^^^^^^^^^^^^^^^^^^^
[INFO] [stdout]    |
[INFO] [stdout]    = note: source type: `*mut ()` (64 bits)
[INFO] [stdout]    = note: target type: `Thread` (128 bits)

I'm sure the answer is "don't do that!" -- but at least we can have an issue for reference.

Version it worked on

It most recently worked on: 1.83.0

Version with regression

Using rustc 1.84.0-beta.4 in crater #134138.

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged

@cuviper cuviper added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Dec 23, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-untriaged Untriaged performance or correctness regression. labels Dec 23, 2024
@compiler-errors
Copy link
Member

This bisects to #123550.

The regressed crates were probably relying on specific layout guarantees about the Thread struct which are no longer upheld after the internal representation of Thread changed (namely, that the size of Thread is no longer 64 bits).

@cuviper
Copy link
Member Author

cuviper commented Dec 23, 2024

I don't think it was ever a guarantee, just Hyrum's Law in action.

@compiler-errors
Copy link
Member

sorry, when I wrote guarantee I really meant assumptions. False guarantees :)

@cuviper
Copy link
Member Author

cuviper commented Dec 24, 2024

The may crate had the courtesy to assert it first:

  1. https://crater-reports.s3.amazonaws.com/beta-1.84.0-4-retry2/beta-2024-12-08/gh/Alex-q-z.kvcachesim/log.txt
  2. https://crater-reports.s3.amazonaws.com/beta-1.84.0-4-retry2/beta-2024-12-08/gh/AnfriH.MechSync/log.txt
  3. https://crater-reports.s3.amazonaws.com/beta-1.84.0-4-retry2/beta-2024-12-08/gh/Netnix-SA.moquist/log.txt
  4. https://crater-reports.s3.amazonaws.com/beta-1.84.0-4-retry2/beta-2024-12-08/gh/Vitalick.rust-prj/log.txt
  5. https://crater-reports.s3.amazonaws.com/beta-1.84.0-4-retry2/beta-2024-12-08/gh/asagikaki.thaqqa/log.txt
  6. https://crater-reports.s3.amazonaws.com/beta-1.84.0-4-retry2/beta-2024-12-08/gh/jonataslaw.server_nano/log.txt
  7. https://crater-reports.s3.amazonaws.com/beta-1.84.0-4-retry2/beta-2024-12-08/gh/natanaeladit.may/log.txt
[INFO] [stdout] error[E0080]: evaluation of constant value failed
[INFO] [stdout]   --> /opt/rustwide/cargo-home/registry/src/index.crates.io-6f17d22bba15001f/may-0.3.45/src/sync/spsc.rs:72:15
[INFO] [stdout]    |
[INFO] [stdout] 72 | const _: () = assert!(std::mem::size_of::<Thread>() == std::mem::size_of::<usize>());
[INFO] [stdout]    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: std::mem::size_of::<Thread>() == std::mem::size_of::<usize>()', /opt/rustwide/cargo-home/registry/src/index.crates.io-6f17d22bba15001f/may-0.3.45/src/sync/spsc.rs:72:15
[INFO] [stdout]    |
[INFO] [stdout]    = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
[INFO] [stdout] 
[INFO] [stdout] 
[INFO] [stdout] error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
[INFO] [stdout]   --> /opt/rustwide/cargo-home/registry/src/index.crates.io-6f17d22bba15001f/may-0.3.45/src/sync/spsc.rs:86:35
[INFO] [stdout]    |
[INFO] [stdout] 86 |         let mut handle = unsafe { std::mem::transmute(thread) };
[INFO] [stdout]    |                                   ^^^^^^^^^^^^^^^^^^^
[INFO] [stdout]    |
[INFO] [stdout]    = note: source type: `Thread` (128 bits)
[INFO] [stdout]    = note: target type: `NonZero<usize>` (64 bits)

That appears to be fixed in may v0.3.47: Xudong-Huang/may@e965379

@cuviper cuviper added this to the 1.84.0 milestone Dec 24, 2024
@Mark-Simulacrum
Copy link
Member

cc #132619 (another report of the same problem)

It looks like this is almost ready to be fixed by landing #132654, so a future release will probably "fix" these crates again -- but since this isn't a stable implementation detail it feels reasonable to let Thread change in size back and forth a few times.

@Mark-Simulacrum
Copy link
Member

I'm going to go ahead and close this as won't fix; I don't think it merits compat notes that are something like "standard library types may change in size". The breakage seems fairly limited too.

@Mark-Simulacrum Mark-Simulacrum closed this as not planned Won't fix, can't repro, duplicate, stale Jan 3, 2025
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 3, 2025
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Projects
None yet
Development

No branches or pull requests

6 participants