Skip to content

Commit

Permalink
Auto merge of #101946 - matthiaskrgr:rollup-jqkhsku, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - #101672 (array docs - advertise how to get array from slice)
 - #101781 (Extend list of targets that support dyanmic linking for llvm tools)
 - #101783 (Improve handing of env vars during bootstrap process)
 - #101801 (add note for `layout_of` when query depth overflows)
 - #101824 (rustdoc: add test cases for turning ``[Vec<T>]`` into ``[`Vec<T>`]``)
 - #101861 (Update stdarch)
 - #101873 (Allow building `rust-analyzer-proc-macro-srv` as a standalone tool)
 - #101918 (rustdoc: clean up CSS for All Items and All Crates lists)
 - #101934 (Continue migration of CSS themes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Sep 17, 2022
2 parents c773c13 + 1f31bee commit 98ad6a5
Show file tree
Hide file tree
Showing 31 changed files with 476 additions and 154 deletions.
8 changes: 6 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-core",
]

[[package]]
name = "chalk-derive"
Expand Down Expand Up @@ -4613,7 +4617,7 @@ version = "0.0.0"
dependencies = [
"addr2line 0.16.0",
"alloc",
"cfg-if 0.1.10",
"cfg-if 1.0.0",
"compiler_builtins",
"core",
"dlmalloc",
Expand All @@ -4637,7 +4641,7 @@ dependencies = [
name = "std_detect"
version = "0.1.5"
dependencies = [
"cfg-if 0.1.10",
"cfg-if 1.0.0",
"compiler_builtins",
"libc",
"rustc-std-workspace-alloc",
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/query_system.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ query_system_cycle_recursive_trait_alias = trait aliases cannot be recursive
query_system_cycle_which_requires = ...which requires {$desc}...
query_system_query_overflow = queries overflow the depth limit!
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
query_system_layout_of_depth = query depth increased by {$depth} when {$desc}
29 changes: 27 additions & 2 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ use rustc_query_system::query::{
force_query, QueryConfig, QueryContext, QueryDescription, QueryJobId, QueryMap,
QuerySideEffects, QueryStackFrame,
};
use rustc_query_system::Value;
use rustc_query_system::{LayoutOfDepth, QueryOverflow, Value};
use rustc_serialize::Decodable;
use rustc_session::Limit;
use rustc_span::def_id::LOCAL_CRATE;
use std::any::Any;
use std::num::NonZeroU64;
use thin_vec::ThinVec;
Expand Down Expand Up @@ -109,7 +111,7 @@ impl QueryContext for QueryCtxt<'_> {
// when accessing the `ImplicitCtxt`.
tls::with_related_context(**self, move |current_icx| {
if depth_limit && !self.recursion_limit().value_within_limit(current_icx.query_depth) {
self.depth_limit_error();
self.depth_limit_error(token);
}

// Update the `ImplicitCtxt` to point to our new query job.
Expand All @@ -127,6 +129,29 @@ impl QueryContext for QueryCtxt<'_> {
})
})
}

fn depth_limit_error(&self, job: QueryJobId) {
let mut span = None;
let mut layout_of_depth = None;
if let Some(map) = self.try_collect_active_jobs() {
if let Some((info, depth)) = job.try_find_layout_root(map) {
span = Some(info.job.span);
layout_of_depth = Some(LayoutOfDepth { desc: info.query.description, depth });
}
}

let suggested_limit = match self.recursion_limit() {
Limit(0) => Limit(2),
limit => limit * 2,
};

self.sess.emit_fatal(QueryOverflow {
span,
layout_of_depth,
suggested_limit,
crate_name: self.crate_name(LOCAL_CRATE),
});
}
}

impl<'tcx> QueryCtxt<'tcx> {
Expand Down
20 changes: 18 additions & 2 deletions compiler/rustc_query_system/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc_errors::AddSubdiagnostic;
use rustc_span::Span;
use rustc_session::Limit;
use rustc_span::{Span, Symbol};

pub struct CycleStack {
pub span: Span,
Expand Down Expand Up @@ -76,5 +77,20 @@ pub struct IncrementCompilation {
}

#[derive(SessionDiagnostic)]
#[help]
#[diag(query_system::query_overflow)]
pub struct QueryOverflow;
pub struct QueryOverflow {
#[primary_span]
pub span: Option<Span>,
#[subdiagnostic]
pub layout_of_depth: Option<LayoutOfDepth>,
pub suggested_limit: Limit,
pub crate_name: Symbol,
}

#[derive(SessionSubdiagnostic)]
#[note(query_system::layout_of_depth)]
pub struct LayoutOfDepth {
pub desc: String,
pub depth: usize,
}
2 changes: 2 additions & 0 deletions compiler/rustc_query_system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ pub mod query;
mod values;

pub use error::HandleCycleError;
pub use error::LayoutOfDepth;
pub use error::QueryOverflow;
pub use values::Value;
21 changes: 20 additions & 1 deletion compiler/rustc_query_system/src/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl QueryJobId {
}
}

#[derive(Clone)]
pub struct QueryJobInfo {
pub query: QueryStackFrame,
pub job: QueryJob,
Expand Down Expand Up @@ -116,10 +117,10 @@ impl QueryJob {
}
}

#[cfg(not(parallel_compiler))]
impl QueryJobId {
#[cold]
#[inline(never)]
#[cfg(not(parallel_compiler))]
pub(super) fn find_cycle_in_stack(
&self,
query_map: QueryMap,
Expand Down Expand Up @@ -156,6 +157,24 @@ impl QueryJobId {

panic!("did not find a cycle")
}

#[cold]
#[inline(never)]
pub fn try_find_layout_root(&self, query_map: QueryMap) -> Option<(QueryJobInfo, usize)> {
let mut last_layout = None;
let mut current_id = Some(*self);
let mut depth = 0;

while let Some(id) = current_id {
let info = query_map.get(&id).unwrap();
if info.query.name == "layout_of" {
depth += 1;
last_layout = Some((info.clone(), depth));
}
current_id = info.job.parent;
}
last_layout
}
}

#[cfg(parallel_compiler)]
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_query_system/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use self::caches::{
mod config;
pub use self::config::{QueryConfig, QueryDescription, QueryVTable};

use crate::dep_graph::{DepContext, DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
use rustc_data_structures::sync::Lock;
use rustc_errors::Diagnostic;
use rustc_hir::def::DefKind;
Expand Down Expand Up @@ -123,7 +123,5 @@ pub trait QueryContext: HasDepContext {
compute: impl FnOnce() -> R,
) -> R;

fn depth_limit_error(&self) {
self.dep_context().sess().emit_fatal(crate::error::QueryOverflow);
}
fn depth_limit_error(&self, job: QueryJobId);
}
48 changes: 48 additions & 0 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ impl<T, const N: usize> const BorrowMut<[T]> for [T; N] {
}
}

/// Tries to create an array `[T; N]` by copying from a slice `&[T]`. Succeeds if
/// `slice.len() == N`.
///
/// ```
/// let bytes: [u8; 3] = [1, 0, 2];
///
/// let bytes_head: [u8; 2] = <[u8; 2]>::try_from(&bytes[0..2]).unwrap();
/// assert_eq!(1, u16::from_le_bytes(bytes_head));
///
/// let bytes_tail: [u8; 2] = bytes[1..3].try_into().unwrap();
/// assert_eq!(512, u16::from_le_bytes(bytes_tail));
/// ```
#[stable(feature = "try_from", since = "1.34.0")]
impl<T, const N: usize> TryFrom<&[T]> for [T; N]
where
Expand All @@ -196,6 +208,18 @@ where
}
}

/// Tries to create an array `[T; N]` by copying from a mutable slice `&mut [T]`.
/// Succeeds if `slice.len() == N`.
///
/// ```
/// let mut bytes: [u8; 3] = [1, 0, 2];
///
/// let bytes_head: [u8; 2] = <[u8; 2]>::try_from(&mut bytes[0..2]).unwrap();
/// assert_eq!(1, u16::from_le_bytes(bytes_head));
///
/// let bytes_tail: [u8; 2] = (&mut bytes[1..3]).try_into().unwrap();
/// assert_eq!(512, u16::from_le_bytes(bytes_tail));
/// ```
#[stable(feature = "try_from_mut_slice_to_array", since = "1.59.0")]
impl<T, const N: usize> TryFrom<&mut [T]> for [T; N]
where
Expand All @@ -208,6 +232,18 @@ where
}
}

/// Tries to create an array ref `&[T; N]` from a slice ref `&[T]`. Succeeds if
/// `slice.len() == N`.
///
/// ```
/// let bytes: [u8; 3] = [1, 0, 2];
///
/// let bytes_head: &[u8; 2] = <&[u8; 2]>::try_from(&bytes[0..2]).unwrap();
/// assert_eq!(1, u16::from_le_bytes(*bytes_head));
///
/// let bytes_tail: &[u8; 2] = bytes[1..3].try_into().unwrap();
/// assert_eq!(512, u16::from_le_bytes(*bytes_tail));
/// ```
#[stable(feature = "try_from", since = "1.34.0")]
impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] {
type Error = TryFromSliceError;
Expand All @@ -223,6 +259,18 @@ impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] {
}
}

