Skip to content

Zero-sized data structures are not initialised in MIR #675

Description

@jberthold

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions