runtimeverification / runtimeverification/mir-semantics

Zero-sized data structures are not initialised in MIR

Open
#675 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
52
Forks
5
PR merge metrics
No merged PRs in 30d

Description

I played around a bit with empty data structures ((), [usize;0] , and struct EmptyStruct(), which all don't require any stored bytes...
Interestingly, the MIR I am getting somewhat relies on the fact that there are no stored bytes for these. I have a program like this (example: (), but the same happens for the other types):

const EMPTY: () = ();
fn main() {
    let e = ();
    assert!(e == EMPTY);
}

The first statement in main (block 0, first statement) becomes _3 <- &_1. which assumes there is nothing to do to initialise _1 to be ().
That assumption is untrue for our semantics, though, where () is represented as Aggregate(variantIdx(0), .List) but we get newValue(...) in _1 and end up with a reference pointing to it in _3.
For my 3 programs with empty data I did not find any point where that reference would be Dereferenced but I cannot be sure. The eq instances for () and EmptyStruct() just return constant true but the one for [usize;0] blindly calls the raw_eq intrinsic.
We should adapt our forthcoming implementation of raw_eq to this.

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

Reproduce the three examples involving (), [usize; 0], and EmptyStruct(), then inspect the generated MIR where _1 is assigned and _3 takes a reference to it. Read the planned raw_eq implementation and determine how zero-sized Aggregate values should be initialized and compared. Done means the examples no longer rely on an uninitialized zero-sized value.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.