Skip to content

Commit 80ee7cb

Browse files
authored
Rollup merge of #82492 - CDirkx:sys_common_alloc, r=m-ou-se
Move `std::sys_common::alloc` to new module `std::sys::common` https://github.com/rust-lang/rust/blob/6b56603e35b39c9f6cc76782330e5e415f9e43d5/library/std/src/sys_common/mod.rs#L7-L13 It was my impression that the goal for `std::sys` has changed from extracting it into a separate crate to making std work with features. However the fact remains that there is a lot of interdependence between `sys` and `sys_common`, this is because `sys_common` contains two types of code: - abstractions over the different platform implementations in `std::sys` (for example [`std::sys_common::mutex`](https://github.com/rust-lang/rust/blob/master/library/std/src/sys_common/mutex.rs)) - code shared between platforms (for example [`std::sys_common::alloc`](https://github.com/rust-lang/rust/blob/master/library/std/src/sys_common/alloc.rs)) This PR attempts to address this by adding a new module `common` to `std::sys` which will contain code shared between platforms, `alloc.rs` in this case but more can be moved over in the future.
2 parents 16bf626 + cac0dd6 commit 80ee7cb

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

Diff for: library/std/src/sys_common/alloc.rs renamed to library/std/src/sys/common/alloc.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(dead_code)]
2-
31
use crate::alloc::{GlobalAlloc, Layout, System};
42
use crate::cmp;
53
use crate::ptr;

Diff for: library/std/src/sys/common/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This module contains code that is shared between all platforms, mostly utility or fallback code.
2+
// This explicitly does not include code that is shared between only a few platforms,
3+
// such as when reusing an implementation from `unix` or `unsupported`.
4+
// In those cases the desired code should be included directly using the #[path] attribute,
5+
// not moved to this module.
6+
//
7+
// Currently `sys_common` contains a lot of code that should live in this module,
8+
// ideally `sys_common` would only contain platform-independent abstractions on top of `sys`.
9+
// Progress on this is tracked in #84187.
10+
11+
#![allow(dead_code)]
12+
13+
pub mod alloc;

Diff for: library/std/src/sys/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
2323
#![allow(missing_debug_implementations)]
2424

25+
mod common;
26+
2527
cfg_if::cfg_if! {
2628
if #[cfg(target_os = "vxworks")] {
2729
mod vxworks;

Diff for: library/std/src/sys/unix/alloc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::alloc::{GlobalAlloc, Layout, System};
22
use crate::ptr;
3-
use crate::sys_common::alloc::{realloc_fallback, MIN_ALIGN};
3+
use crate::sys::common::alloc::{realloc_fallback, MIN_ALIGN};
44

55
#[stable(feature = "alloc_system_type", since = "1.28.0")]
66
unsafe impl GlobalAlloc for System {

Diff for: library/std/src/sys/windows/alloc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::ffi::c_void;
55
use crate::ptr;
66
use crate::sync::atomic::{AtomicPtr, Ordering};
77
use crate::sys::c;
8-
use crate::sys_common::alloc::{realloc_fallback, MIN_ALIGN};
8+
use crate::sys::common::alloc::{realloc_fallback, MIN_ALIGN};
99

1010
#[cfg(test)]
1111
mod tests;

Diff for: library/std/src/sys_common/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
//! rest of `std` is complex, with dependencies going in all
99
//! directions: `std` depending on `sys_common`, `sys_common`
1010
//! depending on `sys`, and `sys` depending on `sys_common` and `std`.
11-
//! Ideally `sys_common` would be split into two and the dependencies
12-
//! between them all would form a dag, facilitating the extraction of
13-
//! `std::sys` from the standard library.
11+
//! This is because `sys_common` not only contains platform-independent code,
12+
//! but also code that is shared between the different platforms in `sys`.
13+
//! Ideally all that shared code should be moved to `sys::common`,
14+
//! and the dependencies between `std`, `sys_common` and `sys` all would form a dag.
15+
//! Progress on this is tracked in #84187.
1416
1517
#![allow(missing_docs)]
1618
#![allow(missing_debug_implementations)]
@@ -46,7 +48,6 @@ macro_rules! rtunwrap {
4648
};
4749
}
4850

49-
pub mod alloc;
5051
pub mod at_exit_imp;
5152
pub mod backtrace;
5253
pub mod bytestring;

0 commit comments

Comments
 (0)