//! returns: 0
//! Safe mutable data can hold anything that the verifier accepts: plain data, pointers whose
//! targets reach no slice, also through recursive records, and empty arrays. A constant can hold a
//! slice, because it is read-only.

/// A plain record.
record Point: Copy {
    x: i32,
    y: i32,
}

/// A record that links to itself, and reaches no slice.
record Node {
    value: u32,
    next: ?*Node,
}

/// A union of plain payloads.
union Shape: Copy {
    Dot(Point),
    Size(u64),
    Nothing,
}

/// A record that holds a slice, which only a read-only place can hold.
record Label: Copy {
    text: *[u8],
}

/// Plain numbers.
static NUMBERS: [u32; 2] = [1, 2];

/// A plain record.
static ORIGIN: Point = Point { x: 3, y: 4 };

/// A union of plain payloads.
static SHAPE: Shape = Shape::Size(5);

/// A pointer to a record that reaches no slice.
static HEAD: ?*Node = nil;

/// Pointers to a recursive record.
static HEADS: [?*Node; 2] = [nil, nil];

/// An array with no slices in it.
static NONE: [*[u8]; 0] = [];

/// A slice in read-only data.
constant NAME: *[u8] = "name";

/// Slices in read-only data.
constant NAMES: [*[u8]; 2] = ["a", "bc"];

/// A record with a slice in read-only data.
constant LABEL: Label = Label { text: "label" };

/// Fill plain storage, and keep pointers to a recursive record in it.
@default fn main(bytes: *mut [u8; 8], points: *mut [Point; 2], links: *mut [?*Node; 2]) -> i32 {
    set bytes[0] = 1;
    set points[1].y = 2;
    assert links[0] == nil;
    assert NUMBERS[1] == 2 and ORIGIN.y == 4;
    assert HEAD == nil and HEADS[1] == nil and NONE.len == 0;
    assert NAME.len == 4 and NAMES[1].len == 2 and LABEL.text.len == 5;
    return 0;
}
