Skip to content

Commit 1e2f8b7

Browse files
committed
WIP
1 parent 23d4599 commit 1e2f8b7

File tree

2 files changed

+14
-50
lines changed

2 files changed

+14
-50
lines changed

compiler/rustc_borrowck/src/region_infer/values.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
use std::fmt::Debug;
22
use std::rc::Rc;
33

4-
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
4+
use rustc_data_structures::fx::FxHashSet;
55
use rustc_index::Idx;
66
use rustc_index::bit_set::SparseBitMatrix;
77
use rustc_index::interval::{IntervalSet, SparseIntervalMatrix};
88
use rustc_middle::mir::{BasicBlock, Location};
9-
use rustc_middle::ty::{self, RegionVid};
9+
use rustc_middle::ty::RegionVid;
1010
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
1111
use tracing::debug;
1212

1313
use crate::BorrowIndex;
1414
use crate::polonius::LiveLoans;
1515

16-
rustc_index::newtype_index! {
17-
/// A single integer representing a `ty::Placeholder`.
18-
#[debug_format = "PlaceholderIndex({})"]
19-
pub(crate) struct PlaceholderIndex {}
20-
}
21-
2216
/// An individual element in a region value -- the value of a
2317
/// particular region variable consists of a set of these elements.
2418
#[derive(Debug, Clone, PartialEq)]
@@ -186,23 +180,6 @@ impl LivenessValues {
186180
}
187181
}
188182

189-
/// Maps from `ty::PlaceholderRegion` values that are used in the rest of
190-
/// rustc to the internal `PlaceholderIndex` values that are used in
191-
/// NLL.
192-
#[derive(Debug, Default)]
193-
pub(crate) struct PlaceholderIndices {
194-
indices: FxIndexSet<ty::PlaceholderRegion>,
195-
}
196-
197-
// FIXME(amandasystems) Can we get rid of this one too?
198-
impl PlaceholderIndices {
199-
/// Returns the `PlaceholderIndex` for the inserted `PlaceholderRegion`
200-
pub(crate) fn insert(&mut self, placeholder: ty::PlaceholderRegion) -> PlaceholderIndex {
201-
let (index, _) = self.indices.insert_full(placeholder);
202-
index.into()
203-
}
204-
}
205-
206183
/// Stores the full values for a set of regions (in contrast to
207184
/// `LivenessValues`, which only stores those points in the where a
208185
/// region is live). The full value for a region may contain points in

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use std::{fmt, iter, mem};
55

66
use rustc_abi::FieldIdx;
77
use rustc_data_structures::frozen::Frozen;
8-
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
8+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
99
use rustc_errors::ErrorGuaranteed;
1010
use rustc_hir as hir;
1111
use rustc_hir::def::DefKind;
1212
use rustc_hir::def_id::LocalDefId;
1313
use rustc_hir::lang_items::LangItem;
14-
use rustc_index::{IndexSlice, IndexVec};
14+
use rustc_index::IndexSlice;
1515
use rustc_infer::infer::canonical::QueryRegionConstraints;
1616
use rustc_infer::infer::outlives::env::RegionBoundPairs;
1717
use rustc_infer::infer::region_constraints::RegionConstraintData;
@@ -46,7 +46,7 @@ use crate::member_constraints::MemberConstraintSet;
4646
use crate::polonius::legacy::{PoloniusFacts, PoloniusLocationTable};
4747
use crate::polonius::{PoloniusContext, PoloniusLivenessContext};
4848
use crate::region_infer::TypeTest;
49-
use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices};
49+
use crate::region_infer::values::LivenessValues;
5050
use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst};
5151
use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations};
5252
use crate::universal_regions::{DefiningTy, UniversalRegions};
@@ -110,8 +110,7 @@ pub(crate) fn type_check<'tcx>(
110110
location_map: Rc<DenseLocationMap>,
111111
) -> MirTypeckResults<'tcx> {
112112
let mut constraints = MirTypeckRegionConstraints {
113-
placeholder_indices: PlaceholderIndices::default(),
114-
placeholder_index_to_region: IndexVec::default(),
113+
placeholder_to_region: FxHashMap::default(),
115114
liveness_constraints: LivenessValues::with_specific_points(Rc::clone(&location_map)),
116115
outlives_constraints: OutlivesConstraintSet::default(),
117116
member_constraints: MemberConstraintSet::default(),
@@ -236,16 +235,10 @@ pub(crate) struct MirTypeckResults<'tcx> {
236235
/// A collection of region constraints that must be satisfied for the
237236
/// program to be considered well-typed.
238237
pub(crate) struct MirTypeckRegionConstraints<'tcx> {
239-
/// Maps from a `ty::Placeholder` to the corresponding
240-
/// `PlaceholderIndex` bit that we will use for it.
241-
placeholder_indices: PlaceholderIndices,
242-
243-
/// Each time we add a placeholder to `placeholder_indices`, we
244-
/// also create a corresponding "representative" region vid for
245-
/// that wraps it. This vector tracks those. This way, when we
246-
/// convert the same `ty::RePlaceholder(p)` twice, we can map to
247-
/// the same underlying `RegionVid`.
248-
placeholder_index_to_region: IndexVec<PlaceholderIndex, ty::Region<'tcx>>,
238+
/// For each placeholder we create a corresponding representative region vid.
239+
/// This map tracks those. This way, when we convert the same `ty::RePlaceholder(p)`
240+
/// twice, we can map to the same underlying `RegionVid`.
241+
placeholder_to_region: FxHashMap<ty::PlaceholderRegion, ty::Region<'tcx>>,
249242

250243
/// In general, the type-checker is not responsible for enforcing
251244
/// liveness constraints; this job falls to the region inferencer,
@@ -273,16 +266,10 @@ impl<'tcx> MirTypeckRegionConstraints<'tcx> {
273266
infcx: &InferCtxt<'tcx>,
274267
placeholder: ty::PlaceholderRegion,
275268
) -> ty::Region<'tcx> {
276-
let placeholder_index = self.placeholder_indices.insert(placeholder);
277-
match self.placeholder_index_to_region.get(placeholder_index) {
278-
Some(&v) => v,
279-
None => {
280-
let origin = NllRegionVariableOrigin::Placeholder(placeholder);
281-
let region = infcx.next_nll_region_var_in_universe(origin, placeholder.universe);
282-
self.placeholder_index_to_region.push(region);
283-
region
284-
}
285-
}
269+
*self.placeholder_to_region.entry(placeholder).or_insert_with(|| {
270+
let origin = NllRegionVariableOrigin::Placeholder(placeholder);
271+
infcx.next_nll_region_var_in_universe(origin, placeholder.universe)
272+
})
286273
}
287274
}
288275

0 commit comments

Comments
 (0)