Skip to content

Commit 5e4a806

Browse files
committed
---
yaml --- r: 170455 b: refs/heads/try c: 0a2d531 h: refs/heads/master i: 170453: 20624be 170451: 9a2197d 170447: f470b87 v: v3
1 parent 0600d22 commit 5e4a806

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 73a25f55ad748b4d3516417c711b99ce446591af
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 5b3cd3900ceda838f5798c30ab96ceb41f962534
5-
refs/heads/try: 67dab2af81ba64023c526dc96315863a9f7e9e40
5+
refs/heads/try: 0a2d531b94f4c49ecc0b190b1feb438e27c3e882
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/librustc_trans/trans/common.rs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -954,28 +954,47 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
954954

955955
// Currently, we use a fulfillment context to completely resolve
956956
// all nested obligations. This is because they can inform the
957-
// inference of the impl's type parameters. However, in principle,
958-
// we only need to do this until the impl's type parameters are
959-
// fully bound. It could be a slight optimization to stop
960-
// iterating early.
957+
// inference of the impl's type parameters.
961958
let mut fulfill_cx = traits::FulfillmentContext::new();
962959
let vtable = selection.map_move_nested(|predicate| {
963960
fulfill_cx.register_predicate_obligation(&infcx, predicate);
964961
});
965-
match fulfill_cx.select_all_or_error(&infcx, &param_env, tcx) {
962+
let vtable = drain_fulfillment_cx(span, &infcx, &param_env, &mut fulfill_cx, &vtable);
963+
964+
info!("Cache miss: {}", trait_ref.repr(ccx.tcx()));
965+
ccx.trait_cache().borrow_mut().insert(trait_ref,
966+
vtable.clone());
967+
968+
vtable
969+
}
970+
971+
pub fn drain_fulfillment_cx<'a,'tcx,T>(span: Span,
972+
infcx: &infer::InferCtxt<'a,'tcx>,
973+
param_env: &ty::ParameterEnvironment<'tcx>,
974+
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
975+
result: &T)
976+
-> T
977+
where T : TypeFoldable<'tcx> + Repr<'tcx>
978+
{
979+
debug!("drain_fulfillment_cx(result={})",
980+
result.repr(infcx.tcx));
981+
982+
// In principle, we only need to do this so long as `result`
983+
// contains unbound type parameters. It could be a slight
984+
// optimization to stop iterating early.
985+
match fulfill_cx.select_all_or_error(infcx, param_env, infcx.tcx) {
966986
Ok(()) => { }
967987
Err(errors) => {
968988
if errors.iter().all(|e| e.is_overflow()) {
969989
// See Ok(None) case above.
970-
ccx.sess().span_fatal(
990+
infcx.tcx.sess.span_fatal(
971991
span,
972992
"reached the recursion limit during monomorphization");
973993
} else {
974-
tcx.sess.span_bug(
994+
infcx.tcx.sess.span_bug(
975995
span,
976-
format!("Encountered errors `{}` fulfilling `{}` during trans",
977-
errors.repr(tcx),
978-
trait_ref.repr(tcx))[]);
996+
format!("Encountered errors `{}` fulfilling during trans",
997+
errors.repr(infcx.tcx))[]);
979998
}
980999
}
9811000
}
@@ -985,13 +1004,7 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
9851004
// sort of overkill because we do not expect there to be any
9861005
// unbound type variables, hence no `TyFresh` types should ever be
9871006
// inserted.
988-
let vtable = vtable.fold_with(&mut infcx.freshener());
989-
990-
info!("Cache miss: {}", trait_ref.repr(ccx.tcx()));
991-
ccx.trait_cache().borrow_mut().insert(trait_ref,
992-
vtable.clone());
993-
994-
vtable
1007+
result.fold_with(&mut infcx.freshener())
9951008
}
9961009

9971010
// Key used to lookup values supplied for type parameters in an expr.

branches/try/src/librustc_trans/trans/monomorphize.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use syntax::ast;
3131
use syntax::ast_map;
3232
use syntax::ast_util::{local_def, PostExpansionMethod};
3333
use syntax::attr;
34+
use syntax::codemap::DUMMY_SP;
3435
use std::hash::{sip, Hash};
3536

3637
pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
@@ -331,7 +332,11 @@ pub fn normalize_associated_type<'tcx,T>(tcx: &ty::ctxt<'tcx>, value: &T) -> T
331332
result.repr(tcx),
332333
obligations.repr(tcx));
333334

334-
assert_eq!(obligations.len(), 0); // TODO not good enough
335+
let mut fulfill_cx = traits::FulfillmentContext::new();
336+
for obligation in obligations.into_iter() {
337+
fulfill_cx.register_predicate_obligation(&infcx, obligation);
338+
}
339+
let result = drain_fulfillment_cx(DUMMY_SP, &infcx, &param_env, &mut fulfill_cx, &result);
335340

336341
result
337342
}

0 commit comments

Comments
 (0)