Skip to content

Commit 8f07f8a

Browse files
committed
trans: Reify functions & methods to fn ptrs only where necessary.
1 parent c284099 commit 8f07f8a

File tree

28 files changed

+685
-1320
lines changed

28 files changed

+685
-1320
lines changed

src/librustc/middle/subst.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ impl<'tcx> Substs<'tcx> {
148148
Substs { types: types, regions: regions }
149149
}
150150

151-
pub fn with_method_from(self,
151+
pub fn with_method_from(&self,
152152
meth_substs: &Substs<'tcx>)
153153
-> Substs<'tcx>
154154
{
155-
let Substs { types, regions } = self;
155+
let Substs { types, regions } = self.clone();
156156
let types = types.with_slice(FnSpace, meth_substs.types.get_slice(FnSpace));
157157
let regions = regions.map(|r| {
158158
r.with_slice(FnSpace, meth_substs.regions().get_slice(FnSpace))

src/librustc/middle/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub enum Vtable<'tcx, N> {
278278
#[derive(Clone, PartialEq, Eq)]
279279
pub struct VtableImplData<'tcx, N> {
280280
pub impl_def_id: DefId,
281-
pub substs: subst::Substs<'tcx>,
281+
pub substs: &'tcx subst::Substs<'tcx>,
282282
pub nested: Vec<N>
283283
}
284284

src/librustc/middle/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ fn confirm_impl_candidate<'cx,'tcx>(
948948
for impl_item in &selcx.tcx().impl_items.borrow()[&impl_vtable.impl_def_id] {
949949
if let ty::TypeTraitItem(ref assoc_ty) = impl_or_trait_items_map[&impl_item.def_id()] {
950950
if assoc_ty.name == obligation.predicate.item_name {
951-
return (assoc_ty.ty.unwrap().subst(selcx.tcx(), &impl_vtable.substs),
951+
return (assoc_ty.ty.unwrap().subst(selcx.tcx(), impl_vtable.substs),
952952
impl_vtable.nested);
953953
}
954954
}

src/librustc/middle/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
23052305
impl_obligations.append(&mut substs.obligations);
23062306

23072307
VtableImplData { impl_def_id: impl_def_id,
2308-
substs: substs.value,
2308+
substs: self.tcx().mk_substs(substs.value),
23092309
nested: impl_obligations }
23102310
}
23112311

src/librustc/middle/traits/structural_impls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,10 @@ impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx
147147

148148
impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableImplData<'tcx, N> {
149149
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
150+
let substs = self.substs.fold_with(folder);
150151
traits::VtableImplData {
151152
impl_def_id: self.impl_def_id,
152-
substs: self.substs.fold_with(folder),
153+
substs: folder.tcx().mk_substs(substs),
153154
nested: self.nested.fold_with(folder),
154155
}
155156
}

src/librustc/middle/ty/util.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,14 @@ impl<'tcx> TyCtxt<'tcx> {
602602
#[derive(Debug)]
603603
pub struct ImplMethod<'tcx> {
604604
pub method: Rc<ty::Method<'tcx>>,
605-
pub substs: Substs<'tcx>,
605+
pub substs: &'tcx Substs<'tcx>,
606606
pub is_provided: bool
607607
}
608608

609609
impl<'tcx> TyCtxt<'tcx> {
610610
pub fn get_impl_method(&self,
611611
impl_def_id: DefId,
612-
substs: Substs<'tcx>,
612+
substs: &'tcx Substs<'tcx>,
613613
name: Name)
614614
-> ImplMethod<'tcx>
615615
{
@@ -636,9 +636,10 @@ impl<'tcx> TyCtxt<'tcx> {
636636
if meth.name == name {
637637
let impl_to_trait_substs = self
638638
.make_substs_for_receiver_types(&trait_ref, meth);
639+
let substs = impl_to_trait_substs.subst(self, substs);
639640
return ImplMethod {
640641
method: meth.clone(),
641-
substs: impl_to_trait_substs.subst(self, &substs),
642+
substs: self.mk_substs(substs),
642643
is_provided: true
643644
}
644645
}

src/librustc/mir/repr.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -861,20 +861,10 @@ impl<'tcx> Debug for TypedConstVal<'tcx> {
861861
}
862862
}
863863

864-
#[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, RustcDecodable)]
865-
pub enum ItemKind {
866-
Constant,
867-
/// This is any sort of callable (usually those that have a type of `fn(…) -> …`). This
868-
/// includes functions, constructors, but not methods which have their own ItemKind.
869-
Function,
870-
Method,
871-
}
872-
873864
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
874865
pub enum Literal<'tcx> {
875866
Item {
876867
def_id: DefId,
877-
kind: ItemKind,
878868
substs: &'tcx Substs<'tcx>,
879869
},
880870
Value {

src/librustc_mir/build/misc.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//! kind of thing.
1313
1414
use build::Builder;
15-
use hair::*;
1615
use rustc::middle::ty::Ty;
1716
use rustc::mir::repr::*;
1817
use std::u32;
@@ -59,16 +58,4 @@ impl<'a,'tcx> Builder<'a,'tcx> {
5958
});
6059
temp
6160
}
62-
63-
pub fn item_ref_operand(&mut self,
64-
span: Span,
65-
item_ref: ItemRef<'tcx>)
66-
-> Operand<'tcx> {
67-
let literal = Literal::Item {
68-
def_id: item_ref.def_id,
69-
kind: item_ref.kind,
70-
substs: item_ref.substs,
71-
};
72-
self.literal_operand(span, item_ref.ty, literal)
73-
}
7461
}

src/librustc_mir/build/scope.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ impl<'a,'tcx> Builder<'a,'tcx> {
503503
ty: self.hir.tcx().lookup_item_type(funcdid).ty,
504504
literal: Literal::Item {
505505
def_id: funcdid,
506-
kind: ItemKind::Function,
507506
substs: self.hir.tcx().mk_substs(Substs::empty())
508507
}
509508
}
@@ -641,7 +640,6 @@ fn build_free<'tcx>(tcx: &TyCtxt<'tcx>,
641640
ty: tcx.lookup_item_type(free_func).ty.subst(tcx, substs),
642641
literal: Literal::Item {
643642
def_id: free_func,
644-
kind: ItemKind::Function,
645643
substs: substs
646644
}
647645
}),

src/librustc_mir/hair/cx/expr.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ fn method_callee<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
581581
kind: ExprKind::Literal {
582582
literal: Literal::Item {
583583
def_id: callee.def_id,
584-
kind: ItemKind::Method,
585584
substs: callee.substs,
586585
},
587586
},
@@ -618,14 +617,13 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
618617
let substs = cx.tcx.mk_substs(cx.tcx.node_id_item_substs(expr.id).substs);
619618
// Otherwise there may be def_map borrow conflicts
620619
let def = cx.tcx.def_map.borrow()[&expr.id].full_def();
621-
let (def_id, kind) = match def {
620+
let def_id = match def {
622621
// A regular function.
623-
Def::Fn(def_id) => (def_id, ItemKind::Function),
624-
Def::Method(def_id) => (def_id, ItemKind::Method),
622+
Def::Fn(def_id) | Def::Method(def_id) => def_id,
625623
Def::Struct(def_id) => match cx.tcx.node_id_to_type(expr.id).sty {
626624
// A tuple-struct constructor. Should only be reached if not called in the same
627625
// expression.
628-
ty::TyFnDef(..) => (def_id, ItemKind::Function),
626+
ty::TyFnDef(..) => def_id,
629627
// A unit struct which is used as a value. We return a completely different ExprKind
630628
// here to account for this special case.
631629
ty::TyStruct(adt_def, substs) => return ExprKind::Adt {
@@ -640,7 +638,7 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
640638
Def::Variant(enum_id, variant_id) => match cx.tcx.node_id_to_type(expr.id).sty {
641639
// A variant constructor. Should only be reached if not called in the same
642640
// expression.
643-
ty::TyFnDef(..) => (variant_id, ItemKind::Function),
641+
ty::TyFnDef(..) => variant_id,
644642
// A unit variant, similar special case to the struct case above.
645643
ty::TyEnum(adt_def, substs) => {
646644
debug_assert!(adt_def.did == enum_id);
@@ -660,7 +658,7 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
660658
if let Some(v) = cx.try_const_eval_literal(expr) {
661659
return ExprKind::Literal { literal: v };
662660
} else {
663-
(def_id, ItemKind::Constant)
661+
def_id
664662
}
665663
}
666664

@@ -677,7 +675,7 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
677675
&format!("def `{:?}` not yet implemented", def)),
678676
};
679677
ExprKind::Literal {
680-
literal: Literal::Item { def_id: def_id, kind: kind, substs: substs }
678+
literal: Literal::Item { def_id: def_id, substs: substs }
681679
}
682680
}
683681

0 commit comments

Comments
 (0)