Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 53 additions & 32 deletions compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,28 @@ fn check_attributes(attrs: Vec<Attribute>) -> Result<Vec<Attribute>> {
attrs.into_iter().map(inner).collect()
}

/// A compiler query. `query ... { ... }`
/// Declaration of a compiler query.
///
/// ```ignore (illustrative)
/// /// Doc comment for `my_query`.
/// // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doc_comments
/// query my_query(key: DefId) -> Value { anon }
/// // ^^^^^^^^ name
/// // ^^^ key_pat
/// // ^^^^^ key_ty
/// // ^^^^^^^^ return_ty
/// // ^^^^ modifiers
/// ```
struct Query {
doc_comments: Vec<Attribute>,
modifiers: QueryModifiers,
name: Ident,
key: Pat,
arg: Type,
result: ReturnType,

/// Parameter name for the key, or an arbitrary irrefutable pattern (e.g. `_`).
key_pat: Pat,
key_ty: Type,
return_ty: ReturnType,

modifiers: QueryModifiers,
}

impl Parse for Query {
Expand All @@ -47,26 +61,30 @@ impl Parse for Query {
// Parse the query declaration. Like `query type_of(key: DefId) -> Ty<'tcx>`
input.parse::<kw::query>()?;
let name: Ident = input.parse()?;
let arg_content;
parenthesized!(arg_content in input);
let key = Pat::parse_single(&arg_content)?;
arg_content.parse::<Token![:]>()?;
let arg = arg_content.parse()?;
let _ = arg_content.parse::<Option<Token![,]>>()?;
let result = input.parse()?;

// `(key: DefId)`
let parens_content;
parenthesized!(parens_content in input);
let key_pat = Pat::parse_single(&parens_content)?;
parens_content.parse::<Token![:]>()?;
let key_ty = parens_content.parse::<Type>()?;
let _trailing_comma = parens_content.parse::<Option<Token![,]>>()?;

// `-> Value`
let return_ty = input.parse::<ReturnType>()?;

// Parse the query modifiers
let content;
braced!(content in input);
let modifiers = parse_query_modifiers(&content)?;
let braces_content;
braced!(braces_content in input);
let modifiers = parse_query_modifiers(&braces_content)?;

// If there are no doc-comments, give at least some idea of what
// it does by showing the query description.
if doc_comments.is_empty() {
doc_comments.push(doc_comment_from_desc(&modifiers.desc.expr_list)?);
}

Ok(Query { doc_comments, modifiers, name, key, arg, result })
Ok(Query { doc_comments, modifiers, name, key_pat, key_ty, return_ty })
}
}

Expand Down Expand Up @@ -288,7 +306,7 @@ struct HelperTokenStreams {
}

fn make_helpers_for_query(query: &Query, streams: &mut HelperTokenStreams) {
let Query { name, key, modifiers, arg, .. } = &query;
let Query { name, key_pat, key_ty, modifiers, .. } = &query;

// Replace span for `name` to make rust-analyzer ignore it.
let mut erased_name = name.clone();
Expand All @@ -301,7 +319,7 @@ fn make_helpers_for_query(query: &Query, streams: &mut HelperTokenStreams) {
streams.cache_on_disk_if_fns_stream.extend(quote! {
#[allow(unused_variables, rustc::pass_by_value)]
#[inline]
pub fn #erased_name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::queries::#name::Key<'tcx>) -> bool
pub fn #erased_name<'tcx>(#tcx: TyCtxt<'tcx>, #key_pat: &crate::queries::#name::Key<'tcx>) -> bool
#block
});
}
Expand All @@ -311,8 +329,8 @@ fn make_helpers_for_query(query: &Query, streams: &mut HelperTokenStreams) {

let desc = quote! {
#[allow(unused_variables)]
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, key: #arg) -> String {
let (#tcx, #key) = (tcx, key);
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, key: #key_ty) -> String {
let (#tcx, #key_pat) = (tcx, key);
format!(#expr_list)
}
};
Expand Down Expand Up @@ -373,7 +391,7 @@ fn add_to_analyzer_stream(query: &Query, analyzer_stream: &mut proc_macro2::Toke
let mut erased_name = name.clone();
erased_name.set_span(Span::call_site());

let result = &query.result;
let result = &query.return_ty;

// This dead code exists to instruct rust-analyzer about the link between the `rustc_queries`
// query names and the corresponding produced provider. The issue is that by nature of this
Expand Down Expand Up @@ -417,19 +435,20 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
}

for query in queries.0 {
let Query { name, arg, modifiers, .. } = &query;
let result_full = &query.result;
let result = match query.result {
let Query { doc_comments, name, key_ty, return_ty, modifiers, .. } = &query;

// Normalize an absent return type into `-> ()` to make macro-rules parsing easier.
let return_ty = match return_ty {
ReturnType::Default => quote! { -> () },
_ => quote! { #result_full },
ReturnType::Type(..) => quote! { #return_ty },
};

let mut attributes = Vec::new();
let mut modifiers_out = vec![];

macro_rules! passthrough {
( $( $modifier:ident ),+ $(,)? ) => {
$( if let Some($modifier) = &modifiers.$modifier {
attributes.push(quote! { (#$modifier) });
modifiers_out.push(quote! { (#$modifier) });
}; )+
}
}
Expand All @@ -452,7 +471,7 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
// on a synthetic `(cache_on_disk)` modifier that can be inspected by
// macro-rules macros.
if modifiers.cache_on_disk_if.is_some() {
attributes.push(quote! { (cache_on_disk) });
modifiers_out.push(quote! { (cache_on_disk) });
}

// This uses the span of the query definition for the commas,
Expand All @@ -462,12 +481,13 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
// at the entire `rustc_queries!` invocation, which wouldn't
// be very useful.
let span = name.span();
let attribute_stream = quote_spanned! {span=> #(#attributes),*};
let doc_comments = &query.doc_comments;
let modifiers_stream = quote_spanned! { span => #(#modifiers_out),* };

// Add the query to the group
query_stream.extend(quote! {
#(#doc_comments)*
[#attribute_stream] fn #name(#arg) #result,
[#modifiers_stream]
fn #name(#key_ty) #return_ty,
});

if let Some(feedable) = &modifiers.feedable {
Expand All @@ -482,7 +502,8 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
"Query {name} cannot be both `feedable` and `eval_always`."
);
feedable_queries.extend(quote! {
[#attribute_stream] fn #name(#arg) #result,
[#modifiers_stream]
fn #name(#key_ty) #return_ty,
});
}

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
if i.name == ident.name {
return None;
} // Never suggest the same name
if i.name == kw::Underscore {
return None;
} // `use _` is never valid

let resolution = resolution.borrow();
if let Some(name_binding) = resolution.best_decl() {
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ pub const trait Iterator {
/// without giving up ownership of the original iterator,
/// so you can use the original iterator afterwards.
///
/// Uses [`impl<I: Iterator + ?Sized> Iterator for &mut I { type Item = I::Item; ...}`](https://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#impl-Iterator-for-%26mut+I).
/// Uses [`impl<I: Iterator + ?Sized> Iterator for &mut I { type Item = I::Item; ...}`](Iterator#impl-Iterator-for-%26mut+I).
///
/// # Examples
///
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/mem/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub struct Trait {
pub is_auto: bool,
}

/// Compile-time type information about arrays.
/// Compile-time type information about structs.
#[derive(Debug)]
#[non_exhaustive]
#[unstable(feature = "type_info", issue = "146922")]
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<B, C> ControlFlow<B, C> {
}
}

/// Converts the `ControlFlow` into an `Result` which is `Ok` if the
/// Converts the `ControlFlow` into a `Result` which is `Ok` if the
/// `ControlFlow` was `Break` and `Err` if otherwise.
///
/// # Examples
Expand Down Expand Up @@ -311,7 +311,7 @@ impl<B, C> ControlFlow<B, C> {
}
}

/// Converts the `ControlFlow` into an `Result` which is `Ok` if the
/// Converts the `ControlFlow` into a `Result` which is `Ok` if the
/// `ControlFlow` was `Continue` and `Err` if otherwise.
///
/// # Examples
Expand Down
10 changes: 9 additions & 1 deletion src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,15 @@ fn configure_cmake(
.define("CMAKE_CXX_COMPILER", sanitize_cc(&cxx))
.define("CMAKE_ASM_COMPILER", sanitize_cc(&cc));

cfg.build_arg("-j").build_arg(builder.jobs().to_string());
// If we are running under a FIFO jobserver, we should not pass -j to CMake; otherwise it
// overrides the jobserver settings and can lead to oversubscription.
let has_modern_jobserver = env::var("MAKEFLAGS")
.map(|flags| flags.contains("--jobserver-auth=fifo:"))
.unwrap_or(false);

if !has_modern_jobserver {
cfg.build_arg("-j").build_arg(builder.jobs().to_string());
}
let mut cflags = ccflags.cflags.clone();
// FIXME(madsmtm): Allow `cmake-rs` to select flags by itself by passing
// our flags via `.cflag`/`.cxxflag` instead.
Expand Down
14 changes: 11 additions & 3 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,17 @@ impl Builder<'_> {
assert_eq!(target, compiler.host);
}

// Remove make-related flags to ensure Cargo can correctly set things up
cargo.env_remove("MAKEFLAGS");
cargo.env_remove("MFLAGS");
// Bootstrap only supports modern FIFO jobservers. Older pipe-based jobservers can run into
// "invalid file descriptor" errors, as the jobserver file descriptors are not inherited by
// scripts like bootstrap.py, while the environment variable is propagated. So, we pass
// MAKEFLAGS only if we detect a FIFO jobserver, otherwise we clear it.
let has_modern_jobserver = env::var("MAKEFLAGS")
.map(|flags| flags.contains("--jobserver-auth=fifo:"))
.unwrap_or(false);

if !has_modern_jobserver {
cargo.env_remove("MAKEFLAGS");
}

cargo
}
Expand Down
Loading
Loading