Skip to content

Commit 4eb7362

Browse files
committed
simplify DepNode for trait selection
1 parent b44d94a commit 4eb7362

File tree

5 files changed

+33
-39
lines changed

5 files changed

+33
-39
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub enum DepNode<D: Clone + Debug> {
132132
// which would yield an overly conservative dep-graph.
133133
TraitItems(D),
134134
ReprHints(D),
135-
TraitSelect(D, Vec<D>),
135+
TraitSelect(Vec<D>),
136136
}
137137

138138
impl<D: Clone + Debug> DepNode<D> {
@@ -237,10 +237,9 @@ impl<D: Clone + Debug> DepNode<D> {
237237
TraitImpls(ref d) => op(d).map(TraitImpls),
238238
TraitItems(ref d) => op(d).map(TraitItems),
239239
ReprHints(ref d) => op(d).map(ReprHints),
240-
TraitSelect(ref d, ref type_ds) => {
241-
let d = try_opt!(op(d));
240+
TraitSelect(ref type_ds) => {
242241
let type_ds = try_opt!(type_ds.iter().map(|d| op(d)).collect());
243-
Some(TraitSelect(d, type_ds))
242+
Some(TraitSelect(type_ds))
244243
}
245244
}
246245
}

src/librustc/infer/mod.rs

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
670670
self.drain_fulfillment_cx_or_panic(DUMMY_SP, &mut fulfill_cx, &result)
671671
}
672672

673+
/// Finishes processes any obligations that remain in the
674+
/// fulfillment context, and then returns the result with all type
675+
/// variables removed and regions erased. Because this is intended
676+
/// for use after type-check has completed, if any errors occur,
677+
/// it will panic. It is used during normalization and other cases
678+
/// where processing the obligations in `fulfill_cx` may cause
679+
/// type inference variables that appear in `result` to be
680+
/// unified, and hence we need to process those obligations to get
681+
/// the complete picture of the type.
673682
pub fn drain_fulfillment_cx_or_panic<T>(&self,
674683
span: Span,
675684
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
@@ -679,47 +688,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
679688
{
680689
debug!("drain_fulfillment_cx_or_panic()");
681690

682-
let when = "resolving bounds after type-checking";
683-
let v = match self.drain_fulfillment_cx(fulfill_cx, result) {
684-
Ok(v) => v,
691+
// In principle, we only need to do this so long as `result`
692+
// contains unbound type parameters. It could be a slight
693+
// optimization to stop iterating early.
694+
match fulfill_cx.select_all_or_error(self) {
695+
Ok(()) => { }
685696
Err(errors) => {
686-
span_bug!(span, "Encountered errors `{:?}` {}", errors, when);
697+
span_bug!(span, "Encountered errors `{:?}` resolving bounds after type-checking",
698+
errors);
687699
}
688-
};
700+
}
689701

690-
match self.tcx.lift_to_global(&v) {
691-
Some(v) => v,
702+
let result = self.resolve_type_vars_if_possible(result);
703+
let result = self.tcx.erase_regions(&result);
704+
705+
match self.tcx.lift_to_global(&result) {
706+
Some(result) => result,
692707
None => {
693-
span_bug!(span, "Uninferred types/regions in `{:?}` {}", v, when);
708+
span_bug!(span, "Uninferred types/regions in `{:?}`", result);
694709
}
695710
}
696711
}
697712

698-
/// Finishes processes any obligations that remain in the fulfillment
699-
/// context, and then "freshens" and returns `result`. This is
700-
/// primarily used during normalization and other cases where
701-
/// processing the obligations in `fulfill_cx` may cause type
702-
/// inference variables that appear in `result` to be unified, and
703-
/// hence we need to process those obligations to get the complete
704-
/// picture of the type.
705-
pub fn drain_fulfillment_cx<T>(&self,
706-
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
707-
result: &T)
708-
-> Result<T,Vec<traits::FulfillmentError<'tcx>>>
709-
where T : TypeFoldable<'tcx>
710-
{
711-
debug!("drain_fulfillment_cx(result={:?})",
712-
result);
713-
714-
// In principle, we only need to do this so long as `result`
715-
// contains unbound type parameters. It could be a slight
716-
// optimization to stop iterating early.
717-
fulfill_cx.select_all_or_error(self)?;
718-
719-
let result = self.resolve_type_vars_if_possible(result);
720-
Ok(self.tcx.erase_regions(&result))
721-
}
722-
723713
pub fn projection_mode(&self) -> Reveal {
724714
self.projection_mode
725715
}

src/librustc/ty/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,9 @@ impl<'tcx> TraitPredicate<'tcx> {
958958
_ =>
959959
None
960960
})
961+
.chain(iter::once(self.def_id()))
961962
.collect();
962-
DepNode::TraitSelect(self.def_id(), def_ids)
963+
DepNode::TraitSelect(def_ids)
963964
}
964965

965966
pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item=Ty<'tcx>> + 'a {

src/librustc_trans/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10281028
fulfill_cx.register_predicate_obligation(&infcx, obligation);
10291029
}
10301030

1031-
fulfill_cx.select_all_or_error(infcx).is_ok()
1031+
fulfill_cx.select_all_or_error(&infcx).is_ok()
10321032
})
10331033
}
10341034

src/librustc_trans/monomorphize.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ pub fn apply_param_substs<'a, 'tcx, T>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4848
-> T
4949
where T: TransNormalize<'tcx>
5050
{
51+
debug!("apply_param_substs(param_substs={:?}, value={:?})", param_substs, value);
5152
let substituted = value.subst(tcx, param_substs);
53+
debug!("apply_param_substs: substituted={:?}{}",
54+
substituted,
55+
if substituted.has_projection_types() { " [needs projection]" } else { "" });
5256
tcx.normalize_associated_type(&substituted)
5357
}
5458

0 commit comments

Comments
 (0)