Skip to content
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

Rollup of 9 pull requests #33632

Merged
merged 27 commits into from
May 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
00f6513
Only break critical edges where actually needed
dotdash May 10, 2016
5541fdf
Use symlink_metadata in tidy to avoid panicking on broken symlinks.
eddyb May 11, 2016
e3f19cb
trans: Move TransItem to its own module.
michaelwoerister May 9, 2016
85b155f
trans: Don't try to place declarations during codegen unit partitioning.
michaelwoerister May 9, 2016
dace306
Inspect MIR for statics in item collection
Aatch May 9, 2016
f4dd4be
Add test for collecting items in statics
Aatch May 9, 2016
64bc3c2
trans: Make collector handle the drop_in_place() intrinsic.
michaelwoerister May 10, 2016
4e5a2e0
Remove unification despite ambiguity in projection
soltanmm-google May 11, 2016
49b2cdf
[MIR trans] Optimize trans for biased switches
dotdash May 11, 2016
802bb57
trans: Use CrateContext::empty_substs_for_def_id() instead of Substs:…
michaelwoerister May 11, 2016
fd70788
Do not use const Rib for associated constants
nagisa May 11, 2016
5af829b
Gen right parameter envirnoment for assoc consts
nagisa May 11, 2016
8628cce
Add inferred obligation storage to all Vtable variants and SelectionC…
soltanmm-google May 11, 2016
ec7c483
Don't mutate the inference context when assembling
soltanmm-google May 11, 2016
d3218fa
Check the constants’ parameter environment
nagisa May 11, 2016
f52b655
Plumb inference obligations through selection
soltanmm-google May 12, 2016
9393e52
Don't use env::current_exe with libbacktrace
sfackler May 8, 2016
8ad6d27
[MIR] Enhance the SimplifyCfg pass to merge consecutive blocks
dotdash Nov 14, 2015
36c4c6d
Rollup merge of #33544 - dotdash:baby_dont_break_me_no_more, r=Aatch
Manishearth May 14, 2016
ea68dd8
Rollup merge of #33552 - dotdash:scfg, r=luqmana
Manishearth May 14, 2016
4a1ce98
Rollup merge of #33554 - sfackler:no-current-exe, r=alexcrichton
Manishearth May 14, 2016
8bc265b
Rollup merge of #33555 - soltanmm:ambiguous-nixon, r=nikomatsakis
Manishearth May 14, 2016
f546201
Rollup merge of #33560 - eddyb:symtidy, r=alexcrichton
Manishearth May 14, 2016
25ca82a
Rollup merge of #33566 - dotdash:biased_switch, r=nagisa
Manishearth May 14, 2016
8845592
Rollup merge of #33572 - nagisa:assoc-const-types, r=eddyb
Manishearth May 14, 2016
c62d65c
Rollup merge of #33574 - michaelwoerister:collector-cleanup, r=nikoma…
Manishearth May 14, 2016
61d87f0
Rollup merge of #33576 - soltanmm:vtable, r=nikomatsakis
Manishearth May 14, 2016
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: 38 additions & 10 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub enum Vtable<'tcx, N> {
VtableParam(Vec<N>),

