-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
120 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
compiler/rustc_infer/src/infer/region_constraints/leak_check.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use super::region_constraints::RegionSnapshot; | ||
use super::InferCtxt; | ||
use rustc_data_structures::undo_log::UndoLogs; | ||
use rustc_middle::ty; | ||
|
||
mod fudge; | ||
pub(crate) mod undo_log; | ||
|
||
use undo_log::{Snapshot, UndoLog}; | ||
|
||
#[must_use = "once you start a snapshot, you should always consume it"] | ||
pub struct CombinedSnapshot<'tcx> { | ||
pub(super) undo_snapshot: Snapshot<'tcx>, | ||
region_constraints_snapshot: RegionSnapshot, | ||
universe: ty::UniverseIndex, | ||
} | ||
|
||
impl<'tcx> InferCtxt<'tcx> { | ||
pub fn in_snapshot(&self) -> bool { | ||
UndoLogs::<UndoLog<'tcx>>::in_snapshot(&self.inner.borrow_mut().undo_log) | ||
} | ||
|
||
pub fn num_open_snapshots(&self) -> usize { | ||
UndoLogs::<UndoLog<'tcx>>::num_open_snapshots(&self.inner.borrow_mut().undo_log) | ||
} | ||
|
||
fn start_snapshot(&self) -> CombinedSnapshot<'tcx> { | ||
debug!("start_snapshot()"); | ||
|
||
let mut inner = self.inner.borrow_mut(); | ||
|
||
CombinedSnapshot { | ||
undo_snapshot: inner.undo_log.start_snapshot(), | ||
region_constraints_snapshot: inner.unwrap_region_constraints().start_snapshot(), | ||
universe: self.universe(), | ||
} | ||
} | ||
|
||
#[instrument(skip(self, snapshot), level = "debug")] | ||
fn rollback_to(&self, snapshot: CombinedSnapshot<'tcx>) { | ||
let CombinedSnapshot { undo_snapshot, region_constraints_snapshot, universe } = snapshot; | ||
|
||
self.universe.set(universe); | ||
|
||
let mut inner = self.inner.borrow_mut(); | ||
inner.rollback_to(undo_snapshot); | ||
inner.unwrap_region_constraints().rollback_to(region_constraints_snapshot); | ||
} | ||
|
||
#[instrument(skip(self, snapshot), level = "debug")] | ||
fn commit_from(&self, snapshot: CombinedSnapshot<'tcx>) { | ||
let CombinedSnapshot { undo_snapshot, region_constraints_snapshot: _, universe: _ } = | ||
snapshot; | ||
|
||
self.inner.borrow_mut().commit(undo_snapshot); | ||
} | ||
|
||
/// Execute `f` and commit the bindings if closure `f` returns `Ok(_)`. | ||
#[instrument(skip(self, f), level = "debug")] | ||
pub fn commit_if_ok<T, E, F>(&self, f: F) -> Result<T, E> | ||
where | ||
F: FnOnce(&CombinedSnapshot<'tcx>) -> Result<T, E>, | ||
{ | ||
let snapshot = self.start_snapshot(); | ||
let r = f(&snapshot); | ||
debug!("commit_if_ok() -- r.is_ok() = {}", r.is_ok()); | ||
match r { | ||
Ok(_) => { | ||
self.commit_from(snapshot); | ||
} | ||
Err(_) => { | ||
self.rollback_to(snapshot); | ||
} | ||
} | ||
r | ||
} | ||
|
||
/// Execute `f` then unroll any bindings it creates. | ||
#[instrument(skip(self, f), level = "debug")] | ||
pub fn probe<R, F>(&self, f: F) -> R | ||
where | ||
F: FnOnce(&CombinedSnapshot<'tcx>) -> R, | ||
{ | ||
let snapshot = self.start_snapshot(); | ||
let r = f(&snapshot); | ||
self.rollback_to(snapshot); | ||
r | ||
} | ||
|
||
/// Scan the constraints produced since `snapshot` and check whether | ||
/// we added any region constraints. | ||
pub fn region_constraints_added_in_snapshot(&self, snapshot: &CombinedSnapshot<'tcx>) -> bool { | ||
self.inner | ||
.borrow_mut() | ||
.unwrap_region_constraints() | ||
.region_constraints_added_in_snapshot(&snapshot.undo_snapshot) | ||
} | ||
|
||
pub fn opaque_types_added_in_snapshot(&self, snapshot: &CombinedSnapshot<'tcx>) -> bool { | ||
self.inner.borrow().undo_log.opaque_types_in_snapshot(&snapshot.undo_snapshot) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters