Auto merge of #124961 - matthiaskrgr:rollup-1jj65p6, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #124551 (Add benchmarks for `impl Debug for str`) - #124915 (`rustc_target` cleanups) - #124918 (Eliminate some `FIXME(lcnr)` comments) - #124927 (opt-dist: use xz2 instead of xz crate) - #124936 (analyse visitor: build proof tree in probe) - #124943 (always use `GenericArgsRef`) - #124955 (Use fewer origins when creating type variables.) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
f7b1501ce7
66 changed files with 366 additions and 467 deletions
|
@ -19,12 +19,10 @@ use rustc_infer::infer::canonical::query_response::make_query_region_constraints
|
|||
use rustc_infer::infer::canonical::CanonicalVarValues;
|
||||
use rustc_infer::infer::canonical::{CanonicalExt, QueryRegionConstraints};
|
||||
use rustc_infer::infer::resolve::EagerResolver;
|
||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
||||
use rustc_infer::infer::RegionVariableOrigin;
|
||||
use rustc_infer::infer::{InferCtxt, InferOk};
|
||||
use rustc_infer::traits::solve::NestedNormalizationGoals;
|
||||
use rustc_middle::infer::canonical::Canonical;
|
||||
use rustc_middle::infer::unify_key::ConstVariableOrigin;
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::traits::solve::{
|
||||
ExternalConstraintsData, MaybeCause, PredefinedOpaquesData, QueryInput,
|
||||
|
@ -409,6 +407,7 @@ pub(in crate::solve) fn make_canonical_state<'tcx, T: TypeFoldable<TyCtxt<'tcx>>
|
|||
/// This currently assumes that unifying the var values trivially succeeds.
|
||||
/// Adding any inference constraints which weren't present when originally
|
||||
/// computing the canonical query can result in bugs.
|
||||
#[instrument(level = "debug", skip(infcx, span, param_env))]
|
||||
pub(in crate::solve) fn instantiate_canonical_state<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
span: Span,
|
||||
|
@ -424,12 +423,8 @@ pub(in crate::solve) fn instantiate_canonical_state<'tcx, T: TypeFoldable<TyCtxt
|
|||
ty::GenericArgKind::Lifetime(_) => {
|
||||
infcx.next_region_var(RegionVariableOrigin::MiscVariable(span)).into()
|
||||
}
|
||||
ty::GenericArgKind::Type(_) => {
|
||||
infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span }).into()
|
||||
}
|
||||
ty::GenericArgKind::Const(ct) => infcx
|
||||
.next_const_var(ct.ty(), ConstVariableOrigin { param_def_id: None, span })
|
||||
.into(),
|
||||
ty::GenericArgKind::Type(_) => infcx.next_ty_var(span).into(),
|
||||
ty::GenericArgKind::Const(ct) => infcx.next_const_var(ct.ty(), span).into(),
|
||||
};
|
||||
|
||||
orig_values.push(unconstrained);
|
||||
|
|
|
@ -2,7 +2,6 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_infer::infer::at::ToTrace;
|
||||
use rustc_infer::infer::canonical::CanonicalVarValues;
|
||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
||||
use rustc_infer::infer::{
|
||||
BoundRegionConversionTime, DefineOpaqueTypes, InferCtxt, InferOk, TyCtxtInferExt,
|
||||
};
|
||||
|
@ -11,7 +10,6 @@ use rustc_infer::traits::solve::{MaybeCause, NestedNormalizationGoals};
|
|||
use rustc_infer::traits::ObligationCause;
|
||||
use rustc_macros::{extension, HashStable};
|
||||
use rustc_middle::infer::canonical::CanonicalVarInfos;
|
||||
use rustc_middle::infer::unify_key::ConstVariableOrigin;
|
||||
use rustc_middle::traits::solve::inspect;
|
||||
use rustc_middle::traits::solve::{
|
||||
CanonicalInput, CanonicalResponse, Certainty, PredefinedOpaques, PredefinedOpaquesData,
|
||||
|
@ -600,15 +598,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
}
|
||||
|
||||
pub(super) fn next_ty_infer(&mut self) -> Ty<'tcx> {
|
||||
let ty = self.infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span: DUMMY_SP });
|
||||
let ty = self.infcx.next_ty_var(DUMMY_SP);
|
||||
self.inspect.add_var_value(ty);
|
||||
ty
|
||||
}
|
||||
|
||||
pub(super) fn next_const_infer(&mut self, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
||||
let ct = self
|
||||
.infcx
|
||||
.next_const_var(ty, ConstVariableOrigin { param_def_id: None, span: DUMMY_SP });
|
||||
let ct = self.infcx.next_const_var(ty, DUMMY_SP);
|
||||
self.inspect.add_var_value(ct);
|
||||
ct
|
||||
}
|
||||
|
|
|
@ -12,10 +12,8 @@
|
|||
use rustc_ast_ir::try_visit;
|
||||
use rustc_ast_ir::visit::VisitorResult;
|
||||
use rustc_infer::infer::resolve::EagerResolver;
|
||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
||||
use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, InferOk};
|
||||
use rustc_macros::extension;
|
||||
use rustc_middle::infer::unify_key::ConstVariableOrigin;
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::traits::solve::{inspect, QueryResult};
|
||||
use rustc_middle::traits::solve::{Certainty, Goal};
|
||||
|
@ -146,6 +144,11 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
|
|||
/// inference constraints, and optionally the args of an impl if this candidate
|
||||
/// came from a `CandidateSource::Impl`. This function modifies the state of the
|
||||
/// `infcx`.
|
||||
#[instrument(
|
||||
level = "debug",
|
||||
skip_all,
|
||||
fields(goal = ?self.goal.goal, nested_goals = ?self.nested_goals)
|
||||
)]
|
||||
pub fn instantiate_nested_goals_and_opt_impl_args(
|
||||
&self,
|
||||
span: Span,
|
||||
|
@ -201,22 +204,28 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
|
|||
.map(|(source, goal)| match goal.predicate.kind().no_bound_vars() {
|
||||
Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => {
|
||||
let unconstrained_term = match term.unpack() {
|
||||
ty::TermKind::Ty(_) => infcx
|
||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span })
|
||||
.into(),
|
||||
ty::TermKind::Const(ct) => infcx
|
||||
.next_const_var(
|
||||
ct.ty(),
|
||||
ConstVariableOrigin { param_def_id: None, span },
|
||||
)
|
||||
.into(),
|
||||
ty::TermKind::Ty(_) => infcx.next_ty_var(span).into(),
|
||||
ty::TermKind::Const(ct) => infcx.next_const_var(ct.ty(), span).into(),
|
||||
};
|
||||
let goal =
|
||||
goal.with(infcx.tcx, ty::NormalizesTo { alias, term: unconstrained_term });
|
||||
let proof_tree = EvalCtxt::enter_root(infcx, GenerateProofTree::Yes, |ecx| {
|
||||
ecx.evaluate_goal_raw(GoalEvaluationKind::Root, GoalSource::Misc, goal)
|
||||
})
|
||||
.1;
|
||||
// We have to use a `probe` here as evaluating a `NormalizesTo` can constrain the
|
||||
// expected term. This means that candidates which only fail due to nested goals
|
||||
// and which normalize to a different term then the final result could ICE: when
|
||||
// building their proof tree, the expected term was unconstrained, but when
|
||||
// instantiating the candidate it is already constrained to the result of another
|
||||
// candidate.
|
||||
let proof_tree = infcx
|
||||
.probe(|_| {
|
||||
EvalCtxt::enter_root(infcx, GenerateProofTree::Yes, |ecx| {
|
||||
ecx.evaluate_goal_raw(
|
||||
GoalEvaluationKind::Root,
|
||||
GoalSource::Misc,
|
||||
goal,
|
||||
)
|
||||
})
|
||||
})
|
||||
.1;
|
||||
InspectGoal::new(
|
||||
infcx,
|
||||
self.goal.depth + 1,
|
||||
|
@ -225,13 +234,17 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
|
|||
source,
|
||||
)
|
||||
}
|
||||
_ => InspectGoal::new(
|
||||
infcx,
|
||||
self.goal.depth + 1,
|
||||
infcx.evaluate_root_goal(goal, GenerateProofTree::Yes).1.unwrap(),
|
||||
None,
|
||||
source,
|
||||
),
|
||||
_ => {
|
||||
// We're using a probe here as evaluating a goal could constrain
|
||||
// inference variables by choosing one candidate. If we then recurse
|
||||
// into another candidate who ends up with different inference
|
||||
// constraints, we get an ICE if we already applied the constraints
|
||||
// from the chosen candidate.
|
||||
let proof_tree = infcx
|
||||
.probe(|_| infcx.evaluate_root_goal(goal, GenerateProofTree::Yes).1)
|
||||
.unwrap();
|
||||
InspectGoal::new(infcx, self.goal.depth + 1, proof_tree, None, source)
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
|
|
@ -3,11 +3,9 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt;
|
|||
use crate::traits::{BoundVarReplacer, PlaceholderReplacer};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_infer::infer::at::At;
|
||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
||||
use rustc_infer::infer::InferCtxt;
|
||||
use rustc_infer::traits::TraitEngineExt;
|
||||
use rustc_infer::traits::{FulfillmentError, Obligation, TraitEngine};
|
||||
use rustc_middle::infer::unify_key::ConstVariableOrigin;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::{self, AliasTy, Ty, TyCtxt, UniverseIndex};
|
||||
use rustc_middle::ty::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable};
|
||||
|
@ -74,8 +72,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
|||
|
||||
self.depth += 1;
|
||||
|
||||
let new_infer_ty =
|
||||
infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span: self.at.cause.span });
|
||||
let new_infer_ty = infcx.next_ty_var(self.at.cause.span);
|
||||
let obligation = Obligation::new(
|
||||
tcx,
|
||||
self.at.cause.clone(),
|
||||
|
@ -120,10 +117,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
|||
|
||||
self.depth += 1;
|
||||
|
||||
let new_infer_ct = infcx.next_const_var(
|
||||
ty,
|
||||
ConstVariableOrigin { param_def_id: None, span: self.at.cause.span },
|
||||
);
|
||||
let new_infer_ct = infcx.next_const_var(ty, self.at.cause.span);
|
||||
let obligation = Obligation::new(
|
||||
tcx,
|
||||
self.at.cause.clone(),
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::infer::type_variable::TypeVariableOrigin;
|
||||
use crate::infer::InferCtxt;
|
||||
use crate::traits::{Obligation, ObligationCause, ObligationCtxt};
|
||||
use rustc_errors::{codes::*, pluralize, struct_span_code_err, Applicability, Diag};
|
||||
|
@ -218,8 +217,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
let Some(trait_def_id) = trait_def_id else { continue };
|
||||
// Make a fresh inference variable so we can determine what the generic parameters
|
||||
// of the trait are.
|
||||
let var =
|
||||
self.next_ty_var(TypeVariableOrigin { span: DUMMY_SP, param_def_id: None });
|
||||
let var = self.next_ty_var(DUMMY_SP);
|
||||
// FIXME(effects)
|
||||
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, [ty.skip_binder(), var]);
|
||||
let obligation = Obligation::new(
|
||||
|
|
|
@ -24,7 +24,6 @@ use rustc_hir::is_range_literal;
|
|||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, HirId, Node};
|
||||
use rustc_infer::infer::error_reporting::TypeErrCtxt;
|
||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
||||
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk};
|
||||
use rustc_macros::extension;
|
||||
use rustc_middle::hir::map;
|
||||
|
@ -1893,8 +1892,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id) => {
|
||||
infcx.tcx.mk_fn_sig(
|
||||
*inputs,
|
||||
infcx
|
||||
.next_ty_var(TypeVariableOrigin { span: DUMMY_SP, param_def_id: None }),
|
||||
infcx.next_ty_var(DUMMY_SP),
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
abi::Abi::Rust,
|
||||
|
@ -1902,7 +1900,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
_ => infcx.tcx.mk_fn_sig(
|
||||
[inputs],
|
||||
infcx.next_ty_var(TypeVariableOrigin { span: DUMMY_SP, param_def_id: None }),
|
||||
infcx.next_ty_var(DUMMY_SP),
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
abi::Abi::Rust,
|
||||
|
@ -4263,7 +4261,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
continue;
|
||||
};
|
||||
|
||||
let origin = TypeVariableOrigin { param_def_id: None, span };
|
||||
// Make `Self` be equivalent to the type of the call chain
|
||||
// expression we're looking at now, so that we can tell what
|
||||
// for example `Iterator::Item` is at this point in the chain.
|
||||
|
@ -4277,7 +4274,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
// This will hold the resolved type of the associated type, if the
|
||||
// current expression implements the trait that associated type is
|
||||
// in. For example, this would be what `Iterator::Item` is here.
|
||||
let ty = self.infcx.next_ty_var(origin);
|
||||
let ty = self.infcx.next_ty_var(span);
|
||||
// This corresponds to `<ExprTy as Iterator>::Item = _`.
|
||||
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
|
||||
ty::ClauseKind::Projection(ty::ProjectionPredicate {
|
||||
|
|
|
@ -6,7 +6,6 @@ use crate::errors::{
|
|||
AsyncClosureNotFn, ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch,
|
||||
};
|
||||
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
|
||||
use crate::infer::type_variable::TypeVariableOrigin;
|
||||
use crate::infer::InferCtxtExt as _;
|
||||
use crate::infer::{self, InferCtxt};
|
||||
use crate::traits::error_reporting::infer_ctxt_ext::InferCtxtExt;
|
||||
|
@ -2826,9 +2825,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
if let ty::Param(_) = *ty.kind() {
|
||||
let infcx = self.infcx;
|
||||
*self.var_map.entry(ty).or_insert_with(|| {
|
||||
infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span: DUMMY_SP })
|
||||
})
|
||||
*self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var(DUMMY_SP))
|
||||
} else {
|
||||
ty.super_fold_with(self)
|
||||
}
|
||||
|
@ -3443,8 +3440,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
self.dcx().try_steal_replace_and_emit_err(self.tcx.def_span(def_id), StashKey::Cycle, err)
|
||||
}
|
||||
|
||||
// FIXME(@lcnr): This function could be changed to trait `TraitRef` directly
|
||||
// instead of using a `Binder`.
|
||||
fn report_signature_mismatch_error(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
|
|
|
@ -10,7 +10,7 @@ use rustc_infer::infer::canonical::Canonical;
|
|||
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
|
||||
use rustc_infer::traits::query::NoSolution;
|
||||
use rustc_infer::{infer::outlives::env::OutlivesEnvironment, traits::FulfillmentError};
|
||||
use rustc_middle::ty::{self, AdtDef, GenericArg, List, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_span::DUMMY_SP;
|
||||
|
||||
use super::outlives_bounds::InferCtxtExt;
|
||||
|
@ -129,7 +129,7 @@ pub fn all_fields_implement_trait<'tcx>(
|
|||
param_env: ty::ParamEnv<'tcx>,
|
||||
self_type: Ty<'tcx>,
|
||||
adt: AdtDef<'tcx>,
|
||||
args: &'tcx List<GenericArg<'tcx>>,
|
||||
args: ty::GenericArgsRef<'tcx>,
|
||||
parent_cause: ObligationCause<'tcx>,
|
||||
lang_item: LangItem,
|
||||
) -> Result<(), Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>> {
|
||||
|
|
|
@ -18,7 +18,6 @@ use rustc_middle::traits::ImplSource;
|
|||
use rustc_middle::traits::ImplSourceUserDefinedData;
|
||||
|
||||
use crate::errors::InherentProjectionNormalizationOverflow;
|
||||
use crate::infer::type_variable::TypeVariableOrigin;
|
||||
use crate::infer::{BoundRegionConversionTime, InferOk};
|
||||
use crate::traits::normalize::normalize_with_depth;
|
||||
use crate::traits::normalize::normalize_with_depth_to;
|
||||
|
@ -521,10 +520,7 @@ fn normalize_to_error<'a, 'tcx>(
|
|||
predicate: trait_ref.to_predicate(selcx.tcx()),
|
||||
};
|
||||
let tcx = selcx.infcx.tcx;
|
||||
let new_value = selcx.infcx.next_ty_var(TypeVariableOrigin {
|
||||
param_def_id: None,
|
||||
span: tcx.def_span(projection_ty.def_id),
|
||||
});
|
||||
let new_value = selcx.infcx.next_ty_var(tcx.def_span(projection_ty.def_id));
|
||||
Normalized { value: new_value, obligations: vec![trait_obligation] }
|
||||
}
|
||||
|
||||
|
|
|
@ -693,7 +693,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
let vtable_base = vtable_trait_first_method_offset(
|
||||
tcx,
|
||||
(unnormalized_upcast_trait_ref, ty::Binder::dummy(object_trait_ref)),
|
||||
unnormalized_upcast_trait_ref,
|
||||
ty::Binder::dummy(object_trait_ref),
|
||||
);
|
||||
|
||||
Ok(ImplSource::Builtin(BuiltinImplSource::Object { vtable_base: vtable_base }, nested))
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use rustc_infer::infer::at::At;
|
||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
||||
use rustc_infer::traits::{FulfillmentError, TraitEngine};
|
||||
use rustc_macros::extension;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
|
@ -20,9 +19,7 @@ impl<'tcx> At<'_, 'tcx> {
|
|||
return Ok(ty);
|
||||
};
|
||||
|
||||
let new_infer_ty = self
|
||||
.infcx
|
||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: self.cause.span });
|
||||
let new_infer_ty = self.infcx.next_ty_var(self.cause.span);
|
||||
|
||||
// We simply emit an `alias-eq` goal here, since that will take care of
|
||||
// normalizing the LHS of the projection until it is a rigid projection
|
||||
|
|
|
@ -320,16 +320,11 @@ fn vtable_entries<'tcx>(
|
|||
}
|
||||
|
||||
/// Find slot base for trait methods within vtable entries of another trait
|
||||
// FIXME(@lcnr): This isn't a query, so why does it take a tuple as its argument.
|
||||
pub(super) fn vtable_trait_first_method_offset<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
key: (
|
||||
ty::PolyTraitRef<'tcx>, // trait_to_be_found
|
||||
ty::PolyTraitRef<'tcx>, // trait_owning_vtable
|
||||
),
|
||||
trait_to_be_found: ty::PolyTraitRef<'tcx>,
|
||||
trait_owning_vtable: ty::PolyTraitRef<'tcx>,
|
||||
) -> usize {
|
||||
let (trait_to_be_found, trait_owning_vtable) = key;
|
||||
|
||||
// #90177
|
||||
let trait_to_be_found_erased = tcx.erase_regions(trait_to_be_found);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue