Skip to content

Commit

Permalink
Auto merge of #134492 - jhpratt:rollup-elpdwd9, r=jhpratt
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - #132056 (Stabilize `#[diagnostic::do_not_recommend]`)
 - #133643 (-Znext-solver: modify candidate preference rules)
 - #134388 (Update books)
 - #134418 (Advent of `tests/ui` (misc cleanups and improvements) [3/N])
 - #134473 (chore: fix some typos)
 - #134481 (Point at lint name instead of whole attr for gated lints)
 - #134484 (Add nnethercote to the `triagebot.toml` vacation list.)
 - #134490 (Fix typo in ptr/mod.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 19, 2024
2 parents 023521e + 80cf85d commit bab18a5
Show file tree
Hide file tree
Showing 101 changed files with 724 additions and 399 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/compiler_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ffi::c_int;
#[cfg(feature = "jit")]
use std::ffi::c_void;

// FIXME replace with core::ffi::c_size_t once stablized
// FIXME replace with core::ffi::c_size_t once stabilized
#[allow(non_camel_case_types)]
#[cfg(feature = "jit")]
type size_t = usize;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
sym::log2f64 => "log2",
sym::fmaf32 => "fmaf",
sym::fmaf64 => "fma",
// FIXME: calling `fma` from libc without FMA target feature uses expensive sofware emulation
// FIXME: calling `fma` from libc without FMA target feature uses expensive software emulation
sym::fmuladdf32 => "fmaf", // TODO: use gcc intrinsic analogous to llvm.fmuladd.f32
sym::fmuladdf64 => "fma", // TODO: use gcc intrinsic analogous to llvm.fmuladd.f64
sym::fabsf32 => "fabsf",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2523,7 +2523,7 @@ impl HumanEmitter {
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
}
[] => {
// FIXME: needed? Doesn't get excercised in any test.
// FIXME: needed? Doesn't get exercised in any test.
self.draw_col_separator_no_space(buffer, *row_num, max_line_num_len + 1);
}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/markdown/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ fn parse_with_end_pat<'a>(
None
}

/// Resturn `(match, residual)` to end of line. The EOL is returned with the
/// Return `(match, residual)` to end of line. The EOL is returned with the
/// residual.
fn parse_to_newline(buf: &[u8]) -> (&[u8], &[u8]) {
buf.iter().position(|ch| *ch == b'\n').map_or((buf, &[]), |pos| buf.split_at(pos))
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ declare_features! (
(accepted, destructuring_assignment, "1.59.0", Some(71126)),
/// Allows using the `#[diagnostic]` attribute tool namespace
(accepted, diagnostic_namespace, "1.78.0", Some(111996)),
/// Controls errors in trait implementations.
(accepted, do_not_recommend, "CURRENT_RUSTC_VERSION", Some(51992)),
/// Allows `#[doc(alias = "...")]`.
(accepted, doc_alias, "1.48.0", Some(50146)),
/// Allows `..` in tuple (struct) patterns.
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,10 +1187,9 @@ pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>>
map
});

