Skip to content

Add snapshotting to ObligationForest, take 2 #31175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions src/librustc/middle/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
use dep_graph::DepGraph;
use middle::infer::InferCtxt;
use middle::ty::{self, Ty, TypeFoldable};
use rustc_data_structures::obligation_forest::{Backtrace, ObligationForest, Error};
use rustc_data_structures::obligation_forest::{Backtrace, ObligationForest, UndoLog, Error};
use rustc_data_structures::undoable::{Undoable, UndoableTracker, Undoer};
use std::cell::RefCell;
use std::iter;
use std::rc::Rc;
use syntax::ast;
use util::common::ErrorReported;
use util::nodemap::{FnvHashMap, FnvHashSet, NodeMap};
Expand All @@ -31,14 +34,18 @@ use super::select::SelectionContext;
use super::Unimplemented;
use super::util::predicate_for_builtin_bound;

pub type ObligationForestUndoLog<'tcx> = UndoLog<PendingPredicateObligation<'tcx>,
LocalFulfilledPredicates<'tcx>>;

pub struct GlobalFulfilledPredicates<'tcx> {
set: FnvHashSet<ty::PolyTraitPredicate<'tcx>>,
dep_graph: DepGraph,
}

#[derive(Debug)]
pub struct LocalFulfilledPredicates<'tcx> {
set: FnvHashSet<ty::Predicate<'tcx>>
set: FnvHashSet<ty::Predicate<'tcx>>,
log: Option<(Rc<RefCell<ObligationForestUndoLog<'tcx>>>, usize)>,
}

/// The fulfillment context is used to drive trait resolution. It
Expand Down Expand Up @@ -110,6 +117,12 @@ pub struct PendingPredicateObligation<'tcx> {
pub stalled_on: Vec<Ty<'tcx>>,
}

#[derive(Debug)]
pub enum LocalFulfilledPredicatesAction<'tcx> {
Add { key: ty::Predicate<'tcx> }
}


impl<'tcx> FulfillmentContext<'tcx> {
/// Creates a new fulfillment context.
pub fn new() -> FulfillmentContext<'tcx> {
Expand Down Expand Up @@ -670,19 +683,46 @@ fn register_region_obligation<'tcx>(t_a: Ty<'tcx>,
impl<'tcx> LocalFulfilledPredicates<'tcx> {
pub fn new() -> LocalFulfilledPredicates<'tcx> {
LocalFulfilledPredicates {
set: FnvHashSet()
set: FnvHashSet(),
log: None,
}
}

fn is_duplicate_or_add(&mut self, key: &ty::Predicate<'tcx>) -> bool {
let insert_result = self.set.insert(key.clone());
if insert_result {
if let Some((ref log, id)) = self.log {
(*log).borrow_mut().push_action(
id, LocalFulfilledPredicatesAction::Add { key: key.clone() });
}
}
// For a `LocalFulfilledPredicates`, if we find a match, we
// don't need to add a read edge to the dep-graph. This is
// because it means that the predicate has already been
// considered by this `FulfillmentContext`, and hence the
// containing task will already have an edge. (Here we are
// assuming each `FulfillmentContext` only gets used from one
// task; but to do otherwise makes no sense)
!self.set.insert(key.clone())
!insert_result
}
}

impl<'tcx> Undoer for LocalFulfilledPredicatesAction<'tcx> {
type Undoable = LocalFulfilledPredicates<'tcx>;
fn undo(self, predicates: &mut LocalFulfilledPredicates<'tcx>) {
match self {
LocalFulfilledPredicatesAction::Add { key } => {
assert!(predicates.set.remove(&key));
}
}
}
}

impl<'tcx> Undoable for LocalFulfilledPredicates<'tcx> {
type Undoer = LocalFulfilledPredicatesAction<'tcx>;
type Tracker = ObligationForestUndoLog<'tcx>;
fn register_tracker(&mut self, log: Rc<RefCell<Self::Tracker>>, id: usize) {
self.log = Some((log, id));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod transitive_relation;
pub mod unify;
pub mod fnv;
pub mod tuple_slice;
pub mod undoable;
pub mod veccell;

// See comments in src/librustc/lib.rs
Expand Down
Loading