From: Bastian Kauschke Date: Sat, 6 Jun 2020 14:41:48 +0000 (+0200) Subject: remove `pop_placeholders` X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=180334c7a8ce250d878e96d3336e1c54b3d8b0e3;p=rust.git remove `pop_placeholders` --- diff --git a/src/librustc_infer/infer/higher_ranked/mod.rs b/src/librustc_infer/infer/higher_ranked/mod.rs index ef18918c177..0499dc9ed22 100644 --- a/src/librustc_infer/infer/higher_ranked/mod.rs +++ b/src/librustc_infer/infer/higher_ranked/mod.rs @@ -63,14 +63,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// placeholder region. This is the first step of checking subtyping /// when higher-ranked things are involved. /// - /// **Important:** you must call this function from within a snapshot. - /// Moreover, before committing the snapshot, you must eventually call - /// either `plug_leaks` or `pop_placeholders` to remove the placeholder - /// regions. If you rollback the snapshot (or are using a probe), then - /// the pop occurs as part of the rollback, so an explicit call is not - /// needed (but is also permitted). - /// - /// For more information about how placeholders and HRTBs work, see + /// **Important:** You have to be careful to not leak these placeholders, + /// for more information about how placeholders and HRTBs work, see /// the [rustc dev guide]. /// /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html diff --git a/src/librustc_infer/infer/region_constraints/leak_check.rs b/src/librustc_infer/infer/region_constraints/leak_check.rs index 473550d5433..91c39a0e78f 100644 --- a/src/librustc_infer/infer/region_constraints/leak_check.rs +++ b/src/librustc_infer/infer/region_constraints/leak_check.rs @@ -128,7 +128,7 @@ fn fixed_point<'a>( verifys[i].origin.span(), "we never add verifications while doing higher-ranked things", ), - &Purged | &AddCombination(..) | &AddVar(..) => {} + &AddCombination(..) | &AddVar(..) => {} } } } diff --git a/src/librustc_infer/infer/region_constraints/mod.rs b/src/librustc_infer/infer/region_constraints/mod.rs index 42a6a6ff40a..2902c41a6bc 100644 --- a/src/librustc_infer/infer/region_constraints/mod.rs +++ b/src/librustc_infer/infer/region_constraints/mod.rs @@ -289,14 +289,6 @@ pub(crate) enum UndoLog<'tcx> { /// We added a GLB/LUB "combination variable". AddCombination(CombineMapType, TwoRegions<'tcx>), - - /// During freshening, we sometimes purge entries from the undo - /// log in a kind of minisnapshot (unlike other snapshots, this - /// purging actually takes place *on success*). In that case, we - /// replace the corresponding entry with `Noop` so as to avoid the - /// need to do a bunch of swapping. (We can't use `swap_remove` as - /// the order of the vector is important.) - Purged, } #[derive(Copy, Clone, PartialEq)] @@ -357,9 +349,6 @@ pub(crate) fn with_log<'a>( fn rollback_undo_entry(&mut self, undo_entry: UndoLog<'tcx>) { match undo_entry { - Purged => { - // nothing to do here - } AddVar(vid) => { self.var_infos.pop().unwrap(); assert_eq!(self.var_infos.len(), vid.index() as usize); @@ -488,62 +477,6 @@ pub fn var_origin(&self, vid: RegionVid) -> RegionVariableOrigin { self.var_infos[vid].origin } - /// Removes all the edges to/from the placeholder regions that are - /// in `placeholders`. This is used after a higher-ranked operation - /// completes to remove all trace of the placeholder regions - /// created in that time. - pub fn pop_placeholders(&mut self, placeholders: &FxHashSet>) { - debug!("pop_placeholders(placeholders={:?})", placeholders); - - assert!(UndoLogs::>::in_snapshot(&self.undo_log)); - - let constraints_to_kill: Vec = self - .undo_log - .iter() - .enumerate() - .rev() - .filter(|&(_, undo_entry)| match undo_entry { - super::UndoLog::RegionConstraintCollector(undo_entry) => { - kill_constraint(placeholders, undo_entry) - } - _ => false, - }) - .map(|(index, _)| index) - .collect(); - - for index in constraints_to_kill { - let undo_entry = match &mut self.undo_log[index] { - super::UndoLog::RegionConstraintCollector(undo_entry) => { - mem::replace(undo_entry, Purged) - } - _ => unreachable!(), - }; - self.rollback_undo_entry(undo_entry); - } - - return; - - fn kill_constraint<'tcx>( - placeholders: &FxHashSet>, - undo_entry: &UndoLog<'tcx>, - ) -> bool { - match undo_entry { - &AddConstraint(Constraint::VarSubVar(..)) => false, - &AddConstraint(Constraint::RegSubVar(a, _)) => placeholders.contains(&a), - &AddConstraint(Constraint::VarSubReg(_, b)) => placeholders.contains(&b), - &AddConstraint(Constraint::RegSubReg(a, b)) => { - placeholders.contains(&a) || placeholders.contains(&b) - } - &AddGiven(..) => false, - &AddVerify(_) => false, - &AddCombination(_, ref two_regions) => { - placeholders.contains(&two_regions.a) || placeholders.contains(&two_regions.b) - } - &AddVar(..) | &Purged => false, - } - } - } - fn add_constraint(&mut self, constraint: Constraint<'tcx>, origin: SubregionOrigin<'tcx>) { // cannot add constraints once regions are resolved debug!("RegionConstraintCollector: add_constraint({:?})", constraint); diff --git a/src/librustc_infer/infer/undo_log.rs b/src/librustc_infer/infer/undo_log.rs index e7f1869955d..2cfd6bb904c 100644 --- a/src/librustc_infer/infer/undo_log.rs +++ b/src/librustc_infer/infer/undo_log.rs @@ -198,10 +198,6 @@ fn assert_open_snapshot(&self, snapshot: &Snapshot<'tcx>) { assert!(self.logs.len() >= snapshot.undo_len); assert!(self.num_open_snapshots > 0); } - - pub(crate) fn iter(&self) -> std::slice::Iter<'_, UndoLog<'tcx>> { - self.logs.iter() - } } impl<'tcx> std::ops::Index for InferCtxtUndoLogs<'tcx> {