This is an archive of the discontinued Mercurial Phabricator instance.

rust-dirstatemap: remove additional lookups in traverse
AbandonedPublic

Authored by Alphare on Oct 16 2019, 9:48 AM.

Details

Reviewers
martinvonz
Group Reviewers
hg-reviewers
Summary

We use the same trick as the Python implementation.

Diff Detail

Repository
rHG Mercurial
Branch
default
Lint
No Linters Available
Unit
No Unit Test Coverage

Event Timeline

Alphare created this revision.Oct 16 2019, 9:48 AM
yuja added a subscriber: yuja.Oct 18 2019, 6:47 AM

+++ b/mercurial/dirstate.py
@@ -919,6 +919,9 @@

matchalways = match.always()
matchtdir = match.traversedir
dmap = self._map

+ if rustmod is not None:
+ dmap = self._map._rustmap

If it's the same trick, can't it be abstracted away? if rustmod seems weird.

In D7118#104834, @yuja wrote:

+++ b/mercurial/dirstate.py
@@ -919,6 +919,9 @@

matchalways = match.always()
matchtdir = match.traversedir
dmap = self._map

+ if rustmod is not None:
+ dmap = self._map._rustmap

If it's the same trick, can't it be abstracted away? if rustmod seems weird.

The main issue I faced is that Python classes built from rust-cpython cannot be subclassed, so we have to resort to an additional level of indirection. IIRC, the main reason was that there was no way of enforcing a subclass to call super() which would result in the Rust class not being initialized properly. Or maybe I'm missing the point?

yuja added a comment.Oct 18 2019, 8:40 AM
>> +++ b/mercurial/dirstate.py
>> @@ -919,6 +919,9 @@
>>
>>   matchalways = match.always()
>>   matchtdir = match.traversedir
>>   dmap = self._map
>>
>> +        if rustmod is not None:
>> +            dmap = self._map._rustmap
>
> If it's the same trick, can't it be abstracted away? `if rustmod` seems weird.
The main issue I faced is that Python classes built from `rust-cpython` cannot be subclassed, so we have to resort to an additional level of indirection. IIRC, the main reason was that there was no way of enforcing a subclass to call `super()` which would result in the Rust class not being initialized properly. Or maybe I'm missing the point?

I mean there could be a unified self._map._map call if we need to take
the internal map from both py dirstatemap and rust dirstatemap.

Alphare updated this revision to Diff 18564.Dec 10 2019, 10:26 AM

What's the state of this patch? The description makes it sound like it's a Rust patch, but it only modifies Python code.

What's the state of this patch? The description makes it sound like it's a Rust patch, but it only modifies Python code.

It only impacts the rust module policy, I figured the name was not a bad idea. Maybe I'm wrong?

I also did not find Yuya's suggestion to work, but I may have understood it wrong.

What's the state of this patch? The description makes it sound like it's a Rust patch, but it only modifies Python code.

It only impacts the rust module policy, I figured the name was not a bad idea. Maybe I'm wrong?
I also did not find Yuya's suggestion to work, but I may have understood it wrong.

I think Yuya's suggestion was to make the diff be this:

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -909,7 +909,7 @@ class dirstate(object):
         matchfn = match.matchfn
         matchalways = match.always()
         matchtdir = match.traversedir
-        dmap = self._map
+        dmap = self._map._map
         listdir = util.listdir
         lstat = os.lstat
         dirkind = stat.S_IFDIR

Obviously, you'd need to make some adjustments to allow that, at least renaming _rustmap to _map. The commit message should also change then.

I don't remember what the point of the nested _maps was (perhaps to make it possible to replace the inner _map?). Hopefully we're not breaking that by directly accessing the inner _map.

martinvonz requested changes to this revision.Dec 13 2019, 1:14 PM
This revision now requires changes to proceed.Dec 13 2019, 1:14 PM
Alphare abandoned this revision.Feb 11 2020, 4:43 AM