Skip to content

Commit 2a55274

Browse files
committed
Auto merge of #82999 - cuviper:rustc-rayon-0.3.1, r=Mark-Simulacrum
Update to rustc-rayon 0.3.1 This pulls in rust-lang/rustc-rayon#8 to fix #81425. (h/t `@ammaraskar)` That revealed weak constraints on `rustc_arena::DropArena`, because its `DropType` was holding type-erased raw pointers to generic `T`. We can implement `Send` for `DropType` (under `cfg(parallel_compiler)`) by requiring all `T: Send` before they're type-erased.
2 parents 3963c3d + f7e75a2 commit 2a55274

File tree

8 files changed

+41
-42
lines changed

8 files changed

+41
-42
lines changed

Cargo.lock

+8-26
Original file line numberDiff line numberDiff line change
@@ -839,15 +839,6 @@ dependencies = [
839839
"scopeguard",
840840
]
841841

842-
[[package]]
843-
name = "crossbeam-queue"
844-
version = "0.1.2"
845-
source = "registry+https://github.com/rust-lang/crates.io-index"
846-
checksum = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"
847-
dependencies = [
848-
"crossbeam-utils 0.6.6",
849-
]
850-
851842
[[package]]
852843
name = "crossbeam-queue"
853844
version = "0.2.3"
@@ -859,16 +850,6 @@ dependencies = [
859850
"maybe-uninit",
860851
]
861852

