Skip to content

Commit 90109f2

Browse files
committed
auto merge of #18694 : nikomatsakis/rust/issue-18208-method-dispatch-2, r=nrc
This is a pretty major refactoring of the method dispatch infrastructure. It is intended to avoid gross inefficiencies and enable caching and other optimizations (e.g. #17995), though it itself doesn't seem to execute particularly faster yet. It also solves some cases where we were failing to resolve methods that we theoretically should have succeeded with. Fixes #18674. cc #18208
2 parents f0ca717 + 3dbdd00 commit 90109f2

25 files changed

+2457
-2076
lines changed

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This API is completely unstable and subject to change.
2929
html_root_url = "http://doc.rust-lang.org/nightly/")]
3030

3131
#![feature(default_type_params, globs, if_let, import_shadowing, macro_rules, phase, quote)]
32-
#![feature(slicing_syntax, struct_variant, unsafe_destructor)]
32+
#![feature(slicing_syntax, struct_variant, tuple_indexing, unsafe_destructor)]
3333
#![feature(rustc_diagnostic_macros)]
3434

3535
extern crate arena;

src/librustc/middle/traits/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ pub fn overlapping_impls(infcx: &InferCtxt,
276276
coherence::impl_can_satisfy(infcx, impl2_def_id, impl1_def_id)
277277
}
278278

279+
pub fn impl_obligations(tcx: &ty::ctxt,
280+
cause: ObligationCause,
281+
impl_def_id: ast::DefId,
282+
impl_substs: &subst::Substs)
283+
-> subst::VecPerParamSpace<Obligation>
284+
{
285+
let impl_generics = ty::lookup_item_type(tcx, impl_def_id).generics;
286+
obligations_for_generics(tcx, cause, &impl_generics, impl_substs)
287+
}
288+
279289
pub fn obligations_for_generics(tcx: &ty::ctxt,
280290
cause: ObligationCause,
281291
generics: &ty::Generics,

src/librustc/middle/traits/select.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17091709
closure_type.sig.binder_id,
17101710
&closure_type.sig,
17111711
|br| self.infcx.next_region_var(
1712-
infer::LateBoundRegion(obligation.cause.span, br)));
1712+
infer::LateBoundRegion(obligation.cause.span, br,
1713+
infer::FnCall)));
17131714

17141715
let arguments_tuple = new_signature.inputs[0];
17151716
let trait_ref = Rc::new(ty::TraitRef {

src/librustc/middle/ty.rs

+33-30
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,8 @@ impl CLike for BuiltinBound {
11111111

11121112
#[deriving(Clone, PartialEq, Eq, Hash)]
11131113
pub struct TyVid {
1114-
pub index: uint
1114+
pub index: uint,
1115+
pub counter: uint,
11151116
}
11161117

11171118
#[deriving(Clone, PartialEq, Eq, Hash)]
@@ -1167,7 +1168,7 @@ impl cmp::PartialEq for InferRegion {
11671168

11681169
impl fmt::Show for TyVid {
11691170
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
1170-
write!(f, "_#{}t", self.index)
1171+
write!(f, "_#{}/{}t", self.index, self.counter)
11711172
}
11721173
}
11731174

@@ -3485,43 +3486,45 @@ pub fn adjust_ty(cx: &ctxt,
34853486
}
34863487
}
34873488

3488-
match adj.autoref {
3489-
None => adjusted_ty,
3490-
Some(ref autoref) => adjust_for_autoref(cx, span, adjusted_ty, autoref)
3491-
}
3489+
adjust_ty_for_autoref(cx, span, adjusted_ty, adj.autoref.as_ref())
34923490
}
34933491
}
34943492
}
34953493
None => unadjusted_ty
34963494
};
3495+
}
34973496

3498-
fn adjust_for_autoref(cx: &ctxt,
3499-
span: Span,
3500-
ty: ty::t,
3501-
autoref: &AutoRef) -> ty::t{
3502-
match *autoref {
3503-
AutoPtr(r, m, ref a) => {
3504-
let adjusted_ty = match a {
3505-
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3506-
&None => ty
3507-
};
3508-
mk_rptr(cx, r, mt {
3509-
ty: adjusted_ty,
3510-
mutbl: m
3511-
})
3512-
}
3497+
pub fn adjust_ty_for_autoref(cx: &ctxt,
3498+
span: Span,
3499+
ty: ty::t,
3500+
autoref: Option<&AutoRef>)
3501+
-> ty::t
3502+
{
3503+
match autoref {
3504+
None => ty,
35133505

3514-
AutoUnsafe(m, ref a) => {
3515-
let adjusted_ty = match a {
3516-
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3517-
&None => ty
3518-
};
3519-
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
3520-
}
3506+
Some(&AutoPtr(r, m, ref a)) => {
3507+
let adjusted_ty = match a {
3508+
&Some(box ref a) => adjust_ty_for_autoref(cx, span, ty, Some(a)),
3509+
&None => ty
3510+
};
3511+
mk_rptr(cx, r, mt {
3512+
ty: adjusted_ty,
3513+
mutbl: m
3514+
})
3515+
}
35213516

3522-
AutoUnsize(ref k) => unsize_ty(cx, ty, k, span),
3523-
AutoUnsizeUniq(ref k) => ty::mk_uniq(cx, unsize_ty(cx, ty, k, span)),
3517+
Some(&AutoUnsafe(m, ref a)) => {
3518+
let adjusted_ty = match a {
3519+
&Some(box ref a) => adjust_ty_for_autoref(cx, span, ty, Some(a)),
3520+
&None => ty
3521+
};
3522+
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
35243523
}
3524+
3525+
Some(&AutoUnsize(ref k)) => unsize_ty(cx, ty, k, span),
3526+
3527+
Some(&AutoUnsizeUniq(ref k)) => ty::mk_uniq(cx, unsize_ty(cx, ty, k, span)),
35253528
}
35263529
}
35273530

0 commit comments

Comments
 (0)