Commit Graph

149 Commits

Author SHA1 Message Date
Jun Wu
6b64f9a2bf dag: add import_and_flush API
Summary:
This allows importing from other DAGs. It will be used to import revlog DAG to
the new segmented format.

Reviewed By: sfilipco

Differential Revision: D22970572

fbshipit-source-id: 0a183e7b64831574cc9c60d4639124d02d19cf43
2020-08-21 13:00:45 -07:00
Jun Wu
c448e0f575 renderdag: move to dag
Summary:
This allows dag to use renderdag in tests to verify graph result. Previously
it was hard because dag <-> renderdag would form circular dependency.

It also make it possible to implement more efficient and integrated fast paths
for graph rendering.

Reviewed By: sfilipco

Differential Revision: D22970570

fbshipit-source-id: 526497339bd7aa8898d1af4aa9cf6d2a6797aae0
2020-08-21 13:00:45 -07:00
Jun Wu
6fd7a2e582 dag: use concrete error types
Summary:
This is more complex than previous libraries, mainly because `dag` defines APIs
(traits) used by other code, which might raise error type not interested
by `dag` itself. `BackendError::Other(anyhow::Error)` is currently used to
capture types that do not fit in `dag`'s predefined error types.

Reviewed By: sfilipco

Differential Revision: D22883865

fbshipit-source-id: 3699e14775f335620eec28faa9a05c3cc750e1d1
2020-08-06 12:31:57 -07:00
Jun Wu
ff9c979b07 revlogindex: use concrete error types
Summary:
All dependencies of revlogindex have migrated to concreted error types.
Let's migrate revlogindex itself. This allows compile-time type checks
and makes the error returned by revlogindex APIs more predictable.

Reviewed By: sfilipco

Differential Revision: D22857554

fbshipit-source-id: 7d32599508ad682c6e9c827d4599e6ed0769899c
2020-08-06 12:31:57 -07:00
generatedunixname89002005287564
070b9abf48 Daily arc lint --take RUSTFMT
Reviewed By: zertosh

Differential Revision: D22862880

fbshipit-source-id: cc2a30bb5345ffae1a117bb6220d6c2f4d9f73ba
2020-07-31 04:28:59 -07:00
Jun Wu
5f3f7e49d6 dag: add reachable_roots API
Summary:
I thought it was just `roots & (::heads)`. It is actually more complex than
that.

Reviewed By: sfilipco

Differential Revision: D22657201

fbshipit-source-id: bd0b49fc4cdd2c516384cf70c1c5f79af4da1342
2020-07-30 20:32:37 -07:00
Jun Wu
a2b44103bd dag: add fast path for IdLazySet::contains
Summary:
No need to exhaust the entire IdLazySet if there are hints.
This is important to make `small & lazy` fast.

Reviewed By: sfilipco

Differential Revision: D22638462

fbshipit-source-id: 63a71986e6e254769c42eb6250c042ea6aa5808b
2020-07-30 20:32:32 -07:00
Jun Wu
e3059699ee dag: cross-DAG set operations should use FULL and ANCESTORS hint carefully
Summary:
When multiple DAGs (ex. a local DAG and a commit-cloud DAG) are involved,
certain fast paths become unsound. Namely, the fast paths of the FULL hint
should check DAG compatibility. For example:

  localrepodag.all() & remotedag.all()

should not simply return `localrepodag.all()` or `remotedag.all()`.

Fix it by checking DAG pointers.

A StaticSet might be created without using a DAG, add an optimization
to change `all & static` to `static & all`. So StaticSet without DAG
wouldn't require full DAG scans when intersecting with other sets.

Reviewed By: sfilipco

Differential Revision: D22638454

fbshipit-source-id: 72396417e9c1238d5411829da8f16f2c6d4c2f3a
2020-07-30 20:32:32 -07:00
Jun Wu
34de6956f6 dag: improve fmt::Debug on sets
Summary:
Improve `fmt::Debug` so it fits better in the Rust and Python eco-system:
- Support Rust formatter flags. For example `{:#5.3?}`. `5` defines limit of a
  large set to show, `3` defines hex commit hash length. `#` specifies the
  alternate form.
- Show commit hashes together with integer Ids for IdStaticSet.
- Use HG rev range syntax (`a:b`) to represent ranges for IdStaticSet.
- Limit spans to show for IdStaticSet, similar to StaticSet.
- Show only 8 chars of a long hex commit hash by default.
- Minor renames like `dag` -> `spans`, `difference` -> `diff`.

Python bindings uses `fmt::Debug` as `__repr__` and will be affected.

Reviewed By: sfilipco

Differential Revision: D22638455

fbshipit-source-id: 957784fec9c99c8fc5600b040d964ce5918e1bb4
2020-07-30 20:32:31 -07:00
Jun Wu
7c2dffb955 revlogindex: optimize set intersection with hints
Summary:
This makes intersection set stop early. It's useful to stop iteration on some
lazy sets. For example, the below `ancestors(tip) & span` or
`descendants(1) & span` sets can take seconds to calculate without this
optimization.

```
In [1]: cl.dag.ancestors([cl.tip()]) & cl.tonodes(bindings.dag.spans.unsaferange(len(cl)-10,len(cl)))
Out[1]: <and <lazy-id> <dag [...]>>

In [3]: %time len(cl.dag.ancestors([cl.tip()]) & cl.tonodes(bindings.dag.spans.unsaferange(len(cl)-10,len(cl))))
CPU times: user 364 µs, sys: 0 ns, total: 364 µs
Wall time: 362 µs

In [7]: %time len(cl.dag.descendants([repo[1].node()]) & cl.tonodes(bindings.dag.spans.unsaferange(0,100)))
CPU times: user 0 ns, sys: 574 µs, total: 574 µs
Wall time: 583 µs
```

Reviewed By: sfilipco

Differential Revision: D22638458

fbshipit-source-id: b9064ce2ff1aecc2d7d00025928dfcb3c0d78e0c
2020-07-30 20:32:31 -07:00
Jun Wu
a02c93864f dag: add ANCESTORS hint
Summary:
The hint indicates a set `X` is equivalent to `ancestors(X)`.

This allows us to make `heads` use `heads_ancestors` (which is faster in
segmented changelog) automatically without affecting correctness. It also
makes special queries like `ancestors(all())` super cheap because it'll just
return `all()` as-is.

Reviewed By: sfilipco

Differential Revision: D22638463

fbshipit-source-id: 44d9bbcbb0d7e2975a0c8322181c88daa1ba4e37
2020-07-30 20:32:30 -07:00
Jun Wu
a0c5b1b3a5 revlogindex: is_ancestor(x, x) should return true
Summary: This is discovered by using it in Python world.

Reviewed By: sfilipco

Differential Revision: D22323186

fbshipit-source-id: 295811e0950b94ad2ad73ad242228b6a3f9765d0
2020-07-06 15:50:59 -07:00
Jun Wu
cf1bc37007 dag: avoid using > 2 parents in generic DAG tests
Summary: Some DAG implementations does not support it.

Reviewed By: sfilipco

Differential Revision: D22249158

fbshipit-source-id: ebcdf164677ee647ef44aa1ee3cfd318bac658b0
2020-07-06 15:50:59 -07:00
Jun Wu
9a17be7ce0 dag: do not test the order of vertexes in generic tests
Summary:
Different implementation might return different orders. They should be
considered correct.

Reviewed By: sfilipco

Differential Revision: D22249159

fbshipit-source-id: 36e4cadf814366f7ee2ed8a778948ff810760550
2020-07-06 15:50:58 -07:00
Jun Wu
f24dc621cb dag: make part of the tests generic
Summary: This makes it possible to run tests for other DAGs, like the revlog.

Reviewed By: sfilipco

Differential Revision: D22249155

fbshipit-source-id: 205579eeaccd42a21297d965973957168bb8726e
2020-07-06 15:50:58 -07:00
Jun Wu
2bc4dd01ca dag: add a trait to convert IdSet to Set
Summary:
The reverse `to_id_set` exists.
It turns out that the Python land wants this in many places.

Reviewed By: sfilipco

Differential Revision: D22240175

fbshipit-source-id: b6a3a3a3869dc0c521a21b1d86394421b816632b
2020-07-06 15:50:58 -07:00
Jun Wu
07b3d60f80 dag: add "only(x, y)" to DagAlgorithm
Summary:
This provides a way for implementations to optimize the operation.

For segmented changelog, the default implementation is good enough.

For revlog, `only` can have a fast path that does not iterate through the
entire changelog.

A related API `only_both` is added. For revlog it has multiple use-cases,
including narrow-heads phase calculation and revlog.findcommonmissing used by
discovery.

Reviewed By: markbt

Differential Revision: D21944132

