Skip to content

Commit f7e75a2

Browse files
committed
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.
1 parent f98721f commit f7e75a2

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
@@ -844,15 +844,6 @@ dependencies = [
844844
"scopeguard",
845845
]
846846

847-
[[package]]
848-
name = "crossbeam-queue"
849-
version = "0.1.2"
850-
source = "registry+https://github.com/rust-lang/crates.io-index"
851-
checksum = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"
852-
dependencies = [
853-
"crossbeam-utils 0.6.6",
854-
]
855-
856847
[[package]]
857848
name = "crossbeam-queue"
858849
version = "0.2.3"
@@ -864,16 +855,6 @@ dependencies = [
864855
"maybe-uninit",
865856
]
866857

867-
[[package]]
868-
name = "crossbeam-utils"
869-
version = "0.6.6"
870-
source = "registry+https://github.com/rust-lang/crates.io-index"
871-
checksum = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
872-
dependencies = [
873-
"cfg-if 0.1.10",
874-
"lazy_static",
875-
]
876-
877858
[[package]]
878859
name = "crossbeam-utils"
879860
version = "0.7.2"
@@ -3013,7 +2994,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
30132994
checksum = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280"
30142995
dependencies = [
30152996
"crossbeam-deque",
3016-
"crossbeam-queue 0.2.3",
2997+
"crossbeam-queue",
30172998
"crossbeam-utils 0.7.2",
30182999
"lazy_static",
30193000
"num_cpus",
@@ -3581,9 +3562,9 @@ dependencies = [
35813562

35823563
[[package]]
35833564
name = "rustc-rayon"
3584-
version = "0.3.0"
3565+
version = "0.3.1"
35853566
source = "registry+https://github.com/rust-lang/crates.io-index"
3586-
checksum = "f32767f90d938f1b7199a174ef249ae1924f6e5bbdb9d112fea141e016f25b3a"
3567+
checksum = "ed7d6a39f8bfd4421ce720918234d1e672b83824c91345b47c93746839cf1629"
35873568
dependencies = [
35883569
"crossbeam-deque",
35893570
"either",
@@ -3592,13 +3573,13 @@ dependencies = [
35923573

35933574
[[package]]
35943575
name = "rustc-rayon-core"
3595-
version = "0.3.0"
3576+
version = "0.3.1"
35963577
source = "registry+https://github.com/rust-lang/crates.io-index"
3597-
checksum = "ea2427831f0053ea3ea73559c8eabd893133a51b251d142bacee53c62a288cb3"
3578+
checksum = "e94187d9ea3e8c38fafdbc38acb94eafa7ce155867f6ccb13830466a0d0db8c6"
35983579
dependencies = [
35993580
"crossbeam-deque",
3600-
"crossbeam-queue 0.1.2",
3601-
"crossbeam-utils 0.6.6",
3581+
"crossbeam-queue",
3582+
"crossbeam-utils 0.7.2",
36023583
"lazy_static",
36033584
"num_cpus",
36043585
]
@@ -3661,6 +3642,7 @@ dependencies = [
36613642
name = "rustc_arena"
36623643
version = "0.0.0"
36633644
dependencies = [
3645+
"rustc_data_structures",
36643646
"smallvec 1.6.1",
36653647
]
36663648

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)