Skip to content

Commit

Permalink
Pass constraints to RegionInferenceContext::new.
Browse files Browse the repository at this point in the history
Instead of destructuring it in advance and passing all the components
individually. It's less code that way.
  • Loading branch information
nnethercote committed Nov 19, 2024
1 parent 801b150 commit c9283f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
28 changes: 2 additions & 26 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::diagnostics::RegionErrors;
use crate::facts::{AllFacts, AllFactsExt, RustcFacts};
use crate::location::LocationTable;
use crate::region_infer::RegionInferenceContext;
use crate::type_check::{self, MirTypeckRegionConstraints, MirTypeckResults};
use crate::type_check::{self, MirTypeckResults};
use crate::universal_regions::UniversalRegions;
use crate::{BorrowckInferCtxt, polonius, renumber};

Expand Down Expand Up @@ -117,15 +117,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
// region inference data that was contained in `infcx`, and the
// base constraints generated by the type-check.
let var_origins = infcx.get_region_var_origins();
let MirTypeckRegionConstraints {
placeholder_indices,
placeholder_index_to_region: _,
liveness_constraints,
mut outlives_constraints,
mut member_constraints,
universe_causes,
type_tests,
} = constraints;

// If requested, emit legacy polonius facts.
polonius::emit_facts(
Expand All @@ -138,26 +129,11 @@ pub(crate) fn compute_regions<'a, 'tcx>(
&universal_region_relations,
);

if let Some(guar) = universal_region_relations.universal_regions.tainted_by_errors() {
// Suppress unhelpful extra errors in `infer_opaque_types` by clearing out all
// outlives bounds that we may end up checking.
outlives_constraints = Default::default();
member_constraints = Default::default();

// Also taint the entire scope.
infcx.set_tainted_by_errors(guar);
}

let mut regioncx = RegionInferenceContext::new(
infcx,
var_origins,
placeholder_indices,
constraints,
universal_region_relations,
outlives_constraints,
member_constraints,
universe_causes,
type_tests,
liveness_constraints,
elements,
);

Expand Down
34 changes: 23 additions & 11 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ use crate::diagnostics::{RegionErrorKind, RegionErrors, UniverseInfo};
use crate::member_constraints::{MemberConstraintSet, NllMemberConstraintIndex};
use crate::nll::PoloniusOutput;
use crate::region_infer::reverse_sccs::ReverseSccGraph;
use crate::region_infer::values::{
LivenessValues, PlaceholderIndices, RegionElement, RegionValues, ToElementIndex,
};
use crate::type_check::Locations;
use crate::region_infer::values::{LivenessValues, RegionElement, RegionValues, ToElementIndex};
use crate::type_check::free_region_relations::UniversalRegionRelations;
use crate::type_check::{Locations, MirTypeckRegionConstraints};
use crate::universal_regions::UniversalRegions;

mod dump_mir;
Expand Down Expand Up @@ -395,22 +393,36 @@ impl<'tcx> RegionInferenceContext<'tcx> {
pub(crate) fn new(
infcx: &BorrowckInferCtxt<'tcx>,
var_infos: VarInfos,
placeholder_indices: PlaceholderIndices,
constraints: MirTypeckRegionConstraints<'tcx>,
universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
mut outlives_constraints: OutlivesConstraintSet<'tcx>,
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
type_tests: Vec<TypeTest<'tcx>>,
liveness_constraints: LivenessValues,
elements: Rc<DenseLocationMap>,
) -> Self {
let universal_regions = &universal_region_relations.universal_regions;
let MirTypeckRegionConstraints {
placeholder_indices,
placeholder_index_to_region: _,
liveness_constraints,
mut outlives_constraints,
mut member_constraints,
universe_causes,
type_tests,
} = constraints;

debug!("universal_regions: {:#?}", universal_region_relations.universal_regions);
debug!("outlives constraints: {:#?}", outlives_constraints);
debug!("placeholder_indices: {:#?}", placeholder_indices);
debug!("type tests: {:#?}", type_tests);

if let Some(guar) = universal_region_relations.universal_regions.tainted_by_errors() {
// Suppress unhelpful extra errors in `infer_opaque_types` by clearing out all
// outlives bounds that we may end up checking.
outlives_constraints = Default::default();
member_constraints = Default::default();

// Also taint the entire scope.
infcx.set_tainted_by_errors(guar);
}

// Create a RegionDefinition for each inference variable.
let definitions: IndexVec<_, _> = var_infos
.iter()
Expand All @@ -435,7 +447,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}

let member_constraints =
Rc::new(member_constraints_in.into_mapped(|r| constraint_sccs.scc(r)));
Rc::new(member_constraints.into_mapped(|r| constraint_sccs.scc(r)));

let mut result = Self {
var_infos,
Expand Down

0 comments on commit c9283f8

Please sign in to comment.