Skip to content

Commit 9a9cd63

Browse files
committed
Remove AST from metadata except for consts and const fns.
1 parent 6bef6d5 commit 9a9cd63

19 files changed

+126
-571
lines changed

src/librustc/hir/map/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ impl<'ast> Map<'ast> {
315315
RootInlinedParent(parent) => match *parent {
316316
InlinedItem::Item(def_id, _) |
317317
InlinedItem::TraitItem(def_id, _) |
318-
InlinedItem::ImplItem(def_id, _) |
319-
InlinedItem::Foreign(def_id, _) =>
318+
InlinedItem::ImplItem(def_id, _) =>
320319
return DepNode::MetaData(def_id)
321320
},
322321

@@ -940,8 +939,6 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
940939
II::ImplItem(fld.fold_ops.new_def_id(d),
941940
ii.map(|ii| fld.fold_impl_item(ii)))
942941
}
943-
II::Foreign(d, i) => II::Foreign(fld.fold_ops.new_def_id(d),
944-
i.map(|i| fld.fold_foreign_item(i)))
945942
};
946943

947944
let ii = map.forest.inlined_items.alloc(ii);

src/librustc/middle/cstore.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,15 @@ pub enum DefLike {
9696
pub enum InlinedItem {
9797
Item(DefId /* def-id in source crate */, P<hir::Item>),
9898
TraitItem(DefId /* impl id */, P<hir::TraitItem>),
99-
ImplItem(DefId /* impl id */, P<hir::ImplItem>),
100-
Foreign(DefId /* extern item */, P<hir::ForeignItem>),
99+
ImplItem(DefId /* impl id */, P<hir::ImplItem>)
101100
}
102101

103102
/// A borrowed version of `hir::InlinedItem`.
104103
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
105104
pub enum InlinedItemRef<'a> {
106105
Item(DefId, &'a hir::Item),
107106
TraitItem(DefId, &'a hir::TraitItem),
108-
ImplItem(DefId, &'a hir::ImplItem),
109-
Foreign(DefId, &'a hir::ForeignItem)
107+
ImplItem(DefId, &'a hir::ImplItem)
110108
}
111109

112110
/// Item definitions in the currently-compiled crate would have the CrateNum
@@ -286,7 +284,6 @@ impl InlinedItem {
286284
{
287285
match *self {
288286
InlinedItem::Item(_, ref i) => visitor.visit_item(&i),
289-
InlinedItem::Foreign(_, ref i) => visitor.visit_foreign_item(&i),
290287
InlinedItem::TraitItem(_, ref ti) => visitor.visit_trait_item(ti),
291288
InlinedItem::ImplItem(_, ref ii) => visitor.visit_impl_item(ii),
292289
}

src/librustc_metadata/astencode.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ pub fn encode_inlined_item(ecx: &e::EncodeContext,
7979
ii: InlinedItemRef) {
8080
let id = match ii {
8181
InlinedItemRef::Item(_, i) => i.id,
82-
InlinedItemRef::Foreign(_, i) => i.id,
8382
InlinedItemRef::TraitItem(_, ti) => ti.id,
8483
InlinedItemRef::ImplItem(_, ii) => ii.id,
8584
};
@@ -147,7 +146,6 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &cstore::CrateMetadata,
147146
dcx);
148147
let name = match *ii {
149148
InlinedItem::Item(_, ref i) => i.name,
150-
InlinedItem::Foreign(_, ref i) => i.name,
151149
InlinedItem::TraitItem(_, ref ti) => ti.name,
152150
InlinedItem::ImplItem(_, ref ii) => ii.name
153151
};
@@ -357,9 +355,6 @@ fn simplify_ast(ii: InlinedItemRef) -> (InlinedItem, IdRange) {
357355
InlinedItemRef::ImplItem(d, ii) => {
358356
InlinedItem::ImplItem(d, P(fold::noop_fold_impl_item(ii.clone(), &mut fld)))
359357
}
360-
InlinedItemRef::Foreign(d, i) => {
361-
InlinedItem::Foreign(d, P(fold::noop_fold_foreign_item(i.clone(), &mut fld)))
362-
}
363358
};
364359

365360
(ii, fld.id_range)
@@ -1208,8 +1203,7 @@ fn copy_item_types(dcx: &DecodeContext, ii: &InlinedItem, orig_did: DefId) {
12081203
let item_node_id = match ii {
12091204
&InlinedItem::Item(_, ref i) => i.id,
12101205
&InlinedItem::TraitItem(_, ref ti) => ti.id,
1211-
&InlinedItem::ImplItem(_, ref ii) => ii.id,
1212-
&InlinedItem::Foreign(_, ref fi) => fi.id
1206+
&InlinedItem::ImplItem(_, ref ii) => ii.id
12131207
};
12141208
copy_item_type(dcx, item_node_id, orig_did);
12151209

src/librustc_metadata/csearch.rs

-5
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
562562
let inlined_root_node_id = find_inlined_item_root(item.id);
563563
cache_inlined_item(def_id, item.id, inlined_root_node_id);
564564
}
565-
decoder::FoundAst::Found(&InlinedItem::Foreign(d, ref item)) => {
566-
assert_eq!(d, def_id);
567-
let inlined_root_node_id = find_inlined_item_root(item.id);
568-
cache_inlined_item(def_id, item.id, inlined_root_node_id);
569-
}
570565
decoder::FoundAst::FoundParent(parent_did, item) => {
571566
let inlined_root_node_id = find_inlined_item_root(item.id);
572567
cache_inlined_item(parent_did, item.id, inlined_root_node_id);

src/librustc_metadata/encoder.rs

+6-20
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use std::io::prelude::*;
4040
use std::io::{Cursor, SeekFrom};
4141
use std::rc::Rc;
4242
use std::u32;
43-
use syntax::abi::Abi;
4443
use syntax::ast::{self, NodeId, Name, CRATE_NODE_ID, CrateNum};
4544
use syntax::attr::{self,AttrMetaMethods,AttributeMethods};
4645
use errors::Handler;
@@ -626,11 +625,6 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
626625

627626
if body.is_some() {
628627
encode_item_sort(self.rbml_w, 'p');
629-
encode_inlined_item(ecx,
630-
self.rbml_w,
631-
InlinedItemRef::TraitItem(
632-
trait_def_id,
633-
trait_item));
634628
self.encode_mir(trait_item.id);
635629
} else {
636630
encode_item_sort(self.rbml_w, 'r');
@@ -728,12 +722,14 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
728722
let types = generics.parent_types as usize + generics.types.len();
729723
let needs_inline = types > 0 || is_default_impl ||
730724
attr::requests_inline(&impl_item.attrs);
731-
if needs_inline || sig.constness == hir::Constness::Const {
725+
if sig.constness == hir::Constness::Const {
732726
encode_inlined_item(
733727
ecx,
734728
self.rbml_w,
735729
InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id),
736730
impl_item));
731+
}
732+
if needs_inline || sig.constness == hir::Constness::Const {
737733
self.encode_mir(impl_item.id);
738734
}
739735
encode_constness(self.rbml_w, sig.constness);
@@ -934,8 +930,10 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
934930
encode_name(self.rbml_w, item.name);
935931
encode_attributes(self.rbml_w, &item.attrs);
936932
let needs_inline = tps_len > 0 || attr::requests_inline(&item.attrs);
937-
if needs_inline || constness == hir::Constness::Const {
933+
if constness == hir::Constness::Const {
938934
encode_inlined_item(ecx, self.rbml_w, InlinedItemRef::Item(def_id, item));
935+
}
936+
if needs_inline || constness == hir::Constness::Const {
939937
self.encode_mir(item.id);
940938
}
941939
encode_constness(self.rbml_w, constness);
@@ -982,8 +980,6 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
982980
for v in &enum_definition.variants {
983981
encode_variant_id(self.rbml_w, ecx.tcx.map.local_def_id(v.node.data.id()));
984982
}
985-
encode_inlined_item(ecx, self.rbml_w, InlinedItemRef::Item(def_id, item));
986-
self.encode_mir(item.id);
987983

988984
// Encode inherent implementations for self enumeration.
989985
encode_inherent_implementations(ecx, self.rbml_w, def_id);
@@ -1019,9 +1015,6 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
10191015
needs to know*/
10201016
self.encode_struct_fields(variant);
10211017

1022-
encode_inlined_item(ecx, self.rbml_w, InlinedItemRef::Item(def_id, item));
1023-
self.encode_mir(item.id);
1024-
10251018
// Encode inherent implementations for self structure.
10261019
encode_inherent_implementations(ecx, self.rbml_w, def_id);
10271020

@@ -1265,7 +1258,6 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
12651258
let ecx = self.ecx();
12661259

12671260
debug!("writing foreign item {}", ecx.tcx.node_path_str(nitem.id));
1268-
let abi = ecx.tcx.map.get_foreign_abi(nitem.id);
12691261

12701262
encode_def_id_and_key(ecx, self.rbml_w, def_id);
12711263
let parent_id = ecx.tcx.map.get_parent(nitem.id);
@@ -1276,12 +1268,6 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
12761268
encode_family(self.rbml_w, FN_FAMILY);
12771269
self.encode_bounds_and_type_for_item(nitem.id);
12781270
encode_name(self.rbml_w, nitem.name);
1279-
if abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
1280-
encode_inlined_item(ecx,
1281-
self.rbml_w,
1282-
InlinedItemRef::Foreign(def_id, nitem));
1283-
self.encode_mir(nitem.id);
1284-
}
12851271
encode_attributes(self.rbml_w, &nitem.attrs);
12861272
let stab = ecx.tcx.lookup_stability(ecx.tcx.map.local_def_id(nitem.id));
12871273
let depr = ecx.tcx.lookup_deprecation(ecx.tcx.map.local_def_id(nitem.id));

src/librustc_trans/base.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ use consts;
6565
use context::{SharedCrateContext, CrateContextList};
6666
use debuginfo::{self, DebugLoc};
6767
use declare;
68-
use inline;
6968
use machine;
7069
use machine::{llalign_of_min, llsize_of};
7170
use meth;
@@ -948,14 +947,17 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
948947
false
949948
};
950949

951-
let debug_context = if let (false, Some((instance, sig, abi))) = (no_debug, definition) {
952-
debuginfo::create_function_debug_context(ccx, instance, sig, abi, llfndecl)
950+
let mir = def_id.and_then(|id| ccx.get_mir(id));
951+
952+
let debug_context = if let (false, Some((instance, sig, abi)), &Some(ref mir)) =
953+
(no_debug, definition, &mir) {
954+
debuginfo::create_function_debug_context(ccx, instance, sig, abi, llfndecl, mir)
953955
} else {
954956
debuginfo::empty_function_debug_context(ccx)
955957
};
956958

957959
FunctionContext {
958-
mir: def_id.and_then(|id| ccx.get_mir(id)),
960+
mir: mir,
959961
llfn: llfndecl,
960962
llretslotptr: Cell::new(None),
961963
param_env: ccx.tcx().empty_parameter_environment(),
@@ -1133,8 +1135,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
11331135
let sig = ccx.tcx().normalize_associated_type(&sig);
11341136
let abi = fn_ty.fn_abi();
11351137

1136-
let local_instance = inline::maybe_inline_instance(ccx, instance);
1137-
let lldecl = match ccx.instances().borrow().get(&local_instance) {
1138+
let lldecl = match ccx.instances().borrow().get(&instance) {
11381139
Some(&val) => val,
11391140
None => bug!("Instance `{:?}` not already declared", instance)
11401141
};
@@ -1143,12 +1144,15 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
11431144
}
11441145

11451146
pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1146-
ctor_id: ast::NodeId,
1147+
def_id: DefId,
1148+
substs: &'tcx Substs<'tcx>,
11471149
disr: Disr,
1148-
param_substs: &'tcx Substs<'tcx>,
11491150
llfndecl: ValueRef) {
1150-
let ctor_ty = ccx.tcx().node_id_to_type(ctor_id);
1151-
let ctor_ty = monomorphize::apply_param_substs(ccx.tcx(), param_substs, &ctor_ty);
1151+
attributes::inline(llfndecl, attributes::InlineAttr::Hint);
1152+
attributes::set_frame_pointer_elimination(ccx, llfndecl);
1153+
1154+
let ctor_ty = ccx.tcx().lookup_item_type(def_id).ty;
1155+
let ctor_ty = monomorphize::apply_param_substs(ccx.tcx(), substs, &ctor_ty);
11521156

11531157
let sig = ccx.tcx().erase_late_bound_regions(&ctor_ty.fn_sig());
11541158
let sig = ccx.tcx().normalize_associated_type(&sig);
@@ -1740,10 +1744,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
17401744
println!("n_null_glues: {}", stats.n_null_glues.get());
17411745
println!("n_real_glues: {}", stats.n_real_glues.get());
17421746

1743-
println!("n_fallback_instantiations: {}", stats.n_fallback_instantiations.get());
1744-
17451747
println!("n_fns: {}", stats.n_fns.get());
1746-
println!("n_monos: {}", stats.n_monos.get());
17471748
println!("n_inlines: {}", stats.n_inlines.get());
17481749
println!("n_closures: {}", stats.n_closures.get());
17491750
println!("fn stats:");

0 commit comments

Comments
 (0)