fbshipit-source-id: d11660dae85ea6158977eb00d1ceaceddf1d8234
2020-07-06 15:50:57 -07:00
Jun Wu
d745424bf9 dag: add a utility to help break cycles
Summary:
This makes it easier to remove cycles in other places.

There are probably fancier and more efficient algorithm for this.
For now I just wrote one that is easy to verify correctness.

Reviewed By: markbt

Differential Revision: D22174975

fbshipit-source-id: 8a2dc755e4bc0b066eda5f42a51208c92409f2f9
2020-07-02 13:22:34 -07:00
Jun Wu
234147239a dag: add ToIdSet trait
Summary: The trait converts NameSet to IdSet. It'll be used by the revlog index.

Reviewed By: sfilipco

Differential Revision: D21795869

fbshipit-source-id: 55f7a238158442db9d8bdfe84e64438be504f618
2020-06-03 13:26:25 -07:00
Jun Wu
45d6b00593 dag: add InverseDag
Summary: Add a way to inverse the DAG (swap parent / children relations).

Reviewed By: sfilipco

Differential Revision: D21795870

fbshipit-source-id: 2d076f4ae491141aa758faa5f5f303c97f7e56dc
2020-06-03 13:26:25 -07:00
Jun Wu
a3b663735e dag: add IdLazySet
Summary:
Similar to LazySet, but the iterator is using Ids. This will be useful for
lazy calculations that are cheaper with Ids.

Reviewed By: sfilipco

Differential Revision: D21626208

fbshipit-source-id: 9a34fbf18f0039caeb4f6e698294c4d335354093
2020-06-03 13:26:24 -07:00
Jun Wu
223faebe5f dag: rename DagSet to IdStaticSet
Summary:
The NameSet is not really about Dag. It is about using Id and is static.
Rename it to clarify. In an upcoming change we'll have IdLazySet.

Reviewed By: sfilipco

Differential Revision: D21626204

fbshipit-source-id: 84f25008f7032f6e26a26fc656ccbcd2a5880ecf
2020-06-03 13:26:24 -07:00
Jun Wu
bf90003c24 dag: implement NameIter automatically
Summary:
This makes it possible to use NameIter without manually specifying out iterator
types, which might be quite long.

Reviewed By: sfilipco

Differential Revision: D21626202

fbshipit-source-id: 67b338765c09629645794cf73a9b496271524f9d
2020-06-03 13:26:24 -07:00
Jun Wu
6292253ef8 dag: add fast paths using hints
Summary: Take advantage of Hints and add fast paths.

Reviewed By: sfilipco

Differential Revision: D21626216

fbshipit-source-id: 6d43666bd6cdec7ff4b93032c1064cafd8de85cf
2020-06-03 13:26:23 -07:00
Jun Wu
d3878732f8 dag: set hints with existing hints
Summary: Update hints if they are easy to obtain or calculate.

Reviewed By: sfilipco

Differential Revision: D21626206

fbshipit-source-id: 453b7db2444406ce51d574c688fe536316fb9b0f
2020-06-03 13:26:23 -07:00
Jun Wu
fb56b1962d dag: move optimization hints to a dedicate structure
Summary:
Previously, the NameSet has properties like "is_all", "is_topo_sorted", etc.
To make lazy sets efficient, it's important to have hints about min / max Ids
and maybe some other information.

Add a dedicated Hints structure for that.

Reviewed By: sfilipco

Differential Revision: D21626219

fbshipit-source-id: 845e88d3333f0f48f60f2739adae3dccc4a2dfc4
2020-06-02 14:00:36 -07:00
Jun Wu
13503a1490 dag: add some default impls for DagAlgorithm
Summary:
Implement a small subset of DagAlgorithm by default. This makes
other implementations of DagAlgorithm slightly easier.

Reviewed By: sfilipco

Differential Revision: D21626199

fbshipit-source-id: ac6dfb5c22bf1da44f521fc9e76d59bfb95063c7
2020-06-02 14:00:36 -07:00
Jun Wu
c920549e09 dag: fix DagSet::contains
Summary:
D21479023 broke it. It should convert to Id, and check Id against the SpanSet,
instead of just checking the IdMap ignoring the SpanSet.

Reviewed By: sfilipco

Differential Revision: D21626193

fbshipit-source-id: 6daf86f292a7acfd3688893a55e2a794cfe068fe
2020-06-02 14:00:36 -07:00
Jun Wu
62719f10eb dag: make to_span_set take reference
Summary: This makes the next change easier to implement.

Reviewed By: sfilipco

Differential Revision: D21626198

fbshipit-source-id: 57ab69cba7f43350767e5d0d52ebfe66764895ca
2020-06-02 14:00:35 -07:00
Jun Wu
14b3c2e0f0 dag: move from_ascii to traits
Summary:
This adds flexibility. Now every type that implements DagAddHeads, including
NameDag, can import ASCII graphs.

Reviewed By: sfilipco

Differential Revision: D21626213

fbshipit-source-id: e258d88f97cbcc9aaf98d353a929803325185df7
2020-05-27 12:16:48 -07:00
Jun Wu
bd6c6fe18b dag: implement IdConvert on Dag structs
Reviewed By: sfilipco

Differential Revision: D21626214

fbshipit-source-id: 90d5a587e42340ac2b0f0b3f35f3bc084e969d40
2020-05-27 12:16:48 -07:00
Jun Wu
be5e3a20b4 dag: IdMapLike -> IdConvert
Summary: The trait was about converting between Id and VertexName. Rename to clarify.

Reviewed By: sfilipco

Differential Revision: D21626195

fbshipit-source-id: 874ca4ca3a1467084a08c6d9aa321201974e1978
2020-05-27 12:16:47 -07:00
Jun Wu
64dc05ab9d dag: move add_heads, flush, add_heads_and_flush to traits
Summary: This allows other kinds of DAG to implement the operations.

Reviewed By: sfilipco

Differential Revision: D21626220

fbshipit-source-id: 896c5ccebb1672324d346dfca6bcac9b4d3b4929
2020-05-27 12:16:47 -07:00
Jun Wu
4934987796 dag: implement PrefixLookup for Dag, MemDag and MemIdMap
Summary: This makes things a bit more flexible.

Reviewed By: sfilipco

Differential Revision: D21626194

fbshipit-source-id: f3ad486bcd5a6478d9e00f674d48f99504cded8c
2020-05-27 12:16:46 -07:00
Jun Wu
26217dcdb5 dag: move hex prefix lookup to a trait
Summary: This makes it possible for other types to implement the hex prefix lookup.

Reviewed By: sfilipco

Differential Revision: D21626218

fbshipit-source-id: 96e8b8c37e5aae2bd60658a238333b61902936d1
2020-05-27 12:16:46 -07:00
Jun Wu
577c9442bb dag: add VertexName::from_hex
Summary: It will be used in the next change.

Reviewed By: sfilipco

Differential Revision: D21626207

fbshipit-source-id: bbef70ef9d4f9aaa2039a6bc15d296e88db7f8dc
2020-05-27 12:16:46 -07:00
Jun Wu
38cc83e1bf dag: add short aliases for main public types
Summary:
Types like IdDag are not really used. The use of the word "name" is sometimes
confusing in other context. Therefore export shorter names like Dag, MemDag,
Vertex, avoid "name" in NameDag, MemNameDag and NameSet. This makes external
code shorter and less ambiguous.

Reviewed By: sfilipco

Differential Revision: D21626212

fbshipit-source-id: 5bcf3cecfd38277149b41bf3ba9e6d4ef2a07b2b
2020-05-27 12:16:45 -07:00
Jun Wu
e0d11803f2 dag: move DagAlgorithm to an independent trait
Summary:
This decouples DagAlgorithm from the IdMap + IdDag backend, making it possible
to support other kinds of backends of DagAlgorithm (ex. a revlog backend).

Reviewed By: sfilipco

Differential Revision: D21626200

fbshipit-source-id: f53cc271a200062e9c02f739b6453e1d7de84e6d
2020-05-27 12:16:45 -07:00
Jun Wu
aeac1551d2 dag: implement beautify
Summary:
This function reorders commits so the graph looks better.
It will be used to optimize graph rendering for cloud smartlog (and perhaps
smartlog in the future).

Reviewed By: markbt

Differential Revision: D21554675

fbshipit-source-id: d3f0f27c7935c49581cfa6e87d7c32eb5a075f75
2020-05-14 12:03:43 -07:00
Jun Wu
cde3140e8f dag: implement BitAnd, BitOr, Sub for NameSet
Summary: This makes it easier to do `a & b`, `a | b`, `a - b`.

Reviewed By: markbt

Differential Revision: D21554677

fbshipit-source-id: e1e2571a3dc83f80a1ec7a056f2c8f71ab292d9e
2020-05-14 12:03:43 -07:00
Jun Wu
60684eb2c5 dag: make ASCII -> MemNameDag a public API
Summary:
It seems handy to construct a Dag just from ASCII. Therefore move it to a
public interface.

Reviewed By: sfilipco

Differential Revision: D21486525

fbshipit-source-id: de7f4b8dfcbcc486798928d4334c655431373276
2020-05-11 09:49:59 -07:00
Jun Wu
a6b7e965f3 dag: remove a TODO comment
Summary: It was done as NameSet.

Reviewed By: sfilipco

Differential Revision: D21479022

fbshipit-source-id: 1c32cabb27d72a6438409ede226104a9ebac6a1d
2020-05-11 09:49:59 -07:00
Jun Wu
4eb9251172 dag: move sort and parent_names to NameDagAlgorithm
Summary:
They are part of the read-only algorithms that are not specific to a certain
type of NameDag.

Reviewed By: sfilipco

Differential Revision: D21479017

fbshipit-source-id: 3fa58071ac43246d3cd45d84384ee93c7385f414
2020-05-11 09:49:59 -07:00
Jun Wu
282e034d30 dag: add MemNameDag
Summary:
Adds an in-memory NameDag so we can construct the DAG and use its algorithms by
just providing parents function and heads.

Reviewed By: sfilipco

Differential Revision: D21479021

fbshipit-source-id: e12d53a97afec77b2307d5efbb280bd506dee0ba
2020-05-11 09:49:58 -07:00
Jun Wu
5cbb99f4eb dag: add MemIdMap
Summary: Adds an in-memory IdMap to be used in an in-memory NameDag.

Reviewed By: sfilipco

Differential Revision: D21479018

fbshipit-source-id: bc702762b059e8659c6ab322f3c39f032e95d5b6
2020-05-11 09:49:58 -07:00
Jun Wu
682e8e96a7 dag: use IdMap traits in NameDag and NameSet
Summary:
This allows them to switch to a different IdMap implementation relatively
easily.

Reviewed By: sfilipco

Differential Revision: D21479023

fbshipit-source-id: 8ecb99cafe2093ec7d14b848ffa08581c5300414
2020-05-11 09:49:57 -07:00
Jun Wu
759f8b35c5 dag: move some IdMap operations to traits
Summary: This will allow different IdMap implementations.

Reviewed By: sfilipco

Differential Revision: D21479016

fbshipit-source-id: 852501896fddcb82624338acd9dceee41150e302
2020-05-11 09:49:57 -07:00
Jun Wu
30163eeb58 dag: update snapshot_map on change
Summary:
`NameDag::add_heads` API changes the internal `dag` state without updating
`snapshot_map`. That will cause queries relying on `snapshot_map` to fail.
Update it so that `snapshot_map` gets updated by `add_heads`.

Reviewed By: sfilipco

Differential Revision: D21479019

fbshipit-source-id: 70528aa4a488cef3dc71bf21dd89e45cfe763794
2020-05-11 09:49:57 -07:00
Jun Wu
f014f86b7a dag: move NameDag algorithms to a trait
Summary:
This makes it easier to add an "in-memory-only" NameDag with all the algorithms
implemented.

Reviewed By: sfilipco

Differential Revision: D21479020

fbshipit-source-id: c1a73e95f3291c273c800650f70db2a7eb0966d7
2020-05-11 09:49:56 -07:00
Stefan Filip
ea89b541e1 segmented_changelog: add Dag struct and location_to_name functionality
Summary:
The IdDag provides graph algorithms using Segments.
The IdMap allows converting from the SegmentedChangelogId domain to the
ChangesetId domain.
The Dag struct wraps IdDag and IdMap in order to provide graph algorithms using
the common application level identifiers for commits (ChangesetId).

The construction of the Dag is currently mocked with something that can only be
used in a test environment (unit tests but also integration tests).

This diff also implements a location_to_name function. This is the most
important new functionality that segmented changelog clients require. It
recovers the hash of a commit for which the client only has a segmented
changelog Id. The current assumption is that clients have identifiers for all
merge commit parents so the path to a known commit always follow a set
of first parents.

The IdMap queries will have to be changed to async in the future, but IdDag
queries we expect to stay sync.

Reviewed By: quark-zju

Differential Revision: D20635577

fbshipit-source-id: 4f9bd8dd4a5bd9b0de55f51086f3434ff507963c
2020-03-27 13:48:52 -07:00