From 97e5ebd02b757403d583a03fd3682a7ed2349671 Mon Sep 17 00:00:00 2001 From: Servo VCS Sync Date: Fri, 14 Jul 2017 10:05:27 +0000 Subject: [PATCH] No bug - Revendor rust dependencies --- .../rust/owning_ref/.cargo-checksum.json | 2 +- third_party/rust/owning_ref/Cargo.toml | 5 +- third_party/rust/owning_ref/README.md | 42 +- third_party/rust/owning_ref/src/lib.rs | 1621 +++++++++++++---- .../rust/parking_lot/.cargo-checksum.json | 2 +- third_party/rust/parking_lot/.travis.yml | 2 +- third_party/rust/parking_lot/Cargo.toml | 36 +- third_party/rust/parking_lot/README.md | 16 +- third_party/rust/parking_lot/appveyor.yml | 8 +- third_party/rust/parking_lot/src/condvar.rs | 8 +- third_party/rust/parking_lot/src/mutex.rs | 2 + third_party/rust/parking_lot/src/once.rs | 75 +- .../rust/parking_lot/src/raw_remutex.rs | 2 +- .../rust/parking_lot/src/raw_rwlock.rs | 71 +- third_party/rust/parking_lot/src/remutex.rs | 10 +- third_party/rust/parking_lot/src/rwlock.rs | 154 +- .../stable_deref_trait/.cargo-checksum.json | 1 + third_party/rust/stable_deref_trait/.cargo-ok | 0 .../rust/stable_deref_trait/Cargo.toml | 18 + .../rust/stable_deref_trait/LICENSE-APACHE | 201 ++ .../rust/stable_deref_trait/LICENSE-MIT | 25 + third_party/rust/stable_deref_trait/README.md | 5 + .../rust/stable_deref_trait/src/lib.rs | 172 ++ toolkit/library/gtest/rust/Cargo.lock | 25 +- toolkit/library/rust/Cargo.lock | 25 +- 25 files changed, 2041 insertions(+), 487 deletions(-) create mode 100644 third_party/rust/stable_deref_trait/.cargo-checksum.json create mode 100644 third_party/rust/stable_deref_trait/.cargo-ok create mode 100644 third_party/rust/stable_deref_trait/Cargo.toml create mode 100644 third_party/rust/stable_deref_trait/LICENSE-APACHE create mode 100644 third_party/rust/stable_deref_trait/LICENSE-MIT create mode 100644 third_party/rust/stable_deref_trait/README.md create mode 100644 third_party/rust/stable_deref_trait/src/lib.rs diff --git a/third_party/rust/owning_ref/.cargo-checksum.json b/third_party/rust/owning_ref/.cargo-checksum.json index 6d2c13266221..09653443031c 100644 --- a/third_party/rust/owning_ref/.cargo-checksum.json +++ b/third_party/rust/owning_ref/.cargo-checksum.json @@ -1 +1 @@ -{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"16ab07cbd79a5419fc141dfdd40f072dfa975bf7abb644e810ca07a8b8de5382","Cargo.toml":"16bd10cad7d8d1b989495c512d0739f32b636b67aa1f7cdf8a87a489235e196d","LICENSE":"90bc15ed094593083fd129fdd1a03607be80fe8839c5564616a5961ab7f7a194","README.md":"dfa901cc27a4c47e8c0685aa83af78edf4928faabfb1982d8ff2382eca452d55","src/lib.rs":"765b9600440045e803b5a0946b7a78f8cdf998859bb8d46f6853fce42e67b211"},"package":"9d52571ddcb42e9c900c901a18d8d67e393df723fcd51dd59c5b1a85d0acb6cc"} \ No newline at end of file +{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"16ab07cbd79a5419fc141dfdd40f072dfa975bf7abb644e810ca07a8b8de5382","Cargo.toml":"d6033830eecd6112eb61e775f848ab6c7ee76822ee1d7f8786b34e6e71f45b7b","LICENSE":"90bc15ed094593083fd129fdd1a03607be80fe8839c5564616a5961ab7f7a194","README.md":"e18ff10a148a8316e89bbe9f45cb57657170abe1a19154f8a5c968d529fe895e","src/lib.rs":"5d8857eee0de9863c3b6fce98732427cc1868a5ec3f0e3ce652ec011391aa842"},"package":"cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"} \ No newline at end of file diff --git a/third_party/rust/owning_ref/Cargo.toml b/third_party/rust/owning_ref/Cargo.toml index 6558dacd8823..24edb378f7b2 100644 --- a/third_party/rust/owning_ref/Cargo.toml +++ b/third_party/rust/owning_ref/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "owning_ref" -version = "0.2.4" +version = "0.3.3" authors = ["Marvin Löbel "] license = "MIT" @@ -10,3 +10,6 @@ documentation = "http://kimundi.github.io/owning-ref-rs/owning_ref/index.html" repository = "https://github.com/Kimundi/owning-ref-rs" keywords = ["reference", "sibling", "field", "owning"] + +[dependencies] +stable_deref_trait = "1.0.0" diff --git a/third_party/rust/owning_ref/README.md b/third_party/rust/owning_ref/README.md index 29723d1d68ed..c4c74f1f9a56 100644 --- a/third_party/rust/owning_ref/README.md +++ b/third_party/rust/owning_ref/README.md @@ -1,29 +1,49 @@ owning-ref-rs ============== -[![Travis-CI Status](https://travis-ci.org/Kimundi/owning-ref-rs.png?branch=master)](https://travis-ci.org/Kimundi/owning-ref-rs) - A library for creating references that carry their owner with them. -For more details, see the [docs](http://kimundi.github.io/owning-ref-rs/owning_ref/index.html). +This can sometimes be useful because Rust borrowing rules normally prevent +moving a type that has been moved from. For example, this kind of code gets rejected: + +```rust +fn return_owned_and_referenced<'a>() -> (Vec, &'a [u8]) { + let v = vec![1, 2, 3, 4]; + let s = &v[1..3]; + (v, s) +} +``` + +This library enables this safe usage by keeping the owner and the reference +bundled together in a wrapper type that ensure that lifetime constraint: + +```rust +fn return_owned_and_referenced() -> OwningRef, [u8]> { + let v = vec![1, 2, 3, 4]; + let or = OwningRef::new(v); + let or = or.map(|v| &v[1..3]); + or +} +``` + +[![Travis-CI Status](https://travis-ci.org/Kimundi/owning-ref-rs.png?branch=master)](https://travis-ci.org/Kimundi/owning-ref-rs) # Getting Started [owning-ref-rs is available on crates.io](https://crates.io/crates/owning_ref). -Add the following dependency to your Cargo manifest to get the latest version of the 0.2 branch: +It is recommended to look there for the newest released version, as well as links to the newest builds of the docs. + +At the point of the last update of this README, the latest published version could be used like this: + +Add the following dependency to your Cargo manifest... ```toml [dependencies] -owning_ref = "0.2" +owning_ref = "0.3" ``` -To always get the latest version, add this git repository to your -Cargo manifest: +...and see the [docs](http://kimundi.github.io/owning-ref-rs/owning_ref/index.html) for how to use it. -```toml -[dependencies.owning_ref] -git = "https://github.com/Kimundi/owning-ref-rs" -``` # Example ```rust diff --git a/third_party/rust/owning_ref/src/lib.rs b/third_party/rust/owning_ref/src/lib.rs index 14cbc5ce7db9..21ed086571af 100644 --- a/third_party/rust/owning_ref/src/lib.rs +++ b/third_party/rust/owning_ref/src/lib.rs @@ -3,19 +3,52 @@ /*! # An owning reference. -This crate provides the _owning reference_ type `OwningRef` that enables it -to bundle a reference together with the owner of the data it points to. +This crate provides the _owning reference_ types `OwningRef` and `OwningRefMut` +that enables it to bundle a reference together with the owner of the data it points to. This allows moving and dropping of a `OwningRef` without needing to recreate the reference. -It works by requiring owner types to dereference to stable memory locations and preventing mutable access, which in practice requires an heap allocation as -provided by `Box`, `Rc`, etc. +This can sometimes be useful because Rust borrowing rules normally prevent +moving a type that has been moved from. For example, this kind of code gets rejected: + +```rust,ignore +fn return_owned_and_referenced<'a>() -> (Vec, &'a [u8]) { + let v = vec![1, 2, 3, 4]; + let s = &v[1..3]; + (v, s) +} +``` + +Even though, from a memory-layout point of view, this can be entirely safe +if the new location of the vector still lives longer than the lifetime `'a` +of the reference because the backing allocation of the vector does not change. + +This library enables this safe usage by keeping the owner and the reference +bundled together in a wrapper type that ensure that lifetime constraint: + +```rust +# extern crate owning_ref; +# use owning_ref::OwningRef; +# fn main() { +fn return_owned_and_referenced() -> OwningRef, [u8]> { + let v = vec![1, 2, 3, 4]; + let or = OwningRef::new(v); + let or = or.map(|v| &v[1..3]); + or +} +# } +``` + +It works by requiring owner types to dereference to stable memory locations +and preventing mutable access to root containers, which in practice requires heap allocation +as provided by `Box`, `Rc`, etc. Also provided are typedefs for common owner type combinations, -which allows for less verbose type signatures. For example, `BoxRef` instead of `OwningRef, T>`. +which allow for less verbose type signatures. For example, `BoxRef` instead of `OwningRef, T>`. -The crate also provides the `OwningHandle` type, which allows bundling -a dependent handle object along with the data it depends on. See the -documentation around `OwningHandle` for more details. +The crate also provides the more advanced `OwningHandle` type, +which allows more freedom in bundling a dependent handle object +along with the data it depends on, at the cost of some unsafe needed in the API. +See the documentation around `OwningHandle` for more details. # Examples @@ -178,15 +211,40 @@ fn main() { assert_eq!(*refcell.borrow(), (1, 2, 3, 4)); } ``` + +## Mutable reference + +When the owned container implements `DerefMut`, it is also possible to make +a _mutable owning reference_. (E.g. with `Box`, `RefMut`, `MutexGuard`) + +``` +extern crate owning_ref; +use owning_ref::RefMutRefMut; +use std::cell::{RefCell, RefMut}; + +fn main() { + let refcell = RefCell::new((1, 2, 3, 4)); + + let mut refmut_refmut = { + let mut refmut_refmut = RefMutRefMut::new(refcell.borrow_mut()).map_mut(|x| &mut x.3); + assert_eq!(*refmut_refmut, 4); + *refmut_refmut *= 2; + + refmut_refmut + }; + + assert_eq!(*refmut_refmut, 8); + *refmut_refmut *= 2; + + drop(refmut_refmut); + + assert_eq!(*refcell.borrow(), (1, 2, 3, 16)); +} +``` */ -/// Marker trait for expressing that the memory address of the value -/// reachable via a dereference remains identical even if `self` gets moved. -pub unsafe trait StableAddress: Deref {} - -/// Marker trait for expressing that the memory address of the value -/// reachable via a dereference remains identical even if `self` is a clone. -pub unsafe trait CloneStableAddress: StableAddress + Clone {} +extern crate stable_deref_trait; +pub use stable_deref_trait::{StableDeref as StableAddress, CloneStableDeref as CloneStableAddress}; /// An owning reference. /// @@ -202,6 +260,20 @@ pub struct OwningRef { reference: *const T, } +/// An mutable owning reference. +/// +/// This wraps an owner `O` and a reference `&mut T` pointing +/// at something reachable from `O::Target` while keeping +/// the ability to move `self` around. +/// +/// The owner is usually a pointer that points at some base type. +/// +/// For more details and examples, see the module and method docs. +pub struct OwningRefMut { + owner: O, + reference: *mut T, +} + /// Helper trait for an erased concrete type an owner dereferences to. /// This is used in form of a trait object for keeping /// something around to (virtually) call the destructor. @@ -246,10 +318,10 @@ impl OwningRef { } } - /// Like `new`, but dosen’t require `O` to implement the `StableAddress` trait. + /// Like `new`, but doesn’t require `O` to implement the `StableAddress` trait. /// Instead, the caller is responsible to make the same promises as implementing the trait. /// - /// This is useful to use when coherence rules prevent implememnting the trait + /// This is useful for cases where coherence rules prevents implementing the trait /// without adding a dependency to this crate in a third-party library. pub unsafe fn new_assert_stable_address(o: O) -> Self where O: Deref, @@ -290,7 +362,28 @@ impl OwningRef { } } - /// Variant of `map()` that may fail. + /// Tries to convert `self` into a new owning reference that points + /// at something reachable from the previous one. + /// + /// This can be a reference to a field of `U`, something reachable from a field of + /// `U`, or even something unrelated with a `'static` lifetime. + /// + /// # Example + /// ``` + /// extern crate owning_ref; + /// use owning_ref::OwningRef; + /// + /// fn main() { + /// let owning_ref = OwningRef::new(Box::new([1, 2, 3, 4])); + /// + /// // create a owning reference that points at the + /// // third element of the array. + /// let owning_ref = owning_ref.try_map(|array| { + /// if array[2] == 3 { Ok(&array[2]) } else { Err(()) } + /// }); + /// assert_eq!(*owning_ref.unwrap(), 3); + /// } + /// ``` pub fn try_map(self, f: F) -> Result, E> where O: StableAddress, F: FnOnce(&T) -> Result<&U, E> @@ -317,7 +410,7 @@ impl OwningRef { } } - /// Converts `self` into a new owning reference where the onwer is wrapped + /// Converts `self` into a new owning reference where the owner is wrapped /// in an additional `Box`. /// /// This can be used to safely erase the owner of any `OwningRef` @@ -385,6 +478,252 @@ impl OwningRef { } } +impl OwningRefMut { + /// Creates a new owning reference from a owner + /// initialized to the direct dereference of it. + /// + /// # Example + /// ``` + /// extern crate owning_ref; + /// use owning_ref::OwningRefMut; + /// + /// fn main() { + /// let owning_ref_mut = OwningRefMut::new(Box::new(42)); + /// assert_eq!(*owning_ref_mut, 42); + /// } + /// ``` + pub fn new(mut o: O) -> Self + where O: StableAddress, + O: DerefMut, + { + OwningRefMut { + reference: &mut *o, + owner: o, + } + } + + /// Like `new`, but doesn’t require `O` to implement the `StableAddress` trait. + /// Instead, the caller is responsible to make the same promises as implementing the trait. + /// + /// This is useful for cases where coherence rules prevents implementing the trait + /// without adding a dependency to this crate in a third-party library. + pub unsafe fn new_assert_stable_address(mut o: O) -> Self + where O: DerefMut, + { + OwningRefMut { + reference: &mut *o, + owner: o, + } + } + + /// Converts `self` into a new _shared_ owning reference that points at + /// something reachable from the previous one. + /// + /// This can be a reference to a field of `U`, something reachable from a field of + /// `U`, or even something unrelated with a `'static` lifetime. + /// + /// # Example + /// ``` + /// extern crate owning_ref; + /// use owning_ref::OwningRefMut; + /// + /// fn main() { + /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); + /// + /// // create a owning reference that points at the + /// // third element of the array. + /// let owning_ref = owning_ref_mut.map(|array| &array[2]); + /// assert_eq!(*owning_ref, 3); + /// } + /// ``` + pub fn map(mut self, f: F) -> OwningRef + where O: StableAddress, + F: FnOnce(&mut T) -> &U + { + OwningRef { + reference: f(&mut self), + owner: self.owner, + } + } + + /// Converts `self` into a new _mutable_ owning reference that points at + /// something reachable from the previous one. + /// + /// This can be a reference to a field of `U`, something reachable from a field of + /// `U`, or even something unrelated with a `'static` lifetime. + /// + /// # Example + /// ``` + /// extern crate owning_ref; + /// use owning_ref::OwningRefMut; + /// + /// fn main() { + /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); + /// + /// // create a owning reference that points at the + /// // third element of the array. + /// let owning_ref_mut = owning_ref_mut.map_mut(|array| &mut array[2]); + /// assert_eq!(*owning_ref_mut, 3); + /// } + /// ``` + pub fn map_mut(mut self, f: F) -> OwningRefMut + where O: StableAddress, + F: FnOnce(&mut T) -> &mut U + { + OwningRefMut { + reference: f(&mut self), + owner: self.owner, + } + } + + /// Tries to convert `self` into a new _shared_ owning reference that points + /// at something reachable from the previous one. + /// + /// This can be a reference to a field of `U`, something reachable from a field of + /// `U`, or even something unrelated with a `'static` lifetime. + /// + /// # Example + /// ``` + /// extern crate owning_ref; + /// use owning_ref::OwningRefMut; + /// + /// fn main() { + /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); + /// + /// // create a owning reference that points at the + /// // third element of the array. + /// let owning_ref = owning_ref_mut.try_map(|array| { + /// if array[2] == 3 { Ok(&array[2]) } else { Err(()) } + /// }); + /// assert_eq!(*owning_ref.unwrap(), 3); + /// } + /// ``` + pub fn try_map(mut self, f: F) -> Result, E> + where O: StableAddress, + F: FnOnce(&mut T) -> Result<&U, E> + { + Ok(OwningRef { + reference: f(&mut self)?, + owner: self.owner, + }) + } + + /// Tries to convert `self` into a new _mutable_ owning reference that points + /// at something reachable from the previous one. + /// + /// This can be a reference to a field of `U`, something reachable from a field of + /// `U`, or even something unrelated with a `'static` lifetime. + /// + /// # Example + /// ``` + /// extern crate owning_ref; + /// use owning_ref::OwningRefMut; + /// + /// fn main() { + /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); + /// + /// // create a owning reference that points at the + /// // third element of the array. + /// let owning_ref_mut = owning_ref_mut.try_map_mut(|array| { + /// if array[2] == 3 { Ok(&mut array[2]) } else { Err(()) } + /// }); + /// assert_eq!(*owning_ref_mut.unwrap(), 3); + /// } + /// ``` + pub fn try_map_mut(mut self, f: F) -> Result, E> + where O: StableAddress, + F: FnOnce(&mut T) -> Result<&mut U, E> + { + Ok(OwningRefMut { + reference: f(&mut self)?, + owner: self.owner, + }) + } + + /// Converts `self` into a new owning reference with a different owner type. + /// + /// The new owner type needs to still contain the original owner in some way + /// so that the reference into it remains valid. This function is marked unsafe + /// because the user needs to manually uphold this guarantee. + pub unsafe fn map_owner(self, f: F) -> OwningRefMut + where O: StableAddress, + P: StableAddress, + F: FnOnce(O) -> P + { + OwningRefMut { + reference: self.reference, + owner: f(self.owner), + } + } + + /// Converts `self` into a new owning reference where the owner is wrapped + /// in an additional `Box`. + /// + /// This can be used to safely erase the owner of any `OwningRefMut` + /// to a `OwningRefMut, T>`. + pub fn map_owner_box(self) -> OwningRefMut, T> { + OwningRefMut { + reference: self.reference, + owner: Box::new(self.owner), + } + } + + /// Erases the concrete base type of the owner with a trait object. + /// + /// This allows mixing of owned references with different owner base types. + /// + /// # Example + /// ``` + /// extern crate owning_ref; + /// use owning_ref::{OwningRefMut, Erased}; + /// + /// fn main() { + /// // NB: Using the concrete types here for explicitnes. + /// // For less verbose code type aliases like `BoxRef` are provided. + /// + /// let owning_ref_mut_a: OwningRefMut, [i32; 4]> + /// = OwningRefMut::new(Box::new([1, 2, 3, 4])); + /// + /// let owning_ref_mut_b: OwningRefMut>, Vec<(i32, bool)>> + /// = OwningRefMut::new(Box::new(vec![(0, false), (1, true)])); + /// + /// let owning_ref_mut_a: OwningRefMut, i32> + /// = owning_ref_mut_a.map_mut(|a| &mut a[0]); + /// + /// let owning_ref_mut_b: OwningRefMut>, i32> + /// = owning_ref_mut_b.map_mut(|a| &mut a[1].0); + /// + /// let owning_refs_mut: [OwningRefMut, i32>; 2] + /// = [owning_ref_mut_a.erase_owner(), owning_ref_mut_b.erase_owner()]; + /// + /// assert_eq!(*owning_refs_mut[0], 1); + /// assert_eq!(*owning_refs_mut[1], 1); + /// } + /// ``` + pub fn erase_owner<'a>(self) -> OwningRefMut + where O: IntoErased<'a>, + { + OwningRefMut { + reference: self.reference, + owner: self.owner.into_erased(), + } + } + + // TODO: wrap_owner + + // FIXME: Naming convention? + /// A getter for the underlying owner. + pub fn owner(&self) -> &O { + &self.owner + } + + // FIXME: Naming convention? + /// Discards the reference and retrieves the owner. + pub fn into_inner(self) -> O { + self.owner + } +} + ///////////////////////////////////////////////////////////////////////////// // OwningHandle ///////////////////////////////////////////////////////////////////////////// @@ -406,14 +745,10 @@ use std::ops::{Deref, DerefMut}; /// mint a dependent object, with the guarantee that the returned object will /// not outlive the referent of the pointer. /// -/// This does foist some unsafety onto the callback, which needs an `unsafe` -/// block to dereference the pointer. It would be almost good enough for -/// OwningHandle to pass a transmuted &'statc reference to the callback -/// since the lifetime is infinite as far as the minted handle is concerned. -/// However, even an `Fn` callback can still allow the reference to escape -/// via a `StaticMutex` or similar, which technically violates the safety -/// contract. Some sort of language support in the lifetime system could -/// make this API a bit nicer. +/// Since the callback needs to dereference a raw pointer, it requires `unsafe` +/// code. To avoid forcing this unsafety on most callers, the `ToHandle` trait is +/// implemented for common data structures. Types that implement `ToHandle` can +/// be wrapped into an `OwningHandle` without passing a callback. pub struct OwningHandle where O: StableAddress, H: Deref, { @@ -442,6 +777,46 @@ impl DerefMut for OwningHandle } } +/// Trait to implement the conversion of owner to handle for common types. +pub trait ToHandle { + /// The type of handle to be encapsulated by the OwningHandle. + type Handle: Deref; + + /// Given an appropriately-long-lived pointer to ourselves, create a + /// handle to be encapsulated by the `OwningHandle`. + unsafe fn to_handle(x: *const Self) -> Self::Handle; +} + +/// Trait to implement the conversion of owner to mutable handle for common types. +pub trait ToHandleMut { + /// The type of handle to be encapsulated by the OwningHandle. + type HandleMut: DerefMut; + + /// Given an appropriately-long-lived pointer to ourselves, create a + /// mutable handle to be encapsulated by the `OwningHandle`. + unsafe fn to_handle_mut(x: *const Self) -> Self::HandleMut; +} + +impl OwningHandle + where O: StableAddress, O::Target: ToHandle, H: Deref, +{ + /// Create a new `OwningHandle` for a type that implements `ToHandle`. For types + /// that don't implement `ToHandle`, callers may invoke `new_with_fn`, which accepts + /// a callback to perform the conversion. + pub fn new(o: O) -> Self { + OwningHandle::new_with_fn(o, |x| unsafe { O::Target::to_handle(x) }) + } +} + +impl OwningHandle + where O: StableAddress, O::Target: ToHandleMut, H: DerefMut, +{ + /// Create a new mutable `OwningHandle` for a type that implements `ToHandleMut`. + pub fn new_mut(o: O) -> Self { + OwningHandle::new_with_fn(o, |x| unsafe { O::Target::to_handle_mut(x) }) + } +} + impl OwningHandle where O: StableAddress, H: Deref, { @@ -449,8 +824,8 @@ impl OwningHandle /// a pointer to the object owned by `o`, and the returned value is stored /// as the object to which this `OwningHandle` will forward `Deref` and /// `DerefMut`. - pub fn new(o: O, f: F) -> Self - where F: Fn(*const O::Target) -> H + pub fn new_with_fn(o: O, f: F) -> Self + where F: FnOnce(*const O::Target) -> H { let h: H; { @@ -468,7 +843,7 @@ impl OwningHandle /// as the object to which this `OwningHandle` will forward `Deref` and /// `DerefMut`. pub fn try_new(o: O, f: F) -> Result - where F: Fn(*const O::Target) -> Result + where F: FnOnce(*const O::Target) -> Result { let h: H; { @@ -503,6 +878,24 @@ impl Deref for OwningRef { } } +impl Deref for OwningRefMut { + type Target = T; + + fn deref(&self) -> &T { + unsafe { + &*self.reference + } + } +} + +impl DerefMut for OwningRefMut { + fn deref_mut(&mut self) -> &mut T { + unsafe { + &mut *self.reference + } + } +} + unsafe impl StableAddress for OwningRef {} impl AsRef for OwningRef { @@ -511,6 +904,18 @@ impl AsRef for OwningRef { } } +impl AsRef for OwningRefMut { + fn as_ref(&self) -> &T { + &*self + } +} + +impl AsMut for OwningRefMut { + fn as_mut(&mut self) -> &mut T { + &mut *self + } +} + impl Borrow for OwningRef { fn borrow(&self) -> &T { &*self @@ -518,21 +923,58 @@ impl Borrow for OwningRef { } impl From for OwningRef - where O: StableAddress, O: Deref, + where O: StableAddress, + O: Deref, { fn from(owner: O) -> Self { OwningRef::new(owner) } } +impl From for OwningRefMut + where O: StableAddress, + O: DerefMut +{ + fn from(owner: O) -> Self { + OwningRefMut::new(owner) + } +} + +impl From> for OwningRef + where O: StableAddress, + O: DerefMut +{ + fn from(other: OwningRefMut) -> Self { + OwningRef { + owner: other.owner, + reference: other.reference, + } + } +} + // ^ FIXME: Is a Into impl for calling into_inner() possible as well? impl Debug for OwningRef - where O: Debug, T: Debug, + where O: Debug, + T: Debug, { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "OwningRef {{ owner: {:?}, reference: {:?} }}", - self.owner(), &**self) + write!(f, + "OwningRef {{ owner: {:?}, reference: {:?} }}", + self.owner(), + &**self) + } +} + +impl Debug for OwningRefMut + where O: Debug, + T: Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(f, + "OwningRefMut {{ owner: {:?}, reference: {:?} }}", + self.owner(), + &**self) } } @@ -550,8 +992,15 @@ impl Clone for OwningRef unsafe impl CloneStableAddress for OwningRef where O: CloneStableAddress {} -unsafe impl Send for OwningRef {} -unsafe impl Sync for OwningRef {} +unsafe impl Send for OwningRef + where O: Send, for<'a> (&'a T): Send {} +unsafe impl Sync for OwningRef + where O: Sync, for<'a> (&'a T): Sync {} + +unsafe impl Send for OwningRefMut + where O: Send, for<'a> (&'a mut T): Send {} +unsafe impl Sync for OwningRefMut + where O: Sync, for<'a> (&'a mut T): Sync {} impl Debug for Erased { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { @@ -585,6 +1034,32 @@ impl Hash for OwningRef where T: Hash { } } +impl PartialEq for OwningRefMut where T: PartialEq { + fn eq(&self, other: &Self) -> bool { + (&*self as &T).eq(&*other as &T) + } +} + +impl Eq for OwningRefMut where T: Eq {} + +impl PartialOrd for OwningRefMut where T: PartialOrd { + fn partial_cmp(&self, other: &Self) -> Option { + (&*self as &T).partial_cmp(&*other as &T) + } +} + +impl Ord for OwningRefMut where T: Ord { + fn cmp(&self, other: &Self) -> Ordering { + (&*self as &T).cmp(&*other as &T) + } +} + +impl Hash for OwningRefMut where T: Hash { + fn hash(&self, state: &mut H) { + (&*self as &T).hash(state); + } +} + ///////////////////////////////////////////////////////////////////////////// // std types integration and convenience type defs ///////////////////////////////////////////////////////////////////////////// @@ -593,22 +1068,21 @@ use std::boxed::Box; use std::rc::Rc; use std::sync::Arc; use std::sync::{MutexGuard, RwLockReadGuard, RwLockWriteGuard}; -use std::cell::{Ref, RefMut}; +use std::cell::{Ref, RefCell, RefMut}; -unsafe impl StableAddress for Box {} -unsafe impl StableAddress for Vec {} -unsafe impl StableAddress for String {} +impl ToHandle for RefCell { + type Handle = Ref<'static, T>; + unsafe fn to_handle(x: *const Self) -> Self::Handle { (*x).borrow() } +} -unsafe impl StableAddress for Rc {} -unsafe impl CloneStableAddress for Rc {} -unsafe impl StableAddress for Arc {} -unsafe impl CloneStableAddress for Arc {} +impl ToHandleMut for RefCell { + type HandleMut = RefMut<'static, T>; + unsafe fn to_handle_mut(x: *const Self) -> Self::HandleMut { (*x).borrow_mut() } +} -unsafe impl<'a, T: ?Sized> StableAddress for Ref<'a, T> {} -unsafe impl<'a, T: ?Sized> StableAddress for RefMut<'a, T> {} -unsafe impl<'a, T: ?Sized> StableAddress for MutexGuard<'a, T> {} -unsafe impl<'a, T: ?Sized> StableAddress for RwLockReadGuard<'a, T> {} -unsafe impl<'a, T: ?Sized> StableAddress for RwLockWriteGuard<'a, T> {} +// NB: Implementing ToHandle{,Mut} for Mutex and RwLock requires a decision +// about which handle creation to use (i.e. read() vs try_read()) as well as +// what to do with error results. /// Typedef of a owning reference that uses a `Box` as the owner. pub type BoxRef = OwningRef, U>; @@ -629,23 +1103,41 @@ pub type RefMutRef<'a, T, U = T> = OwningRef, U>; /// Typedef of a owning reference that uses a `MutexGuard` as the owner. pub type MutexGuardRef<'a, T, U = T> = OwningRef, U>; /// Typedef of a owning reference that uses a `RwLockReadGuard` as the owner. -pub type RwLockReadGuardRef<'a, T, U = T> - = OwningRef, U>; +pub type RwLockReadGuardRef<'a, T, U = T> = OwningRef, U>; /// Typedef of a owning reference that uses a `RwLockWriteGuard` as the owner. -pub type RwLockWriteGuardRef<'a, T, U = T> - = OwningRef, U>; +pub type RwLockWriteGuardRef<'a, T, U = T> = OwningRef, U>; + +/// Typedef of a mutable owning reference that uses a `Box` as the owner. +pub type BoxRefMut = OwningRefMut, U>; +/// Typedef of a mutable owning reference that uses a `Vec` as the owner. +pub type VecRefMut = OwningRefMut, U>; +/// Typedef of a mutable owning reference that uses a `String` as the owner. +pub type StringRefMut = OwningRefMut; + +/// Typedef of a mutable owning reference that uses a `RefMut` as the owner. +pub type RefMutRefMut<'a, T, U = T> = OwningRefMut, U>; +/// Typedef of a mutable owning reference that uses a `MutexGuard` as the owner. +pub type MutexGuardRefMut<'a, T, U = T> = OwningRefMut, U>; +/// Typedef of a mutable owning reference that uses a `RwLockWriteGuard` as the owner. +pub type RwLockWriteGuardRefMut<'a, T, U = T> = OwningRef, U>; unsafe impl<'a, T: 'a> IntoErased<'a> for Box { type Erased = Box; - fn into_erased(self) -> Self::Erased { self } + fn into_erased(self) -> Self::Erased { + self + } } unsafe impl<'a, T: 'a> IntoErased<'a> for Rc { type Erased = Rc; - fn into_erased(self) -> Self::Erased { self } + fn into_erased(self) -> Self::Erased { + self + } } unsafe impl<'a, T: 'a> IntoErased<'a> for Arc { type Erased = Arc; - fn into_erased(self) -> Self::Erased { self } + fn into_erased(self) -> Self::Erased { + self + } } /// Typedef of a owning reference that uses an erased `Box` as the owner. @@ -655,336 +1147,745 @@ pub type ErasedRcRef = OwningRef, U>; /// Typedef of a owning reference that uses an erased `Arc` as the owner. pub type ErasedArcRef = OwningRef, U>; +/// Typedef of a mutable owning reference that uses an erased `Box` as the owner. +pub type ErasedBoxRefMut = OwningRefMut, U>; + #[cfg(test)] mod tests { - use super::{OwningHandle, OwningRef}; - use super::{RcRef, BoxRef, Erased, ErasedBoxRef}; - use std::cmp::{PartialEq, Ord, PartialOrd, Ordering}; - use std::hash::{Hash, Hasher, SipHasher}; - use std::collections::HashMap; - use std::rc::Rc; + mod owning_ref { + use super::super::OwningRef; + use super::super::{RcRef, BoxRef, Erased, ErasedBoxRef}; + use std::cmp::{PartialEq, Ord, PartialOrd, Ordering}; + use std::hash::{Hash, Hasher}; + use std::collections::hash_map::DefaultHasher; + use std::collections::HashMap; + use std::rc::Rc; - #[derive(Debug, PartialEq)] - struct Example(u32, String, [u8; 3]); - fn example() -> Example { - Example(42, "hello world".to_string(), [1, 2, 3]) + #[derive(Debug, PartialEq)] + struct Example(u32, String, [u8; 3]); + fn example() -> Example { + Example(42, "hello world".to_string(), [1, 2, 3]) + } + + #[test] + fn new_deref() { + let or: OwningRef, ()> = OwningRef::new(Box::new(())); + assert_eq!(&*or, &()); + } + + #[test] + fn into() { + let or: OwningRef, ()> = Box::new(()).into(); + assert_eq!(&*or, &()); + } + + #[test] + fn map_offset_ref() { + let or: BoxRef = Box::new(example()).into(); + let or: BoxRef<_, u32> = or.map(|x| &x.0); + assert_eq!(&*or, &42); + + let or: BoxRef = Box::new(example()).into(); + let or: BoxRef<_, u8> = or.map(|x| &x.2[1]); + assert_eq!(&*or, &2); + } + + #[test] + fn map_heap_ref() { + let or: BoxRef = Box::new(example()).into(); + let or: BoxRef<_, str> = or.map(|x| &x.1[..5]); + assert_eq!(&*or, "hello"); + } + + #[test] + fn map_static_ref() { + let or: BoxRef<()> = Box::new(()).into(); + let or: BoxRef<_, str> = or.map(|_| "hello"); + assert_eq!(&*or, "hello"); + } + + #[test] + fn map_chained() { + let or: BoxRef = Box::new(example().1).into(); + let or: BoxRef<_, str> = or.map(|x| &x[1..5]); + let or: BoxRef<_, str> = or.map(|x| &x[..2]); + assert_eq!(&*or, "el"); + } + + #[test] + fn map_chained_inference() { + let or = BoxRef::new(Box::new(example().1)) + .map(|x| &x[..5]) + .map(|x| &x[1..3]); + assert_eq!(&*or, "el"); + } + + #[test] + fn owner() { + let or: BoxRef = Box::new(example().1).into(); + let or = or.map(|x| &x[..5]); + assert_eq!(&*or, "hello"); + assert_eq!(&**or.owner(), "hello world"); + } + + #[test] + fn into_inner() { + let or: BoxRef = Box::new(example().1).into(); + let or = or.map(|x| &x[..5]); + assert_eq!(&*or, "hello"); + let s = *or.into_inner(); + assert_eq!(&s, "hello world"); + } + + #[test] + fn fmt_debug() { + let or: BoxRef = Box::new(example().1).into(); + let or = or.map(|x| &x[..5]); + let s = format!("{:?}", or); + assert_eq!(&s, "OwningRef { owner: \"hello world\", reference: \"hello\" }"); + } + + #[test] + fn erased_owner() { + let o1: BoxRef = BoxRef::new(Box::new(example())) + .map(|x| &x.1[..]); + + let o2: BoxRef = BoxRef::new(Box::new(example().1)) + .map(|x| &x[..]); + + let os: Vec> = vec![o1.erase_owner(), o2.erase_owner()]; + assert!(os.iter().all(|e| &e[..] == "hello world")); + } + + #[test] + fn non_static_erased_owner() { + let foo = [413, 612]; + let bar = &foo; + + let o: BoxRef<&[i32; 2]> = Box::new(bar).into(); + let o: BoxRef<&[i32; 2], i32> = o.map(|a: &&[i32; 2]| &a[0]); + let o: BoxRef = o.erase_owner(); + + assert_eq!(*o, 413); + } + + #[test] + fn raii_locks() { + use super::super::{RefRef, RefMutRef}; + use std::cell::RefCell; + use super::super::{MutexGuardRef, RwLockReadGuardRef, RwLockWriteGuardRef}; + use std::sync::{Mutex, RwLock}; + + { + let a = RefCell::new(1); + let a = { + let a = RefRef::new(a.borrow()); + assert_eq!(*a, 1); + a + }; + assert_eq!(*a, 1); + drop(a); + } + { + let a = RefCell::new(1); + let a = { + let a = RefMutRef::new(a.borrow_mut()); + assert_eq!(*a, 1); + a + }; + assert_eq!(*a, 1); + drop(a); + } + { + let a = Mutex::new(1); + let a = { + let a = MutexGuardRef::new(a.lock().unwrap()); + assert_eq!(*a, 1); + a + }; + assert_eq!(*a, 1); + drop(a); + } + { + let a = RwLock::new(1); + let a = { + let a = RwLockReadGuardRef::new(a.read().unwrap()); + assert_eq!(*a, 1); + a + }; + assert_eq!(*a, 1); + drop(a); + } + { + let a = RwLock::new(1); + let a = { + let a = RwLockWriteGuardRef::new(a.write().unwrap()); + assert_eq!(*a, 1); + a + }; + assert_eq!(*a, 1); + drop(a); + } + } + + #[test] + fn eq() { + let or1: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); + let or2: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); + assert_eq!(or1.eq(&or2), true); + } + + #[test] + fn cmp() { + let or1: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); + let or2: BoxRef<[u8]> = BoxRef::new(vec![4, 5, 6].into_boxed_slice()); + assert_eq!(or1.cmp(&or2), Ordering::Less); + } + + #[test] + fn partial_cmp() { + let or1: BoxRef<[u8]> = BoxRef::new(vec![4, 5, 6].into_boxed_slice()); + let or2: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); + assert_eq!(or1.partial_cmp(&or2), Some(Ordering::Greater)); + } + + #[test] + fn hash() { + let mut h1 = DefaultHasher::new(); + let mut h2 = DefaultHasher::new(); + + let or1: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); + let or2: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); + + or1.hash(&mut h1); + or2.hash(&mut h2); + + assert_eq!(h1.finish(), h2.finish()); + } + + #[test] + fn borrow() { + let mut hash = HashMap::new(); + let key = RcRef::::new(Rc::new("foo-bar".to_string())).map(|s| &s[..]); + + hash.insert(key.clone().map(|s| &s[..3]), 42); + hash.insert(key.clone().map(|s| &s[4..]), 23); + + assert_eq!(hash.get("foo"), Some(&42)); + assert_eq!(hash.get("bar"), Some(&23)); + } + + #[test] + fn total_erase() { + let a: OwningRef, [u8]> + = OwningRef::new(vec![]).map(|x| &x[..]); + let b: OwningRef, [u8]> + = OwningRef::new(vec![].into_boxed_slice()).map(|x| &x[..]); + + let c: OwningRef>, [u8]> = unsafe {a.map_owner(Rc::new)}; + let d: OwningRef>, [u8]> = unsafe {b.map_owner(Rc::new)}; + + let e: OwningRef, [u8]> = c.erase_owner(); + let f: OwningRef, [u8]> = d.erase_owner(); + + let _g = e.clone(); + let _h = f.clone(); + } + + #[test] + fn total_erase_box() { + let a: OwningRef, [u8]> + = OwningRef::new(vec![]).map(|x| &x[..]); + let b: OwningRef, [u8]> + = OwningRef::new(vec![].into_boxed_slice()).map(|x| &x[..]); + + let c: OwningRef>, [u8]> = a.map_owner_box(); + let d: OwningRef>, [u8]> = b.map_owner_box(); + + let _e: OwningRef, [u8]> = c.erase_owner(); + let _f: OwningRef, [u8]> = d.erase_owner(); + } + + #[test] + fn try_map1() { + use std::any::Any; + + let x = Box::new(123_i32); + let y: Box = x; + + OwningRef::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_ok(); + } + + #[test] + fn try_map2() { + use std::any::Any; + + let x = Box::new(123_i32); + let y: Box = x; + + OwningRef::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_err(); + } } - #[test] - fn new_deref() { - let or: OwningRef, ()> = OwningRef::new(Box::new(())); - assert_eq!(&*or, &()); - } - - #[test] - fn into() { - let or: OwningRef, ()> = Box::new(()).into(); - assert_eq!(&*or, &()); - } - - #[test] - fn map_offset_ref() { - let or: BoxRef = Box::new(example()).into(); - let or: BoxRef<_, u32> = or.map(|x| &x.0); - assert_eq!(&*or, &42); - - let or: BoxRef = Box::new(example()).into(); - let or: BoxRef<_, u8> = or.map(|x| &x.2[1]); - assert_eq!(&*or, &2); - } - - #[test] - fn map_heap_ref() { - let or: BoxRef = Box::new(example()).into(); - let or: BoxRef<_, str> = or.map(|x| &x.1[..5]); - assert_eq!(&*or, "hello"); - } - - #[test] - fn map_static_ref() { - let or: BoxRef<()> = Box::new(()).into(); - let or: BoxRef<_, str> = or.map(|_| "hello"); - assert_eq!(&*or, "hello"); - } - - #[test] - fn map_chained() { - let or: BoxRef = Box::new(example().1).into(); - let or: BoxRef<_, str> = or.map(|x| &x[1..5]); - let or: BoxRef<_, str> = or.map(|x| &x[..2]); - assert_eq!(&*or, "el"); - } - - #[test] - fn map_chained_inference() { - let or = BoxRef::new(Box::new(example().1)) - .map(|x| &x[..5]) - .map(|x| &x[1..3]); - assert_eq!(&*or, "el"); - } - - #[test] - fn owner() { - let or: BoxRef = Box::new(example().1).into(); - let or = or.map(|x| &x[..5]); - assert_eq!(&*or, "hello"); - assert_eq!(&**or.owner(), "hello world"); - } - - #[test] - fn into_inner() { - let or: BoxRef = Box::new(example().1).into(); - let or = or.map(|x| &x[..5]); - assert_eq!(&*or, "hello"); - let s = *or.into_inner(); - assert_eq!(&s, "hello world"); - } - - #[test] - fn fmt_debug() { - let or: BoxRef = Box::new(example().1).into(); - let or = or.map(|x| &x[..5]); - let s = format!("{:?}", or); - assert_eq!(&s, "OwningRef { owner: \"hello world\", reference: \"hello\" }"); - } - - #[test] - fn erased_owner() { - let o1: BoxRef = BoxRef::new(Box::new(example())) - .map(|x| &x.1[..]); - - let o2: BoxRef = BoxRef::new(Box::new(example().1)) - .map(|x| &x[..]); - - let os: Vec> = vec![o1.erase_owner(), o2.erase_owner()]; - assert!(os.iter().all(|e| &e[..] == "hello world")); - } - - #[test] - fn non_static_erased_owner() { - let foo = [413, 612]; - let bar = &foo; - - let o: BoxRef<&[i32; 2]> = Box::new(bar).into(); - let o: BoxRef<&[i32; 2], i32> = o.map(|a: &&[i32; 2]| &a[0]); - let o: BoxRef = o.erase_owner(); - - assert_eq!(*o, 413); - } - - #[test] - fn raii_locks() { - use super::{RefRef, RefMutRef}; + mod owning_handle { + use super::super::OwningHandle; + use super::super::RcRef; + use std::rc::Rc; use std::cell::RefCell; - use super::{MutexGuardRef, RwLockReadGuardRef, RwLockWriteGuardRef}; - use std::sync::{Mutex, RwLock}; + use std::sync::Arc; + use std::sync::RwLock; - { - let a = RefCell::new(1); - let a = { - let a = RefRef::new(a.borrow()); - assert_eq!(*a, 1); - a - }; - assert_eq!(*a, 1); - drop(a); + #[test] + fn owning_handle() { + use std::cell::RefCell; + let cell = Rc::new(RefCell::new(2)); + let cell_ref = RcRef::new(cell); + let mut handle = OwningHandle::new_with_fn(cell_ref, |x| unsafe { x.as_ref() }.unwrap().borrow_mut()); + assert_eq!(*handle, 2); + *handle = 3; + assert_eq!(*handle, 3); } - { - let a = RefCell::new(1); - let a = { - let a = RefMutRef::new(a.borrow_mut()); - assert_eq!(*a, 1); - a - }; - assert_eq!(*a, 1); - drop(a); - } - { - let a = Mutex::new(1); - let a = { - let a = MutexGuardRef::new(a.lock().unwrap()); - assert_eq!(*a, 1); - a - }; - assert_eq!(*a, 1); - drop(a); - } - { - let a = RwLock::new(1); - let a = { - let a = RwLockReadGuardRef::new(a.read().unwrap()); - assert_eq!(*a, 1); - a - }; - assert_eq!(*a, 1); - drop(a); - } - { - let a = RwLock::new(1); - let a = { - let a = RwLockWriteGuardRef::new(a.write().unwrap()); - assert_eq!(*a, 1); - a - }; - assert_eq!(*a, 1); - drop(a); - } - } - #[test] - fn eq() { - let or1: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); - let or2: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); - assert_eq!(or1.eq(&or2), true); - } - - #[test] - fn cmp() { - let or1: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); - let or2: BoxRef<[u8]> = BoxRef::new(vec![4, 5, 6].into_boxed_slice()); - assert_eq!(or1.cmp(&or2), Ordering::Less); - } - - #[test] - fn partial_cmp() { - let or1: BoxRef<[u8]> = BoxRef::new(vec![4, 5, 6].into_boxed_slice()); - let or2: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); - assert_eq!(or1.partial_cmp(&or2), Some(Ordering::Greater)); - } - - #[test] - fn hash() { - let mut h1 = SipHasher::new(); - let mut h2 = SipHasher::new(); - - let or1: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); - let or2: BoxRef<[u8]> = BoxRef::new(vec![1, 2, 3].into_boxed_slice()); - - or1.hash(&mut h1); - or2.hash(&mut h2); - - assert_eq!(h1.finish(), h2.finish()); - } - - #[test] - fn borrow() { - let mut hash = HashMap::new(); - let key = RcRef::::new(Rc::new("foo-bar".to_string())).map(|s| &s[..]); - - hash.insert(key.clone().map(|s| &s[..3]), 42); - hash.insert(key.clone().map(|s| &s[4..]), 23); - - assert_eq!(hash.get("foo"), Some(&42)); - assert_eq!(hash.get("bar"), Some(&23)); - } - - #[test] - fn owning_handle() { - use std::cell::RefCell; - let cell = Rc::new(RefCell::new(2)); - let cell_ref = RcRef::new(cell); - let mut handle = OwningHandle::new(cell_ref, |x| unsafe { x.as_ref() }.unwrap().borrow_mut()); - assert_eq!(*handle, 2); - *handle = 3; - assert_eq!(*handle, 3); - } - - #[test] - fn try_owning_handle_ok() { - use std::cell::RefCell; - let cell = Rc::new(RefCell::new(2)); - let cell_ref = RcRef::new(cell); - let mut handle = OwningHandle::try_new::<_, ()>(cell_ref, |x| { - Ok(unsafe { - x.as_ref() - }.unwrap().borrow_mut()) - }).unwrap(); - assert_eq!(*handle, 2); - *handle = 3; - assert_eq!(*handle, 3); - } - - #[test] - fn try_owning_handle_err() { - use std::cell::RefCell; - let cell = Rc::new(RefCell::new(2)); - let cell_ref = RcRef::new(cell); - let handle = OwningHandle::try_new::<_, ()>(cell_ref, |x| { - if false { - return Ok(unsafe { + #[test] + fn try_owning_handle_ok() { + use std::cell::RefCell; + let cell = Rc::new(RefCell::new(2)); + let cell_ref = RcRef::new(cell); + let mut handle = OwningHandle::try_new::<_, ()>(cell_ref, |x| { + Ok(unsafe { x.as_ref() }.unwrap().borrow_mut()) + }).unwrap(); + assert_eq!(*handle, 2); + *handle = 3; + assert_eq!(*handle, 3); + } + + #[test] + fn try_owning_handle_err() { + use std::cell::RefCell; + let cell = Rc::new(RefCell::new(2)); + let cell_ref = RcRef::new(cell); + let handle = OwningHandle::try_new::<_, ()>(cell_ref, |x| { + if false { + return Ok(unsafe { + x.as_ref() + }.unwrap().borrow_mut()) + } + Err(()) + }); + assert!(handle.is_err()); + } + + #[test] + fn nested() { + use std::cell::RefCell; + use std::sync::{Arc, RwLock}; + + let result = { + let complex = Rc::new(RefCell::new(Arc::new(RwLock::new("someString")))); + let curr = RcRef::new(complex); + let curr = OwningHandle::new_with_fn(curr, |x| unsafe { x.as_ref() }.unwrap().borrow_mut()); + let mut curr = OwningHandle::new_with_fn(curr, |x| unsafe { x.as_ref() }.unwrap().try_write().unwrap()); + assert_eq!(*curr, "someString"); + *curr = "someOtherString"; + curr + }; + assert_eq!(*result, "someOtherString"); + } + + #[test] + fn owning_handle_safe() { + use std::cell::RefCell; + let cell = Rc::new(RefCell::new(2)); + let cell_ref = RcRef::new(cell); + let handle = OwningHandle::new(cell_ref); + assert_eq!(*handle, 2); + } + + #[test] + fn owning_handle_mut_safe() { + use std::cell::RefCell; + let cell = Rc::new(RefCell::new(2)); + let cell_ref = RcRef::new(cell); + let mut handle = OwningHandle::new_mut(cell_ref); + assert_eq!(*handle, 2); + *handle = 3; + assert_eq!(*handle, 3); + } + + #[test] + fn owning_handle_safe_2() { + let result = { + let complex = Rc::new(RefCell::new(Arc::new(RwLock::new("someString")))); + let curr = RcRef::new(complex); + let curr = OwningHandle::new_with_fn(curr, |x| unsafe { x.as_ref() }.unwrap().borrow_mut()); + let mut curr = OwningHandle::new_with_fn(curr, |x| unsafe { x.as_ref() }.unwrap().try_write().unwrap()); + assert_eq!(*curr, "someString"); + *curr = "someOtherString"; + curr + }; + assert_eq!(*result, "someOtherString"); + } + } + + mod owning_ref_mut { + use super::super::{OwningRefMut, BoxRefMut, Erased, ErasedBoxRefMut}; + use super::super::BoxRef; + use std::cmp::{PartialEq, Ord, PartialOrd, Ordering}; + use std::hash::{Hash, Hasher}; + use std::collections::hash_map::DefaultHasher; + use std::collections::HashMap; + + #[derive(Debug, PartialEq)] + struct Example(u32, String, [u8; 3]); + fn example() -> Example { + Example(42, "hello world".to_string(), [1, 2, 3]) + } + + #[test] + fn new_deref() { + let or: OwningRefMut, ()> = OwningRefMut::new(Box::new(())); + assert_eq!(&*or, &()); + } + + #[test] + fn new_deref_mut() { + let mut or: OwningRefMut, ()> = OwningRefMut::new(Box::new(())); + assert_eq!(&mut *or, &mut ()); + } + + #[test] + fn mutate() { + let mut or: OwningRefMut, usize> = OwningRefMut::new(Box::new(0)); + assert_eq!(&*or, &0); + *or = 1; + assert_eq!(&*or, &1); + } + + #[test] + fn into() { + let or: OwningRefMut, ()> = Box::new(()).into(); + assert_eq!(&*or, &()); + } + + #[test] + fn map_offset_ref() { + let or: BoxRefMut = Box::new(example()).into(); + let or: BoxRef<_, u32> = or.map(|x| &mut x.0); + assert_eq!(&*or, &42); + + let or: BoxRefMut = Box::new(example()).into(); + let or: BoxRef<_, u8> = or.map(|x| &mut x.2[1]); + assert_eq!(&*or, &2); + } + + #[test] + fn map_heap_ref() { + let or: BoxRefMut = Box::new(example()).into(); + let or: BoxRef<_, str> = or.map(|x| &mut x.1[..5]); + assert_eq!(&*or, "hello"); + } + + #[test] + fn map_static_ref() { + let or: BoxRefMut<()> = Box::new(()).into(); + let or: BoxRef<_, str> = or.map(|_| "hello"); + assert_eq!(&*or, "hello"); + } + + #[test] + fn map_mut_offset_ref() { + let or: BoxRefMut = Box::new(example()).into(); + let or: BoxRefMut<_, u32> = or.map_mut(|x| &mut x.0); + assert_eq!(&*or, &42); + + let or: BoxRefMut = Box::new(example()).into(); + let or: BoxRefMut<_, u8> = or.map_mut(|x| &mut x.2[1]); + assert_eq!(&*or, &2); + } + + #[test] + fn map_mut_heap_ref() { + let or: BoxRefMut = Box::new(example()).into(); + let or: BoxRefMut<_, str> = or.map_mut(|x| &mut x.1[..5]); + assert_eq!(&*or, "hello"); + } + + #[test] + fn map_mut_static_ref() { + static mut MUT_S: [u8; 5] = *b"hello"; + + let mut_s: &'static mut [u8] = unsafe { &mut MUT_S }; + + let or: BoxRefMut<()> = Box::new(()).into(); + let or: BoxRefMut<_, [u8]> = or.map_mut(move |_| mut_s); + assert_eq!(&*or, b"hello"); + } + + #[test] + fn map_mut_chained() { + let or: BoxRefMut = Box::new(example().1).into(); + let or: BoxRefMut<_, str> = or.map_mut(|x| &mut x[1..5]); + let or: BoxRefMut<_, str> = or.map_mut(|x| &mut x[..2]); + assert_eq!(&*or, "el"); + } + + #[test] + fn map_chained_inference() { + let or = BoxRefMut::new(Box::new(example().1)) + .map_mut(|x| &mut x[..5]) + .map_mut(|x| &mut x[1..3]); + assert_eq!(&*or, "el"); + } + + #[test] + fn try_map_mut() { + let or: BoxRefMut = Box::new(example().1).into(); + let or: Result, ()> = or.try_map_mut(|x| Ok(&mut x[1..5])); + assert_eq!(&*or.unwrap(), "ello"); + + let or: BoxRefMut = Box::new(example().1).into(); + let or: Result, ()> = or.try_map_mut(|_| Err(())); + assert!(or.is_err()); + } + + #[test] + fn owner() { + let or: BoxRefMut = Box::new(example().1).into(); + let or = or.map_mut(|x| &mut x[..5]); + assert_eq!(&*or, "hello"); + assert_eq!(&**or.owner(), "hello world"); + } + + #[test] + fn into_inner() { + let or: BoxRefMut = Box::new(example().1).into(); + let or = or.map_mut(|x| &mut x[..5]); + assert_eq!(&*or, "hello"); + let s = *or.into_inner(); + assert_eq!(&s, "hello world"); + } + + #[test] + fn fmt_debug() { + let or: BoxRefMut = Box::new(example().1).into(); + let or = or.map_mut(|x| &mut x[..5]); + let s = format!("{:?}", or); + assert_eq!(&s, + "OwningRefMut { owner: \"hello world\", reference: \"hello\" }"); + } + + #[test] + fn erased_owner() { + let o1: BoxRefMut = BoxRefMut::new(Box::new(example())) + .map_mut(|x| &mut x.1[..]); + + let o2: BoxRefMut = BoxRefMut::new(Box::new(example().1)) + .map_mut(|x| &mut x[..]); + + let os: Vec> = vec![o1.erase_owner(), o2.erase_owner()]; + assert!(os.iter().all(|e| &e[..] == "hello world")); + } + + #[test] + fn non_static_erased_owner() { + let mut foo = [413, 612]; + let bar = &mut foo; + + let o: BoxRefMut<&mut [i32; 2]> = Box::new(bar).into(); + let o: BoxRefMut<&mut [i32; 2], i32> = o.map_mut(|a: &mut &mut [i32; 2]| &mut a[0]); + let o: BoxRefMut = o.erase_owner(); + + assert_eq!(*o, 413); + } + + #[test] + fn raii_locks() { + use super::super::RefMutRefMut; + use std::cell::RefCell; + use super::super::{MutexGuardRefMut, RwLockWriteGuardRefMut}; + use std::sync::{Mutex, RwLock}; + + { + let a = RefCell::new(1); + let a = { + let a = RefMutRefMut::new(a.borrow_mut()); + assert_eq!(*a, 1); + a + }; + assert_eq!(*a, 1); + drop(a); } - Err(()) - }); - assert!(handle.is_err()); - } + { + let a = Mutex::new(1); + let a = { + let a = MutexGuardRefMut::new(a.lock().unwrap()); + assert_eq!(*a, 1); + a + }; + assert_eq!(*a, 1); + drop(a); + } + { + let a = RwLock::new(1); + let a = { + let a = RwLockWriteGuardRefMut::new(a.write().unwrap()); + assert_eq!(*a, 1); + a + }; + assert_eq!(*a, 1); + drop(a); + } + } - #[test] - fn nested() { - use std::cell::RefCell; - use std::sync::{Arc, RwLock}; + #[test] + fn eq() { + let or1: BoxRefMut<[u8]> = BoxRefMut::new(vec![1, 2, 3].into_boxed_slice()); + let or2: BoxRefMut<[u8]> = BoxRefMut::new(vec![1, 2, 3].into_boxed_slice()); + assert_eq!(or1.eq(&or2), true); + } - let result = { - let complex = Rc::new(RefCell::new(Arc::new(RwLock::new("someString")))); - let curr = RcRef::new(complex); - let curr = OwningHandle::new(curr, |x| unsafe { x.as_ref() }.unwrap().borrow_mut()); - let mut curr = OwningHandle::new(curr, |x| unsafe { x.as_ref() }.unwrap().try_write().unwrap()); - assert_eq!(*curr, "someString"); - *curr = "someOtherString"; - curr - }; - assert_eq!(*result, "someOtherString"); - } + #[test] + fn cmp() { + let or1: BoxRefMut<[u8]> = BoxRefMut::new(vec![1, 2, 3].into_boxed_slice()); + let or2: BoxRefMut<[u8]> = BoxRefMut::new(vec![4, 5, 6].into_boxed_slice()); + assert_eq!(or1.cmp(&or2), Ordering::Less); + } - #[test] - fn total_erase() { - let a: OwningRef, [u8]> - = OwningRef::new(vec![]).map(|x| &x[..]); - let b: OwningRef, [u8]> - = OwningRef::new(vec![].into_boxed_slice()).map(|x| &x[..]); + #[test] + fn partial_cmp() { + let or1: BoxRefMut<[u8]> = BoxRefMut::new(vec![4, 5, 6].into_boxed_slice()); + let or2: BoxRefMut<[u8]> = BoxRefMut::new(vec![1, 2, 3].into_boxed_slice()); + assert_eq!(or1.partial_cmp(&or2), Some(Ordering::Greater)); + } - let c: OwningRef>, [u8]> = unsafe {a.map_owner(Rc::new)}; - let d: OwningRef>, [u8]> = unsafe {b.map_owner(Rc::new)}; + #[test] + fn hash() { + let mut h1 = DefaultHasher::new(); + let mut h2 = DefaultHasher::new(); - let e: OwningRef, [u8]> = c.erase_owner(); - let f: OwningRef, [u8]> = d.erase_owner(); + let or1: BoxRefMut<[u8]> = BoxRefMut::new(vec![1, 2, 3].into_boxed_slice()); + let or2: BoxRefMut<[u8]> = BoxRefMut::new(vec![1, 2, 3].into_boxed_slice()); - let _g = e.clone(); - let _h = f.clone(); - } + or1.hash(&mut h1); + or2.hash(&mut h2); - #[test] - fn total_erase_box() { - let a: OwningRef, [u8]> - = OwningRef::new(vec![]).map(|x| &x[..]); - let b: OwningRef, [u8]> - = OwningRef::new(vec![].into_boxed_slice()).map(|x| &x[..]); + assert_eq!(h1.finish(), h2.finish()); + } - let c: OwningRef>, [u8]> = a.map_owner_box(); - let d: OwningRef>, [u8]> = b.map_owner_box(); + #[test] + fn borrow() { + let mut hash = HashMap::new(); + let key1 = BoxRefMut::::new(Box::new("foo".to_string())).map(|s| &s[..]); + let key2 = BoxRefMut::::new(Box::new("bar".to_string())).map(|s| &s[..]); - let _e: OwningRef, [u8]> = c.erase_owner(); - let _f: OwningRef, [u8]> = d.erase_owner(); - } + hash.insert(key1, 42); + hash.insert(key2, 23); - #[test] - fn try_map1() { - use std::any::Any; + assert_eq!(hash.get("foo"), Some(&42)); + assert_eq!(hash.get("bar"), Some(&23)); + } - let x = Box::new(123_i32); - let y: Box = x; + #[test] + fn total_erase() { + let a: OwningRefMut, [u8]> + = OwningRefMut::new(vec![]).map_mut(|x| &mut x[..]); + let b: OwningRefMut, [u8]> + = OwningRefMut::new(vec![].into_boxed_slice()).map_mut(|x| &mut x[..]); - OwningRef::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_ok(); - } + let c: OwningRefMut>, [u8]> = unsafe {a.map_owner(Box::new)}; + let d: OwningRefMut>, [u8]> = unsafe {b.map_owner(Box::new)}; - #[test] - fn try_map2() { - use std::any::Any; + let _e: OwningRefMut, [u8]> = c.erase_owner(); + let _f: OwningRefMut, [u8]> = d.erase_owner(); + } - let x = Box::new(123_i32); - let y: Box = x; + #[test] + fn total_erase_box() { + let a: OwningRefMut, [u8]> + = OwningRefMut::new(vec![]).map_mut(|x| &mut x[..]); + let b: OwningRefMut, [u8]> + = OwningRefMut::new(vec![].into_boxed_slice()).map_mut(|x| &mut x[..]); - OwningRef::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_err(); + let c: OwningRefMut>, [u8]> = a.map_owner_box(); + let d: OwningRefMut>, [u8]> = b.map_owner_box(); + + let _e: OwningRefMut, [u8]> = c.erase_owner(); + let _f: OwningRefMut, [u8]> = d.erase_owner(); + } + + #[test] + fn try_map1() { + use std::any::Any; + + let x = Box::new(123_i32); + let y: Box = x; + + OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::().ok_or(())).is_ok(); + } + + #[test] + fn try_map2() { + use std::any::Any; + + let x = Box::new(123_i32); + let y: Box = x; + + OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::().ok_or(())).is_err(); + } + + #[test] + fn try_map3() { + use std::any::Any; + + let x = Box::new(123_i32); + let y: Box = x; + + OwningRefMut::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_ok(); + } + + #[test] + fn try_map4() { + use std::any::Any; + + let x = Box::new(123_i32); + let y: Box = x; + + OwningRefMut::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_err(); + } + + #[test] + fn into_owning_ref() { + use super::super::BoxRef; + + let or: BoxRefMut<()> = Box::new(()).into(); + let or: BoxRef<()> = or.into(); + assert_eq!(&*or, &()); + } + + struct Foo { + u: u32, + } + struct Bar { + f: Foo, + } + + #[test] + fn ref_mut() { + use std::cell::RefCell; + + let a = RefCell::new(Bar { f: Foo { u: 42 } }); + let mut b = OwningRefMut::new(a.borrow_mut()); + assert_eq!(b.f.u, 42); + b.f.u = 43; + let mut c = b.map_mut(|x| &mut x.f); + assert_eq!(c.u, 43); + c.u = 44; + let mut d = c.map_mut(|x| &mut x.u); + assert_eq!(*d, 44); + *d = 45; + assert_eq!(*d, 45); + } } } diff --git a/third_party/rust/parking_lot/.cargo-checksum.json b/third_party/rust/parking_lot/.cargo-checksum.json index db34dd09c57c..aefedf6ea23e 100644 --- a/third_party/rust/parking_lot/.cargo-checksum.json +++ b/third_party/rust/parking_lot/.cargo-checksum.json @@ -1 +1 @@ -{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"9b39b9d42d077d028d5742450256c9f11f3456ff185ce2a987f4606b152bf440","Cargo.toml":"8a0938f1fd49ceae700f27333cdacd754d7b2205664265de4bd67be3d37a9525","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"c9a75f18b9ab2927829a208fc6aa2cf4e63b8420887ba29cdb265d6619ae82d5","README.md":"d7bb9d24f29da05ef02c232f6354c01a93a8205f55d137f8b7d7a74f88163994","appveyor.yml":"1181ecde6a5df38051107a3ef4051751499f5a462ed761c1eafd6d4c62fde73e","src/condvar.rs":"227cd171d14ee54b115a5d1bff38ac4a01460ca2d85a40773b08035b6f39e94e","src/elision.rs":"0fef04d2991afeabafb041e81afeec74e89095d0eca49e5516bdcd5bc90c086f","src/lib.rs":"50951210148941266ce3a7d4017c339f8ad4419a9a8db6f915023890ed27d638","src/mutex.rs":"956b58465f78ac97d8ecf4dda7bbd973998cb29c4057f51cc3d8c8bdfa47f460","src/once.rs":"dee225c5472d152ed820eb90a3dcb96f7af409d8315f006b2179fa3f350de4ed","src/raw_mutex.rs":"225cbf0ef951be062866da674e5eea8245fcc43ecd8a26da7097dea03b770bf5","src/raw_remutex.rs":"a451cc3ce7bf11bc94777148b81d39b07b5a2a2fc698f6db2ca2fc765b158fa8","src/raw_rwlock.rs":"f7a206d0d401dae475d42f06d8a8fe6d8f2ca986b60633aaa4d3d588a997793e","src/remutex.rs":"a5cefa1a97e4669e3b2dffa9007988e6a6088500472d9eefea1a28ed1443e1b0","src/rwlock.rs":"3de0dded88f3dd339e962aba1cc778a03d5a10ac743325a81859617c455c31d3","src/stable.rs":"cc18c58404dc6017924d88fb9f4ed94e5320b8cb0a36985162b23130b8cd7480","src/util.rs":"2d07c0c010a857790ae2ed6a1215eeed8af76859e076797ea1ba8dec82169e84"},"package":"fa12d706797d42551663426a45e2db2e0364bd1dbf6aeada87e89c5f981f43e9"} \ No newline at end of file +{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"8e424960f1e47843f45cae205873e9590e4317b5b2316090f9f94cf2f5d704e8","Cargo.toml":"a31940ea072ae30f6df4c28f4fcbae206929a9e7e8adf19956dd9ed75fa7e75d","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"c9a75f18b9ab2927829a208fc6aa2cf4e63b8420887ba29cdb265d6619ae82d5","README.md":"0c248175303f7dc19ce2cb30882c950a55a49da6b8c765c5ba49feb3e6eb7553","appveyor.yml":"cc608360622923f6f693cd68b4d7c1f64daa55f6b38f0df90f270825c6c276bc","src/condvar.rs":"962a3838e95cb664b261a44f536b003a284fe7bfdcb94a80c9a07c7679cae3dd","src/elision.rs":"0fef04d2991afeabafb041e81afeec74e89095d0eca49e5516bdcd5bc90c086f","src/lib.rs":"50951210148941266ce3a7d4017c339f8ad4419a9a8db6f915023890ed27d638","src/mutex.rs":"59cd61dd8deeaacceabd05e15b7fd6d2942e3f6c3c592221898d84a2ca804a6e","src/once.rs":"eada2e82bd8dcb9ed68d4fb2d9f8c336878eeb122f0bf8dde3feb2d77adfb598","src/raw_mutex.rs":"225cbf0ef951be062866da674e5eea8245fcc43ecd8a26da7097dea03b770bf5","src/raw_remutex.rs":"6c6d2aa83abe8f45db04de0efc04c70564cd0c55b6655da8ef4afe841c0add95","src/raw_rwlock.rs":"a7aebf70b8f7a43f96136388be1a54e5ca5b565c9da623f23434c99fb4c0b147","src/remutex.rs":"7f1640fa5a6eb43b592db47d9afa63904895030d246708ec8eac413dc8093514","src/rwlock.rs":"87d648c5fcccda784da165801b888a3592b6a85ddb605c1df3ae0e881dd22417","src/stable.rs":"cc18c58404dc6017924d88fb9f4ed94e5320b8cb0a36985162b23130b8cd7480","src/util.rs":"2d07c0c010a857790ae2ed6a1215eeed8af76859e076797ea1ba8dec82169e84"},"package":"37f364e2ce5efa24c7d0b6646d5bb61145551a0112f107ffd7499f1a3e322fbd"} \ No newline at end of file diff --git a/third_party/rust/parking_lot/.travis.yml b/third_party/rust/parking_lot/.travis.yml index 1b8fe5ebe47b..fce307d70126 100644 --- a/third_party/rust/parking_lot/.travis.yml +++ b/third_party/rust/parking_lot/.travis.yml @@ -2,7 +2,7 @@ language: rust sudo: false rust: -- 1.9.0 +- 1.13.0 - stable - beta - nightly diff --git a/third_party/rust/parking_lot/Cargo.toml b/third_party/rust/parking_lot/Cargo.toml index 10e3d1c07c18..97ce257a1648 100644 --- a/third_party/rust/parking_lot/Cargo.toml +++ b/third_party/rust/parking_lot/Cargo.toml @@ -1,24 +1,36 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g. crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + [package] name = "parking_lot" -version = "0.3.8" +version = "0.4.4" authors = ["Amanieu d'Antras "] description = "More compact and efficient implementations of the standard synchronization primitives." documentation = "https://amanieu.github.io/parking_lot/parking_lot/index.html" -license = "Apache-2.0/MIT" -repository = "https://github.com/Amanieu/parking_lot" readme = "README.md" keywords = ["mutex", "condvar", "rwlock", "once", "thread"] +license = "Apache-2.0/MIT" +repository = "https://github.com/Amanieu/parking_lot" +[dependencies.owning_ref] +version = "0.3" +optional = true -[dependencies] -parking_lot_core = { path = "core", version = "0.2" } -owning_ref = { version = "0.2", optional = true } - -[target.'cfg(not(target_os = "emscripten"))'.dependencies] -thread-id = "3.0" - -[dev-dependencies] -rand = "0.3" +[dependencies.parking_lot_core] +version = "0.2" +[dev-dependencies.rand] +version = "0.3" [features] default = ["owning_ref"] nightly = ["parking_lot_core/nightly"] +[target."cfg(not(target_os = \"emscripten\"))".dependencies.thread-id] +version = "3.0" diff --git a/third_party/rust/parking_lot/README.md b/third_party/rust/parking_lot/README.md index 6e0983e477ab..d9049a645532 100644 --- a/third_party/rust/parking_lot/README.md +++ b/third_party/rust/parking_lot/README.md @@ -68,12 +68,12 @@ in the Rust standard library: To keep these primitives small, all thread queuing and suspending functionality is offloaded to the *parking lot*. The idea behind this is -based on the Webkit [`WTF::ParkingLot`] -(https://webkit.org/blog/6161/locking-in-webkit/) class, which essentially -consists of a hash table mapping of lock addresses to queues of parked -(sleeping) threads. The Webkit parking lot was itself inspired by Linux -[futexes](http://man7.org/linux/man-pages/man2/futex.2.html), but it is more -powerful since it allows invoking callbacks while holding a queue lock. +based on the Webkit [`WTF::ParkingLot`](https://webkit.org/blog/6161/locking-in-webkit/) +class, which essentially consists of a hash table mapping of lock addresses +to queues of parked (sleeping) threads. The Webkit parking lot was itself +inspired by Linux [futexes](http://man7.org/linux/man-pages/man2/futex.2.html), +but it is more powerful since it allows invoking callbacks while holding a queue +lock. ## Nightly vs stable @@ -93,7 +93,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -parking_lot = "0.3" +parking_lot = "0.4" ``` and this to your crate root: @@ -106,7 +106,7 @@ To enable nightly-only features, add this to your `Cargo.toml` instead: ```toml [dependencies] -parking_lot = {version = "0.3", features = ["nightly"]} +parking_lot = {version = "0.4", features = ["nightly"]} ``` The core parking lot API is provided by the `parking_lot_core` crate. It is diff --git a/third_party/rust/parking_lot/appveyor.yml b/third_party/rust/parking_lot/appveyor.yml index 369d73ccffc7..4fae1d95794a 100644 --- a/third_party/rust/parking_lot/appveyor.yml +++ b/third_party/rust/parking_lot/appveyor.yml @@ -5,10 +5,10 @@ environment: - TARGET: nightly-i686-pc-windows-msvc - TARGET: nightly-x86_64-pc-windows-gnu - TARGET: nightly-i686-pc-windows-gnu - - TARGET: 1.9.0-x86_64-pc-windows-msvc - - TARGET: 1.9.0-i686-pc-windows-msvc - - TARGET: 1.9.0-x86_64-pc-windows-gnu - - TARGET: 1.9.0-i686-pc-windows-gnu + - TARGET: 1.13.0-x86_64-pc-windows-msvc + - TARGET: 1.13.0-i686-pc-windows-msvc + - TARGET: 1.13.0-x86_64-pc-windows-gnu + - TARGET: 1.13.0-i686-pc-windows-gnu install: - SET PATH=C:\Python27;C:\Python27\Scripts;%PATH%;%APPDATA%\Python\Scripts diff --git a/third_party/rust/parking_lot/src/condvar.rs b/third_party/rust/parking_lot/src/condvar.rs index a4115c8dc068..d44f86b4b6d6 100644 --- a/third_party/rust/parking_lot/src/condvar.rs +++ b/third_party/rust/parking_lot/src/condvar.rs @@ -143,19 +143,19 @@ impl Condvar { #[inline] pub fn notify_all(&self) { // Nothing to do if there are no waiting threads - if self.state.load(Ordering::Relaxed).is_null() { + let state = self.state.load(Ordering::Relaxed); + if state.is_null() { return; } - self.notify_all_slow(); + self.notify_all_slow(state); } #[cold] #[inline(never)] - fn notify_all_slow(&self) { + fn notify_all_slow(&self, mutex: *mut RawMutex) { unsafe { // Unpark one thread and requeue the rest onto the mutex - let mutex = self.state.load(Ordering::Relaxed); let from = self as *const _ as usize; let to = mutex as usize; let validate = || { diff --git a/third_party/rust/parking_lot/src/mutex.rs b/third_party/rust/parking_lot/src/mutex.rs index b60e3d416843..c898c10878e0 100644 --- a/third_party/rust/parking_lot/src/mutex.rs +++ b/third_party/rust/parking_lot/src/mutex.rs @@ -9,6 +9,7 @@ use std::cell::UnsafeCell; use std::ops::{Deref, DerefMut}; use std::time::{Duration, Instant}; use std::fmt; +use std::mem; use std::marker::PhantomData; use raw_mutex::RawMutex; @@ -300,6 +301,7 @@ impl<'a, T: ?Sized + 'a> MutexGuard<'a, T> { #[inline] pub fn unlock_fair(self) { self.mutex.raw.unlock(true); + mem::forget(self); } } diff --git a/third_party/rust/parking_lot/src/once.rs b/third_party/rust/parking_lot/src/once.rs index 1c0400554b3c..07a5582378cb 100644 --- a/third_party/rust/parking_lot/src/once.rs +++ b/third_party/rust/parking_lot/src/once.rs @@ -22,9 +22,21 @@ const POISON_BIT: U8 = 2; const LOCKED_BIT: U8 = 4; const PARKED_BIT: U8 = 8; -/// State yielded to the `call_once_force` method which can be used to query -/// whether the `Once` was previously poisoned or not. -pub struct OnceState(bool); +/// Current state of a `Once`. +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub enum OnceState { + /// A closure has not been executed yet + New, + + /// A closure was executed but panicked. + Poisoned, + + /// A thread is currently executing a closure. + InProgress, + + /// A closure has completed sucessfully. + Done, +} impl OnceState { /// Returns whether the associated `Once` has been poisoned. @@ -33,7 +45,20 @@ impl OnceState { /// indicate to future forced initialization routines that it is poisoned. #[inline] pub fn poisoned(&self) -> bool { - self.0 + match *self { + OnceState::Poisoned => true, + _ => false, + } + } + + /// Returns whether the associated `Once` has successfullly executed a + /// closure. + #[inline] + pub fn done(&self) -> bool { + match *self { + OnceState::Done => true, + _ => false, + } } } @@ -80,6 +105,21 @@ impl Once { Once(AtomicU8::new(0)) } + /// Returns the current state of this `Once`. + #[inline] + pub fn state(&self) -> OnceState { + let state = self.0.load(Ordering::Acquire); + if state & DONE_BIT != 0 { + OnceState::Done + } else if state & LOCKED_BIT != 0 { + OnceState::InProgress + } else if state & POISON_BIT != 0 { + OnceState::Poisoned + } else { + OnceState::New + } + } + /// Performs an initialization routine once and only once. The given closure /// will be executed if this is the first time `call_once` has been called, /// and otherwise the routine will *not* be invoked. @@ -160,9 +200,7 @@ impl Once { let mut f = Some(f); self.call_once_slow(true, - &mut |state| unsafe { - f.take().unchecked_unwrap()(state) - }); + &mut |state| unsafe { f.take().unchecked_unwrap()(state) }); } // This is a non-generic function to reduce the monomorphization cost of @@ -267,7 +305,12 @@ impl Once { // At this point we have the lock, so run the closure. Make sure we // properly clean up if the closure panicks. let guard = PanicGuard(self); - f(OnceState(state & POISON_BIT != 0)); + let once_state = if state & POISON_BIT != 0 { + OnceState::Poisoned + } else { + OnceState::New + }; + f(once_state); mem::forget(guard); // Now unlock the state, set the done bit and unpark all threads @@ -348,15 +391,11 @@ mod tests { static O: Once = ONCE_INIT; // poison the once - let t = panic::catch_unwind(|| { - O.call_once(|| panic!()); - }); + let t = panic::catch_unwind(|| { O.call_once(|| panic!()); }); assert!(t.is_err()); // poisoning propagates - let t = panic::catch_unwind(|| { - O.call_once(|| {}); - }); + let t = panic::catch_unwind(|| { O.call_once(|| {}); }); assert!(t.is_err()); // we can subvert poisoning, however @@ -377,9 +416,7 @@ mod tests { static O: Once = ONCE_INIT; // poison the once - let t = panic::catch_unwind(|| { - O.call_once(|| panic!()); - }); + let t = panic::catch_unwind(|| { O.call_once(|| panic!()); }); assert!(t.is_err()); // make sure someone's waiting inside the once via a force @@ -398,9 +435,7 @@ mod tests { // put another waiter on the once let t2 = thread::spawn(|| { let mut called = false; - O.call_once(|| { - called = true; - }); + O.call_once(|| { called = true; }); assert!(!called); }); diff --git a/third_party/rust/parking_lot/src/raw_remutex.rs b/third_party/rust/parking_lot/src/raw_remutex.rs index a118c53f30f2..cc852797e9e3 100644 --- a/third_party/rust/parking_lot/src/raw_remutex.rs +++ b/third_party/rust/parking_lot/src/raw_remutex.rs @@ -23,7 +23,7 @@ fn get_thread_id() -> usize { // reserved value to indicate an empty slot. We instead fall // back to using the address of a thread-local variable, which // is slightly slower but guaranteed to produce a non-zero value. - thread_local!(static KEY: u8 = unsafe { std::mem::uninitialized() }); + thread_local!(static KEY: u8 = unsafe { ::std::mem::uninitialized() }); KEY.with(|x| x as *const _ as usize) } diff --git a/third_party/rust/parking_lot/src/raw_rwlock.rs b/third_party/rust/parking_lot/src/raw_rwlock.rs index e35e0d5e00da..8a5599a60bed 100644 --- a/third_party/rust/parking_lot/src/raw_rwlock.rs +++ b/third_party/rust/parking_lot/src/raw_rwlock.rs @@ -101,14 +101,22 @@ impl RawRwLock { } #[inline(always)] - fn try_lock_shared_fast(&self) -> bool { + fn try_lock_shared_fast(&self, recursive: bool) -> bool { let state = self.state.load(Ordering::Relaxed); - // Even if there are no exclusive locks, we can't allow grabbing a - // shared lock while there are parked threads since that could lead to - // writer starvation. - if state & (LOCKED_BIT | PARKED_BIT) != 0 { - return false; + if !recursive { + // Even if there are no exclusive locks, we can't allow grabbing a + // shared lock while there are parked threads since that could lead to + // writer starvation. + if state & (LOCKED_BIT | PARKED_BIT) != 0 { + return false; + } + } else { + // Allow acquiring a lock even if a thread is parked to avoid + // deadlocks for recursive read locks. + if state & LOCKED_BIT != 0 { + return false; + } } // Use hardware lock elision to avoid cache conflicts when multiple @@ -126,34 +134,34 @@ impl RawRwLock { } #[inline] - pub fn lock_shared(&self) { - if !self.try_lock_shared_fast() { - self.lock_shared_slow(None); + pub fn lock_shared(&self, recursive: bool) { + if !self.try_lock_shared_fast(recursive) { + self.lock_shared_slow(recursive, None); } } #[inline] - pub fn try_lock_shared_until(&self, timeout: Instant) -> bool { - if self.try_lock_shared_fast() { + pub fn try_lock_shared_until(&self, recursive: bool, timeout: Instant) -> bool { + if self.try_lock_shared_fast(recursive) { return true; } - self.lock_shared_slow(Some(timeout)) + self.lock_shared_slow(recursive, Some(timeout)) } #[inline] - pub fn try_lock_shared_for(&self, timeout: Duration) -> bool { - if self.try_lock_shared_fast() { + pub fn try_lock_shared_for(&self, recursive: bool, timeout: Duration) -> bool { + if self.try_lock_shared_fast(recursive) { return true; } - self.lock_shared_slow(Some(Instant::now() + timeout)) + self.lock_shared_slow(recursive, Some(Instant::now() + timeout)) } #[inline] - pub fn try_lock_shared(&self) -> bool { - if self.try_lock_shared_fast() { + pub fn try_lock_shared(&self, recursive: bool) -> bool { + if self.try_lock_shared_fast(recursive) { return true; } - self.try_lock_shared_slow() + self.try_lock_shared_slow(recursive) } #[inline] @@ -359,7 +367,7 @@ impl RawRwLock { #[cold] #[inline(never)] - fn lock_shared_slow(&self, timeout: Option) -> bool { + fn lock_shared_slow(&self, recursive: bool, timeout: Option) -> bool { let mut spinwait = SpinWait::new(); let mut spinwait_shared = SpinWait::new(); let mut state = self.state.load(Ordering::Relaxed); @@ -378,7 +386,7 @@ impl RawRwLock { // Grab the lock if there are no exclusive threads locked or // waiting. However if we were unparked then we are allowed to grab // the lock even if there are pending exclusive threads. - if state & LOCKED_BIT == 0 && (unparked || state & PARKED_BIT == 0) { + if state & LOCKED_BIT == 0 && (unparked || recursive || state & PARKED_BIT == 0) { let new = state.checked_add(SHARED_COUNT_INC) .expect("RwLock shared count overflow"); if self.state @@ -468,10 +476,15 @@ impl RawRwLock { #[cold] #[inline(never)] - pub fn try_lock_shared_slow(&self) -> bool { + pub fn try_lock_shared_slow(&self, recursive: bool) -> bool { let mut state = self.state.load(Ordering::Relaxed); loop { - if state & (LOCKED_BIT | PARKED_BIT) != 0 { + let mask = if recursive { + LOCKED_BIT + } else { + LOCKED_BIT | PARKED_BIT + }; + if state & mask != 0 { return false; } if have_elision() && state == 0 { @@ -546,15 +559,15 @@ impl RawRwLock { // unlocking. If we are then we should set the exclusive // locked bit and tell the thread that we are handing it // the lock directly. - let token; - if result.unparked_threads != 0 && new & SHARED_COUNT_MASK == 0 && - first_token.get().unchecked_unwrap() == TOKEN_EXCLUSIVE && - (force_fair || result.be_fair) { + let token = if result.unparked_threads != 0 && + new & SHARED_COUNT_MASK == 0 && + first_token.get().unchecked_unwrap() == TOKEN_EXCLUSIVE && + (force_fair || result.be_fair) { new |= LOCKED_BIT; - token = TOKEN_HANDOFF; + TOKEN_HANDOFF } else { - token = TOKEN_NORMAL; - } + TOKEN_NORMAL + }; match self.state .compare_exchange_weak(state, diff --git a/third_party/rust/parking_lot/src/remutex.rs b/third_party/rust/parking_lot/src/remutex.rs index f8ed78c61511..971d0e476097 100644 --- a/third_party/rust/parking_lot/src/remutex.rs +++ b/third_party/rust/parking_lot/src/remutex.rs @@ -9,6 +9,7 @@ use std::cell::UnsafeCell; use std::ops::Deref; use std::time::{Duration, Instant}; use std::fmt; +use std::mem; use std::marker::PhantomData; use raw_remutex::RawReentrantMutex; @@ -239,6 +240,7 @@ impl<'a, T: ?Sized + 'a> ReentrantMutexGuard<'a, T> { #[inline] pub fn unlock_fair(self) { self.mutex.raw.unlock(true); + mem::forget(self); } } @@ -308,9 +310,11 @@ mod tests { let _lock = m.try_lock(); let _lock2 = m.try_lock(); thread::spawn(move || { - let lock = m2.try_lock(); - assert!(lock.is_none()); - }).join().unwrap(); + let lock = m2.try_lock(); + assert!(lock.is_none()); + }) + .join() + .unwrap(); let _lock3 = m.try_lock(); } } diff --git a/third_party/rust/parking_lot/src/rwlock.rs b/third_party/rust/parking_lot/src/rwlock.rs index 582e66184b30..bbf461310df4 100644 --- a/third_party/rust/parking_lot/src/rwlock.rs +++ b/third_party/rust/parking_lot/src/rwlock.rs @@ -178,7 +178,7 @@ impl RwLock { /// once it is dropped. #[inline] pub fn read(&self) -> RwLockReadGuard { - self.raw.lock_shared(); + self.raw.lock_shared(false); RwLockReadGuard { rwlock: self, marker: PhantomData, @@ -194,7 +194,7 @@ impl RwLock { /// This function does not block. #[inline] pub fn try_read(&self) -> Option> { - if self.raw.try_lock_shared() { + if self.raw.try_lock_shared(false) { Some(RwLockReadGuard { rwlock: self, marker: PhantomData, @@ -212,7 +212,7 @@ impl RwLock { /// release the shared access when it is dropped. #[inline] pub fn try_read_for(&self, timeout: Duration) -> Option> { - if self.raw.try_lock_shared_for(timeout) { + if self.raw.try_lock_shared_for(false, timeout) { Some(RwLockReadGuard { rwlock: self, marker: PhantomData, @@ -230,7 +230,93 @@ impl RwLock { /// release the shared access when it is dropped. #[inline] pub fn try_read_until(&self, timeout: Instant) -> Option> { - if self.raw.try_lock_shared_until(timeout) { + if self.raw.try_lock_shared_until(false, timeout) { + Some(RwLockReadGuard { + rwlock: self, + marker: PhantomData, + }) + } else { + None + } + } + + /// Locks this rwlock with shared read access, blocking the current thread + /// until it can be acquired. + /// + /// The calling thread will be blocked until there are no more writers which + /// hold the lock. There may be other readers currently inside the lock when + /// this method returns. + /// + /// Unlike `read`, this method is guaranteed to succeed without blocking if + /// another read lock is held at the time of the call. This allows a thread + /// to recursively lock a `RwLock`. However using this method can cause + /// writers to starve since readers no longer block if a writer is waiting + /// for the lock. + /// + /// Returns an RAII guard which will release this thread's shared access + /// once it is dropped. + #[inline] + pub fn read_recursive(&self) -> RwLockReadGuard { + self.raw.lock_shared(true); + RwLockReadGuard { + rwlock: self, + marker: PhantomData, + } + } + + /// Attempts to acquire this rwlock with shared read access. + /// + /// If the access could not be granted at this time, then `None` is returned. + /// Otherwise, an RAII guard is returned which will release the shared access + /// when it is dropped. + /// + /// This method is guaranteed to succeed if another read lock is held at the + /// time of the call. See the documentation for `read_recursive` for details. + /// + /// This function does not block. + #[inline] + pub fn try_read_recursive(&self) -> Option> { + if self.raw.try_lock_shared(true) { + Some(RwLockReadGuard { + rwlock: self, + marker: PhantomData, + }) + } else { + None + } + } + + /// Attempts to acquire this rwlock with shared read access until a timeout + /// is reached. + /// + /// If the access could not be granted before the timeout expires, then + /// `None` is returned. Otherwise, an RAII guard is returned which will + /// release the shared access when it is dropped. + /// + /// This method is guaranteed to succeed without blocking if another read + /// lock is held at the time of the call. See the documentation for + /// `read_recursive` for details. + #[inline] + pub fn try_read_recursive_for(&self, timeout: Duration) -> Option> { + if self.raw.try_lock_shared_for(true, timeout) { + Some(RwLockReadGuard { + rwlock: self, + marker: PhantomData, + }) + } else { + None + } + } + + /// Attempts to acquire this rwlock with shared read access until a timeout + /// is reached. + /// + /// If the access could not be granted before the timeout expires, then + /// `None` is returned. Otherwise, an RAII guard is returned which will + /// release the shared access when it is dropped. + #[inline] + pub fn try_read_recursive_until(&self, timeout: Instant) -> Option> { + if self.raw.try_lock_shared_until(true, timeout) { Some(RwLockReadGuard { rwlock: self, marker: PhantomData, @@ -405,23 +491,44 @@ impl RwLock<()> { /// rwlock. #[inline] pub fn raw_read(&self) { - self.raw.lock_shared(); + self.raw.lock_shared(false); } /// Attempts to acquire this rwlock with shared read access. /// - /// This is similar to `read`, except that a `RwLockReadGuard` is not + /// This is similar to `try_read`, except that a `RwLockReadGuard` is not /// returned. Instead you will need to call `raw_unlock` to release the /// rwlock. #[inline] pub fn raw_try_read(&self) -> bool { - self.raw.try_lock_shared() + self.raw.try_lock_shared(false) + } + + /// Locks this rwlock with shared read access, blocking the current thread + /// until it can be acquired. + /// + /// This is similar to `read_recursive`, except that a `RwLockReadGuard` is + /// not returned. Instead you will need to call `raw_unlock` to release the + /// rwlock. + #[inline] + pub fn raw_read_recursive(&self) { + self.raw.lock_shared(true); + } + + /// Attempts to acquire this rwlock with shared read access. + /// + /// This is similar to `try_read_recursive`, except that a `RwLockReadGuard` is not + /// returned. Instead you will need to call `raw_unlock` to release the + /// rwlock. + #[inline] + pub fn raw_try_read_recursive(&self) -> bool { + self.raw.try_lock_shared(true) } /// Locks this rwlock with exclusive write access, blocking the current /// thread until it can be acquired. /// - /// This is similar to `read`, except that a `RwLockReadGuard` is not + /// This is similar to `write`, except that a `RwLockReadGuard` is not /// returned. Instead you will need to call `raw_unlock` to release the /// rwlock. #[inline] @@ -431,7 +538,7 @@ impl RwLock<()> { /// Attempts to lock this rwlock with exclusive write access. /// - /// This is similar to `read`, except that a `RwLockReadGuard` is not + /// This is similar to `try_write`, except that a `RwLockReadGuard` is not /// returned. Instead you will need to call `raw_unlock` to release the /// rwlock. #[inline] @@ -472,6 +579,7 @@ impl<'a, T: ?Sized + 'a> RwLockReadGuard<'a, T> { #[inline] pub fn unlock_fair(self) { self.rwlock.raw.unlock_shared(true); + mem::forget(self); } } @@ -525,6 +633,7 @@ impl<'a, T: ?Sized + 'a> RwLockWriteGuard<'a, T> { #[inline] pub fn unlock_fair(self) { self.rwlock.raw.unlock_exclusive(true); + mem::forget(self); } } @@ -561,6 +670,7 @@ mod tests { use std::thread; use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; + use std::time::Duration; use RwLock; #[derive(Eq, PartialEq, Debug)] @@ -788,14 +898,12 @@ mod tests { let mut handles = Vec::new(); for _ in 0..8 { let x = x.clone(); - handles.push(thread::spawn(move || { - for _ in 0..100 { - let mut writer = x.write(); - *writer += 1; - let cur_val = *writer; - let reader = writer.downgrade(); - assert_eq!(cur_val, *reader); - } + handles.push(thread::spawn(move || for _ in 0..100 { + let mut writer = x.write(); + *writer += 1; + let cur_val = *writer; + let reader = writer.downgrade(); + assert_eq!(cur_val, *reader); })); } for handle in handles { @@ -803,4 +911,16 @@ mod tests { } assert_eq!(*x.read(), 800); } + + #[test] + fn test_rwlock_recursive() { + let arc = Arc::new(RwLock::new(1)); + let arc2 = arc.clone(); + let _lock1 = arc.read(); + thread::spawn(move || { let _lock = arc2.write(); }); + thread::sleep(Duration::from_millis(100)); + + // A normal read would block here since there is a pending writer + let _lock2 = arc.read_recursive(); + } } diff --git a/third_party/rust/stable_deref_trait/.cargo-checksum.json b/third_party/rust/stable_deref_trait/.cargo-checksum.json new file mode 100644 index 000000000000..59ebec4b5f31 --- /dev/null +++ b/third_party/rust/stable_deref_trait/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","Cargo.toml":"409f95e74eb045b1e188b71514c785feb0b55e69afa3545b72678115b46448fb","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"5e05b024f653a5ce199e77cbbbd42fb5553562ec714b819421ed0c3e552a75d7","README.md":"4a6ab55d5ce8d3ca804db6886b1d926dc12dbc874a526ec5febca61149e2c6c0","src/lib.rs":"868e71a2538bdec347a92bc7e3d16b0f5fa6a2be6a0ade4de37fd373a85626c5"},"package":"15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"} \ No newline at end of file diff --git a/third_party/rust/stable_deref_trait/.cargo-ok b/third_party/rust/stable_deref_trait/.cargo-ok new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/third_party/rust/stable_deref_trait/Cargo.toml b/third_party/rust/stable_deref_trait/Cargo.toml new file mode 100644 index 000000000000..139e558a3457 --- /dev/null +++ b/third_party/rust/stable_deref_trait/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "stable_deref_trait" +version = "1.0.0" +authors = ["Robert Grosse "] +license = "MIT/Apache-2.0" +readme = "README.md" +repository = "https://github.com/storyyeller/stable_deref_trait" +documentation = "https://docs.rs/stable_deref_trait/1.0.0/stable_deref_trait" +categories = ["no-std"] +description = """ +An unsafe marker trait for types like Box and Rc that dereference to a stable address even when moved, and hence can be used with libraries such as owning_ref and rental. +""" + +[features] +default = ["std"] +std = [] + +[dependencies] diff --git a/third_party/rust/stable_deref_trait/LICENSE-APACHE b/third_party/rust/stable_deref_trait/LICENSE-APACHE new file mode 100644 index 000000000000..16fe87b06e80 --- /dev/null +++ b/third_party/rust/stable_deref_trait/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/third_party/rust/stable_deref_trait/LICENSE-MIT b/third_party/rust/stable_deref_trait/LICENSE-MIT new file mode 100644 index 000000000000..3bf61a09010e --- /dev/null +++ b/third_party/rust/stable_deref_trait/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2017 Robert Grosse + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/third_party/rust/stable_deref_trait/README.md b/third_party/rust/stable_deref_trait/README.md new file mode 100644 index 000000000000..7a3a7b0b3db4 --- /dev/null +++ b/third_party/rust/stable_deref_trait/README.md @@ -0,0 +1,5 @@ +This crate defines an unsafe marker trait, StableDeref, for container types which deref to a fixed address which is valid even when the containing type is moved. For example, Box, Vec, Rc, Arc and String implement this trait. Additionally, it defines CloneStableDeref for types like Rc where clones deref to the same address. + +It is intended to be used by crates such as [owning_ref](https://crates.io/crates/owning_ref) and [rental](https://crates.io/crates/rental), as well as library authors who wish to make their code interoperable with such crates. For example, if you write a custom Vec type, you can implement StableDeref, and then users will be able to use your custom Vec type together with owning_ref and rental. + +no_std support can be enabled by disabling default features (specifically "std"). In this case, the trait will not be implemented for the std types mentioned above, but you can still use it for your own types. diff --git a/third_party/rust/stable_deref_trait/src/lib.rs b/third_party/rust/stable_deref_trait/src/lib.rs new file mode 100644 index 000000000000..f3432a8b416c --- /dev/null +++ b/third_party/rust/stable_deref_trait/src/lib.rs @@ -0,0 +1,172 @@ +// Copyright 2017 Robert Grosse + +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +/*! +This module defines an unsafe marker trait, StableDeref, for container types that deref to a fixed address which is valid even when the containing type is moved. For example, Box, Vec, Rc, Arc and String implement this trait. Additionally, it defines CloneStableDeref for types like Rc where clones deref to the same address. + +It is intended to be used by crates such as [owning_ref](https://crates.io/crates/owning_ref) and [rental](https://crates.io/crates/rental), as well as library authors who wish to make their code interoperable with such crates. For example, if you write a custom Vec type, you can implement StableDeref, and then users will be able to use your custom type together with owning_ref and rental. + +no_std support can be enabled by disabling default features (specifically "std"). In this case, the trait will not be implemented for the std types mentioned above, but you can still use it for your own types. +*/ + +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(feature = "std")] +extern crate core; + +use core::ops::Deref; + + +/** +An unsafe marker trait for types that deref to a stable address, even when moved. For example, this is implemented by Box, Vec, Rc, Arc and String, among others. Even when a Box is moved, the underlying storage remains at a fixed location. + +More specifically, implementors must ensure that the result of calling deref() is valid for the lifetime of the object, not just the lifetime of the borrow, and that the deref is valid even if the object is moved. Also, it must be valid even after invoking arbitrary &self methods or doing anything transitively accessible from &Self. If Self also implements DerefMut, the same restrictions apply to deref_mut() and it must remain valid if anything transitively accessible from the result of deref_mut() is mutated/called. Additionally, multiple calls to deref, (and deref_mut if implemented) must return the same address. No requirements are placed on &mut self methods other than deref_mut() and drop(), if applicable. + +Basically, it must be valid to convert the result of deref() to a pointer, and later dereference that pointer, as long as the original object is still live, even if it has been moved or &self methods have been called on it. If DerefMut is also implemented, it must be valid to get pointers from deref() and deref_mut() and dereference them while the object is live, as long as you don't simultaneously dereference both of them. + +Additionally, Deref and DerefMut implementations must not panic, but users of the trait are not allowed to rely on this fact (so that this restriction can be removed later without breaking backwards compatibility, should the need arise). + +Here are some examples to help illustrate the requirements for implementing this trait: + +``` +# use std::ops::Deref; +struct Foo(u8); +impl Deref for Foo { + type Target = u8; + fn deref(&self) -> &Self::Target { &self.0 } +} +``` + +Foo cannot implement StableDeref because the int will move when Foo is moved, invalidating the result of deref(). + +``` +# use std::ops::Deref; +struct Foo(Box); +impl Deref for Foo { + type Target = u8; + fn deref(&self) -> &Self::Target { &*self.0 } +} +``` + +Foo can safely implement StableDeref, due to the use of Box. + + +``` +# use std::ops::Deref; +# use std::ops::DerefMut; +# use std::rc::Rc; +#[derive(Clone)] +struct Foo(Rc); +impl Deref for Foo { + type Target = u8; + fn deref(&self) -> &Self::Target { &*self.0 } +} +impl DerefMut for Foo { + fn deref_mut(&mut self) -> &mut Self::Target { Rc::make_mut(&mut self.0) } +} +``` + +This is a simple implementation of copy-on-write: Foo's deref_mut will copy the underlying int if it is not uniquely owned, ensuring unique access at the point where deref_mut() returns. However, Foo cannot implement StableDeref because calling deref_mut(), followed by clone().deref() will result in mutable and immutable references to the same location. Note that if the DerefMut implementation were removed, Foo could safely implement StableDeref. Likewise, if the Clone implementation were removed, it would be safe to implement StableDeref, although Foo would not be very useful in that case, (without clones, the rc will always be uniquely owned). + + +``` +# use std::ops::Deref; +struct Foo; +impl Deref for Foo { + type Target = str; + fn deref(&self) -> &Self::Target { &"Hello" } +} +``` +Foo can safely implement StableDeref. It doesn't own the data being derefed, but the data is gaurenteed to live long enough, due to it being 'static. + +``` +# use std::ops::Deref; +# use std::cell::Cell; +struct Foo(Cell); +impl Deref for Foo { + type Target = str; + fn deref(&self) -> &Self::Target { + let b = self.0.get(); + self.0.set(!b); + if b { &"Hello" } else { &"World" } + } +} +``` +Foo cannot safely implement StableDeref, even though every possible result of deref lives long enough. In order to safely implement StableAddress, multiple calls to deref must return the same result. + +``` +# use std::ops::Deref; +# use std::ops::DerefMut; +struct Foo(Box<(u8, u8)>); +impl Deref for Foo { + type Target = u8; + fn deref(&self) -> &Self::Target { &self.0.deref().0 } +} +impl DerefMut for Foo { + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0.deref_mut().1 } +} +``` + +Foo cannot implement StableDeref because deref and deref_mut return different addresses. + + +*/ +pub unsafe trait StableDeref: Deref {} + +/** +An unsafe marker trait for types where clones deref to the same address. This has all the requirements of StableDeref, and additionally requires that after calling clone(), both the old and new value deref to the same address. For example, Rc and Arc implement CloneStableDeref, but Box and Vec do not. + +Note that a single type should never implement both DerefMut and CloneStableDeref. If it did, this would let you get two mutable references to the same location, by cloning and then calling deref_mut() on both values. +*/ +pub unsafe trait CloneStableDeref: StableDeref + Clone {} + +///////////////////////////////////////////////////////////////////////////// +// std types integration +///////////////////////////////////////////////////////////////////////////// + +#[cfg(feature = "std")] +use std::boxed::Box; +#[cfg(feature = "std")] +use std::rc::Rc; +#[cfg(feature = "std")] +use std::sync::Arc; +#[cfg(feature = "std")] +use std::sync::{MutexGuard, RwLockReadGuard, RwLockWriteGuard}; +#[cfg(feature = "std")] +use std::cell::{Ref, RefMut}; + +#[cfg(feature = "std")] +unsafe impl StableDeref for Box {} +#[cfg(feature = "std")] +unsafe impl StableDeref for Vec {} +#[cfg(feature = "std")] +unsafe impl StableDeref for String {} + +#[cfg(feature = "std")] +unsafe impl StableDeref for Rc {} +#[cfg(feature = "std")] +unsafe impl CloneStableDeref for Rc {} +#[cfg(feature = "std")] +unsafe impl StableDeref for Arc {} +#[cfg(feature = "std")] +unsafe impl CloneStableDeref for Arc {} + +#[cfg(feature = "std")] +unsafe impl<'a, T: ?Sized> StableDeref for Ref<'a, T> {} +#[cfg(feature = "std")] +unsafe impl<'a, T: ?Sized> StableDeref for RefMut<'a, T> {} +#[cfg(feature = "std")] +unsafe impl<'a, T: ?Sized> StableDeref for MutexGuard<'a, T> {} +#[cfg(feature = "std")] +unsafe impl<'a, T: ?Sized> StableDeref for RwLockReadGuard<'a, T> {} +#[cfg(feature = "std")] +unsafe impl<'a, T: ?Sized> StableDeref for RwLockWriteGuard<'a, T> {} + +unsafe impl<'a, T: ?Sized> StableDeref for &'a T {} +unsafe impl<'a, T: ?Sized> CloneStableDeref for &'a T {} +unsafe impl<'a, T: ?Sized> StableDeref for &'a mut T {} diff --git a/toolkit/library/gtest/rust/Cargo.lock b/toolkit/library/gtest/rust/Cargo.lock index 5b413e478940..3e438284625c 100644 --- a/toolkit/library/gtest/rust/Cargo.lock +++ b/toolkit/library/gtest/rust/Cargo.lock @@ -381,7 +381,7 @@ dependencies = [ "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "nsstring_vendor 0.1.0", - "parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.19.0", "style 0.0.1", "style_traits 0.0.1", @@ -606,15 +606,18 @@ dependencies = [ [[package]] name = "owning_ref" -version = "0.2.4" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "parking_lot" -version = "0.3.8" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "owning_ref 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "thread-id 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -882,6 +885,7 @@ name = "servo_arc" version = "0.0.1" dependencies = [ "nodrop 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -904,6 +908,11 @@ name = "smallvec" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "stable_deref_trait" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "strsim" version = "0.6.0" @@ -935,7 +944,8 @@ dependencies = [ "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "pdqsort 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "precomputed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1307,8 +1317,8 @@ dependencies = [ "checksum num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a225d1e2717567599c24f88e49f00856c6e825a12125181ee42c4257e3688d39" "checksum odds 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "c3df9b730298cea3a1c3faa90b7e2f9df3a9c400d0936d6015e6165734eefcba" "checksum ordered-float 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "da12c96037889ae0be29dd2bdd260e5a62a7df24e6466d5a15bb8131c1c200a8" -"checksum owning_ref 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9d52571ddcb42e9c900c901a18d8d67e393df723fcd51dd59c5b1a85d0acb6cc" -"checksum parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "fa12d706797d42551663426a45e2db2e0364bd1dbf6aeada87e89c5f981f43e9" +"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" +"checksum parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "37f364e2ce5efa24c7d0b6646d5bb61145551a0112f107ffd7499f1a3e322fbd" "checksum parking_lot_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "56a19dcbb5d1e32b6cccb8a9aa1fc2a38418c8699652e735e2bf391a3dc0aa16" "checksum pdqsort 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ceca1642c89148ca05611cc775a0c383abef355fc4907c4e95f49f7b09d6287c" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" @@ -1341,6 +1351,7 @@ dependencies = [ "checksum siphasher 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ffc669b726f2bc9a3bcff66e5e23b56ba6bf70e22a34c3d7b6d0b3450b65b84" "checksum smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4f8266519bc1d17d0b5b16f6c21295625d562841c708f6376f49028a43e9c11e" "checksum smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e40af10aafe98b4d8294ae8388d8a5cd0707c65d364872efe72d063ec44bee0" +"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "27e31aa4b09b9f4cb12dff3c30ba503e17b1a624413d764d32dab76e3920e5bc" diff --git a/toolkit/library/rust/Cargo.lock b/toolkit/library/rust/Cargo.lock index cf452dff3f47..6062b0fd939f 100644 --- a/toolkit/library/rust/Cargo.lock +++ b/toolkit/library/rust/Cargo.lock @@ -379,7 +379,7 @@ dependencies = [ "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "nsstring_vendor 0.1.0", - "parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.19.0", "style 0.0.1", "style_traits 0.0.1", @@ -593,15 +593,18 @@ dependencies = [ [[package]] name = "owning_ref" -version = "0.2.4" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "parking_lot" -version = "0.3.8" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "owning_ref 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "thread-id 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -869,6 +872,7 @@ name = "servo_arc" version = "0.0.1" dependencies = [ "nodrop 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -891,6 +895,11 @@ name = "smallvec" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "stable_deref_trait" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "strsim" version = "0.6.0" @@ -922,7 +931,8 @@ dependencies = [ "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "pdqsort 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "precomputed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1294,8 +1304,8 @@ dependencies = [ "checksum num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a225d1e2717567599c24f88e49f00856c6e825a12125181ee42c4257e3688d39" "checksum odds 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "c3df9b730298cea3a1c3faa90b7e2f9df3a9c400d0936d6015e6165734eefcba" "checksum ordered-float 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "da12c96037889ae0be29dd2bdd260e5a62a7df24e6466d5a15bb8131c1c200a8" -"checksum owning_ref 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9d52571ddcb42e9c900c901a18d8d67e393df723fcd51dd59c5b1a85d0acb6cc" -"checksum parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "fa12d706797d42551663426a45e2db2e0364bd1dbf6aeada87e89c5f981f43e9" +"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" +"checksum parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "37f364e2ce5efa24c7d0b6646d5bb61145551a0112f107ffd7499f1a3e322fbd" "checksum parking_lot_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "56a19dcbb5d1e32b6cccb8a9aa1fc2a38418c8699652e735e2bf391a3dc0aa16" "checksum pdqsort 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ceca1642c89148ca05611cc775a0c383abef355fc4907c4e95f49f7b09d6287c" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" @@ -1328,6 +1338,7 @@ dependencies = [ "checksum siphasher 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ffc669b726f2bc9a3bcff66e5e23b56ba6bf70e22a34c3d7b6d0b3450b65b84" "checksum smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4f8266519bc1d17d0b5b16f6c21295625d562841c708f6376f49028a43e9c11e" "checksum smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e40af10aafe98b4d8294ae8388d8a5cd0707c65d364872efe72d063ec44bee0" +"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "27e31aa4b09b9f4cb12dff3c30ba503e17b1a624413d764d32dab76e3920e5bc"