Skip to content

Commit 14007b7

Browse files
committed
---
yaml --- r: 273228 b: refs/heads/beta c: e097049 h: refs/heads/master
1 parent 3e44f8f commit 14007b7

File tree

5 files changed

+43
-165
lines changed

5 files changed

+43
-165
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 16201d45f16845cb5dc2fc0b48bcf34a6715ea14
26+
refs/heads/beta: e0970498c79de1a1381d697b3c27895ef798e288
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_trans/trans/base.rs

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,7 @@ fn set_global_section(ccx: &CrateContext, llval: ValueRef, i: &hir::Item) {
24762476
pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
24772477
let _icx = push_ctxt("trans_item");
24782478

2479+
let tcx = ccx.tcx();
24792480
let from_external = ccx.external_srcs().borrow().contains_key(&item.id);
24802481

24812482
match item.node {
@@ -2532,20 +2533,39 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
25322533
}
25332534
}
25342535
hir::ItemImpl(_, _, ref generics, _, _, ref impl_items) => {
2535-
meth::trans_impl(ccx, item.name, impl_items, generics, item.id);
2536-
}
2537-
hir::ItemMod(_) => {
2538-
// modules have no equivalent at runtime, they just affect
2539-
// the mangled names of things contained within
2536+
// Both here and below with generic methods, be sure to recurse and look for
2537+
// items that we need to translate.
2538+
if !generics.ty_params.is_empty() {
2539+
return;
2540+
}
2541+
2542+
for impl_item in impl_items {
2543+
if let hir::ImplItemKind::Method(ref sig, ref body) = impl_item.node {
2544+
if sig.generics.ty_params.is_empty() {
2545+
let trans_everywhere = attr::requests_inline(&impl_item.attrs);
2546+
for (ref ccx, is_origin) in ccx.maybe_iter(trans_everywhere) {
2547+
let empty_substs = tcx.mk_substs(Substs::trans_empty());
2548+
let def_id = tcx.map.local_def_id(impl_item.id);
2549+
let llfn = Callee::def(ccx, def_id, empty_substs).reify(ccx).val;
2550+
trans_fn(ccx, &sig.decl, body, llfn, empty_substs,
2551+
impl_item.id, &impl_item.attrs);
2552+
update_linkage(ccx, llfn, Some(impl_item.id),
2553+
if is_origin {
2554+
OriginalTranslation
2555+
} else {
2556+
InlinedCopy
2557+
});
2558+
}
2559+
}
2560+
}
2561+
}
25402562
}
25412563
hir::ItemEnum(ref enum_definition, ref gens) => {
25422564
if gens.ty_params.is_empty() {
25432565
// sizes only make sense for non-generic types
2544-
25452566
enum_variant_size_lint(ccx, enum_definition, item.span, item.id);
25462567
}
25472568
}
2548-
hir::ItemConst(..) => {}
25492569
hir::ItemStatic(_, m, ref expr) => {
25502570
let g = match consts::trans_static(ccx, m, expr, item.id, &item.attrs) {
25512571
Ok(g) => g,
@@ -2554,13 +2574,16 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
25542574
set_global_section(ccx, g, item);
25552575
update_linkage(ccx, g, Some(item.id), OriginalTranslation);
25562576
}
2557-
hir::ItemForeignMod(ref foreign_mod) => {
2558-
foreign::trans_foreign_mod(ccx, foreign_mod);
2559-
}
2560-
hir::ItemTrait(..) => {}
2561-
_ => {
2562-
// fall through
2577+
hir::ItemForeignMod(ref m) => {
2578+
if m.abi == Abi::RustIntrinsic || m.abi == Abi::PlatformIntrinsic {
2579+
return;
2580+
}
2581+
for fi in &m.items {
2582+
let lname = foreign::link_name(fi.name, &fi.attrs).to_string();
2583+
ccx.item_symbols().borrow_mut().insert(fi.id, lname);
2584+
}
25632585
}
2586+
_ => {}
25642587
}
25652588
}
25662589

branches/beta/src/librustc_trans/trans/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<'tcx> Callee<'tcx> {
158158
// those from the impl and those from the method:
159159
let impl_substs = vtable_impl.substs.with_method_from(&substs);
160160
let substs = tcx.mk_substs(impl_substs);
161-
let mth = tcx.get_impl_method(impl_did, substs, mname);
161+
let mth = meth::get_impl_method(tcx, impl_did, substs, mname);
162162

163163
// Translate the function, bypassing Callee::def.
164164
// That is because default methods have the same ID as the

branches/beta/src/librustc_trans/trans/foreign.rs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -463,31 +463,6 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
463463
return bcx;
464464
}
465465

