Skip to content

Commit

Permalink
Auto merge of rust-lang#131980 - matthiaskrgr:rollup-iy5nw71, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#131814 (`optimize` attribute applied to things other than methods/functions/c…)
 - rust-lang#131927 (Check for filecheck directives in files marked `skip-filecheck`)
 - rust-lang#131967 (Remove `lower_mono_bounds`)
 - rust-lang#131973 (fix(rustdoc-json-types): document rustc-hash feature)
 - rust-lang#131976 (feat(rustdoc-json-types): mark simple enums as copy)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 20, 2024
2 parents 662180b + 4b65865 commit 7ed1a51
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 121 deletions.
7 changes: 5 additions & 2 deletions compiler/rustc_hir_analysis/src/collect/item_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use tracing::{debug, instrument};

use super::ItemCtxt;
use super::predicates_of::assert_only_contains_predicates_from;
use crate::bounds::Bounds;
use crate::hir_ty_lowering::{HirTyLowerer, PredicateFilter};

/// For associated types we include both bounds written on the type
Expand All @@ -36,7 +37,8 @@ fn associated_type_bounds<'tcx>(
);

let icx = ItemCtxt::new(tcx, assoc_item_def_id);
let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, hir_bounds, filter);
let mut bounds = Bounds::default();
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
// Associated types are implicitly sized unless a `?Sized` bound is found
icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span);

Expand Down Expand Up @@ -303,7 +305,8 @@ fn opaque_type_bounds<'tcx>(
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
ty::print::with_reduced_queries!({
let icx = ItemCtxt::new(tcx, opaque_def_id);
let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, hir_bounds, filter);
let mut bounds = Bounds::default();
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
// Opaque types are implicitly sized unless a `?Sized` bound is found
icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span);
debug!(?bounds);
Expand Down
20 changes: 12 additions & 8 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
// on a trait we must also consider the bounds that follow the trait's name,
// like `trait Foo: A + B + C`.
if let Some(self_bounds) = is_trait {
let bounds = icx.lowerer().lower_mono_bounds(
let mut bounds = Bounds::default();
icx.lowerer().lower_bounds(
tcx.types.self_param,
self_bounds,
&mut bounds,
ty::List::empty(),
PredicateFilter::All,
);
predicates.extend(bounds.clauses(tcx));
Expand Down Expand Up @@ -265,9 +268,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
}

let mut bounds = Bounds::default();
icx.lowerer().lower_poly_bounds(
icx.lowerer().lower_bounds(
ty,
bound_pred.bounds.iter(),
bound_pred.bounds,
&mut bounds,
bound_vars,
PredicateFilter::All,
Expand Down Expand Up @@ -626,7 +629,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
bug!("trait_def_id {trait_def_id:?} is not an item");
};

let (generics, bounds) = match item.kind {
let (generics, superbounds) = match item.kind {
hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
hir::ItemKind::TraitAlias(generics, supertraits) => (generics, supertraits),
_ => span_bug!(item.span, "super_predicates invoked on non-trait"),
Expand All @@ -635,7 +638,8 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
let icx = ItemCtxt::new(tcx, trait_def_id);

let self_param_ty = tcx.types.self_param;
let superbounds = icx.lowerer().lower_mono_bounds(self_param_ty, bounds, filter);
let mut bounds = Bounds::default();
icx.lowerer().lower_bounds(self_param_ty, superbounds, &mut bounds, ty::List::empty(), filter);

let where_bounds_that_match = icx.probe_ty_param_bounds_in_generics(
generics,
Expand All @@ -646,7 +650,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(

// Combine the two lists to form the complete set of superbounds:
let implied_bounds =
&*tcx.arena.alloc_from_iter(superbounds.clauses(tcx).chain(where_bounds_that_match));
&*tcx.arena.alloc_from_iter(bounds.clauses(tcx).chain(where_bounds_that_match));
debug!(?implied_bounds);

// Now require that immediate supertraits are lowered, which will, in
Expand Down Expand Up @@ -834,9 +838,9 @@ impl<'tcx> ItemCtxt<'tcx> {
};

let bound_vars = self.tcx.late_bound_vars(predicate.hir_id);
self.lowerer().lower_poly_bounds(
self.lowerer().lower_bounds(
bound_ty,
predicate.bounds.iter(),
predicate.bounds,
&mut bounds,
bound_vars,
filter,
Expand Down
35 changes: 3 additions & 32 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
/// There is an implied binder around `param_ty` and `hir_bounds`.
/// See `lower_poly_trait_ref` for more details.
#[instrument(level = "debug", skip(self, hir_bounds, bounds))]
pub(crate) fn lower_poly_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>(
pub(crate) fn lower_bounds<'hir, I: IntoIterator<Item = &'hir hir::GenericBound<'tcx>>>(
&self,
param_ty: Ty<'tcx>,
hir_bounds: I,
Expand Down Expand Up @@ -212,35 +212,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
}

/// Lower HIR bounds into `bounds` given the self type `param_ty` and *no* overarching late-bound vars.
///
/// ### Example
///
/// ```ignore (illustrative)
/// fn foo<T: Bar + Baz>() { }
/// // ^ ^^^^^^^^^ hir_bounds
/// // param_ty
/// ```
pub(crate) fn lower_mono_bounds(
&self,
param_ty: Ty<'tcx>,
hir_bounds: &[hir::GenericBound<'tcx>],
predicate_filter: PredicateFilter,
) -> Bounds<'tcx> {
let mut bounds = Bounds::default();

self.lower_poly_bounds(
param_ty,
hir_bounds.iter(),
&mut bounds,
ty::List::empty(),
predicate_filter,
);
debug!(?bounds);

bounds
}

/// Lower an associated item constraint from the HIR into `bounds`.
///
/// ### A Note on Binders
Expand Down Expand Up @@ -444,9 +415,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// parameter to have a skipped binder.
let param_ty =
Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());
self.lower_poly_bounds(
self.lower_bounds(
param_ty,
hir_bounds.iter(),
hir_bounds,
bounds,
projection_ty.bound_vars(),
predicate_filter,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,9 @@ passes_only_has_effect_on =
*[unspecified] (unspecified--this is a compiler bug)
}
passes_optimize_not_fn_or_closure =
attribute should be applied to function or closure
.label = not a function or closure
passes_optimize_invalid_target =
attribute applied to an invalid target
.label = invalid target
passes_outer_crate_level_attr =
crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
Expand Down
30 changes: 13 additions & 17 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
[sym::inline, ..] => self.check_inline(hir_id, attr, span, target),
[sym::coverage, ..] => self.check_coverage(attr, span, target),
[sym::optimize, ..] => self.check_optimize(hir_id, attr, target),
[sym::optimize, ..] => self.check_optimize(hir_id, attr, span, target),
[sym::no_sanitize, ..] => {
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
}
Expand Down Expand Up @@ -433,23 +433,19 @@ impl<'tcx> CheckAttrVisitor<'tcx> {

/// Checks that `#[optimize(..)]` is applied to a function/closure/method,
/// or to an impl block or module.
// FIXME(#128488): this should probably be elevated to an error?
fn check_optimize(&self, hir_id: HirId, attr: &Attribute, target: Target) {
match target {
fn check_optimize(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
let is_valid = matches!(
target,
Target::Fn
| Target::Closure
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent)
| Target::Impl
| Target::Mod => {}

_ => {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span,
errors::OptimizeNotFnOrClosure,
);
}
| Target::Closure
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent)
);
if !is_valid {
self.dcx().emit_err(errors::OptimizeInvalidTarget {
attr_span: attr.span,
defn_span: span,
on_crate: hir_id == CRATE_HIR_ID,
});
}
}

Expand Down
12 changes: 9 additions & 3 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ pub(crate) struct CoverageNotFnOrClosure {
pub defn_span: Span,
}

#[derive(LintDiagnostic)]
#[diag(passes_optimize_not_fn_or_closure)]
pub(crate) struct OptimizeNotFnOrClosure;
#[derive(Diagnostic)]
#[diag(passes_optimize_invalid_target)]
pub(crate) struct OptimizeInvalidTarget {
#[primary_span]
pub attr_span: Span,
#[label]
pub defn_span: Span,
pub on_crate: bool,
}

#[derive(Diagnostic)]
#[diag(passes_should_be_applied_to_fn)]
Expand Down
26 changes: 19 additions & 7 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
//!
//! These types are the public API exposed through the `--output-format json` flag. The [`Crate`]
//! struct is the root of the JSON blob and all other items are contained within.
//!
//! We expose a `rustc-hash` feature that is disabled by default. This feature switches the
//! [`std::collections::HashMap`] for [`rustc_hash::FxHashMap`] to improve the performance of said
//! `HashMap` in specific situations.
//!
//! `cargo-semver-checks` for example, saw a [-3% improvement][1] when benchmarking using the
//! `aws_sdk_ec2` JSON output (~500MB of JSON). As always, we recommend measuring the impact before
//! turning this feature on, as [`FxHashMap`][2] only concerns itself with hash speed, and may
//! increase the number of collisions.
//!
//! [1]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/rustc-hash.20and.20performance.20of.20rustdoc-types/near/474855731
//! [2]: https://crates.io/crates/rustc-hash
#[cfg(not(feature = "rustc-hash"))]
use std::collections::HashMap;
Expand Down Expand Up @@ -305,10 +317,10 @@ pub enum AssocItemConstraintKind {
// FIXME(aDotInTheVoid): Consider making this non-public in rustdoc-types.
pub struct Id(pub u32);

/// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any aditional info.
/// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any additional info.
///
/// Part of [`ItemSummary`].
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ItemKind {
/// A module declaration, e.g. `mod foo;` or `mod foo {}`
Expand Down Expand Up @@ -698,7 +710,7 @@ pub enum Abi {
Aapcs { unwind: bool },
/// Can be specified as `extern "win64"`.
Win64 { unwind: bool },
/// Can be specifed as `extern "sysv64"`.
/// Can be specified as `extern "sysv64"`.
SysV64 { unwind: bool },
/// Can be specified as `extern "system"`.
System { unwind: bool },
Expand Down Expand Up @@ -892,7 +904,7 @@ pub enum GenericBound {
}

/// A set of modifiers applied to a trait.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TraitBoundModifier {
/// Marks the absence of a modifier.
Expand Down Expand Up @@ -996,7 +1008,7 @@ pub enum Type {
QualifiedPath {
/// The name of the associated type in the parent type.
///
/// ```ignore (incomplete expresssion)
/// ```ignore (incomplete expression)
/// <core::array::IntoIter<u32, 42> as Iterator>::Item
/// // ^^^^
/// ```
Expand Down Expand Up @@ -1083,7 +1095,7 @@ pub struct FunctionSignature {
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Trait {
/// Whether the trait is marked `auto` and is thus implemented automatically
/// for all aplicable types.
/// for all applicable types.
pub is_auto: bool,
/// Whether the trait is marked as `unsafe`.
pub is_unsafe: bool,
Expand Down Expand Up @@ -1193,7 +1205,7 @@ pub struct ProcMacro {
}

/// The way a [`ProcMacro`] is declared to be used.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MacroKind {
/// A bang macro `foo!()`.
Expand Down
3 changes: 3 additions & 0 deletions src/tools/miropt-test-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ pub fn files_for_miropt_test(

out.push(MiroptTestFile { expected_file, from_file, to_file });
}
if !run_filecheck && l.trim_start().starts_with("// CHECK") {
panic!("error: test contains filecheck directive but is marked `skip-filecheck`");
}
}

MiroptTest { run_filecheck, suffix, files: out, passes }
Expand Down
3 changes: 1 addition & 2 deletions tests/mir-opt/dest-prop/union.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//! Tests that we can propagate into places that are projections into unions
//@ compile-flags: -Zunsound-mir-opts -C debuginfo=full
Expand All @@ -8,7 +7,7 @@ fn val() -> u32 {

// EMIT_MIR union.main.DestinationPropagation.diff
fn main() {
// CHECK-LABEL: fn args(
// CHECK-LABEL: fn main(
// CHECK: {{_.*}} = Un { us: const 1_u32 };
union Un {
us: u32,
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/issues/issue_59352.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// This test is a mirror of codegen/issue-59352.rs.
// The LLVM inliner doesn't inline `char::method::is_digit()` and so it doesn't recognize this case
Expand Down
22 changes: 18 additions & 4 deletions tests/ui/attributes/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#![deny(unused_attributes)]
#![allow(dead_code)]

#[optimize(speed)] //~ ERROR attribute should be applied to function or closure
//@ edition: 2018

#[optimize(speed)] //~ ERROR attribute applied to an invalid target
struct F;

fn invalid() {
#[optimize(speed)] //~ ERROR attribute should be applied to function or closure
#[optimize(speed)] //~ ERROR attribute applied to an invalid target
{
1
};
Expand All @@ -16,13 +18,25 @@ fn invalid() {
#[optimize(speed)]
fn valid() {}

#[optimize(speed)]
#[optimize(speed)] //~ ERROR attribute applied to an invalid target
mod valid_module {}

#[optimize(speed)]
#[optimize(speed)] //~ ERROR attribute applied to an invalid target
impl F {}

fn main() {
let _ = #[optimize(speed)]
(|| 1);
}

use std::future::Future;

fn async_block() -> impl Future<Output = ()> {
#[optimize(speed)]
async { }
}

#[optimize(speed)]
async fn async_fn() {
()
}
Loading

0 comments on commit 7ed1a51

Please sign in to comment.