Skip to content

Commit 17d5e99

Browse files
committed
---
yaml --- r: 273226 b: refs/heads/beta c: 062a05d h: refs/heads/master
1 parent f8c5a79 commit 17d5e99

File tree

5 files changed

+71
-102
lines changed

5 files changed

+71
-102
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: b918e37eb3e393c5a5b0408430e146c0b66ec7ed
26+
refs/heads/beta: 062a05dde8c3ea5386fa358d882e1eaca99a9ff0
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/middle/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub struct ChildItem {
122122

123123
pub enum FoundAst<'ast> {
124124
Found(&'ast InlinedItem),
125-
FoundParent(DefId, &'ast InlinedItem),
125+
FoundParent(DefId, &'ast hir::Item),
126126
NotFound,
127127
}
128128

branches/beta/src/librustc_metadata/astencode.rs

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -125,61 +125,51 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
125125
tcx: &TyCtxt<'tcx>,
126126
parent_path: Vec<ast_map::PathElem>,
127127
parent_def_path: ast_map::DefPath,
128-
par_doc: rbml::Doc,
128+
ast_doc: rbml::Doc,
129129
orig_did: DefId)
130-
-> Result<&'tcx InlinedItem, (Vec<ast_map::PathElem>,
131-
ast_map::DefPath)> {
132-
match par_doc.opt_child(c::tag_ast) {
133-
None => Err((parent_path, parent_def_path)),
134-
Some(ast_doc) => {
135-
let mut path_as_str = None;
136-
debug!("> Decoding inlined fn: {:?}::?",
137-
{
138-
// Do an Option dance to use the path after it is moved below.
139-
let s = ast_map::path_to_string(parent_path.iter().cloned());
140-
path_as_str = Some(s);
141-
path_as_str.as_ref().map(|x| &x[..])
142-
});
143-
let mut ast_dsr = reader::Decoder::new(ast_doc);
144-
let from_id_range = Decodable::decode(&mut ast_dsr).unwrap();
145-
let to_id_range = reserve_id_range(&tcx.sess, from_id_range);
146-
let dcx = &DecodeContext {
147-
cdata: cdata,
148-
tcx: tcx,
149-
from_id_range: from_id_range,
150-
to_id_range: to_id_range,
151-
last_filemap_index: Cell::new(0)
152-
};
153-
let raw_ii = decode_ast(ast_doc);
154-
let ii = ast_map::map_decoded_item(&dcx.tcx.map,
155-
parent_path,
156-
parent_def_path,
157-
raw_ii,
158-
dcx);
159-
let name = match *ii {
160-
InlinedItem::Item(ref i) => i.name,
161-
InlinedItem::Foreign(ref i) => i.name,
162-
InlinedItem::TraitItem(_, ref ti) => ti.name,
163-
InlinedItem::ImplItem(_, ref ii) => ii.name
164-
};
165-
debug!("Fn named: {}", name);
166-
debug!("< Decoded inlined fn: {}::{}",
167-
path_as_str.unwrap(),
168-
name);
169-
region::resolve_inlined_item(&tcx.sess, &tcx.region_maps, ii);
170-
decode_side_tables(dcx, ast_doc);
171-
copy_item_types(dcx, ii, orig_did);
172-
match *ii {
173-
InlinedItem::Item(ref i) => {
174-
debug!(">>> DECODED ITEM >>>\n{}\n<<< DECODED ITEM <<<",
175-
::rustc_front::print::pprust::item_to_string(&i));
176-
}
177-
_ => { }
178-
}
179-
180-
Ok(ii)
181-
}
182-
}
130+
-> &'tcx InlinedItem {
131+
let mut path_as_str = None;
132+
debug!("> Decoding inlined fn: {:?}::?",
133+
{
134+
// Do an Option dance to use the path after it is moved below.
135+
let s = ast_map::path_to_string(parent_path.iter().cloned());
136+
path_as_str = Some(s);
137+
path_as_str.as_ref().map(|x| &x[..])
138+
});
139+
let mut ast_dsr = reader::Decoder::new(ast_doc);
140+
let from_id_range = Decodable::decode(&mut ast_dsr).unwrap();
141+
let to_id_range = reserve_id_range(&tcx.sess, from_id_range);
142+
let dcx = &DecodeContext {
143+
cdata: cdata,
144+
tcx: tcx,
145+
from_id_range: from_id_range,
146+
to_id_range: to_id_range,
147+
last_filemap_index: Cell::new(0)
148+
};
149+
let ii = ast_map::map_decoded_item(&dcx.tcx.map,
150+
parent_path,
151+
parent_def_path,
152+
decode_ast(ast_doc),
153+
dcx);
154+
let name = match *ii {
155+
InlinedItem::Item(ref i) => i.name,
156+
InlinedItem::Foreign(ref i) => i.name,
157+
InlinedItem::TraitItem(_, ref ti) => ti.name,
158+
InlinedItem::ImplItem(_, ref ii) => ii.name
159+
};
160+
debug!("Fn named: {}", name);
161+
debug!("< Decoded inlined fn: {}::{}",
162+
path_as_str.unwrap(),
163+
name);
164+
region::resolve_inlined_item(&tcx.sess, &tcx.region_maps, ii);
165+
decode_side_tables(dcx, ast_doc);
166+
copy_item_types(dcx, ii, orig_did);
167+
if let InlinedItem::Item(ref i) = *ii {
168+
debug!(">>> DECODED ITEM >>>\n{}\n<<< DECODED ITEM <<<",
169+
::rustc_front::print::pprust::item_to_string(&i));
170+
}
171+
172+
ii
183173
}
184174

185175
// ______________________________________________________________________

branches/beta/src/librustc_metadata/decoder.rs

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -798,53 +798,36 @@ pub fn get_item_name(intr: &IdentInterner, cdata: Cmd, id: DefIndex) -> ast::Nam
798798
item_name(intr, cdata.lookup_item(id))
799799
}
800800

