Stream: git-wasmtime

Topic: wasmtime / issue #5876 Cranelift: MIRI complaining about ...


view this post on Zulip Wasmtime GitHub notifications bot (Feb 24 2023 at 16:21):

mokhaled2992 opened issue #5876:

rror: Undefined Behavior: trying to retag from <11026494> for Unique permission at alloc3449930[0x110c], but that tag does not exist in the borrow stack for this location
   --> /home/i572922/.rustup/toolchains/nightly-2022-12-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:145:9
    |
145 |         &mut *ptr::slice_from_raw_parts_mut(data, len)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |         |
    |         trying to retag from <11026494> for Unique permission at alloc3449930[0x110c], but that tag does not exist in the borrow stack for this location
    |         this error occurs as part of retag at alloc3449930[0x110c..0x1118]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <11026494> was created by a SharedReadWrite retag at offsets [0x110c..0x1118]
   -->:339:9
    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.func_id, &mut self.ctx)
    | |____________________________________________________________________^
help: <11026494> was later invalidated at offsets [0x110c..0x1118] by a Unique FnEntry retag inside this call
   -->.rs:339:9
    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.func_id, &mut self.ctx)
    | |____________________________________________________________________^
    = note: BACKTRACE:
    = note: inside `std::slice::from_raw_parts_mut::<'_, regalloc2::ion::data_structures::Use>` at /home/i572922/.rustup/toolchains/nightly-2022-12-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:145:9: 145:55
    = note: inside `<slice_group_by::linear_group::linear_group_by_key::LinearGroupByKeyMut<'_, regalloc2::ion::data_structures::Use, [closure@regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs::{closure#0}]> as std::iter::Iterator>::next` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:60:38: 60:63
    = note: inside `regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/liveranges.rs:1304:29: 1306:56
    = note: inside `regalloc2::ion::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::init` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/mod.rs:97:9: 97:39
    = note: inside `regalloc2::ion::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/mod.rs:125:5: 125:15
    = note: inside `regalloc2::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/lib.rs:1464:5: 1464:45
    = note: inside `cranelift_codegen::machinst::compile::compile::<cranelift_codegen::isa::x64::X64Backend>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/machinst/compile.rs:41:9: 41:54
    = note: inside `cranelift_codegen::isa::x64::X64Backend::compile_vcode` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/isa/x64/mod.rs:58:9: 58:83
    = note: inside `<cranelift_codegen::isa::x64::X64Backend as cranelift_codegen::isa::TargetIsa>::compile_function` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/isa/x64/mod.rs:69:40: 69:79
    = note: inside `cranelift_codegen::Context::compile_stencil` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/context.rs:173:9: 173:59
    = note: inside `cranelift_codegen::Context::compile` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/context.rs:185:23: 185:48
    = note: inside `<cranelift_jit::JITModule as cranelift_module::Module>::define_function` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-jit-0.88.2/src/backend.rs:687:19: 687:42

    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.serializer_func_id, &mut self.ctx)
    | |____________________________________________________________________^

Rust version rustc 1.68.0-nightly (935dc0721 2022-12-19)

view this post on Zulip Wasmtime GitHub notifications bot (Feb 24 2023 at 16:21):

mokhaled2992 labeled issue #5876:

rror: Undefined Behavior: trying to retag from <11026494> for Unique permission at alloc3449930[0x110c], but that tag does not exist in the borrow stack for this location
   --> /home/i572922/.rustup/toolchains/nightly-2022-12-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:145:9
    |
145 |         &mut *ptr::slice_from_raw_parts_mut(data, len)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |         |
    |         trying to retag from <11026494> for Unique permission at alloc3449930[0x110c], but that tag does not exist in the borrow stack for this location
    |         this error occurs as part of retag at alloc3449930[0x110c..0x1118]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <11026494> was created by a SharedReadWrite retag at offsets [0x110c..0x1118]
   -->:339:9
    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.func_id, &mut self.ctx)
    | |____________________________________________________________________^
help: <11026494> was later invalidated at offsets [0x110c..0x1118] by a Unique FnEntry retag inside this call
   -->.rs:339:9
    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.func_id, &mut self.ctx)
    | |____________________________________________________________________^
    = note: BACKTRACE:
    = note: inside `std::slice::from_raw_parts_mut::<'_, regalloc2::ion::data_structures::Use>` at /home/i572922/.rustup/toolchains/nightly-2022-12-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:145:9: 145:55
    = note: inside `<slice_group_by::linear_group::linear_group_by_key::LinearGroupByKeyMut<'_, regalloc2::ion::data_structures::Use, [closure@regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs::{closure#0}]> as std::iter::Iterator>::next` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:60:38: 60:63
    = note: inside `regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/liveranges.rs:1304:29: 1306:56
    = note: inside `regalloc2::ion::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::init` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/mod.rs:97:9: 97:39
    = note: inside `regalloc2::ion::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/mod.rs:125:5: 125:15
    = note: inside `regalloc2::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/lib.rs:1464:5: 1464:45
    = note: inside `cranelift_codegen::machinst::compile::compile::<cranelift_codegen::isa::x64::X64Backend>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/machinst/compile.rs:41:9: 41:54
    = note: inside `cranelift_codegen::isa::x64::X64Backend::compile_vcode` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/isa/x64/mod.rs:58:9: 58:83
    = note: inside `<cranelift_codegen::isa::x64::X64Backend as cranelift_codegen::isa::TargetIsa>::compile_function` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/isa/x64/mod.rs:69:40: 69:79
    = note: inside `cranelift_codegen::Context::compile_stencil` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/context.rs:173:9: 173:59
    = note: inside `cranelift_codegen::Context::compile` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/context.rs:185:23: 185:48
    = note: inside `<cranelift_jit::JITModule as cranelift_module::Module>::define_function` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-jit-0.88.2/src/backend.rs:687:19: 687:42

    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.serializer_func_id, &mut self.ctx)
    | |____________________________________________________________________^

Rust version rustc 1.68.0-nightly (935dc0721 2022-12-19)

view this post on Zulip Wasmtime GitHub notifications bot (Feb 24 2023 at 16:21):

mokhaled2992 labeled issue #5876:

rror: Undefined Behavior: trying to retag from <11026494> for Unique permission at alloc3449930[0x110c], but that tag does not exist in the borrow stack for this location
   --> /home/i572922/.rustup/toolchains/nightly-2022-12-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:145:9
    |
145 |         &mut *ptr::slice_from_raw_parts_mut(data, len)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |         |
    |         trying to retag from <11026494> for Unique permission at alloc3449930[0x110c], but that tag does not exist in the borrow stack for this location
    |         this error occurs as part of retag at alloc3449930[0x110c..0x1118]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <11026494> was created by a SharedReadWrite retag at offsets [0x110c..0x1118]
   -->:339:9
    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.func_id, &mut self.ctx)
    | |____________________________________________________________________^
help: <11026494> was later invalidated at offsets [0x110c..0x1118] by a Unique FnEntry retag inside this call
   -->.rs:339:9
    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.func_id, &mut self.ctx)
    | |____________________________________________________________________^
    = note: BACKTRACE:
    = note: inside `std::slice::from_raw_parts_mut::<'_, regalloc2::ion::data_structures::Use>` at /home/i572922/.rustup/toolchains/nightly-2022-12-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:145:9: 145:55
    = note: inside `<slice_group_by::linear_group::linear_group_by_key::LinearGroupByKeyMut<'_, regalloc2::ion::data_structures::Use, [closure@regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs::{closure#0}]> as std::iter::Iterator>::next` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:60:38: 60:63
    = note: inside `regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/liveranges.rs:1304:29: 1306:56
    = note: inside `regalloc2::ion::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::init` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/mod.rs:97:9: 97:39
    = note: inside `regalloc2::ion::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/mod.rs:125:5: 125:15
    = note: inside `regalloc2::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/lib.rs:1464:5: 1464:45
    = note: inside `cranelift_codegen::machinst::compile::compile::<cranelift_codegen::isa::x64::X64Backend>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/machinst/compile.rs:41:9: 41:54
    = note: inside `cranelift_codegen::isa::x64::X64Backend::compile_vcode` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/isa/x64/mod.rs:58:9: 58:83
    = note: inside `<cranelift_codegen::isa::x64::X64Backend as cranelift_codegen::isa::TargetIsa>::compile_function` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/isa/x64/mod.rs:69:40: 69:79
    = note: inside `cranelift_codegen::Context::compile_stencil` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/context.rs:173:9: 173:59
    = note: inside `cranelift_codegen::Context::compile` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/context.rs:185:23: 185:48
    = note: inside `<cranelift_jit::JITModule as cranelift_module::Module>::define_function` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-jit-0.88.2/src/backend.rs:687:19: 687:42

    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.serializer_func_id, &mut self.ctx)
    | |____________________________________________________________________^

