Bug 1894756 - Remove owning_ref. r=firefox-style-system-reviewers,supply-chain-reviewers,zrhoffman,sylvestre

The only use of this type used to be carrying around an owning reference
to a thread-local. However, since bug 1577439 we're leaking the
allocation intentionally, so we can simplify the code to explicitly use
`Box::leak()`, which in turn removes all unsafe usage around these, and
allows us to drop the owning_ref dependency altogether.

Differential Revision: https://phabricator.services.mozilla.com/D209912
This commit is contained in:
Emilio Cobos Álvarez 2024-05-09 17:11:52 +00:00
Родитель a1b2e60eec
Коммит 1ebcef86f4
12 изменённых файлов: 12 добавлений и 2170 удалений

10
Cargo.lock сгенерированный
Просмотреть файл

@ -4340,15 +4340,6 @@ dependencies = [
"log",
]
[[package]]
name = "owning_ref"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce"
dependencies = [
"stable_deref_trait",
]
[[package]]
name = "oxilangtag"
version = "0.1.3"
@ -5489,7 +5480,6 @@ dependencies = [
"num-integer",
"num-traits",
"num_cpus",
"owning_ref",
"parking_lot",
"precomputed-hash",
"rayon",

Просмотреть файл

@ -52,7 +52,6 @@ num_cpus = {version = "1.1.0"}
num-integer = "0.1"
num-traits = "0.2"
num-derive = "0.4"
owning_ref = "0.4"
parking_lot = "0.12"
precomputed-hash = "0.1.1"
rayon = "1"

Просмотреть файл

@ -10,11 +10,8 @@
use crate::dom::{SendElement, TElement};
use crate::LocalName;
use atomic_refcell::{AtomicRefCell, AtomicRefMut};
use owning_ref::OwningHandle;
use selectors::bloom::BloomFilter;
use servo_arc::Arc;
use smallvec::SmallVec;
use std::mem::ManuallyDrop;
thread_local! {
/// Bloom filters are large allocations, so we store them in thread-local storage
@ -24,10 +21,12 @@ thread_local! {
/// We intentionally leak this from TLS because we don't have the guarantee
/// of TLS destructors to run in worker threads.
///
/// Also, leaking it guarantees that we can borrow it indefinitely.
///
/// We could change this once https://github.com/rayon-rs/rayon/issues/688
/// is fixed, hopefully.
static BLOOM_KEY: ManuallyDrop<Arc<AtomicRefCell<BloomFilter>>> =
ManuallyDrop::new(Arc::new_leaked(Default::default()));
/// is fixed, hopefully, which point we'd need to change the filter member below to be an
/// arc and carry an owning reference around or so.
static BLOOM_KEY: &'static AtomicRefCell<BloomFilter> = Box::leak(Default::default());
}
/// A struct that allows us to fast-reject deep descendant selectors avoiding
@ -66,7 +65,7 @@ pub struct StyleBloom<E: TElement> {
/// was created. We use AtomicRefCell so that this is all |Send|, which allows
/// StyleBloom to live in ThreadLocalStyleContext, which is dropped from the
/// parent thread.
filter: OwningHandle<Arc<AtomicRefCell<BloomFilter>>, AtomicRefMut<'static, BloomFilter>>,
filter: AtomicRefMut<'static, BloomFilter>,
/// The stack of elements that this bloom filter contains, along with the
/// number of hashes pushed for each element.
@ -152,9 +151,7 @@ impl<E: TElement> StyleBloom<E> {
// See https://github.com/servo/servo/pull/18420#issuecomment-328769322
#[inline(never)]
pub fn new() -> Self {
let bloom_arc = BLOOM_KEY.with(|b| Arc::clone(&*b));
let filter =
OwningHandle::new_with_fn(bloom_arc, |x| unsafe { x.as_ref() }.unwrap().borrow_mut());
let filter = BLOOM_KEY.with(|b| b.borrow_mut());
debug_assert!(
filter.is_zeroed(),
"Forgot to zero the bloom filter last time"

Просмотреть файл

@ -76,13 +76,11 @@ use crate::style_resolver::{PrimaryStyle, ResolvedElementStyles};
use crate::stylist::Stylist;
use crate::values::AtomIdent;
use atomic_refcell::{AtomicRefCell, AtomicRefMut};
use owning_ref::OwningHandle;
use selectors::matching::{NeedsSelectorFlags, SelectorCaches, VisitedHandlingMode};
use servo_arc::Arc;
use smallbitvec::SmallBitVec;
use smallvec::SmallVec;
use std::marker::PhantomData;
use std::mem::{self, ManuallyDrop};
use std::mem;
use std::ops::Deref;
use std::ptr::NonNull;
use uluru::LRUCache;
@ -535,12 +533,11 @@ impl<E: TElement> SharingCache<E> {
/// [2] https://github.com/rust-lang/rust/issues/13707
type SharingCache<E> = SharingCacheBase<StyleSharingCandidate<E>>;
type TypelessSharingCache = SharingCacheBase<FakeCandidate>;
type StoredSharingCache = Arc<AtomicRefCell<TypelessSharingCache>>;
thread_local! {
// See the comment on bloom.rs about why do we leak this.
static SHARING_CACHE_KEY: ManuallyDrop<StoredSharingCache> =
ManuallyDrop::new(Arc::new_leaked(Default::default()));
static SHARING_CACHE_KEY: &'static AtomicRefCell<TypelessSharingCache> =
Box::leak(Default::default());
}
/// An LRU cache of the last few nodes seen, so that we can aggressively try to
@ -550,7 +547,7 @@ thread_local! {
/// storing nodes here temporarily is safe.
pub struct StyleSharingCache<E: TElement> {
/// The LRU cache, with the type cast away to allow persisting the allocation.
cache_typeless: OwningHandle<StoredSharingCache, AtomicRefMut<'static, TypelessSharingCache>>,
cache_typeless: AtomicRefMut<'static, TypelessSharingCache>,
/// Bind this structure to the lifetime of E, since that's what we effectively store.
marker: PhantomData<SendElement<E>>,
/// The DOM depth we're currently at. This is used as an optimization to
@ -593,9 +590,7 @@ impl<E: TElement> StyleSharingCache<E> {
mem::align_of::<SharingCache<E>>(),
mem::align_of::<TypelessSharingCache>()
);
let cache_arc = SHARING_CACHE_KEY.with(|c| Arc::clone(&*c));
let cache =
OwningHandle::new_with_fn(cache_arc, |x| unsafe { x.as_ref() }.unwrap().borrow_mut());
let cache = SHARING_CACHE_KEY.with(|c| c.borrow_mut());
debug_assert!(cache.is_empty());
StyleSharingCache {

Просмотреть файл

@ -628,10 +628,6 @@ criteria = "safe-to-deploy"
version = "1.12.0"
criteria = "safe-to-deploy"
[[exemptions.owning_ref]]
version = "0.4.1"
criteria = "safe-to-deploy"
[[exemptions.packed_simd]]
version = "0.3.8"
criteria = "safe-to-deploy"

Просмотреть файл

@ -1 +0,0 @@
{"files":{"CHANGELOG.md":"9a3880e4d5435ca03c0197c45d4ce6b6db6d3fb7eda855f297bafc2ec28af836","Cargo.toml":"91184e6b143ddf621fe7e6757fb28d8eb4c0e01f541fbd0dc440bf076ebfd20d","LICENSE":"90bc15ed094593083fd129fdd1a03607be80fe8839c5564616a5961ab7f7a194","README.md":"0dfea39ad1662ed0a61bb1453eafc207a53dfe577e7846c87d3a5161574fdb12","src/lib.rs":"2e423e210bf2e3ee5e4c426b9a3c9b7756fc434beff1ccf9afa48704e4ac993d"},"package":"6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce"}

8
third_party/rust/owning_ref/CHANGELOG.md поставляемый
Просмотреть файл

@ -1,8 +0,0 @@
# Changelog
## [0.4.1] - 2020-02-27
### Added
- `map_with_owner` (#51)
### Changed
- Use dyn for trait objects (#53)

24
third_party/rust/owning_ref/Cargo.toml поставляемый
Просмотреть файл

@ -1,24 +0,0 @@
# 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 = "owning_ref"
version = "0.4.1"
authors = ["Marvin Löbel <loebel.marvin@gmail.com>"]
description = "A library for creating references that carry their owner with them."
documentation = "http://kimundi.github.io/owning-ref-rs/owning_ref/index.html"
readme = "README.md"
keywords = ["reference", "sibling", "field", "owning"]
license = "MIT"
repository = "https://github.com/Kimundi/owning-ref-rs"
[dependencies.stable_deref_trait]
version = "1.0.0"

21
third_party/rust/owning_ref/LICENSE поставляемый
Просмотреть файл

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Marvin Löbel
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.

64
third_party/rust/owning_ref/README.md поставляемый
Просмотреть файл

@ -1,64 +0,0 @@
[![Build Status](https://travis-ci.org/Kimundi/owning-ref-rs.svg)](https://travis-ci.org/Kimundi/owning-ref-rs)
[![Crate](https://img.shields.io/crates/v/owning_ref.svg)](https://crates.io/crates/owning_ref)
[![Docs](https://docs.rs/owning_ref/badge.svg)](https://docs.rs/owning_ref)
owning-ref-rs
==============
A library for creating references that carry their owner with them.
This can sometimes be useful because Rust borrowing rules normally prevent
moving a type that has been borrowed from. For example, this kind of code gets rejected:
```rust
fn return_owned_and_referenced<'a>() -> (Vec<u8>, &'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<Vec<u8>, [u8]> {
let v = vec![1, 2, 3, 4];
let or = OwningRef::new(v);
let or = or.map(|v| &v[1..3]);
or
}
```
## Getting Started
To get started, add the following to `Cargo.toml`.
```toml
owning_ref = "0.4.1"
```
...and see the [docs](http://kimundi.github.io/owning-ref-rs/owning_ref/index.html) for how to use it.
## Example
```rust
extern crate owning_ref;
use owning_ref::BoxRef;
fn main() {
// Create an array owned by a Box.
let arr = Box::new([1, 2, 3, 4]) as Box<[i32]>;
// Transfer into a BoxRef.
let arr: BoxRef<[i32]> = BoxRef::new(arr);
assert_eq!(&*arr, &[1, 2, 3, 4]);
// We can slice the array without losing ownership or changing type.
let arr: BoxRef<[i32]> = arr.map(|arr| &arr[1..3]);
assert_eq!(&*arr, &[2, 3]);
// Also works for Arc, Rc, String and Vec!
}
```

2016
third_party/rust/owning_ref/src/lib.rs поставляемый

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -3603,7 +3603,6 @@ SOFTWARE.
<li><code>devtools/shared/natural-sort.js</code></li>
<li><code>devtools/shared/node-properties/node-properties.js</code></li>
<li><code>third_party/rust/ordered-float</code></li>
<li><code>third_party/rust/owning_ref</code></li>
<li><code>third_party/rust/phf</code>,
<code>third_party/rust/phf_codegen</code>,
<code>third_party/rust/phf_generator</code>, and