801-
pub fn maybe_get_item_ast<'tcx>(cdata: Cmd,
802-
tcx: &TyCtxt<'tcx>,
803-
id: DefIndex,
801+
pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &TyCtxt<'tcx>, id: DefIndex)
804802
-> FoundAst<'tcx> {
805803
debug!("Looking up item: {:?}", id);
806804
let item_doc = cdata.lookup_item(id);
807805
let item_did = item_def_id(item_doc, cdata);
808-
let parent_path = {
809-
let mut path = item_path(item_doc);
810-
path.pop();
811-
path
812-
};
813-
let parent_def_path = {
814-
let mut def_path = def_path(cdata, id);
815-
def_path.pop();
816-
def_path
817-
};
818-
match decode_inlined_item(cdata,
819-
tcx,
820-
parent_path,
821-
parent_def_path,
822-
item_doc,
823-
item_did) {
824-
Ok(ii) => FoundAst::Found(ii),
825-
Err((mut parent_path, mut parent_def_path)) => {
826-
match item_parent_item(cdata, item_doc) {
827-
Some(parent_did) => {
828-
// Remove the last element from the paths, since we are now
829-
// trying to inline the parent.
830-
parent_path.pop();
831-
parent_def_path.pop();
832-
833-
let parent_item = cdata.lookup_item(parent_did.index);
834-
match decode_inlined_item(cdata,
835-
tcx,
836-
parent_path,
837-
parent_def_path,
838-
parent_item,
839-
parent_did) {
840-
Ok(ii) => FoundAst::FoundParent(parent_did, ii),
841-
Err(_) => FoundAst::NotFound
842-
}
843-
}
844-
None => FoundAst::NotFound
806+
let mut parent_path = item_path(item_doc);
807+
parent_path.pop();
808+
let mut parent_def_path = def_path(cdata, id);
809+
parent_def_path.pop();
810+
if let Some(ast_doc) = reader::maybe_get_doc(item_doc, tag_ast as usize) {
811+
let ii = decode_inlined_item(cdata, tcx, parent_path,
812+
parent_def_path,
813+
ast_doc, item_did);
814+
return FoundAst::Found(ii);
815+
} else if let Some(parent_did) = item_parent_item(cdata, item_doc) {
816+
// Remove the last element from the paths, since we are now
817+
// trying to inline the parent.
818+
parent_path.pop();
819+
parent_def_path.pop();
820+
let parent_doc = cdata.lookup_item(parent_did.index);
821+
if let Some(ast_doc) = reader::maybe_get_doc(parent_doc, tag_ast as usize) {
822+
let ii = decode_inlined_item(cdata, tcx, parent_path,
823+
parent_def_path,
824+
ast_doc, parent_did);
825+
if let &InlinedItem::Item(ref i) = ii {
826+
return FoundAst::FoundParent(parent_did, i);
845827
}
846828
}
847829
}
830+
FoundAst::NotFound
848831
}
849832

850833
pub fn is_item_mir_available<'tcx>(cdata: Cmd, id: DefIndex) -> bool {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: DefId) -> Option<DefId> {
9393
ccx.external_srcs().borrow_mut().insert(item.id, fn_id);
9494
item.id
9595
}
96-
FoundAst::FoundParent(parent_id, &InlinedItem::Item(ref item)) => {
96+
FoundAst::FoundParent(parent_id, item) => {
9797
ccx.external().borrow_mut().insert(parent_id, Some(item.id));
9898
ccx.external_srcs().borrow_mut().insert(item.id, parent_id);
9999

100100
let mut my_id = 0;
101101
match item.node {
102102
hir::ItemEnum(ref ast_def, _) => {
103103
let ast_vs = &ast_def.variants;
104-
let ty_vs = &ccx.tcx().lookup_adt_def(parent_id).variants;
104+
let ty_vs = &tcx.lookup_adt_def(parent_id).variants;
105105
assert_eq!(ast_vs.len(), ty_vs.len());
106106
for (ast_v, ty_v) in ast_vs.iter().zip(ty_vs.iter()) {
107107
if ty_v.did == fn_id { my_id = ast_v.node.data.id(); }
@@ -123,10 +123,6 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: DefId) -> Option<DefId> {
123123
trans_item(ccx, &item);
124124
my_id
125125
}
126-
FoundAst::FoundParent(_, _) => {
127-
ccx.sess().bug("maybe_get_item_ast returned a FoundParent \
128-
with a non-item parent");
129-
}
130126
FoundAst::Found(&InlinedItem::TraitItem(_, ref trait_item)) => {
131127
ccx.external().borrow_mut().insert(fn_id, Some(trait_item.id));
132128
ccx.external_srcs().borrow_mut().insert(trait_item.id, fn_id);

0 commit comments

Comments
 (0)