runtimeverification / runtimeverification/stable-mir-json

`cargo test` fails when `GlobalAlloc::Function` is not `RigidTy::FnPtr`

Open
#88 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
11
Forks
6
PR merge metrics
No merged PRs in 30d

Description

Trying to produce artefacts for stable mir json on test code of a cargo project via cargo test panics.

Reproducer
cd stable-mir-json
cargo build --release && cargo run --bin cargo_stable_mir_json -- $PWD
cd ..
cargo new --lib smir-test-fail
cd smir-test-fail
RUSTC=~/.stable-mir-json/release.sh cargo test

The test fails with:

thread 'rustc' panicked at src/printer.rs:688:13:
assertion failed: kind.unwrap().is_fn_ptr()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Which is from line 688 of stable_mir_json::printer introduced in this PR:

//-snip-
        GlobalAlloc::Function(inst) => {
            assert!(kind.unwrap().is_fn_ptr()); // <-- line 688
            entry.or_insert(AllocInfo::Function(inst));
        }
//-snip-

Printing kind and inst gives

Some(RigidTy(Ref(Region { kind: ReErased }, Ty { id: 116, kind: RigidTy(Adt(AdtDef(DefId { id: 30, name: "tests::test::TestDescAndFn" }), GenericArgs([]))) }, Not)))
Instance { kind: Shim, def: "_ZN4core3ops8function6FnOnce9call_once17h4aa4ff19edd7fd65E", args: GenericArgs([Type(Ty { id: 103, kind: RigidTy(Closure(ClosureDef(DefId { id: 17, name: "tests::it_works::{closure#0}" }), GenericArgs([Type(Ty { id: 106, kind: RigidTy(Int(I8)) }), Type(Ty { id: 117, kind: RigidTy(FnPtr(Binder { value: FnSig { inputs_and_output: [Ty { id: 2, kind: RigidTy(Tuple([])) }, Ty { id: 64, kind: RigidTy(Adt(AdtDef(DefId { id: 23, name: "std::result::Result" }), GenericArgs([Type(Ty { id: 2, kind: RigidTy(Tuple([])) }), Type(Ty { id: 15, kind: RigidTy(Adt(AdtDef(DefId { id: 4, name: "std::string::String" }), GenericArgs([]))) })]))) }], c_variadic: false, safety: Safe, abi: RustCall }, bound_vars: [] })) }), Type(Ty { id: 2, kind: RigidTy(Tuple([])) })]))) }), Type(Ty { id: 2, kind: RigidTy(Tuple([])) })]) }

which is from the #[test] attribute, which is a compiler built in.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/printer.rs:688 and reproduce the panic with the listed stable-mir-json build and cargo test commands. Inspect how GlobalAlloc::Function handles the kind and Instance values produced by the #[test] compiler built-in. Done means the smir-test-fail cargo test run no longer panics while producing the stable MIR JSON artefacts.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.