Skip to content

Commit 4c732f9

Browse files
committed
std: move platform modules into sys::pal
1 parent 54e57e6 commit 4c732f9

File tree

250 files changed

+188
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+188
-180
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -508,29 +508,29 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
508508
// we need to handle re-exports correctly.
509509
//
510510
// For example, take `std::os::unix::process::CommandExt`, this trait is actually
511-
// defined at `std::sys::unix::ext::process::CommandExt` (at time of writing).
511+
// defined at `std::sys::pal::unix::ext::process::CommandExt` (at time of writing).
512512
//
513-
// `std::os::unix` reexports the contents of `std::sys::unix::ext`. `std::sys` is
513+
// `std::os::unix` reexports the contents of `std::sys::pal::unix::ext`. `std::sys` is
514514
// private so the "true" path to `CommandExt` isn't accessible.
515515
//
516516
// In this case, the `visible_parent_map` will look something like this:
517517
//
518518
// (child) -> (parent)
519-
// `std::sys::unix::ext::process::CommandExt` -> `std::sys::unix::ext::process`
520-
// `std::sys::unix::ext::process` -> `std::sys::unix::ext`
521-
// `std::sys::unix::ext` -> `std::os`
519+
// `std::sys::pal::unix::ext::process::CommandExt` -> `std::sys::pal::unix::ext::process`
520+
// `std::sys::pal::unix::ext::process` -> `std::sys::pal::unix::ext`
521+
// `std::sys::pal::unix::ext` -> `std::os`
522522
//
523-
// This is correct, as the visible parent of `std::sys::unix::ext` is in fact
523+
// This is correct, as the visible parent of `std::sys::pal::unix::ext` is in fact
524524
// `std::os`.
525525
//
526526
// When printing the path to `CommandExt` and looking at the `cur_def_key` that
527-
// corresponds to `std::sys::unix::ext`, we would normally print `ext` and then go
527+
// corresponds to `std::sys::pal::unix::ext`, we would normally print `ext` and then go
528528
// to the parent - resulting in a mangled path like
529529
// `std::os::ext::process::CommandExt`.
530530
//
531531
// Instead, we must detect that there was a re-export and instead print `unix`
532-
// (which is the name `std::sys::unix::ext` was re-exported as in `std::os`). To
533-
// do this, we compare the parent of `std::sys::unix::ext` (`std::sys::unix`) with
532+
// (which is the name `std::sys::pal::unix::ext` was re-exported as in `std::os`). To
533+
// do this, we compare the parent of `std::sys::pal::unix::ext` (`std::sys::pal::unix`) with
534534
// the visible parent (`std::os`). If these do not match, then we iterate over
535535
// the children of the visible parent (as was done when computing
536536
// `visible_parent_map`), looking for the specific child we currently have and then

library/std/src/sys/mod.rs

