Skip to content

Commit

Permalink
Rollup merge of #104907 - compiler-errors:selcx-infcx, r=oli-obk
Browse files Browse the repository at this point in the history
Remove `SelectionContext::infcx()` in favor of field access

Encapsulation doesn't seem particularly important here, and having two choices is always more confusing than having one.

r? types
  • Loading branch information
Dylan-DPC authored Nov 28, 2022
2 parents 8a84dd8 + 6436c34 commit 9178bc0
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 92 deletions.
31 changes: 13 additions & 18 deletions compiler/rustc_trait_selection/src/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,17 +599,17 @@ impl<'tcx> AutoTraitFinder<'tcx> {
computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>,
select: &mut SelectionContext<'_, 'tcx>,
selcx: &mut SelectionContext<'_, 'tcx>,
only_projections: bool,
) -> bool {
let dummy_cause = ObligationCause::dummy();

for obligation in nested {
let is_new_pred =
fresh_preds.insert(self.clean_pred(select.infcx(), obligation.predicate));
fresh_preds.insert(self.clean_pred(selcx.infcx, obligation.predicate));

// Resolve any inference variables that we can, to help selection succeed
let predicate = select.infcx().resolve_vars_if_possible(obligation.predicate);
let predicate = selcx.infcx.resolve_vars_if_possible(obligation.predicate);

// We only add a predicate as a user-displayable bound if
// it involves a generic parameter, and doesn't contain
Expand Down Expand Up @@ -717,10 +717,8 @@ impl<'tcx> AutoTraitFinder<'tcx> {
// and turn them into an explicit negative impl for our type.
debug!("Projecting and unifying projection predicate {:?}", predicate);

match project::poly_project_and_unify_type(
select,
&obligation.with(self.tcx, p),
) {
match project::poly_project_and_unify_type(selcx, &obligation.with(self.tcx, p))
{
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
debug!(
"evaluate_nested_obligations: Unable to unify predicate \
Expand All @@ -745,7 +743,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
computed_preds,
fresh_preds,
predicates,
select,
selcx,
only_projections,
) {
return false;
Expand All @@ -768,7 +766,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
}
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(binder)) => {
let binder = bound_predicate.rebind(binder);
select.infcx().region_outlives_predicate(&dummy_cause, binder)
selcx.infcx.region_outlives_predicate(&dummy_cause, binder)
}
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(binder)) => {
let binder = bound_predicate.rebind(binder);
Expand All @@ -777,14 +775,14 @@ impl<'tcx> AutoTraitFinder<'tcx> {
binder.map_bound_ref(|pred| pred.0).no_bound_vars(),
) {
(None, Some(t_a)) => {
select.infcx().register_region_obligation_with_cause(
selcx.infcx.register_region_obligation_with_cause(
t_a,
select.infcx().tcx.lifetimes.re_static,
selcx.infcx.tcx.lifetimes.re_static,
&dummy_cause,
);
}
(Some(ty::OutlivesPredicate(t_a, r_b)), _) => {
select.infcx().register_region_obligation_with_cause(
selcx.infcx.register_region_obligation_with_cause(
t_a,
r_b,
&dummy_cause,
Expand All @@ -796,13 +794,13 @@ impl<'tcx> AutoTraitFinder<'tcx> {
ty::PredicateKind::ConstEquate(c1, c2) => {
let evaluate = |c: ty::Const<'tcx>| {
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
match select.infcx().const_eval_resolve(
match selcx.infcx.const_eval_resolve(
obligation.param_env,
unevaluated,
Some(obligation.cause.span),
) {
Ok(Some(valtree)) => {
Ok(ty::Const::from_value(select.tcx(), valtree, c.ty()))
Ok(ty::Const::from_value(selcx.tcx(), valtree, c.ty()))
}
Ok(None) => {
let tcx = self.tcx;
Expand All @@ -823,10 +821,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {

match (evaluate(c1), evaluate(c2)) {
(Ok(c1), Ok(c2)) => {
match select
.infcx()
.at(&obligation.cause, obligation.param_env)
.eq(c1, c2)
match selcx.infcx.at(&obligation.cause, obligation.param_env).eq(c1, c2)
{
Ok(_) => (),
Err(_) => return false,
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
impl_def_id: DefId,
) -> ty::ImplHeader<'tcx> {
let tcx = selcx.tcx();
let impl_substs = selcx.infcx().fresh_substs_for_item(DUMMY_SP, impl_def_id);
let impl_substs = selcx.infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);

let header = ty::ImplHeader {
impl_def_id,
Expand Down Expand Up @@ -149,7 +149,7 @@ fn overlap<'cx, 'tcx>(
impl1_def_id, impl2_def_id, overlap_mode
);

selcx.infcx().probe_maybe_skip_leak_check(skip_leak_check.is_yes(), |snapshot| {
selcx.infcx.probe_maybe_skip_leak_check(skip_leak_check.is_yes(), |snapshot| {
overlap_within_probe(selcx, impl1_def_id, impl2_def_id, overlap_mode, snapshot)
})
}
Expand All @@ -161,7 +161,7 @@ fn overlap_within_probe<'cx, 'tcx>(
overlap_mode: OverlapMode,
snapshot: &CombinedSnapshot<'tcx>,
) -> Option<OverlapResult<'tcx>> {
let infcx = selcx.infcx();
let infcx = selcx.infcx;

if overlap_mode.use_negative_impl() {
if negative_impl(infcx.tcx, impl1_def_id, impl2_def_id)
Expand Down Expand Up @@ -200,9 +200,9 @@ fn overlap_within_probe<'cx, 'tcx>(
debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes);

let involves_placeholder =
matches!(selcx.infcx().region_constraints_added_in_snapshot(snapshot), Some(true));
matches!(selcx.infcx.region_constraints_added_in_snapshot(snapshot), Some(true));

let impl_header = selcx.infcx().resolve_vars_if_possible(impl1_header);
let impl_header = selcx.infcx.resolve_vars_if_possible(impl1_header);
Some(OverlapResult { impl_header, intercrate_ambiguity_causes, involves_placeholder })
}

Expand All @@ -214,7 +214,7 @@ fn equate_impl_headers<'cx, 'tcx>(
// Do `a` and `b` unify? If not, no overlap.
debug!("equate_impl_headers(impl1_header={:?}, impl2_header={:?}", impl1_header, impl2_header);
selcx
.infcx()
.infcx
.at(&ObligationCause::dummy(), ty::ParamEnv::empty())
.eq_impl_headers(impl1_header, impl2_header)
.map(|infer_ok| infer_ok.obligations)
Expand Down Expand Up @@ -255,7 +255,7 @@ fn implicit_negative<'cx, 'tcx>(
"implicit_negative(impl1_header={:?}, impl2_header={:?}, obligations={:?})",
impl1_header, impl2_header, obligations
);
let infcx = selcx.infcx();
let infcx = selcx.infcx;
let opt_failing_obligation = impl1_header
.predicates
.iter()
Expand Down
31 changes: 15 additions & 16 deletions compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
// code is so hot. 1 and 0 dominate; 2+ is fairly rare.
1 => {
let infer_var = pending_obligation.stalled_on[0];
self.selcx.infcx().ty_or_const_infer_var_changed(infer_var)
self.selcx.infcx.ty_or_const_infer_var_changed(infer_var)
}
0 => {
// In this case we haven't changed, but wish to make a change.
Expand All @@ -210,7 +210,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
// form was a perf win. See #64545 for details.
(|| {
for &infer_var in &pending_obligation.stalled_on {
if self.selcx.infcx().ty_or_const_infer_var_changed(infer_var) {
if self.selcx.infcx.ty_or_const_infer_var_changed(infer_var) {
return true;
}
}
Expand Down Expand Up @@ -240,13 +240,12 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
debug!(?obligation, "pre-resolve");

if obligation.predicate.has_non_region_infer() {
obligation.predicate =
self.selcx.infcx().resolve_vars_if_possible(obligation.predicate);
obligation.predicate = self.selcx.infcx.resolve_vars_if_possible(obligation.predicate);
}

let obligation = &pending_obligation.obligation;

let infcx = self.selcx.infcx();
let infcx = self.selcx.infcx;

if obligation.predicate.has_projections() {
let mut obligations = Vec::new();
Expand Down Expand Up @@ -353,7 +352,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
}

ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
match self.selcx.infcx().closure_kind(closure_substs) {
match self.selcx.infcx.closure_kind(closure_substs) {
Some(closure_kind) => {
if closure_kind.extends(kind) {
ProcessResult::Changed(vec![])
Expand All @@ -367,7 +366,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {

ty::PredicateKind::WellFormed(arg) => {
match wf::obligations(
self.selcx.infcx(),
self.selcx.infcx,
obligation.param_env,
obligation.cause.body_id,
obligation.recursion_depth + 1,
Expand All @@ -384,7 +383,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
}

ty::PredicateKind::Subtype(subtype) => {
match self.selcx.infcx().subtype_predicate(
match self.selcx.infcx.subtype_predicate(
&obligation.cause,
obligation.param_env,
Binder::dummy(subtype),
Expand All @@ -408,7 +407,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
}

ty::PredicateKind::Coerce(coerce) => {
match self.selcx.infcx().coerce_predicate(
match self.selcx.infcx.coerce_predicate(
&obligation.cause,
obligation.param_env,
Binder::dummy(coerce),
Expand All @@ -432,7 +431,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {

ty::PredicateKind::ConstEvaluatable(uv) => {
match const_evaluatable::is_const_evaluatable(
self.selcx.infcx(),
self.selcx.infcx,
uv,
obligation.param_env,
obligation.cause.span,
Expand Down Expand Up @@ -503,7 +502,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {

let mut evaluate = |c: Const<'tcx>| {
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
match self.selcx.infcx().try_const_eval_resolve(
match self.selcx.infcx.try_const_eval_resolve(
obligation.param_env,
unevaluated,
c.ty(),
Expand Down Expand Up @@ -531,7 +530,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
(Ok(c1), Ok(c2)) => {
match self
.selcx
.infcx()
.infcx
.at(&obligation.cause, obligation.param_env)
.eq(c1, c2)
{
Expand Down Expand Up @@ -601,7 +600,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
trait_obligation: TraitObligation<'tcx>,
stalled_on: &mut Vec<TyOrConstInferVar<'tcx>>,
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
let infcx = self.selcx.infcx();
let infcx = self.selcx.infcx;
if obligation.predicate.is_global() {
// no type variables present, can use evaluation for better caching.
// FIXME: consider caching errors too.
Expand Down Expand Up @@ -659,7 +658,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
if obligation.predicate.is_global() {
// no type variables present, can use evaluation for better caching.
// FIXME: consider caching errors too.
if self.selcx.infcx().predicate_must_hold_considering_regions(obligation) {
if self.selcx.infcx.predicate_must_hold_considering_regions(obligation) {
if let Some(key) = ProjectionCacheKey::from_poly_projection_predicate(
&mut self.selcx,
project_obligation.predicate,
Expand All @@ -668,7 +667,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
// evaluated all sub-obligations. We can therefore mark the 'root'
// obligation as complete, and skip evaluating sub-obligations.
self.selcx
.infcx()
.infcx
.inner
.borrow_mut()
.projection_cache()
Expand Down Expand Up @@ -707,7 +706,7 @@ fn substs_infer_vars<'a, 'tcx>(
substs: ty::Binder<'tcx, SubstsRef<'tcx>>,
) -> impl Iterator<Item = TyOrConstInferVar<'tcx>> {
selcx
.infcx()
.infcx
.resolve_vars_if_possible(substs)
.skip_binder() // ok because this check doesn't care about regions
.iter()
Expand Down
Loading

0 comments on commit 9178bc0

Please sign in to comment.