Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #99826

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 29 additions & 9 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
| NativeLibKind::Dylib { .. }
| NativeLibKind::Framework { .. }
| NativeLibKind::RawDylib
| NativeLibKind::LinkArg
| NativeLibKind::Unspecified => continue,
}
if let Some(name) = lib.name {
Expand Down Expand Up @@ -1289,6 +1290,7 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
}
// These are included, no need to print them
NativeLibKind::Static { bundle: None | Some(true), .. }
| NativeLibKind::LinkArg
| NativeLibKind::RawDylib => None,
}
})
Expand Down Expand Up @@ -2243,6 +2245,9 @@ fn add_local_native_libraries(
NativeLibKind::RawDylib => {
// Ignore RawDylib here, they are handled separately in linker_with_args().
}
NativeLibKind::LinkArg => {
cmd.arg(name);
}
}
}
}
Expand Down Expand Up @@ -2380,19 +2385,34 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
(lib.name, lib.kind, lib.verbatim)
};

if let NativeLibKind::Static { bundle: Some(false), whole_archive } =
lib.kind
{
let verbatim = lib.verbatim.unwrap_or(false);
if whole_archive == Some(true) {
match lib.kind {
NativeLibKind::Static {
bundle: Some(false),
whole_archive: Some(true),
} => {
cmd.link_whole_staticlib(
name,
verbatim,
lib.verbatim.unwrap_or(false),
search_path.get_or_init(|| archive_search_paths(sess)),
);
} else {
cmd.link_staticlib(name, verbatim);
}
NativeLibKind::Static {
bundle: Some(false),
whole_archive: Some(false) | None,
} => {
cmd.link_staticlib(name, lib.verbatim.unwrap_or(false));
}
NativeLibKind::LinkArg => {
cmd.arg(name);
}
NativeLibKind::Dylib { .. }
| NativeLibKind::Framework { .. }
| NativeLibKind::Unspecified
| NativeLibKind::RawDylib => {}
NativeLibKind::Static {
bundle: Some(true) | None,
whole_archive: _,
} => {}
}
}
}
Expand Down Expand Up @@ -2583,7 +2603,7 @@ fn add_upstream_native_libraries(
// already included them in add_local_native_libraries and
// add_upstream_rust_crates
NativeLibKind::Static { .. } => {}
NativeLibKind::RawDylib => {}
NativeLibKind::RawDylib | NativeLibKind::LinkArg => {}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub(crate) struct CrateMetadata {

// --- Some data pre-decoded from the metadata blob, usually for performance ---
/// NOTE(eddyb) we pass `'static` to a `'tcx` parameter because this
/// lifetime is only used behind `Lazy`, and therefore acts like a
/// lifetime is only used behind `LazyValue`, `LazyArray`, or `LazyTable`, and therefore acts like a
/// universal (`for<'tcx>`), that is paired up with whichever `TyCtxt`
/// is being used to decode those values.
root: CrateRoot,
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ pub const METADATA_HEADER: &[u8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_V
///
/// Metadata is effective a tree, encoded in post-order,
/// and with the root's position written next to the header.
/// That means every single `Lazy` points to some previous
/// That means every single `LazyValue` points to some previous
/// location in the metadata and is part of a larger node.
///
/// The first `Lazy` in a node is encoded as the backwards
/// The first `LazyValue` in a node is encoded as the backwards
/// distance from the position where the containing node
/// starts and where the `Lazy` points to, while the rest
/// use the forward distance from the previous `Lazy`.
/// starts and where the `LazyValue` points to, while the rest
/// use the forward distance from the previous `LazyValue`.
/// Distances start at 1, as 0-byte nodes are invalid.
/// Also invalid are nodes being referred in a different
/// order than they were encoded in.
Expand All @@ -94,12 +94,12 @@ impl<T> LazyValue<T> {

/// A list of lazily-decoded values.
///
/// Unlike `Lazy<Vec<T>>`, the length is encoded next to the
/// Unlike `LazyValue<Vec<T>>`, the length is encoded next to the
/// position, not at the position, which means that the length
/// doesn't need to be known before encoding all the elements.
///
/// If the length is 0, no position is encoded, but otherwise,
/// the encoding is that of `Lazy`, with the distinction that
/// the encoding is that of `LazyArray`, with the distinction that
/// the minimal distance the length of the sequence, i.e.
/// it's assumed there's no 0-byte element in the sequence.
struct LazyArray<T> {
Expand Down Expand Up @@ -167,17 +167,17 @@ impl<I, T> Clone for LazyTable<I, T> {
}
}

/// Encoding / decoding state for `Lazy`.
/// Encoding / decoding state for `Lazy`s (`LazyValue`, `LazyArray`, and `LazyTable`).
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum LazyState {
/// Outside of a metadata node.
NoNode,

/// Inside a metadata node, and before any `Lazy`.
/// Inside a metadata node, and before any `Lazy`s.
/// The position is that of the node itself.
NodeStart(NonZeroUsize),

/// Inside a metadata node, with a previous `Lazy`.
/// Inside a metadata node, with a previous `Lazy`s.
/// The position is where that previous `Lazy` would start.
Previous(NonZeroUsize),
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fixed_size_enum! {
}
}

// We directly encode `DefPathHash` because a `Lazy` would encur a 25% cost.
// We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
impl FixedSizeEncoding for Option<DefPathHash> {
type ByteArray = [u8; 16];

Expand All @@ -159,7 +159,7 @@ impl FixedSizeEncoding for Option<DefPathHash> {
}
}

// We directly encode RawDefId because using a `Lazy` would incur a 50% overhead in the worst case.
// We directly encode RawDefId because using a `LazyValue` would incur a 50% overhead in the worst case.
impl FixedSizeEncoding for Option<RawDefId> {
type ByteArray = [u8; 8];

Expand Down
17 changes: 15 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1944,9 +1944,22 @@ fn parse_native_lib_kind(
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
"dylib" => NativeLibKind::Dylib { as_needed: None },
"framework" => NativeLibKind::Framework { as_needed: None },
"link-arg" => {
if !nightly_options::is_unstable_enabled(matches) {
let why = if nightly_options::match_is_nightly_build(matches) {
" and only accepted on the nightly compiler"
} else {
", the `-Z unstable-options` flag must also be passed to use it"
};
early_error(error_format, &format!("library kind `link-arg` is unstable{why}"))
}
NativeLibKind::LinkArg
}
_ => early_error(
error_format,
&format!("unknown library kind `{kind}`, expected one of: static, dylib, framework"),
&format!(
"unknown library kind `{kind}`, expected one of: static, dylib, framework, link-arg"
),
),
};
match modifiers {
Expand Down Expand Up @@ -2045,7 +2058,7 @@ fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec<
.into_iter()
.map(|s| {
// Parse string of the form "[KIND[:MODIFIERS]=]lib[:new_name]",
// where KIND is one of "dylib", "framework", "static" and
// where KIND is one of "dylib", "framework", "static", "link-arg" and
// where MODIFIERS are a comma separated list of supported modifiers
// (bundle, verbatim, whole-archive, as-needed). Each modifier is prefixed
// with either + or - to indicate whether it is enabled or disabled.
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_session/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub enum NativeLibKind {
/// Whether the framework will be linked only if it satisfies some undefined symbols
as_needed: Option<bool>,
},
/// Argument which is passed to linker, relative order with libraries and other arguments
/// is preserved
LinkArg,
/// The library kind wasn't specified, `Dylib` is currently used as a default.
Unspecified,
}
Expand All @@ -47,7 +50,7 @@ impl NativeLibKind {
NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
as_needed.is_some()
}
NativeLibKind::RawDylib | NativeLibKind::Unspecified => false,
NativeLibKind::RawDylib | NativeLibKind::Unspecified | NativeLibKind::LinkArg => false,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/os/fd/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::os::wasi::io::OwnedFd;
use crate::sys_common::{AsInner, IntoInner};

/// Raw file descriptors.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "rust1", since = "1.0.0")]
pub type RawFd = raw::c_int;

Expand All @@ -22,6 +23,7 @@ pub type RawFd = raw::c_int;
/// This is only available on unix and WASI platforms and must be imported in
/// order to call the method. Windows platforms have a corresponding
/// `AsRawHandle` and `AsRawSocket` set of traits.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait AsRawFd {
/// Extracts the raw file descriptor.
Expand Down Expand Up @@ -57,6 +59,7 @@ pub trait AsRawFd {

/// A trait to express the ability to construct an object from a raw file
/// descriptor.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "from_raw_os", since = "1.1.0")]
pub trait FromRawFd {
/// Constructs a new instance of `Self` from the given raw file
Expand Down Expand Up @@ -100,6 +103,7 @@ pub trait FromRawFd {

/// A trait to express the ability to consume an object and acquire ownership of
/// its raw file descriptor.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "into_raw_os", since = "1.4.0")]
pub trait IntoRawFd {
/// Consumes this object, returning the raw underlying file descriptor.
Expand Down
15 changes: 15 additions & 0 deletions library/std/src/os/wasi/io/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@

#![unstable(feature = "wasi_ext", issue = "71213")]

// NOTE: despite the fact that this module is unstable,
// stable Rust had the capability to access the stable
// re-exported items from os::fd::raw through this
// unstable module.
// In PR #95956 the stability checker was changed to check
// all path segments of an item rather than just the last,
// which caused the aforementioned stable usage to regress
// (see issue #99502).
// As a result, the items in os::fd::raw were given the
// rustc_allowed_through_unstable_modules attribute.
// No regression tests were added to ensure this property,
// as CI is not configured to test wasm32-wasi.
// If this module is stabilized,
// you may want to remove those attributes
// (assuming no other unstable modules need them).
pub use crate::os::fd::raw::*;
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md)
- [*-pc-windows-gnullvm](platform-support/pc-windows-gnullvm.md)
- [*-unknown-openbsd](platform-support/openbsd.md)
- [\*-unknown-uefi](platform-support/unknown-uefi.md)
- [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md)
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
- [Targets](targets/index.md)
Expand Down