rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.52k stars 94 forks source link

Issue compiling Bevy project on linux gnu cargo target #1361

Closed Hellzbellz123 closed 1 year ago

Hellzbellz123 commented 1 year ago

pretty sure this is related too using simd-nightly feature of rapier2d, disabling that cargo feature got it too compile, however i noticed one strange issue between cranelift and rustc. the following line wouldnt compile with cranelift but would compile with the normal rustc codegen *wtransform.rotation = *(Quat::from_euler(EulerRot::ZYX, aimangle, 0.0, 0.0));

this is the output from trying to using rapier2d/simd-nightly

warning: unnecessary parentheses around assigned value
   --> src/actors/combat/mod.rs:120:36
    |
120 |             *wtransform.rotation = *(Quat::from_euler(EulerRot::ZYX, aimangle, 0.0, 0.0));
    |                                    ^                                                   ^
    |
    = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
    |
120 -             *wtransform.rotation = *(Quat::from_euler(EulerRot::ZYX, aimangle, 0.0, 0.0));
120 +             *wtransform.rotation = Quat::from_euler(EulerRot::ZYX, aimangle, 0.0, 0.0);
    |

error[E0614]: type `bevy::prelude::Quat` cannot be dereferenced
   --> src/actors/combat/mod.rs:120:13
    |
120 |             *wtransform.rotation = *(Quat::from_euler(EulerRot::ZYX, aimangle, 0.0, 0.0));
    |             ^^^^^^^^^^^^^^^^^^^^^
    |
help: parentheses are required to parse this as an expression
    |
115 ~             (if aimangle.to_degrees() > 180.0 || aimangle.to_degrees() < -0.0 {
116 |                 wtransform.scale.x = -1.0
117 |             } else {
118 |                 wtransform.scale.x = 1.0
119 ~             })
    |

For more information about this error, try `rustc --explain E0614`.
warning: `vanillacoffee-wip` (bin "vanillacoffee-wip") generated 1 warning
❯ ~/cargo-clif/cargo-clif build -Zunstable-options --keep-going
   Compiling simba v0.8.0
   Compiling nalgebra v0.32.1
error: VerifierErrors([VerifierError { location: inst5, context: Some("v5 = extractlane.i128 v3, 0"), message: "has an invalid controlling type i128" }, VerifierError { location: inst6, context: Some("v6 = extractlane.i128 v4, 0"), message: "has an invalid controlling type i128" }, VerifierError { location: inst8, context: Some("v9 = insertlane.i128 v8, v7, 0"), message: "has an invalid controlling type i128" }])

error: cranelift verify error:
       function u0:83(i64 sret, i64, i64) system_v {
                                       block0(v0: i64, v1: i64, v2: i64):
                                           v12 = iconst.i64 0
                                           v13 = uextend.i128 v12  ; v12 = 0
                                           v8 -> v13
                                           v11 -> v13
                                           nop 
                                           jump block1

                                       block1:
                                           nop 
       @0001                               v3 = load.i128 notrap v1
       @0002                               v4 = load.i128 notrap v2
                                           v5 = extractlane v3, 0
       ;                                   ^~~~~~~~~~~~~~~~~~~~~~
       ; error: inst5 (v5 = extractlane.i128 v3, 0): has an invalid controlling type i128

                                           v6 = extractlane v4, 0
       ;                                   ^~~~~~~~~~~~~~~~~~~~~~
       ; error: inst6 (v6 = extractlane.i128 v4, 0): has an invalid controlling type i128

                                           v7 = bor v5, v6
                                           v9 = insertlane.i128 v8, v7, 0
                                           v10 -> v9
       ;                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       ; error: inst8 (v9 = insertlane.i128 v8, v7, 0): has an invalid controlling type i128

                                           jump block2

                                       block2:
                                           nop 
       @0004                               store.i128 notrap v10, v0
       @0006                               return
       }

       ; 3 verifier errors detected (see above). Compilation aborted.

fn packed_simd_2::v128::<impl std::ops::BitOr for packed_simd_2::Simd<[packed_simd_2::m128; 1]>>::bitor(_1: packed_simd_2::Simd<[packed_simd_2::m128; 1]>, _2: packed_simd_2::Simd<[packed_simd_2::m128; 1]>) -> packed_simd_2::Simd<[packed_simd_2::m128; 1]> {
    debug self => _1;                    // in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:35:22: 35:26
    debug other => _2;                   // in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:35:28: 35:33
    let mut _0: packed_simd_2::Simd<[packed_simd_2::m128; 1]>; // return place in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:35:44: 35:48
    let mut _3: packed_simd_2::codegen::v128::m128x1; // in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:31: 37:55
    let mut _4: packed_simd_2::codegen::v128::m128x1; // in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:39: 37:45
    let mut _5: packed_simd_2::codegen::v128::m128x1; // in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:47: 37:54
    scope 1 {
    }

    bb0: {
        StorageLive(_3);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:31: 37:55
        StorageLive(_4);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:39: 37:45
        _4 = (_1.0: packed_simd_2::codegen::v128::m128x1); // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:39: 37:45
        StorageLive(_5);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:47: 37:54
        _5 = (_2.0: packed_simd_2::codegen::v128::m128x1); // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:47: 37:54
        _3 = packed_simd_2::codegen::llvm::simd_or::<packed_simd_2::codegen::v128::m128x1>(move _4, move _5) -> bb1; // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:31: 37:55
                                         // mir::Constant
                                         // + span: /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:31: 37:38
                                         // + literal: Const { ty: unsafe extern "platform-intrinsic" fn(packed_simd_2::codegen::v128::m128x1, packed_simd_2::codegen::v128::m128x1) -> packed_simd_2::codegen::v128::m128x1 {packed_simd_2::codegen::llvm::simd_or::<packed_simd_2::codegen::v128::m128x1>}, val: Value(<ZST>) }
    }

    bb1: {
        StorageDead(_5);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:54: 37:55
        StorageDead(_4);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:54: 37:55
        _0 = packed_simd_2::Simd::<[packed_simd_2::m128; 1]>(move _3); // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:26: 37:56
        StorageDead(_3);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:55: 37:56
        return;                          // scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:38:14: 38:14
    }
}

error: could not compile `simba` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
   Compiling parry2d v0.13.1
^C  Building [=======================> ] 490/495: parry2d    
Hellzbellz123 commented 1 year ago

i managed too have fat fingers my apologies, i managed to get the project to compile in release after disabling lto, not sure why the de-reference wasnt working with cranelift but removing the * fixed that compiler error, it works both ways in rustc so it shouldnt be too big of a deal

as for the simd-nightly errors, the simd-nightly feature of rapier is equivelant too this: simd-nightly = [ "simba/packed_simd", "simd-is-enabled" ]

simd-stable compiles fine so i think this issue was probably my fault?

bjorn3 commented 1 year ago

I can reproduce this by compiling simba with the packed_simd feature.

bjorn3 commented 1 year ago

Looks like simba depends on the packed_simd_2 crate from crates.io which has been subsumed by std::simd. packed_simd_2 uses a version of the interface with rustc that cg_clif doesn't support. There is an open issue to migrate to std::simd: https://github.com/dimforge/simba/issues/33 I'm going to close this as the right course of action is for simba to move to std::simd. For now using simd-stable with rapier is the best option.