RustPython icon indicating copy to clipboard operation
RustPython copied to clipboard

Compile error: cannot transmute between types of different sizes, or dependently-sized types [E0512]

Open vvzen opened this issue 4 months ago • 2 comments

Summary

Hi all! And thank you for the super interesting project. I'm not sure if this is a bug or not - technically it's just a compile issue.

I wanted to try the embedded example (https://github.com/RustPython/RustPython/blob/main/examples/hello_embed.rs) :

use rustpython_vm as vm;

fn main() -> vm::PyResult<()> {
    vm::Interpreter::without_stdlib(Default::default()).enter(|vm| {
        let scope = vm.new_scope_with_builtins();
        let source = r#"print("Hello World!")"#;
        let code_obj = vm
            .compile(source, vm::compiler::Mode::Exec, "<embedded>".to_owned())
            .map_err(|err| vm.new_syntax_error(&err, Some(source)))?;

        vm.run_code_obj(code_obj, scope)?;

        Ok(())
    })
}

But when I try a cargo run --release with the code above, I get an assertion error:

   Compiling rustpython-compiler-core v0.3.0
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
  --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustpython-ast-0.3.0/src/impls.rs:60:1
   |
60 | static_assertions::assert_eq_size!(crate::Stmt, [u8; 160]);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: source type: `generic::Stmt` (1216 bits)
   = note: target type: `[u8; 160]` (1280 bits)
   = note: this error originates in the macro `static_assertions::assert_eq_size` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
  --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustpython-ast-0.3.0/src/impls.rs:62:1
   |
62 | static_assertions::assert_eq_size!(crate::Pattern, [u8; 96]);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: source type: `generic::Pattern` (704 bits)
   = note: target type: `[u8; 96]` (768 bits)
   = note: this error originates in the macro `static_assertions::assert_eq_size` (in Nightly builds, run with -Z macro-backtrace for more info)

   Compiling rustpython-derive-impl v0.3.0
For more information about this error, try `rustc --explain E0512`.
error: could not compile `rustpython-ast` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
~/dev/creative/nannou-sketches/rustpython-101 13:51:08 

I'm on:

$ rustc --version
rustc 1.76.0 (07dca489a 2024-02-04)

# Arch linux
$ uname -r
6.7.2-arch1-2

And this is my Cargo.toml:

[package]
name = "rustpython-101"
version = "0.1.0"
edition = "2021"

[dependencies]
rustpython-vm = "0.3.0"

Expected

The hello_embed.rs code run without errors.

Actual

The hello_embed.rs example code doesn't compile.

Thanks!

vvzen avatar Mar 09 '24 21:03 vvzen

its coming from the parser repo: https://github.com/RustPython/Parser/issues/114. looks like its been fixed on the main branch but not released yet.

sum-catnip avatar Mar 13 '24 18:03 sum-catnip

when will parser be released? same problem here on Rust 1.79 nightly

fgadaleta avatar Mar 20 '24 15:03 fgadaleta