/// Tries to create a mutable array ref `&mut [T; N]` from a mutable slice ref
/// `&mut [T]`. Succeeds if `slice.len() == N`.
///
/// ```
/// let mut bytes: [u8; 3] = [1, 0, 2];
///
/// let bytes_head: &mut [u8; 2] = <&mut [u8; 2]>::try_from(&mut bytes[0..2]).unwrap();
/// assert_eq!(1, u16::from_le_bytes(*bytes_head));
///
/// let bytes_tail: &mut [u8; 2] = (&mut bytes[1..3]).try_into().unwrap();
/// assert_eq!(512, u16::from_le_bytes(*bytes_tail));
/// ```
#[stable(feature = "try_from", since = "1.34.0")]
impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] {
type Error = TryFromSliceError;
Expand Down
23 changes: 22 additions & 1 deletion library/core/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,19 @@ mod prim_pointer {}
///
/// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on
/// an array. Indeed, this provides most of the API for working with arrays.
/// Slices have a dynamic size and do not coerce to arrays.
///
/// Slices have a dynamic size and do not coerce to arrays. Instead, use
/// `slice.try_into().unwrap()` or `<ArrayType>::try_from(slice).unwrap()`.
///
/// Array's `try_from(slice)` implementations (and the corresponding `slice.try_into()`
/// array implementations) succeed if the input slice length is the same as the result
/// array length. They optimize especially well when the optimizer can easily determine
/// the slice length, e.g. `<[u8; 4]>::try_from(&slice[4..8]).unwrap()`. Array implements
/// [TryFrom](crate::convert::TryFrom) returning:
///
/// - `[T; N]` copies from the slice's elements
/// - `&[T; N]` references the original slice's elements
/// - `&mut [T; N]` references the original slice's elements
///
/// You can move elements out of an array with a [slice pattern]. If you want
/// one element, see [`mem::replace`].
Expand Down Expand Up @@ -640,6 +652,15 @@ mod prim_pointer {}
/// for x in &array { }
/// ```
///
/// You can use `<ArrayType>::try_from(slice)` or `slice.try_into()` to get an array from
/// a slice:
///
/// ```
/// let bytes: [u8; 3] = [1, 0, 2];
/// assert_eq!(1, u16::from_le_bytes(<[u8; 2]>::try_from(&bytes[0..2]).unwrap()));
/// assert_eq!(512, u16::from_le_bytes(bytes[1..3].try_into().unwrap()));
/// ```
///
/// You can use a [slice pattern] to move elements out of an array:
///
/// ```
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["dylib", "rlib"]

[dependencies]
alloc = { path = "../alloc" }
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core" }
Expand Down
23 changes: 22 additions & 1 deletion library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,19 @@ mod prim_pointer {}
///
/// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on
/// an array. Indeed, this provides most of the API for working with arrays.
/// Slices have a dynamic size and do not coerce to arrays.
///
/// Slices have a dynamic size and do not coerce to arrays. Instead, use
/// `slice.try_into().unwrap()` or `<ArrayType>::try_from(slice).unwrap()`.
///
/// Array's `try_from(slice)` implementations (and the corresponding `slice.try_into()`
/// array implementations) succeed if the input slice length is the same as the result
/// array length. They optimize especially well when the optimizer can easily determine
/// the slice length, e.g. `<[u8; 4]>::try_from(&slice[4..8]).unwrap()`. Array implements
/// [TryFrom](crate::convert::TryFrom) returning:
///
/// - `[T; N]` copies from the slice's elements
/// - `&[T; N]` references the original slice's elements
/// - `&mut [T; N]` references the original slice's elements
///
/// You can move elements out of an array with a [slice pattern]. If you want
/// one element, see [`mem::replace`].
Expand Down Expand Up @@ -640,6 +652,15 @@ mod prim_pointer {}
/// for x in &array { }
/// ```
///
/// You can use `<ArrayType>::try_from(slice)` or `slice.try_into()` to get an array from
/// a slice:
///
/// ```
/// let bytes: [u8; 3] = [1, 0, 2];
/// assert_eq!(1, u16::from_le_bytes(<[u8; 2]>::try_from(&bytes[0..2]).unwrap()));
/// assert_eq!(512, u16::from_le_bytes(bytes[1..3].try_into().unwrap()));
/// ```
///
/// You can use a [slice pattern] to move elements out of an array:
///
/// ```
Expand Down
15 changes: 11 additions & 4 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,19 +732,26 @@ def build_bootstrap(self, color):
(os.pathsep + env["LIBRARY_PATH"]) \
if "LIBRARY_PATH" in env else ""

# Export Stage0 snapshot compiler related env variables
build_section = "target.{}".format(self.build)
host_triple_sanitized = self.build.replace("-", "_")
var_data = {
"CC": "cc", "CXX": "cxx", "LD": "linker", "AR": "ar", "RANLIB": "ranlib"
}
for var_name, toml_key in var_data.items():
toml_val = self.get_toml(toml_key, build_section)
if toml_val != None:
env["{}_{}".format(var_name, host_triple_sanitized)] = toml_val

# preserve existing RUSTFLAGS
env.setdefault("RUSTFLAGS", "")
build_section = "target.{}".format(self.build)
target_features = []
if self.get_toml("crt-static", build_section) == "true":
target_features += ["+crt-static"]
elif self.get_toml("crt-static", build_section) == "false":
target_features += ["-crt-static"]
if target_features:
env["RUSTFLAGS"] += " -C target-feature=" + (",".join(target_features))
target_linker = self.get_toml("linker", build_section)
if target_linker is not None:
env["RUSTFLAGS"] += " -C linker=" + target_linker
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes"
env["RUSTFLAGS"] += " -Wsemicolon_in_expressions_from_macros"
if self.get_toml("deny-warnings", "rust") != "false":
Expand Down
Loading

0 comments on commit 98ad6a5

Please sign in to comment.