pub fn is_stable_diagnostic_attribute(sym: Symbol, features: &Features) -> bool {
pub fn is_stable_diagnostic_attribute(sym: Symbol, _features: &Features) -> bool {
match sym {
sym::on_unimplemented => true,
sym::do_not_recommend => features.do_not_recommend(),
sym::on_unimplemented | sym::do_not_recommend => true,
_ => false,
}
}
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,6 @@ declare_features! (
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
/// Allows deref patterns.
(incomplete, deref_patterns, "1.79.0", Some(87121)),
/// Controls errors in trait implementations.
(unstable, do_not_recommend, "1.67.0", Some(51992)),
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
(unstable, doc_auto_cfg, "1.58.0", Some(43781)),
/// Allows `#[doc(cfg(...))]`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {

let src = LintLevelSource::Node { name, span: sp, reason };
for &id in ids {
if self.check_gated_lint(id, attr.span(), false) {
if self.check_gated_lint(id, sp, false) {
self.insert_spec(id, (level, src));
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ pub struct ParamEnv<'tcx> {
}

impl<'tcx> rustc_type_ir::inherent::ParamEnv<TyCtxt<'tcx>> for ParamEnv<'tcx> {
fn caller_bounds(self) -> impl IntoIterator<Item = ty::Clause<'tcx>> {
fn caller_bounds(self) -> impl inherent::SliceLike<Item = ty::Clause<'tcx>> {
self.caller_bounds()
}
}
Expand Down
119 changes: 95 additions & 24 deletions compiler/rustc_next_trait_solver/src/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::cmp::Ordering;
use rustc_type_ir::data_structures::HashMap;
use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_type_ir::inherent::*;
use rustc_type_ir::solve::{Goal, QueryInput};
use rustc_type_ir::visit::TypeVisitableExt;
use rustc_type_ir::{
self as ty, Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, InferCtxtLike,
Expand All @@ -17,8 +18,11 @@ use crate::delegate::SolverDelegate;
/// while canonicalizing the response happens in the context of the
/// query.
#[derive(Debug, Clone, Copy)]
pub enum CanonicalizeMode {
Input,
enum CanonicalizeMode {
/// When canonicalizing the `param_env`, we keep `'static` as merging
/// trait candidates relies on it when deciding whether a where-bound
/// is trivial.
Input { keep_static: bool },
/// FIXME: We currently return region constraints referring to
/// placeholders and inference variables from a binder instantiated
/// inside of the query.
Expand Down Expand Up @@ -59,15 +63,15 @@ pub struct Canonicalizer<'a, D: SolverDelegate<Interner = I>, I: Interner> {
}

impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
pub fn canonicalize<T: TypeFoldable<I>>(
pub fn canonicalize_response<T: TypeFoldable<I>>(
delegate: &'a D,
canonicalize_mode: CanonicalizeMode,
max_input_universe: ty::UniverseIndex,
variables: &'a mut Vec<I::GenericArg>,
value: T,
) -> ty::Canonical<I, T> {
let mut canonicalizer = Canonicalizer {
delegate,
canonicalize_mode,
canonicalize_mode: CanonicalizeMode::Response { max_input_universe },

variables,
variable_lookup_table: Default::default(),
Expand All @@ -80,9 +84,67 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
let value = value.fold_with(&mut canonicalizer);
assert!(!value.has_infer(), "unexpected infer in {value:?}");
assert!(!value.has_placeholders(), "unexpected placeholders in {value:?}");

let (max_universe, variables) = canonicalizer.finalize();
Canonical { max_universe, variables, value }
}

/// When canonicalizing query inputs, we keep `'static` in the `param_env`
/// but erase it everywhere else. We generally don't want to depend on region
/// identity, so while it should not matter whether `'static` is kept in the
/// value or opaque type storage as well, this prevents us from accidentally
/// relying on it in the future.
///
/// We want to keep the option of canonicalizing `'static` to an existential
/// variable in the future by changing the way we detect global where-bounds.
pub fn canonicalize_input<P: TypeFoldable<I>>(
delegate: &'a D,
variables: &'a mut Vec<I::GenericArg>,
input: QueryInput<I, P>,
) -> ty::Canonical<I, QueryInput<I, P>> {
// First canonicalize the `param_env` while keeping `'static`
let mut env_canonicalizer = Canonicalizer {
delegate,
canonicalize_mode: CanonicalizeMode::Input { keep_static: true },

variables,
variable_lookup_table: Default::default(),
primitive_var_infos: Vec::new(),
binder_index: ty::INNERMOST,

cache: Default::default(),
};
let param_env = input.goal.param_env.fold_with(&mut env_canonicalizer);
debug_assert_eq!(env_canonicalizer.binder_index, ty::INNERMOST);
// Then canonicalize the rest of the input without keeping `'static`
// while *mostly* reusing the canonicalizer from above.
let mut rest_canonicalizer = Canonicalizer {
delegate,
canonicalize_mode: CanonicalizeMode::Input { keep_static: false },

variables: env_canonicalizer.variables,
// We're able to reuse the `variable_lookup_table` as whether or not
// it already contains an entry for `'static` does not matter.
variable_lookup_table: env_canonicalizer.variable_lookup_table,
primitive_var_infos: env_canonicalizer.primitive_var_infos,
binder_index: ty::INNERMOST,

// We do not reuse the cache as it may contain entries whose canonicalized
// value contains `'static`. While we could alternatively handle this by
// checking for `'static` when using cached entries, this does not
// feel worth the effort. I do not expect that a `ParamEnv` will ever
// contain large enough types for caching to be necessary.
cache: Default::default(),
};

let predicate = input.goal.predicate.fold_with(&mut rest_canonicalizer);
let goal = Goal { param_env, predicate };
let predefined_opaques_in_body =
input.predefined_opaques_in_body.fold_with(&mut rest_canonicalizer);
let value = QueryInput { goal, predefined_opaques_in_body };

assert!(!value.has_infer(), "unexpected infer in {value:?}");
assert!(!value.has_placeholders(), "unexpected placeholders in {value:?}");
let (max_universe, variables) = rest_canonicalizer.finalize();
Canonical { max_universe, variables, value }
}

Expand Down Expand Up @@ -126,7 +188,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
// all information which should not matter for the solver.
//
// For this we compress universes as much as possible.
CanonicalizeMode::Input => {}
CanonicalizeMode::Input { .. } => {}
// When canonicalizing a response we map a universes already entered
// by the caller to the root universe and only return useful universe
// information for placeholders and inference variables created inside
Expand Down Expand Up @@ -290,17 +352,15 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
}
},
ty::Placeholder(placeholder) => match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderTy(PlaceholderLike::new(
placeholder.universe(),
self.variables.len().into(),
)),
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderTy(
PlaceholderLike::new(placeholder.universe(), self.variables.len().into()),
),
CanonicalizeMode::Response { .. } => CanonicalVarKind::PlaceholderTy(placeholder),
},
ty::Param(_) => match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderTy(PlaceholderLike::new(
ty::UniverseIndex::ROOT,
self.variables.len().into(),
)),
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderTy(
PlaceholderLike::new(ty::UniverseIndex::ROOT, self.variables.len().into()),
),
CanonicalizeMode::Response { .. } => panic!("param ty in response: {t:?}"),
},
ty::Bool
Expand Down Expand Up @@ -357,29 +417,38 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
let kind = match r.kind() {
ty::ReBound(..) => return r,

// We may encounter `ReStatic` in item signatures or the hidden type
// of an opaque. `ReErased` should only be encountered in the hidden
// We don't canonicalize `ReStatic` in the `param_env` as we use it
// when checking whether a `ParamEnv` candidate is global.
ty::ReStatic => match self.canonicalize_mode {
CanonicalizeMode::Input { keep_static: false } => {
CanonicalVarKind::Region(ty::UniverseIndex::ROOT)
}
CanonicalizeMode::Input { keep_static: true }
| CanonicalizeMode::Response { .. } => return r,
},

// `ReErased` should only be encountered in the hidden
// type of an opaque for regions that are ignored for the purposes of
// captures.
//
// FIXME: We should investigate the perf implications of not uniquifying
// `ReErased`. We may be able to short-circuit registering region
// obligations if we encounter a `ReErased` on one side, for example.
ty::ReStatic | ty::ReErased | ty::ReError(_) => match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
ty::ReErased | ty::ReError(_) => match self.canonicalize_mode {
CanonicalizeMode::Input { .. } => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
CanonicalizeMode::Response { .. } => return r,
},

ty::ReEarlyParam(_) | ty::ReLateParam(_) => match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
CanonicalizeMode::Input { .. } => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
CanonicalizeMode::Response { .. } => {
panic!("unexpected region in response: {r:?}")
}
},

ty::RePlaceholder(placeholder) => match self.canonicalize_mode {
// We canonicalize placeholder regions as existentials in query inputs.
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
CanonicalizeMode::Input { .. } => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
CanonicalizeMode::Response { max_input_universe } => {
// If we have a placeholder region inside of a query, it must be from
// a new universe.
Expand All @@ -397,7 +466,9 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
"region vid should have been resolved fully before canonicalization"
);
match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
CanonicalizeMode::Input { keep_static: _ } => {
CanonicalVarKind::Region(ty::UniverseIndex::ROOT)
}
CanonicalizeMode::Response { .. } => {
CanonicalVarKind::Region(self.delegate.universe_of_lt(vid).unwrap())
}
Expand Down Expand Up @@ -434,15 +505,15 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
ty::InferConst::Fresh(_) => todo!(),
},
ty::ConstKind::Placeholder(placeholder) => match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderConst(
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderConst(
PlaceholderLike::new(placeholder.universe(), self.variables.len().into()),
),
CanonicalizeMode::Response { .. } => {
CanonicalVarKind::PlaceholderConst(placeholder)
}
},
ty::ConstKind::Param(_) => match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderConst(
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderConst(
PlaceholderLike::new(ty::UniverseIndex::ROOT, self.variables.len().into()),
),
CanonicalizeMode::Response { .. } => panic!("param ty in response: {c:?}"),
Expand Down
Loading

0 comments on commit bab18a5

Please sign in to comment.