Skip to content

Remove Value from struct fields #309

Description

@lucic71
struct Item {
  int id;
  char name[8];
  std::vector<int> refs;
};

currently becomes in the refcount model:

pub struct Item {
    pub id: Value<i32>,
    pub name: Value<Box<[u8]>>,
    pub refs: Value<Vec<i32>>,
}

This breaks 2 patterns:

  • field writes of reinterpreted structs are lost. *reinterpreted_p.upgrade().deref().field.borrow_mut = 42 loses the field write because reinterpreted_p.upgrade().deref() is a temporary
  • taking the address of a field from a reinterpreted struct is dangling. reinterpreted_p.upgrade().deref().field.as_pointer() dangles because reinterpreted_p.upgrade().deref() is a temporary

The solution is to write the struct as:

pub struct Item {
    pub id: i32,
    pub name: Box<[u8]>,
    pub refs: Vec<i32>,
}

And add a new PtrKind for field pointers that saves a pointer to the parent struct + an offset into the struct.

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