Rust version rustc 1.68.0-nightly (935dc0721 2022-12-19)

view this post on Zulip Wasmtime GitHub notifications bot (Feb 24 2023 at 17:32):

jameysharp commented on issue #5876:

I haven't looked at MIRI output before, so I'm not sure I'm reading this correctly. From the backtrace, it looks like the last code we wrote on the way to the error is regalloc2's ion/liveranges.rs, in fixup_multi_fixed_vregs.

So at a first guess, probably @cfallin should take a look at this.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 24 2023 at 18:12):

cfallin commented on issue #5876:

@mokhaled2992 thank you for this report; however I have to admit I'm pretty perplexed by it. From the included stacktrace, it looks like the actual issue is in slice_group_by::linear_group::linear_group_by_key, i.e., an iterator-producing helper method on a slice that we call. I don't think this is any problem in regalloc2 itself, for other reasons as well: RA2 uses no unsafe code, and does not play any tricks with lifetimes otherwise.

I also note there are no details on how to reproduce this; in general, issues are more useful when we can reproduce the output to look for ourselves :-)

Would you be able to dig further and let us know where you think the issue is coming from, and e.g. if the issue is actually in group_by as noted above?

view this post on Zulip Wasmtime GitHub notifications bot (Mar 02 2023 at 16:21):

mokhaled2992 edited issue #5876:

rror: Undefined Behavior: trying to retag from <11026494> for Unique permission at alloc3449930[0x110c], but that tag does not exist in the borrow stack for this location
   --> /home/i572922/.rustup/toolchains/nightly-2022-12-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:145:9
    |
145 |         &mut *ptr::slice_from_raw_parts_mut(data, len)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |         |
    |         trying to retag from <11026494> for Unique permission at alloc3449930[0x110c], but that tag does not exist in the borrow stack for this location
    |         this error occurs as part of retag at alloc3449930[0x110c..0x1118]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <11026494> was created by a SharedReadWrite retag at offsets [0x110c..0x1118]
   -->:339:9
    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.func_id, &mut self.ctx)
    | |____________________________________________________________________^
help: <11026494> was later invalidated at offsets [0x110c..0x1118] by a Unique FnEntry retag inside this call
   -->.rs:339:9
    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.func_id, &mut self.ctx)
    | |____________________________________________________________________^
    = note: BACKTRACE:
    = note: inside `std::slice::from_raw_parts_mut::<'_, regalloc2::ion::data_structures::Use>` at /home/i572922/.rustup/toolchains/nightly-2022-12-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:145:9: 145:55
    = note: inside `<slice_group_by::linear_group::linear_group_by_key::LinearGroupByKeyMut<'_, regalloc2::ion::data_structures::Use, [closure@regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs::{closure#0}]> as std::iter::Iterator>::next` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:60:38: 60:63
    = note: inside `regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/liveranges.rs:1304:29: 1306:56
    = note: inside `regalloc2::ion::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::init` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/mod.rs:97:9: 97:39
    = note: inside `regalloc2::ion::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/mod.rs:125:5: 125:15
    = note: inside `regalloc2::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/lib.rs:1464:5: 1464:45
    = note: inside `cranelift_codegen::machinst::compile::compile::<cranelift_codegen::isa::x64::X64Backend>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/machinst/compile.rs:41:9: 41:54
    = note: inside `cranelift_codegen::isa::x64::X64Backend::compile_vcode` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/isa/x64/mod.rs:58:9: 58:83
    = note: inside `<cranelift_codegen::isa::x64::X64Backend as cranelift_codegen::isa::TargetIsa>::compile_function` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/isa/x64/mod.rs:69:40: 69:79
    = note: inside `cranelift_codegen::Context::compile_stencil` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/context.rs:173:9: 173:59
    = note: inside `cranelift_codegen::Context::compile` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/context.rs:185:23: 185:48
    = note: inside `<cranelift_jit::JITModule as cranelift_module::Module>::define_function` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-jit-0.88.2/src/backend.rs:687:19: 687:42

    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.serializer_func_id, &mut self.ctx)
    | |____________________________________________________________________^