+8-121
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,8 @@
1-
//! Platform-dependent platform abstraction.
2-
//!
3-
//! The `std::sys` module is the abstracted interface through which
4-
//! `std` talks to the underlying operating system. It has different
5-
//! implementations for different operating system families, today
6-
//! just Unix and Windows, and initial support for Redox.
7-
//!
8-
//! The centralization of platform-specific code in this module is
9-
//! enforced by the "platform abstraction layer" tidy script in
10-
//! `tools/tidy/src/pal.rs`.
11-
//!
12-
//! This module is closely related to the platform-independent system
13-
//! integration code in `std::sys_common`. See that module's
14-
//! documentation for details.
15-
//!
16-
//! In the future it would be desirable for the independent
17-
//! implementations of this module to be extracted to their own crates
18-
//! that `std` can link to, thus enabling their implementation
19-
//! out-of-tree via crate replacement. Though due to the complex
20-
//! inter-dependencies within `std` that will be a challenging goal to
21-
//! achieve.
22-
23-
#![allow(missing_debug_implementations)]
24-
25-
pub mod common;
26-
mod personality;
27-
28-
cfg_if::cfg_if! {
29-
if #[cfg(unix)] {
30-
mod unix;
31-
pub use self::unix::*;
32-
} else if #[cfg(windows)] {
33-
mod windows;
34-
pub use self::windows::*;
35-
} else if #[cfg(target_os = "solid_asp3")] {
36-
mod solid;
37-
pub use self::solid::*;
38-
} else if #[cfg(target_os = "hermit")] {
39-
mod hermit;
40-
pub use self::hermit::*;
41-
} else if #[cfg(target_os = "wasi")] {
42-
mod wasi;
43-
pub use self::wasi::*;
44-
} else if #[cfg(target_family = "wasm")] {
45-
mod wasm;
46-
pub use self::wasm::*;
47-
} else if #[cfg(target_os = "xous")] {
48-
mod xous;
49-
pub use self::xous::*;
50-
} else if #[cfg(target_os = "uefi")] {
51-
mod uefi;
52-
pub use self::uefi::*;
53-
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
54-
mod sgx;
55-
pub use self::sgx::*;
56-
} else {
57-
mod unsupported;
58-
pub use self::unsupported::*;
59-
}
60-
}
61-
62-
cfg_if::cfg_if! {
63-
// Fuchsia components default to full backtrace.
64-
if #[cfg(target_os = "fuchsia")] {
65-
pub const FULL_BACKTRACE_DEFAULT: bool = true;
66-
} else {
67-
pub const FULL_BACKTRACE_DEFAULT: bool = false;
68-
}
69-
}
70-
71-
#[cfg(not(test))]
72-
cfg_if::cfg_if! {
73-
if #[cfg(target_os = "android")] {
74-
pub use self::android::log2f32;
75-
pub use self::android::log2f64;
76-
} else {
77-
#[inline]
78-
pub fn log2f32(n: f32) -> f32 {
79-
unsafe { crate::intrinsics::log2f32(n) }
80-
}
81-
82-
#[inline]
83-
pub fn log2f64(n: f64) -> f64 {
84-
unsafe { crate::intrinsics::log2f64(n) }
85-
}
86-
}
87-
}
88-
89-
// Solaris/Illumos requires a wrapper around log, log2, and log10 functions
90-
// because of their non-standard behavior (e.g., log(-n) returns -Inf instead
91-
// of expected NaN).
92-
#[cfg(not(test))]
93-
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
94-
#[inline]
95-
pub fn log_wrapper<F: Fn(f64) -> f64>(n: f64, log_fn: F) -> f64 {
96-
if n.is_finite() {
97-
if n > 0.0 {
98-
log_fn(n)
99-
} else if n == 0.0 {
100-
f64::NEG_INFINITY // log(0) = -Inf
101-
} else {
102-
f64::NAN // log(-n) = NaN
103-
}
104-
} else if n.is_nan() {
105-
n // log(NaN) = NaN
106-
} else if n > 0.0 {
107-
n // log(Inf) = Inf
108-
} else {
109-
f64::NAN // log(-Inf) = NaN
110-
}
111-
}
112-
113-
#[cfg(not(test))]
114-
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
115-
#[inline]
116-
pub fn log_wrapper<F: Fn(f64) -> f64>(n: f64, log_fn: F) -> f64 {
117-
log_fn(n)
118-
}
119-
120-
#[cfg(not(target_os = "uefi"))]
121-
pub type RawOsError = i32;
1+
/// The PAL (platform abstraction layer) contains platform-specific abstractions
2+
/// for implementing the features in the other submodules module, e.g. UNIX file
3+
/// descriptors.
4+
mod pal;
5+
6+
// FIXME(117276): remove this, move feature implementations into individual
7+
// submodules.
8+
pub use pal::*;

library/std/src/sys/hermit/alloc.rs renamed to library/std/src/sys/pal/hermit/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::hermit::abi;
3+
use crate::sys::pal::hermit::abi;
44

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

library/std/src/sys/hermit/fd.rs renamed to library/std/src/sys/pal/hermit/fd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use crate::io::{self, Read};
44
use crate::os::hermit::io::{FromRawFd, OwnedFd, RawFd};
55
use crate::sys::cvt;
6-
use crate::sys::hermit::abi;
7-
use crate::sys::unsupported;
6+
use crate::sys::pal::hermit::abi;
7+
use crate::sys::pal::unsupported;
88
use crate::sys_common::{AsInner, FromInner, IntoInner};
99

1010
use crate::os::hermit::io::*;

library/std/src/sys/hermit/fs.rs renamed to library/std/src/sys/pal/hermit/fs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, Raw
77
use crate::path::{Path, PathBuf};
88
use crate::sys::common::small_c_string::run_path_with_cstr;
99
use crate::sys::cvt;
10-
use crate::sys::hermit::abi::{
10+
use crate::sys::pal::hermit::abi::{
1111
self, O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY,
1212
};
13-
use crate::sys::hermit::fd::FileDesc;
13+
use crate::sys::pal::hermit::fd::FileDesc;
14+
use crate::sys::pal::unsupported;
1415
use crate::sys::time::SystemTime;
15-
use crate::sys::unsupported;
1616
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
1717

1818
pub use crate::sys_common::fs::{copy, try_exists};

library/std/src/sys/hermit/mod.rs renamed to library/std/src/sys/pal/hermit/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub unsafe extern "C" fn runtime_entry(
115115
argv: *const *const c_char,
116116
env: *const *const c_char,
117117
) -> ! {
118-
use crate::sys::hermit::thread_local_dtor::run_dtors;
118+
use crate::sys::pal::hermit::thread_local_dtor::run_dtors;
119119
extern "C" {
120120
fn main(argc: isize, argv: *const *const c_char) -> i32;
121121
}

library/std/src/sys/hermit/net.rs renamed to library/std/src/sys/pal/hermit/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut};
55
use crate::mem;
66
use crate::net::{Shutdown, SocketAddr};
77
use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, RawFd};
8-
use crate::sys::hermit::fd::FileDesc;
8+
use crate::sys::pal::hermit::fd::FileDesc;
99
use crate::sys::time::Instant;
1010
use crate::sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr};
1111
use crate::sys_common::{AsInner, FromInner, IntoInner};

library/std/src/sys/hermit/os.rs renamed to library/std/src/sys/pal/hermit/os.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use crate::os::hermit::ffi::OsStringExt;
88
use crate::path::{self, PathBuf};
99
use crate::str;
1010
use crate::sync::Mutex;
11-
use crate::sys::hermit::abi;
1211
use crate::sys::memchr;
13-
use crate::sys::unsupported;
12+
use crate::sys::pal::hermit::abi;
13+
use crate::sys::pal::unsupported;
1414
use crate::vec;
1515

