Skip to content

Commit 416ccef

Browse files
committed
Implement sound map value aliasing
This implementation gets rid of the unsound `ShallowCopy` trait (#74 & rust-lang/unsafe-code-guidelines#35 (comment)), and replaces it with a wrapper type around aliased values. The core mechanism is that the wrapper type holds a `MaybeUninit<T>`, and aliases it by doing a `ptr::read` of the whole `MaybeUninit<T>` to alias. It then takes care to only give out `&T`s, which is allowed to alias. To drop, the implementation casts between two different generic arguments of the new `Aliased` type, where one type causes the `Aliased<T>` to drop the inner `T` and the other does not. The documentation goes into more detail. The resulting cast _should_ be safe (unlike the old `ManuallyDrop` cast). The removal of `ShallowCopy` makes some of the API nicer by removing trait bounds, and obviates the need for `evmap-derive`. While I was going through, I also took the liberty of tidying up the external API of `evmap` a bit. The implementation passes all tests, and I _think_ it is sound (if you think it's not, please let me know!). Note that this does _not_ take care of #78. Fixes #74. Fixes #55 since `ShallowCopy` is no longer neeeded. Also fixes #72 for the same reason.
1 parent 9f3d73d commit 416ccef

22 files changed

+830
-935
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[workspace]
2-
members = ["evmap", "evmap-derive", "left-right"]
2+
members = ["evmap", "left-right"]

azure-pipelines.yml

-12
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ stages:
1212
minrust: 1.40.0
1313
codecov_token: $(CODECOV_TOKEN_SECRET)
1414
dir: "evmap"
15-
- job: derive
16-
displayName: "Test evmap-derive"
17-
pool:
18-
vmImage: ubuntu-latest
19-
steps:
20-
- template: install-rust.yml@templates
21-
parameters:
22-
components:
23-
- rust-src
24-
- script: cargo test
25-
displayName: cargo test
26-
workingDirectory: "evmap-derive"
2715
- job: benchmark
2816
displayName: "Check that benchmark compiles"
2917
pool:

evmap-derive/Cargo.toml

-29
This file was deleted.

evmap-derive/src/lib.rs

-176
This file was deleted.

evmap-derive/tests/failing/lib.rs

-25
This file was deleted.

evmap-derive/tests/failing/lib.stderr

-49
This file was deleted.

evmap-derive/tests/lib.rs

-65
This file was deleted.

evmap/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ eviction = ["indexed", "rand"]
2525
indexmap = { version = "1.1.0", optional = true }
2626
smallvec = "1.0.0"
2727
hashbag = "0.1.2"
28-
bytes = { version = "0.5", optional = true }
2928
rand = { version = "0.7", default-features = false, features = ["alloc"], optional = true }
3029
left-right = { version = "0.9.0", path = "../left-right" }
3130

evmap/benchmark/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

evmap/benchmark/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ impl Backend for sync::Arc<parking_lot::RwLock<HashMap<usize, usize>>> {
213213
}
214214

215215
enum EvHandle {
216-
Read(evmap::ReadHandle<usize, usize>),
217-
Write(sync::Arc<parking_lot::Mutex<(evmap::WriteHandle<usize, usize>, usize, usize)>>),
216+
Read(evmap::handles::ReadHandle<usize, usize>),
217+
Write(sync::Arc<parking_lot::Mutex<(evmap::handles::WriteHandle<usize, usize>, usize, usize)>>),
218218
}
219219

220220
impl Backend for EvHandle {

0 commit comments

Comments
 (0)