Rust version rustc 1.68.0-nightly (935dc0721 2022-12-19)

view this post on Zulip Wasmtime GitHub notifications bot (Mar 03 2023 at 14:32):

jakubDoka commented on issue #5876:

I am experiencing similar problem

error: Undefined Behavior: trying to retag from <25171425> for SharedReadOnly permission at alloc10208590[0x58], but that tag does not exist in the borrow stack for this location
   --> /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:214:1
    |
214 | group_by_key!{ struct LinearGroupByKeyMut, &'a mut [T], from_raw_parts_mut }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | |
    | trying to retag from <25171425> for SharedReadOnly permission at alloc10208590[0x58], but that tag does not exist in the borrow stack for this location
    | this error occurs as part of retag at alloc10208590[0x58..0x64]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <25171425> was created by a SharedReadWrite retag at offsets [0x58..0x70]
   --> /home/mlokis/Documents/src/rust/Catalyst/subcommands/middleware/src/logic/worker.rs:928:36
    |
928 |               if let err @ Err(..) = self
    |  ____________________________________^
929 | |                 .ctx
930 | |                 .cranelift
931 | |                 .compile(&*self.isa.inner)
    | |__________________________________________^
help: <25171425> was later invalidated at offsets [0x58..0x70] by a Unique function-entry retag inside this call
   --> /home/mlokis/Documents/src/rust/Catalyst/subcommands/middleware/src/logic/worker.rs:928:36
    |
928 |               if let err @ Err(..) = self
    |  ____________________________________^
929 | |                 .ctx
930 | |                 .cranelift
931 | |                 .compile(&*self.isa.inner)
    | |__________________________________________^
    = note: BACKTRACE (of the first span):
    = note: inside `<slice_group_by::linear_group::linear_group_by_key::LinearGroupByKeyMut<'_, regalloc2::ion::data_structures::Use, [closure@regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs::{closure#0}]> as std::iter::Iterator>::next` at /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:41:33: 41:38
    = note: inside `regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs` at /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.5.1/src/ion/liveranges.rs:1329:29: 1331:56
    = note: inside `regalloc2::ion::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::init` at /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.5.1/src/ion/mod.rs:100:9: 100:39
    = note: inside `regalloc2::ion::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.5.1/src/ion/mod.rs:133:5: 133:15
    = note: inside `regalloc2::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.5.1/src/lib.rs:1481:5: 1481:67
    = note: inside `cranelift_codegen::machinst::compile::compile::<cranelift_codegen::isa::x64::X64Backend>` at /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.92.0/src/machinst/compile.rs:57:9: 57:54
    = note: inside `cranelift_codegen::isa::x64::X64Backend::compile_vcode` at /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.92.0/src/isa/x64/mod.rs:57:9: 57:68
    = note: inside `<cranelift_codegen::isa::x64::X64Backend as cranelift_codegen::isa::TargetIsa>::compile_function` at /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.92.0/src/isa/x64/mod.rs:67:40: 67:64
    = note: inside `cranelift_codegen::context::Context::compile_stencil` at /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.92.0/src/context.rs:143:9: 143:59
    = note: inside `cranelift_codegen::context::Context::compile` at /home/mlokis/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.92.0/src/context.rs:215:23: 215:48
note: inside `middleware::logic::worker::GeneratorThread::<'_>::generate`
   --> /home/mlokis/Documents/src/rust/Catalyst/subcommands/middleware/src/logic/worker.rs:928:36
    |
928 |               if let err @ Err(..) = self
    |  ____________________________________^
929 | |                 .ctx
930 | |                 .cranelift
931 | |                 .compile(&*self.isa.inner)
    | |__________________________________________^
note: inside closure
   --> /home/mlokis/Documents/src/rust/Catalyst/subcommands/middleware/src/logic/mod.rs:827:21
    |
827 | /                     GeneratorThread {
828 | |                         requests,
829 | |                         mir: &mut task.mir,
830 | |                         resources,
...   |
837 | |                     }
838 | |                     .generate(&mut task.ir_dump)
    | |________________________________________________^
    = note: this error originates in the macro `group_by_key` (in Nightly builds, run with -Z macro-backtrace for more info)

just in case this proves to be useful

view this post on Zulip Wasmtime GitHub notifications bot (Mar 06 2023 at 17:19):

mokhaled2992 commented on issue #5876:

So I was able to reproduce the problem. After doing some reading on these stacked borrows and looking at the code of the slice-group-by its usages in regalloc2, I _guessed_ that miri does not like the pointer to reference conversions done by the slice-group-by crate inside fixup_multi_fixed_vregs. My naive understanding is that the same pointer gets converted to a mut and non mut references in the same scope which miri assumes it breaks the borrow checking rules.

Minimal example:

use slice_group_by::GroupByMut;

fn main() {
    let mut slice = vec![1, 1, 1, 3, 3, 2, 2, 2];

    for i in slice.linear_group_by_key_mut(|a| *a) {
        for j in i.iter() {
            println!("{j}");
        }

        for j in i.iter_mut() {
            *j = 42;
        }

        for j in i.iter() {
            println!("{j}");
        }
    }
}

Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... done
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `/home/ubuntu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/HelloWorld`
warning: crate `HelloWorld` should have a snake case name
  |
  = help: convert the identifier to snake case: `hello_world`
  = note: `#[warn(non_snake_case)]` on by default

error: Undefined Behavior: trying to retag from <3196> for SharedReadOnly permission at alloc1564[0x0], but that tag does not exist in the borrow stack for this location
   --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:214:1
    |
214 | group_by_key!{ struct LinearGroupByKeyMut, &'a mut [T], from_raw_parts_mut }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | |
    | trying to retag from <3196> for SharedReadOnly permission at alloc1564[0x0], but that tag does not exist in the borrow stack for this location
    | this error occurs as part of retag at alloc1564[0x0..0x4]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <3196> was created by a SharedReadWrite retag at offsets [0x0..0x20]
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: <3196> was later invalidated at offsets [0x0..0x20] by a Unique function-entry retag inside this call
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: BACKTRACE (of the first span):
    = note: inside `<slice_group_by::LinearGroupByKeyMut<'_, i32, [closure@src/main.rs:6:44: 6:47]> as std::iter::Iterator>::next` at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:41:33: 41:38
note: inside `main`
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the macro `group_by_key` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error; 1 warning emitted

view this post on Zulip Wasmtime GitHub notifications bot (Mar 06 2023 at 17:20):

mokhaled2992 edited a comment on issue #5876:

So I was able to reproduce the problem. After doing some reading on these stacked borrows and looking at the code of the slice-group-by its usages in regalloc2, I _guessed_ that miri does not like the pointer to reference conversions done by the slice-group-by crate inside fixup_multi_fixed_vregs. My naive understanding is that the same pointer gets converted to a mut and non mut references in the same scope which miri assumes it breaks the borrow checking rules.

Minimal example:

use slice_group_by::GroupByMut;

fn main() {
    let mut slice = vec![1, 1, 1, 3, 3, 2, 2, 2];

    for i in slice.linear_group_by_key_mut(|a| *a) {
        for j in i.iter() {
            println!("{j}");
        }

        for j in i.iter_mut() {
            *j = 42;
        }

        for j in i.iter() {
            println!("{j}");
        }
    }
}

Miri complaining

cargo miri run

Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... done
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `/home/ubuntu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/HelloWorld`
warning: crate `HelloWorld` should have a snake case name
  |
  = help: convert the identifier to snake case: `hello_world`
  = note: `#[warn(non_snake_case)]` on by default

error: Undefined Behavior: trying to retag from <3196> for SharedReadOnly permission at alloc1564[0x0], but that tag does not exist in the borrow stack for this location
   --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:214:1
    |
214 | group_by_key!{ struct LinearGroupByKeyMut, &'a mut [T], from_raw_parts_mut }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | |
    | trying to retag from <3196> for SharedReadOnly permission at alloc1564[0x0], but that tag does not exist in the borrow stack for this location
    | this error occurs as part of retag at alloc1564[0x0..0x4]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <3196> was created by a SharedReadWrite retag at offsets [0x0..0x20]
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: <3196> was later invalidated at offsets [0x0..0x20] by a Unique function-entry retag inside this call
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: BACKTRACE (of the first span):
    = note: inside `<slice_group_by::LinearGroupByKeyMut<'_, i32, [closure@src/main.rs:6:44: 6:47]> as std::iter::Iterator>::next` at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:41:33: 41:38
note: inside `main`
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the macro `group_by_key` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error; 1 warning emitted

view this post on Zulip Wasmtime GitHub notifications bot (Mar 06 2023 at 17:20):

mokhaled2992 edited a comment on issue #5876:

So I was able to reproduce the problem. After doing some reading on these stacked borrows and looking at the code of the slice-group-by its usages in regalloc2, I _guessed_ that miri does not like the pointer to reference conversions done by the slice-group-by crate inside fixup_multi_fixed_vregs. My naive understanding is that the same pointer gets converted to a mut and non mut references in the same scope which miri assumes it breaks the borrow checking rules.

Minimal example

use slice_group_by::GroupByMut;

fn main() {
    let mut slice = vec![1, 1, 1, 3, 3, 2, 2, 2];

    for i in slice.linear_group_by_key_mut(|a| *a) {
        for j in i.iter() {
            println!("{j}");
        }

        for j in i.iter_mut() {
            *j = 42;
        }

        for j in i.iter() {
            println!("{j}");
        }
    }
}

Miri complaining

cargo miri run

Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... done
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `/home/ubuntu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/HelloWorld`
warning: crate `HelloWorld` should have a snake case name
  |
  = help: convert the identifier to snake case: `hello_world`
  = note: `#[warn(non_snake_case)]` on by default

error: Undefined Behavior: trying to retag from <3196> for SharedReadOnly permission at alloc1564[0x0], but that tag does not exist in the borrow stack for this location
   --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:214:1
    |
214 | group_by_key!{ struct LinearGroupByKeyMut, &'a mut [T], from_raw_parts_mut }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | |
    | trying to retag from <3196> for SharedReadOnly permission at alloc1564[0x0], but that tag does not exist in the borrow stack for this location
    | this error occurs as part of retag at alloc1564[0x0..0x4]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <3196> was created by a SharedReadWrite retag at offsets [0x0..0x20]
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: <3196> was later invalidated at offsets [0x0..0x20] by a Unique function-entry retag inside this call
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: BACKTRACE (of the first span):
    = note: inside `<slice_group_by::LinearGroupByKeyMut<'_, i32, [closure@src/main.rs:6:44: 6:47]> as std::iter::Iterator>::next` at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:41:33: 41:38
note: inside `main`
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the macro `group_by_key` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error; 1 warning emitted

view this post on Zulip Wasmtime GitHub notifications bot (Mar 06 2023 at 17:21):

mokhaled2992 edited a comment on issue #5876:

So I was able to reproduce the problem. After doing some reading on these stacked borrows and looking at the code of the slice-group-by its usages in regalloc2, I _guessed_ that miri does not like the pointer to reference conversions done by the slice-group-by crate inside fixup_multi_fixed_vregs. My naive understanding is that the same pointer gets converted to a mut and non mut references in the same scope which miri assumes it breaks the borrow checking rules.

Minimal example

use slice_group_by::GroupByMut;

fn main() {
    let mut slice = vec![1, 1, 1, 3, 3, 2, 2, 2];

    for i in slice.linear_group_by_key_mut(|a| *a) {
        for j in i.iter() {
            println!("{j}");
        }

        for j in i.iter_mut() {
            *j = 42;
        }

        for j in i.iter() {
            println!("{j}");
        }
    }
}

Miri complaining

cargo miri run

Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... done
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `/home/ubuntu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/HelloWorld`
warning: crate `HelloWorld` should have a snake case name
  |
  = help: convert the identifier to snake case: `hello_world`
  = note: `#[warn(non_snake_case)]` on by default

error: Undefined Behavior: trying to retag from <3196> for SharedReadOnly permission at alloc1564[0x0], but that tag does not exist in the borrow stack for this location
   --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:214:1
    |
214 | group_by_key!{ struct LinearGroupByKeyMut, &'a mut [T], from_raw_parts_mut }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | |
    | trying to retag from <3196> for SharedReadOnly permission at alloc1564[0x0], but that tag does not exist in the borrow stack for this location
    | this error occurs as part of retag at alloc1564[0x0..0x4]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <3196> was created by a SharedReadWrite retag at offsets [0x0..0x20]
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: <3196> was later invalidated at offsets [0x0..0x20] by a Unique function-entry retag inside this call
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: BACKTRACE (of the first span):
    = note: inside `<slice_group_by::LinearGroupByKeyMut<'_, i32, [closure@src/main.rs:6:44: 6:47]> as std::iter::Iterator>::next` at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:41:33: 41:38
note: inside `main`
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the macro `group_by_key` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error; 1 warning emitted

I would suggest to replace the slice-group-by with the std::slice::split https://doc.rust-lang.org/std/primitive.slice.html#method.split if that can achieve the same outcome.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 06 2023 at 17:47):

mokhaled2992 edited a comment on issue #5876:

So I was able to reproduce the problem. After doing some reading on these stacked borrows and looking at the code of the slice-group-by and its usages in regalloc2, I _guessed_ that miri does not like the pointer to reference conversions done by the slice-group-by APIs indirectly inside fixup_multi_fixed_vregs. My naive understanding is that the same pointer gets converted to a mut and non mut references in the same scope which miri assumes it breaks the borrow checking rules.

Minimal example

use slice_group_by::GroupByMut;

fn main() {
    let mut slice = vec![1, 1, 1, 3, 3, 2, 2, 2];

    for i in slice.linear_group_by_key_mut(|a| *a) {
        for j in i.iter() {
            println!("{j}");
        }

        for j in i.iter_mut() {
            *j = 42;
        }

        for j in i.iter() {
            println!("{j}");
        }
    }
}

Miri complaining

cargo miri run

Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... done
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `/home/ubuntu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/HelloWorld`
warning: crate `HelloWorld` should have a snake case name
  |
  = help: convert the identifier to snake case: `hello_world`
  = note: `#[warn(non_snake_case)]` on by default

error: Undefined Behavior: trying to retag from <3196> for SharedReadOnly permission at alloc1564[0x0], but that tag does not exist in the borrow stack for this location
   --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:214:1
    |
214 | group_by_key!{ struct LinearGroupByKeyMut, &'a mut [T], from_raw_parts_mut }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | |
    | trying to retag from <3196> for SharedReadOnly permission at alloc1564[0x0], but that tag does not exist in the borrow stack for this location
    | this error occurs as part of retag at alloc1564[0x0..0x4]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <3196> was created by a SharedReadWrite retag at offsets [0x0..0x20]
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: <3196> was later invalidated at offsets [0x0..0x20] by a Unique function-entry retag inside this call
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: BACKTRACE (of the first span):
    = note: inside `<slice_group_by::LinearGroupByKeyMut<'_, i32, [closure@src/main.rs:6:44: 6:47]> as std::iter::Iterator>::next` at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:41:33: 41:38
note: inside `main`
   --> src/main.rs:6:14
    |
6   |     for i in slice.linear_group_by_key_mut(|a| *a) {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the macro `group_by_key` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error; 1 warning emitted

I would suggest to replace the slice-group-by with the std::slice::split https://doc.rust-lang.org/std/primitive.slice.html#method.split if that can achieve the same outcome.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 06 2023 at 22:20):

cfallin commented on issue #5876:

miri does not like the pointer to reference conversions done by the slice-group-by APIs

OK, great; so, to summarize, the issue is in the slice_group_by crate. (Unfortunately your suggestion to use std::slice::split instead doesn't quite work; the semantics are a little different.)

I would recommend filing an issue with that crate. We are simply using the crate according to its API, so the bug is not here, IMHO. Since this isn't an issue with regalloc2 (or Cranelift or Wasmtime, on whose repo this issue is filed), I'll go ahead and close this.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 06 2023 at 22:20):

cfallin closed issue #5876:

rror: Undefined Behavior: trying to retag from <11026494> for Unique permission at alloc3449930[0x110c], but that tag does not exist in the borrow stack for this location
   --> /home/i572922/.rustup/toolchains/nightly-2022-12-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:145:9
    |
145 |         &mut *ptr::slice_from_raw_parts_mut(data, len)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |         |
    |         trying to retag from <11026494> for Unique permission at alloc3449930[0x110c], but that tag does not exist in the borrow stack for this location
    |         this error occurs as part of retag at alloc3449930[0x110c..0x1118]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <11026494> was created by a SharedReadWrite retag at offsets [0x110c..0x1118]
   -->:339:9
    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.func_id, &mut self.ctx)
    | |____________________________________________________________________^
help: <11026494> was later invalidated at offsets [0x110c..0x1118] by a Unique FnEntry retag inside this call
   -->.rs:339:9
    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.func_id, &mut self.ctx)
    | |____________________________________________________________________^
    = note: BACKTRACE:
    = note: inside `std::slice::from_raw_parts_mut::<'_, regalloc2::ion::data_structures::Use>` at /home/i572922/.rustup/toolchains/nightly-2022-12-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:145:9: 145:55
    = note: inside `<slice_group_by::linear_group::linear_group_by_key::LinearGroupByKeyMut<'_, regalloc2::ion::data_structures::Use, [closure@regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs::{closure#0}]> as std::iter::Iterator>::next` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-group-by-0.3.0/src/linear_group/linear_group_by_key.rs:60:38: 60:63
    = note: inside `regalloc2::ion::liveranges::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::fixup_multi_fixed_vregs` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/liveranges.rs:1304:29: 1306:56
    = note: inside `regalloc2::ion::<impl regalloc2::ion::data_structures::Env<'_, cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>>::init` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/mod.rs:97:9: 97:39
    = note: inside `regalloc2::ion::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/ion/mod.rs:125:5: 125:15
    = note: inside `regalloc2::run::<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/lib.rs:1464:5: 1464:45
    = note: inside `cranelift_codegen::machinst::compile::compile::<cranelift_codegen::isa::x64::X64Backend>` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/machinst/compile.rs:41:9: 41:54
    = note: inside `cranelift_codegen::isa::x64::X64Backend::compile_vcode` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/isa/x64/mod.rs:58:9: 58:83
    = note: inside `<cranelift_codegen::isa::x64::X64Backend as cranelift_codegen::isa::TargetIsa>::compile_function` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/isa/x64/mod.rs:69:40: 69:79
    = note: inside `cranelift_codegen::Context::compile_stencil` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/context.rs:173:9: 173:59
    = note: inside `cranelift_codegen::Context::compile` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.88.2/src/context.rs:185:23: 185:48
    = note: inside `<cranelift_jit::JITModule as cranelift_module::Module>::define_function` at /home/i572922/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-jit-0.88.2/src/backend.rs:687:19: 687:42

    |
339 | /         self.module
340 | |             .as_mut()
341 | |             .unwrap()
342 | |             .define_function(self.serializer_func_id, &mut self.ctx)
    | |____________________________________________________________________^

Rust version rustc 1.68.0-nightly (935dc0721 2022-12-19)

view this post on Zulip Wasmtime GitHub notifications bot (Mar 07 2023 at 10:01):

mokhaled2992 commented on issue #5876:

As I said in my comment this is just my guess. The alternatives are:

view this post on Zulip Wasmtime GitHub notifications bot (Mar 07 2023 at 10:05):

mokhaled2992 edited a comment on issue #5876:

As I said in my comment this is just my guess. The alternatives are:

Ideally this should be checked by someone who has more expertise with the stacked borrows.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 07 2023 at 18:21):

cfallin commented on issue #5876:

OK, thanks. The one possibility in your list that involves BA code

A stacked borrows violation in the regalloc2 usage for creating a mut and non mut references to the same pointer

doesn't seem possible to me, as regalloc2 does not have any unsafe Rust code.

Your minimal example above is also more-or-less an argument that this is not regalloc2: you were able to get the same error in slice-group-by when driving it with your own code.

If you do narrow down the issue explicitly to some code that we manage, please do feel free to leave more details here!


Last updated: Nov 22 2024 at 16:03 UTC