1616
pub fn errno() -> i32 {

library/std/src/sys/hermit/stdio.rs renamed to library/std/src/sys/pal/hermit/stdio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::io;
22
use crate::io::{IoSlice, IoSliceMut};
3-
use crate::sys::hermit::abi;
3+
use crate::sys::pal::hermit::abi;
44

55
pub struct Stdin;
66
pub struct Stdout;

library/std/src/sys/hermit/thread.rs renamed to library/std/src/sys/pal/hermit/thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::io;
55
use crate::mem;
66
use crate::num::NonZeroUsize;
77
use crate::ptr;
8-
use crate::sys::hermit::abi;
9-
use crate::sys::hermit::thread_local_dtor::run_dtors;
8+
use crate::sys::pal::hermit::abi;
9+
use crate::sys::pal::hermit::thread_local_dtor::run_dtors;
1010
use crate::time::Duration;
1111

1212
pub type Tid = abi::Tid;

library/std/src/sys/hermit/time.rs renamed to library/std/src/sys/pal/hermit/time.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
use crate::cmp::Ordering;
44
use crate::ops::{Add, AddAssign, Sub, SubAssign};
5-
use crate::sys::hermit::abi;
6-
use crate::sys::hermit::abi::timespec;
7-
use crate::sys::hermit::abi::{CLOCK_MONOTONIC, CLOCK_REALTIME, NSEC_PER_SEC};
5+
use crate::sys::pal::hermit::abi;
6+
use crate::sys::pal::hermit::abi::timespec;
7+
use crate::sys::pal::hermit::abi::{CLOCK_MONOTONIC, CLOCK_REALTIME, NSEC_PER_SEC};
88
use crate::time::Duration;
99
use core::hash::{Hash, Hasher};
1010

library/std/src/sys/pal/mod.rs

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//! Platform-dependent platform abstraction.
2+
//!
3+
//! The `std::sys` module is the abstracted interface through which
4+
//! `std` talks to the underlying operating system. It has different
5+
//! implementations for different operating system families, today
6+
//! just Unix and Windows, and initial support for Redox.
7+
//!
8+
//! The centralization of platform-specific code in this module is
9+
//! enforced by the "platform abstraction layer" tidy script in
10+
//! `tools/tidy/src/pal.rs`.
11+
//!
12+
//! This module is closely related to the platform-independent system
13+
//! integration code in `std::sys_common`. See that module's
14+
//! documentation for details.
15+
//!
16+
//! In the future it would be desirable for the independent
17+
//! implementations of this module to be extracted to their own crates
18+
//! that `std` can link to, thus enabling their implementation
19+
//! out-of-tree via crate replacement. Though due to the complex
20+
//! inter-dependencies within `std` that will be a challenging goal to
21+
//! achieve.
22+
23+
#![allow(missing_debug_implementations)]
24+
25+
pub mod common;
26+
mod personality;
27+
28+
cfg_if::cfg_if! {
29+
if #[cfg(unix)] {
30+
mod unix;
31+
pub use self::unix::*;
32+
} else if #[cfg(windows)] {
33+
mod windows;
34+
pub use self::windows::*;
35+
} else if #[cfg(target_os = "solid_asp3")] {
36+
mod solid;
37+
pub use self::solid::*;
38+
} else if #[cfg(target_os = "hermit")] {
39+
mod hermit;
40+
pub use self::hermit::*;
41+
} else if #[cfg(target_os = "wasi")] {
42+
mod wasi;
43+
pub use self::wasi::*;
44+
} else if #[cfg(target_family = "wasm")] {
45+
mod wasm;
46+
pub use self::wasm::*;
47+
} else if #[cfg(target_os = "xous")] {
48+
mod xous;
49+
pub use self::xous::*;
50+
} else if #[cfg(target_os = "uefi")] {
51+
mod uefi;
52+
pub use self::uefi::*;
53+
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
54+
mod sgx;
55+
pub use self::sgx::*;
56+
} else {
57+
mod unsupported;
58+
pub use self::unsupported::*;
59+
}
60+
}
61+
62+
cfg_if::cfg_if! {
63+
// Fuchsia components default to full backtrace.
64+
if #[cfg(target_os = "fuchsia")] {
65+
pub const FULL_BACKTRACE_DEFAULT: bool = true;
66+
} else {
67+
pub const FULL_BACKTRACE_DEFAULT: bool = false;
68+
}
69+
}
70+
71+
#[cfg(not(test))]
72+
cfg_if::cfg_if! {
73+
if #[cfg(target_os = "android")] {
74+
pub use self::android::log2f32;
75+
pub use self::android::log2f64;
76+
} else {
77+
#[inline]
78+
pub fn log2f32(n: f32) -> f32 {
79+
unsafe { crate::intrinsics::log2f32(n) }
80+
}
81+
82+
#[inline]
83+
pub fn log2f64(n: f64) -> f64 {
84+
unsafe { crate::intrinsics::log2f64(n) }
85+
}
86+
}
87+
}
88+
89+
// Solaris/Illumos requires a wrapper around log, log2, and log10 functions
90+
// because of their non-standard behavior (e.g., log(-n) returns -Inf instead
91+
// of expected NaN).
92+
#[cfg(not(test))]
93+
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
94+
#[inline]
95+
pub fn log_wrapper<F: Fn(f64) -> f64>(n: f64, log_fn: F) -> f64 {
96+
if n.is_finite() {
97+
if n > 0.0 {
98+
log_fn(n)
99+
} else if n == 0.0 {
100+
f64::NEG_INFINITY // log(0) = -Inf
101+
} else {
102+
f64::NAN // log(-n) = NaN
103+
}
104+
} else if n.is_nan() {
105+
n // log(NaN) = NaN
106+
} else if n > 0.0 {
107+
n // log(Inf) = Inf
108+
} else {
109+
f64::NAN // log(-Inf) = NaN
110+
}
111+
}
112+
113+
#[cfg(not(test))]
114+
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
115+
#[inline]
116+
pub fn log_wrapper<F: Fn(f64) -> f64>(n: f64, log_fn: F) -> f64 {
117+
log_fn(n)
118+
}
119+
120+
#[cfg(not(target_os = "uefi"))]
121+
pub type RawOsError = i32;

library/std/src/sys/sgx/alloc.rs renamed to library/std/src/sys/pal/sgx/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::sgx::abi::mem as sgx_mem;
3+
use crate::sys::pal::sgx::abi::mem as sgx_mem;
44
use core::sync::atomic::{AtomicBool, Ordering};
55

66
use super::waitqueue::SpinMutex;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)