nearcore icon indicating copy to clipboard operation
nearcore copied to clipboard

`Instantiatable::instantiate` requires `Arc<dyn Artifact>` which forces an incorrect `Sync` impl on the Artifacts

Open nagisa opened this issue 3 months ago • 0 comments

Today if you look at the instantiate method, it takes Arc<Artifact> as the self receiver. This means that e.g. the cache of Artifacts must store Arcs of the Artifacts as well.

The cache requires the Send bound, which due to Arc becomes a Send + Sync for the contained type. However it is particularly difficult to justify the correctness of the Sync bound for the Artifact.

Fortunately this shouldn't be too difficult to fix -- our use of instances follow the Rust scoping rules very well so in principle we could change the Instance to be !'static and contain the Artifact by reference:

struct Instance<'a> {
    artifact: &'a dyn Artifact,
    ...
}

which would then allow us to drop the Arc from the receiver and Sync implementation on the Artifact that we can't prove.

nagisa avatar Mar 20 '24 10:03 nagisa