Skip to content

Commit 4e83da0

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 sets a thread-local that the wrapper uses to determine if it should truly drop the inner `T` (i.e., to indicate that this is the last copy, and the `T` is no longer aliased). The removal of `ShallowCopy` makes some of the API nicer, and obviates the need for `evmap-derive`. Unfortunately the introduction of the wrapper also complicates certain bounds which now need to know about the wrapping. Overall though, an ergonomic win. The implementation passes all tests, and I _think_ it is sound (if you think it's not, please let me know!). The one bit that I'm not sure about is the thread-local if a user nests `evmap`s (since they'll share that thread local). Note that this does _not_ take care of #78. Fixes #74. Fixes #55 since `ShallowCopy` is no longer neeeded.
1 parent 9f3d73d commit 4e83da0

File tree

16 files changed

+358
-761
lines changed

16 files changed

+358
-761
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 12 deletions
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

Lines changed: 0 additions & 29 deletions
This file was deleted.

evmap-derive/src/lib.rs

Lines changed: 0 additions & 176 deletions
This file was deleted.

evmap-derive/tests/failing/lib.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

evmap-derive/tests/failing/lib.stderr

Lines changed: 0 additions & 49 deletions
This file was deleted.

evmap-derive/tests/lib.rs

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)