466-
467-
pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) {
468-
let _icx = push_ctxt("foreign::trans_foreign_mod");
469-
for foreign_item in &foreign_mod.items {
470-
let lname = link_name(foreign_item);
471-
472-
if let hir::ForeignItemFn(ref decl, _) = foreign_item.node {
473-
match foreign_mod.abi {
474-
Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic => {}
475-
abi => {
476-
let ty = ccx.tcx().node_id_to_type(foreign_item.id);
477-
register_foreign_item_fn(ccx, abi, ty, &lname, &foreign_item.attrs);
478-
// Unlike for other items, we shouldn't call
479-
// `base::update_linkage` here. Foreign items have
480-
// special linkage requirements, which are handled
481-
// inside `foreign::register_*`.
482-
}
483-
}
484-
}
485-
486-
ccx.item_symbols().borrow_mut().insert(foreign_item.id,
487-
lname.to_string());
488-
}
489-
}
490-
491466
///////////////////////////////////////////////////////////////////////////
492467
// Rust functions with foreign ABIs
493468
//
@@ -890,12 +865,12 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
890865
// This code is kind of a confused mess and needs to be reworked given
891866
// the massive simplifications that have occurred.
892867

893-
pub fn link_name(i: &hir::ForeignItem) -> InternedString {
894-
match attr::first_attr_value_str_by_name(&i.attrs, "link_name") {
868+
pub fn link_name(name: ast::Name, attrs: &[ast::Attribute]) -> InternedString {
869+
match attr::first_attr_value_str_by_name(attrs, "link_name") {
895870
Some(ln) => ln.clone(),
896-
None => match weak_lang_items::link_name(&i.attrs) {
871+
None => match weak_lang_items::link_name(attrs) {
897872
Some(name) => name,
898-
None => i.name.as_str(),
873+
None => name.as_str(),
899874
}
900875
}
901876
}

branches/beta/src/librustc_trans/trans/meth.rs

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use middle::subst;
2020
use middle::traits::{self, ProjectionMode};
2121
use trans::base::*;
2222
use trans::build::*;
23-
use trans::callee::{Callee, Virtual, ArgVals,
24-
trans_fn_pointer_shim, trans_fn_ref_with_substs};
23+
use trans::callee::{Callee, Virtual, ArgVals, trans_fn_pointer_shim};
2524
use trans::closure;
2625
use trans::common::*;
2726
use trans::consts;
@@ -37,130 +36,11 @@ use trans::value::Value;
3736
use middle::ty::{self, Ty, TyCtxt, TypeFoldable};
3837

3938
use syntax::ast::{self, Name};
40-
use syntax::attr;
4139
use syntax::codemap::DUMMY_SP;
4240

43-
use rustc_front::hir;
44-
4541
// drop_glue pointer, size, align.
4642
const VTABLE_OFFSET: usize = 3;
4743

48-
/// The main "translation" pass for methods. Generates code
49-
/// for non-monomorphized methods only. Other methods will
50-
/// be generated once they are invoked with specific type parameters,
51-
/// see `trans::base::lval_static_fn()` or `trans::base::monomorphic_fn()`.
52-
pub fn trans_impl(ccx: &CrateContext,
53-
name: ast::Name,
54-
impl_items: &[hir::ImplItem],
55-
generics: &hir::Generics,
56-
id: ast::NodeId) {
57-
let _icx = push_ctxt("meth::trans_impl");
58-
let tcx = ccx.tcx();
59-
60-
debug!("trans_impl(name={}, id={})", name, id);
61-
62-
// Both here and below with generic methods, be sure to recurse and look for
63-
// items that we need to translate.
64-
if !generics.ty_params.is_empty() {
65-
return;
66-
}
67-
68-
for impl_item in impl_items {
69-
match impl_item.node {
70-
hir::ImplItemKind::Method(ref sig, ref body) => {
71-
if sig.generics.ty_params.is_empty() {
72-
let trans_everywhere = attr::requests_inline(&impl_item.attrs);
73-
for (ref ccx, is_origin) in ccx.maybe_iter(trans_everywhere) {
74-
let llfn = get_item_val(ccx, impl_item.id);
75-
let empty_substs = tcx.mk_substs(Substs::trans_empty());
76-
trans_fn(ccx,
77-
&sig.decl,
78-
body,
79-
llfn,
80-
empty_substs,
81-
impl_item.id,
82-
&impl_item.attrs);
83-
update_linkage(ccx,
84-
llfn,
85-
Some(impl_item.id),
86-
if is_origin { OriginalTranslation } else { InlinedCopy });
87-
}
88-
}
89-
}
90-
_ => {}
91-
}
92-
}
93-
}
94-
95-
/// Compute the appropriate callee, give na method's ID, trait ID,
96-
/// substitutions and a Vtable for that trait.
97-
pub fn callee_for_trait_impl<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
98-
method_id: DefId,
99-
substs: &'tcx subst::Substs<'tcx>,
100-
trait_id: DefId,
101-
method_ty: Ty<'tcx>,
102-
vtable: traits::Vtable<'tcx, ()>)
103-
-> Callee<'tcx> {
104-
let _icx = push_ctxt("meth::callee_for_trait_impl");
105-
match vtable {
106-
traits::VtableImpl(vtable_impl) => {
107-
let impl_did = vtable_impl.impl_def_id;
108-
let mname = ccx.tcx().item_name(method_id);
109-
// create a concatenated set of substitutions which includes
110-
// those from the impl and those from the method:
111-
let impl_substs = vtable_impl.substs.with_method_from(&substs);
112-
let substs = ccx.tcx().mk_substs(impl_substs);
113-
let mth = get_impl_method(ccx.tcx(), impl_did, substs, mname);
114-
115-
// Translate the function, bypassing Callee::def.
116-
// That is because default methods have the same ID as the
117-
// trait method used to look up the impl method that ended
118-
// up here, so calling Callee::def would infinitely recurse.
119-
Callee::ptr(trans_fn_ref_with_substs(ccx, mth.method.def_id,
120-
Some(method_ty), mth.substs))
121-
}
122-
traits::VtableClosure(vtable_closure) => {
123-
// The substitutions should have no type parameters remaining
124-
// after passing through fulfill_obligation
125-
let trait_closure_kind = ccx.tcx().lang_items.fn_trait_kind(trait_id).unwrap();
126-
let llfn = closure::trans_closure_method(ccx,
127-
vtable_closure.closure_def_id,
128-
vtable_closure.substs,
129-
trait_closure_kind);
130-
let fn_ptr_ty = match method_ty.sty {
131-
ty::TyFnDef(_, _, fty) => ccx.tcx().mk_ty(ty::TyFnPtr(fty)),
132-
_ => unreachable!("expected fn item type, found {}",
133-
method_ty)
134-
};
135-
Callee::ptr(immediate_rvalue(llfn, fn_ptr_ty))
136-
}
137-
traits::VtableFnPointer(fn_ty) => {
138-
let trait_closure_kind = ccx.tcx().lang_items.fn_trait_kind(trait_id).unwrap();
139-
let llfn = trans_fn_pointer_shim(ccx, trait_closure_kind, fn_ty);
140-
let fn_ptr_ty = match method_ty.sty {
141-
ty::TyFnDef(_, _, fty) => ccx.tcx().mk_ty(ty::TyFnPtr(fty)),
142-
_ => unreachable!("expected fn item type, found {}",
143-
method_ty)
144-
};
145-
Callee::ptr(immediate_rvalue(llfn, fn_ptr_ty))
146-
}
147-
traits::VtableObject(ref data) => {
148-
Callee {
149-
data: Virtual(traits::get_vtable_index_of_object_method(
150-
ccx.tcx(), data, method_id)),
151-
ty: method_ty
152-
}
153-
}
154-
traits::VtableBuiltin(..) |
155-
traits::VtableDefaultImpl(..) |
156-
traits::VtableParam(..) => {
157-
ccx.sess().bug(
158-
&format!("resolved vtable bad vtable {:?} in trans",
159-
vtable));
160-
}
161-
}
162-
}
163-
16444
/// Extracts a method from a trait object's vtable, at the
16545
/// specified index, and casts it to the given type.
16646
pub fn get_virtual_method<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,

0 commit comments

Comments
 (0)