This is an archive of the discontinued Mercurial Phabricator instance.

rust: Make OwningDirstateMap generic and move it into hg-core
ClosedPublic

Authored by SimonSapin on Sep 10 2021, 11:11 AM.

Details

Summary

This will enable using it in rhg too.

The OwningDirstateMap::new_empty constructor is generic and accepts a value
of any type that gives acces to a bytes buffer. That buffer must stay valid
as long as the value hasn’t been dropped, and must keep its memory address
even if the value is moved. The StableDeref marker trait encodes those
constraints. Previously no trait was needed because the value was always
of type PyBytes which we know satisfies those constraints.

The buffer type is ereased in the struct itself through boxing and
dynamic dispatch, in order to simplify other signatures that mention
OwningDirstateMap.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

SimonSapin created this revision.Sep 10 2021, 11:11 AM
Alphare requested changes to this revision.Sep 13 2021, 6:25 AM
Alphare added a subscriber: Alphare.

I feel like the commit message should have a small explanation of why we're switching to using StableDeref and what is does.

Other than that, the change looks good, though the get_mut_pair name might be a little confusing since only the value part of the pair is mutable, but this is obvious enough from the signature of the function (yay static types?).

This revision now requires changes to proceed.Sep 13 2021, 6:25 AM
SimonSapin edited the summary of this revision. (Show Details)Sep 13 2021, 6:38 AM

I’ve edited the commit message to discuss genericity and StableDeref

Alphare accepted this revision.Sep 13 2021, 6:45 AM

Thanks for the quick fix

This revision is now accepted and ready to land.Sep 13 2021, 6:45 AM