/// Virtual calls through an object
VtableObject(VtableObjectData<'tcx>),
VtableObject(VtableObjectData<'tcx, N>),

/// Successful resolution for a builtin trait.
VtableBuiltin(VtableBuiltinData<N>),
Expand All @@ -250,7 +250,7 @@ pub enum Vtable<'tcx, N> {
VtableClosure(VtableClosureData<'tcx, N>),

/// Same as above, but for a fn pointer type with the given signature.
VtableFnPointer(ty::Ty<'tcx>),
VtableFnPointer(VtableFnPointerData<'tcx, N>),
}

/// Identifies a particular impl in the source, along with a set of
Expand Down Expand Up @@ -293,14 +293,22 @@ pub struct VtableBuiltinData<N> {
/// A vtable for some object-safe trait `Foo` automatically derived
/// for the object type `Foo`.
#[derive(PartialEq,Eq,Clone)]
pub struct VtableObjectData<'tcx> {
pub struct VtableObjectData<'tcx, N> {
/// `Foo` upcast to the obligation trait. This will be some supertrait of `Foo`.
pub upcast_trait_ref: ty::PolyTraitRef<'tcx>,

/// The vtable is formed by concatenating together the method lists of
/// the base object trait and all supertraits; this is the start of
/// `upcast_trait_ref`'s methods in that vtable.
pub vtable_base: usize
pub vtable_base: usize,

pub nested: Vec<N>,
}

#[derive(Clone, PartialEq, Eq)]
pub struct VtableFnPointerData<'tcx, N> {
pub fn_ty: ty::Ty<'tcx>,
pub nested: Vec<N>
}

/// Creates predicate obligations from the generic bounds.
Expand Down Expand Up @@ -569,7 +577,20 @@ impl<'tcx, N> Vtable<'tcx, N> {
VtableBuiltin(i) => i.nested,
VtableDefaultImpl(d) => d.nested,
VtableClosure(c) => c.nested,
VtableObject(_) | VtableFnPointer(..) => vec![]
VtableObject(d) => d.nested,
VtableFnPointer(d) => d.nested,
}
}

fn nested_obligations_mut(&mut self) -> &mut Vec<N> {
match self {
&mut VtableImpl(ref mut i) => &mut i.nested,
&mut VtableParam(ref mut n) => n,
&mut VtableBuiltin(ref mut i) => &mut i.nested,
&mut VtableDefaultImpl(ref mut d) => &mut d.nested,
&mut VtableClosure(ref mut c) => &mut c.nested,
&mut VtableObject(ref mut d) => &mut d.nested,
&mut VtableFnPointer(ref mut d) => &mut d.nested,
}
}

Expand All @@ -578,18 +599,25 @@ impl<'tcx, N> Vtable<'tcx, N> {
VtableImpl(i) => VtableImpl(VtableImplData {
impl_def_id: i.impl_def_id,
substs: i.substs,
nested: i.nested.into_iter().map(f).collect()
nested: i.nested.into_iter().map(f).collect(),
}),
VtableParam(n) => VtableParam(n.into_iter().map(f).collect()),
VtableBuiltin(i) => VtableBuiltin(VtableBuiltinData {
nested: i.nested.into_iter().map(f).collect()
nested: i.nested.into_iter().map(f).collect(),
}),
VtableObject(o) => VtableObject(VtableObjectData {
upcast_trait_ref: o.upcast_trait_ref,
vtable_base: o.vtable_base,
nested: o.nested.into_iter().map(f).collect(),
}),
VtableObject(o) => VtableObject(o),
VtableDefaultImpl(d) => VtableDefaultImpl(VtableDefaultImplData {
trait_def_id: d.trait_def_id,
nested: d.nested.into_iter().map(f).collect()
nested: d.nested.into_iter().map(f).collect(),
}),
VtableFnPointer(p) => VtableFnPointer(VtableFnPointerData {
fn_ty: p.fn_ty,
nested: p.nested.into_iter().map(f).collect(),
}),
VtableFnPointer(f) => VtableFnPointer(f),
VtableClosure(c) => VtableClosure(VtableClosureData {
closure_def_id: c.closure_def_id,
substs: c.substs,
Expand Down
76 changes: 12 additions & 64 deletions src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use super::PredicateObligation;
use super::SelectionContext;
use super::SelectionError;
use super::VtableClosureData;
use super::VtableFnPointerData;
use super::VtableImplData;
use super::util;

Expand Down Expand Up @@ -158,7 +159,7 @@ enum ProjectionTyCandidate<'tcx> {
Closure(VtableClosureData<'tcx, PredicateObligation<'tcx>>),

// fn pointer return type
FnPointer(Ty<'tcx>),
FnPointer(VtableFnPointerData<'tcx, PredicateObligation<'tcx>>),
}

struct ProjectionTyCandidateSet<'tcx> {
Expand Down Expand Up @@ -218,10 +219,7 @@ fn project_and_unify_type<'cx, 'gcx, 'tcx>(
obligation.cause.clone(),
obligation.recursion_depth) {
Some(n) => n,
None => {
consider_unification_despite_ambiguity(selcx, obligation);
return Ok(None);
}
None => return Ok(None),
};

debug!("project_and_unify_type: normalized_ty={:?} obligations={:?}",
Expand All @@ -240,59 +238,6 @@ fn project_and_unify_type<'cx, 'gcx, 'tcx>(
}
}

fn consider_unification_despite_ambiguity<'cx, 'gcx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
obligation: &ProjectionObligation<'tcx>)
{
debug!("consider_unification_despite_ambiguity(obligation={:?})",
obligation);

let def_id = obligation.predicate.projection_ty.trait_ref.def_id;
match selcx.tcx().lang_items.fn_trait_kind(def_id) {
Some(_) => { }
None => { return; }
}

let infcx = selcx.infcx();
let self_ty = obligation.predicate.projection_ty.trait_ref.self_ty();
let self_ty = infcx.shallow_resolve(self_ty);
debug!("consider_unification_despite_ambiguity: self_ty.sty={:?}",
self_ty.sty);
match self_ty.sty {
ty::TyClosure(closure_def_id, substs) => {
let closure_typer = selcx.closure_typer();
let closure_type = closure_typer.closure_type(closure_def_id, substs);
let ty::Binder((_, ret_type)) =
infcx.tcx.closure_trait_ref_and_return_type(def_id,
self_ty,
&closure_type.sig,
util::TupleArgumentsFlag::No);
// We don't have to normalize the return type here - this is only
// reached for TyClosure: Fn inputs where the closure kind is
// still unknown, which should only occur in typeck where the
// closure type is already normalized.
let (ret_type, _) =
infcx.replace_late_bound_regions_with_fresh_var(
obligation.cause.span,
infer::AssocTypeProjection(obligation.predicate.projection_ty.item_name),
&ty::Binder(ret_type));

debug!("consider_unification_despite_ambiguity: ret_type={:?}",
ret_type);
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
let obligation_ty = obligation.predicate.ty;
match infcx.eq_types(true, origin, obligation_ty, ret_type) {
Ok(InferOk { obligations, .. }) => {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());
}
Err(_) => { /* ignore errors */ }
}
}
_ => { }
}
}

/// Normalizes any associated type projections in `value`, replacing
/// them with a fully resolved type where possible. The return value
/// combines the normalized result and any additional obligations that
Expand Down Expand Up @@ -929,9 +874,9 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
candidate_set.vec.push(
ProjectionTyCandidate::Closure(data));
}
super::VtableFnPointer(fn_type) => {
super::VtableFnPointer(data) => {
candidate_set.vec.push(
ProjectionTyCandidate::FnPointer(fn_type));
ProjectionTyCandidate::FnPointer(data));
}
super::VtableParam(..) => {
// This case tell us nothing about the value of an
Expand Down Expand Up @@ -997,19 +942,22 @@ fn confirm_candidate<'cx, 'gcx, 'tcx>(
confirm_closure_candidate(selcx, obligation, closure_vtable)
}

ProjectionTyCandidate::FnPointer(fn_type) => {
confirm_fn_pointer_candidate(selcx, obligation, fn_type)
ProjectionTyCandidate::FnPointer(fn_pointer_vtable) => {
confirm_fn_pointer_candidate(selcx, obligation, fn_pointer_vtable)
}
}
}

fn confirm_fn_pointer_candidate<'cx, 'gcx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>,
fn_type: Ty<'tcx>)
fn_pointer_vtable: VtableFnPointerData<'tcx, PredicateObligation<'tcx>>)
-> (Ty<'tcx>, Vec<PredicateObligation<'tcx>>)
{
let fn_type = selcx.infcx().shallow_resolve(fn_type);
// FIXME(#32730) propagate obligations (fn pointer vtable nested obligations ONLY come from
// unification in inference)
assert!(fn_pointer_vtable.nested.is_empty());
let fn_type = selcx.infcx().shallow_resolve(fn_pointer_vtable.fn_ty);
let sig = fn_type.fn_sig();
confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes)
}
Expand Down
Loading