Skip to content

Arc vs & in AddressSpace #7

Open
@rileyshahar

Description

@rileyshahar

The methods of AddressSpace take &dyn DataSource, e.g.:

pub fn add_mapping(
&self,
source: &dyn DataSource,
offset: usize,
span: usize,
) -> Result<VirtualAddress, &str> {
todo!()
}

But the struct itself stores Arc<dyn DataSource>:

source: Arc<dyn DataSource>,

My instinct is that add_mapping should just take an Arc. The broader issue is that the methods of DataSource only have shared access to self, and there's no way to safely upcast &self to Arc<self>. So as I see it, either:

  1. The DataSource methods to have a stronger reference to self.
  2. MapType needs to store &dyn DataSource (maybe fine! The DataSource API is immutable anyway).
  3. There's some clever invariant that will make it ok to unsafely mutate &dyn DataSource into Arc<dyn DataSource>. This seems pretty unlikely to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions