rust/hg-core/Cargo.toml
author Raphaël Gomès <rgomes@octobus.net>
Tue, 05 Apr 2022 10:55:28 +0200
branchstable
changeset 49000 dd6b67d5c256
parent 48554 0dc698c91ca0
child 49005 12adf8c695ed
child 49245 13c37f1c7c4b
permissions -rw-r--r--
rust: fix unsound `OwningDirstateMap` As per the previous patch, `OwningDirstateMap` is unsound. Self-referential structs are difficult to implement correctly in Rust since the compiler is free to move structs around as much as it wants to. They are also very rarely needed in practice, so the state-of-the-art on how they should be done within the Rust rules is still a bit new. The crate `ouroboros` is an attempt at providing a safe way (in the Rust sense) of declaring self-referential structs. It is getting a lot attention and was improved very quickly when soundness issues were found in the past: rather than relying on our own (limited) review circle, we might as well use the de-facto common crate to fix this problem. This will give us a much better chance of finding issues should any new ones be discovered as well as the benefit of fewer `unsafe` APIs of our own. I was starting to think about how I would present a safe API to the old struct but soon realized that the callback-based approach was already done in `ouroboros`, along with a lot more care towards refusing incorrect structs. In short: we don't return a mutable reference to the `DirstateMap` anymore, we expect users of its API to pass a `FnOnce` that takes the map as an argument. This allows our `OwningDirstateMap` to control the input and output lifetimes of the code that modifies it to prevent such issues. Changing to `ouroboros` meant changing every API with it, but it is relatively low churn in the end. It correctly identified the example buggy modification of `copy_map_insert` outlined in the previous patch as violating the borrow rules. Differential Revision: https://phab.mercurial-scm.org/D12429

[package]
name = "hg-core"
version = "0.1.0"
authors = ["Georges Racinet <gracinet@anybox.fr>"]
description = "Mercurial pure Rust core library, with no assumption on Python bindings (FFI)"
edition = "2018"

[lib]
name = "hg"

[dependencies]
bitflags = "1.2"
bytes-cast = "0.2"
byteorder = "1.3.4"
derive_more = "0.99"
home = "0.5"
im-rc = "15.0.*"
itertools = "0.9"
lazy_static = "1.4.0"
libc = "0.2"
ouroboros = "0.15.0"
rand = "0.8.4"
rand_pcg = "0.3.1"
rand_distr = "0.4.2"
rayon = "1.3.0"
regex = "1.3.9"
sha-1 = "0.9.6"
twox-hash = "1.5.0"
same-file = "1.0.6"
tempfile = "3.1.0"
crossbeam-channel = "0.4"
micro-timer = "0.3.0"
log = "0.4.8"
memmap2 = {version = "0.4", features = ["stable_deref_trait"]}
zstd = "0.5.3"
format-bytes = "0.3.0"

# We don't use the `miniz-oxide` backend to not change rhg benchmarks and until
# we have a clearer view of which backend is the fastest.
[dependencies.flate2]
version = "1.0.16"
features = ["zlib"]
default-features = false

[dev-dependencies]
clap = "*"
pretty_assertions = "0.6.1"