862-
[[package]]
863-
name = "crossbeam-utils"
864-
version = "0.6.6"
865-
source = "registry+https://github.com/rust-lang/crates.io-index"
866-
checksum = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
867-
dependencies = [
868-
"cfg-if 0.1.10",
869-
"lazy_static",
870-
]
871-
872853
[[package]]
873854
name = "crossbeam-utils"
874855
version = "0.7.2"
@@ -3008,7 +2989,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
30082989
checksum = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280"
30092990
dependencies = [
30102991
"crossbeam-deque",
3011-
"crossbeam-queue 0.2.3",
2992+
"crossbeam-queue",
30122993
"crossbeam-utils 0.7.2",
30132994
"lazy_static",
30142995
"num_cpus",
@@ -3576,9 +3557,9 @@ dependencies = [
35763557

35773558
[[package]]
35783559
name = "rustc-rayon"
3579-
version = "0.3.0"
3560+
version = "0.3.1"
35803561
source = "registry+https://github.com/rust-lang/crates.io-index"
3581-
checksum = "f32767f90d938f1b7199a174ef249ae1924f6e5bbdb9d112fea141e016f25b3a"
3562+
checksum = "ed7d6a39f8bfd4421ce720918234d1e672b83824c91345b47c93746839cf1629"
35823563
dependencies = [
35833564
"crossbeam-deque",
35843565
"either",
@@ -3587,13 +3568,13 @@ dependencies = [
35873568

35883569
[[package]]
35893570
name = "rustc-rayon-core"
3590-
version = "0.3.0"
3571+
version = "0.3.1"
35913572
source = "registry+https://github.com/rust-lang/crates.io-index"
3592-
checksum = "ea2427831f0053ea3ea73559c8eabd893133a51b251d142bacee53c62a288cb3"
3573+
checksum = "e94187d9ea3e8c38fafdbc38acb94eafa7ce155867f6ccb13830466a0d0db8c6"
35933574
dependencies = [
35943575
"crossbeam-deque",
3595-
"crossbeam-queue 0.1.2",
3596-
"crossbeam-utils 0.6.6",
3576+
"crossbeam-queue",
3577+
"crossbeam-utils 0.7.2",
35973578
"lazy_static",
35983579
"num_cpus",
35993580
]
@@ -3656,6 +3637,7 @@ dependencies = [
36563637
name = "rustc_arena"
36573638
version = "0.0.0"
36583639
dependencies = [
3640+
"rustc_data_structures",
36593641
"smallvec 1.6.1",
36603642
]
36613643

compiler/rustc_arena/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ version = "0.0.0"
55
edition = "2018"
66

77
[dependencies]
8+
rustc_data_structures = { path = "../rustc_data_structures" }
89
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }

compiler/rustc_arena/src/lib.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#![feature(min_specialization)]
1818
#![cfg_attr(test, feature(test))]
1919

20+
use rustc_data_structures::sync;
2021
use smallvec::SmallVec;
2122

2223
use std::alloc::Layout;
@@ -556,8 +557,19 @@ struct DropType {
556557
obj: *mut u8,
557558
}
558559

559-
unsafe fn drop_for_type<T>(to_drop: *mut u8) {
560-
std::ptr::drop_in_place(to_drop as *mut T)
560+
// SAFETY: we require `T: Send` before type-erasing into `DropType`.
561+
#[cfg(parallel_compiler)]
562+
unsafe impl sync::Send for DropType {}
563+
564+
impl DropType {
565+
#[inline]
566+
unsafe fn new<T: sync::Send>(obj: *mut T) -> Self {
567+
unsafe fn drop_for_type<T>(to_drop: *mut u8) {
568+
std::ptr::drop_in_place(to_drop as *mut T)
569+
}
570+
571+
DropType { drop_fn: drop_for_type::<T>, obj: obj as *mut u8 }
572+
}
561573
}
562574

563575
impl Drop for DropType {
@@ -585,21 +597,26 @@ pub struct DropArena {
585597

586598
impl DropArena {
587599
#[inline]
588-
pub unsafe fn alloc<T>(&self, object: T) -> &mut T {
600+
pub unsafe fn alloc<T>(&self, object: T) -> &mut T
601+
where
602+
T: sync::Send,
603+
{
589604
let mem = self.arena.alloc_raw(Layout::new::<T>()) as *mut T;
590605
// Write into uninitialized memory.
591606
ptr::write(mem, object);
592607
let result = &mut *mem;
593608
// Record the destructor after doing the allocation as that may panic
594609
// and would cause `object`'s destructor to run twice if it was recorded before.
595-
self.destructors
596-
.borrow_mut()
597-
.push(DropType { drop_fn: drop_for_type::<T>, obj: result as *mut T as *mut u8 });
610+
self.destructors.borrow_mut().push(DropType::new(result));
598611
result
599612
}
600613

601614
#[inline]
602-
pub unsafe fn alloc_from_iter<T, I: IntoIterator<Item = T>>(&self, iter: I) -> &mut [T] {
615+
pub unsafe fn alloc_from_iter<T, I>(&self, iter: I) -> &mut [T]
616+
where
617+
T: sync::Send,
618+
I: IntoIterator<Item = T>,
619+
{
603620
let mut vec: SmallVec<[_; 8]> = iter.into_iter().collect();
604621
if vec.is_empty() {
605622
return &mut [];
@@ -620,8 +637,7 @@ impl DropArena {
620637
// Record the destructors after doing the allocation as that may panic
621638
// and would cause `object`'s destructor to run twice if it was recorded before.
622639
for i in 0..len {
623-
destructors
624-
.push(DropType { drop_fn: drop_for_type::<T>, obj: start_ptr.add(i) as *mut u8 });
640+
destructors.push(DropType::new(start_ptr.add(i)));
625641
}
626642

627643
slice::from_raw_parts_mut(start_ptr, len)

compiler/rustc_data_structures/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ rustc_graphviz = { path = "../rustc_graphviz" }
1919
cfg-if = "0.1.2"
2020
crossbeam-utils = { version = "0.7", features = ["nightly"] }
2121
stable_deref_trait = "1.0.0"
22-
rayon = { version = "0.3.0", package = "rustc-rayon" }
23-
rayon-core = { version = "0.3.0", package = "rustc-rayon-core" }
22+
rayon = { version = "0.3.1", package = "rustc-rayon" }
23+
rayon-core = { version = "0.3.1", package = "rustc-rayon-core" }
2424
rustc-hash = "1.1.0"
2525
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
2626
rustc_index = { path = "../rustc_index", package = "rustc_index" }

compiler/rustc_interface/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ doctest = false
1010
[dependencies]
1111
libc = "0.2"
1212
tracing = "0.1"
13-
rustc-rayon-core = "0.3.0"
14-
rayon = { version = "0.3.0", package = "rustc-rayon" }
13+
rustc-rayon-core = "0.3.1"
14+
rayon = { version = "0.3.1", package = "rustc-rayon" }
1515
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
1616
rustc_ast = { path = "../rustc_ast" }
1717
rustc_attr = { path = "../rustc_attr" }

compiler/rustc_middle/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ doctest = false
1111
rustc_arena = { path = "../rustc_arena" }
1212
bitflags = "1.2.1"
1313
tracing = "0.1"
14-
rustc-rayon-core = "0.3.0"
14+
rustc-rayon-core = "0.3.1"
1515
polonius-engine = "0.12.0"
1616
rustc_apfloat = { path = "../rustc_apfloat" }
1717
rustc_attr = { path = "../rustc_attr" }

compiler/rustc_query_impl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ doctest = false
99

1010
[dependencies]
1111
measureme = "9.0.0"
12-
rustc-rayon-core = "0.3.0"
12+
rustc-rayon-core = "0.3.1"
1313
tracing = "0.1"
1414
rustc_ast = { path = "../rustc_ast" }
1515
rustc_attr = { path = "../rustc_attr" }

compiler/rustc_query_system/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ doctest = false
1010
[dependencies]
1111
rustc_arena = { path = "../rustc_arena" }
1212
tracing = "0.1"
13-
rustc-rayon-core = "0.3.0"
13+
rustc-rayon-core = "0.3.1"
1414
rustc_data_structures = { path = "../rustc_data_structures" }
1515
rustc_errors = { path = "../rustc_errors" }
1616
rustc_macros = { path = "../rustc_macros" }

0 commit comments

Comments
 (0)