Skip to content

[beta] backport various PRs #50027

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

Merged
merged 16 commits into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Use LazySeq instead of Vec
  • Loading branch information
oli-obk committed Apr 17, 2018
commit 0734f0e3f452546e529260983571567fd75ffe0f
22 changes: 17 additions & 5 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub struct DecodeContext<'a, 'tcx: 'a> {

// interpreter allocation cache
interpret_alloc_cache: FxHashMap<usize, interpret::AllocId>,

// Read from the LazySeq CrateRoot::inpterpret_alloc_index on demand
interpret_alloc_index: Option<Vec<u32>>,
}

/// Abstract over the various ways one can create metadata decoders.
Expand All @@ -78,6 +81,7 @@ pub trait Metadata<'a, 'tcx>: Copy {
last_filemap_index: 0,
lazy_state: LazyState::NoNode,
interpret_alloc_cache: FxHashMap::default(),
interpret_alloc_index: None,
}
}
}
Expand Down Expand Up @@ -176,6 +180,17 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
self.lazy_state = LazyState::Previous(position + min_size);
Ok(position)
}

fn interpret_alloc(&mut self, idx: usize) -> usize {
if let Some(index) = self.interpret_alloc_index.as_mut() {
return index[idx] as usize;
}
let index = self.cdata().root.interpret_alloc_index;
let index: Vec<u32> = index.decode(self.cdata()).collect();
let pos = index[idx];
self.interpret_alloc_index = Some(index);
pos as usize
}
}

impl<'a, 'tcx: 'a> TyDecoder<'a, 'tcx> for DecodeContext<'a, 'tcx> {
Expand Down Expand Up @@ -292,11 +307,8 @@ impl<'a, 'tcx> SpecializedDecoder<interpret::AllocId> for DecodeContext<'a, 'tcx
if let Some(cached) = self.interpret_alloc_cache.get(&idx).cloned() {
return Ok(cached);
}
let pos = self
.cdata()
.root
.interpret_alloc_index[idx];
self.with_position(pos as usize, |this| {
let pos = self.interpret_alloc(idx);
self.with_position(pos, |this| {
interpret::specialized_decode_alloc_id(
this,
tcx,
Expand Down
39 changes: 22 additions & 17 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
start - min_end
}
LazyState::Previous(last_min_end) => {
assert!(last_min_end <= position);
assert!(
last_min_end <= position,
"make sure that the calls to `lazy*` \
are in the same order as the metadata fields",
);
position - last_min_end
}
};
Expand Down Expand Up @@ -439,21 +443,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
IsolatedEncoder::encode_wasm_custom_sections,
&wasm_custom_sections);

// Encode and index the items.
i = self.position();
let items = self.encode_info_for_items();
let item_bytes = self.position() - i;

i = self.position();
let index = items.write_index(&mut self.opaque.cursor);
let index_bytes = self.position() - i;

let tcx = self.tcx;
let link_meta = self.link_meta;
let is_proc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeProcMacro);
let has_default_lib_allocator =
attr::contains_name(tcx.hir.krate_attrs(), "default_lib_allocator");
let has_global_allocator = tcx.sess.has_global_allocator.get();

// Encode the allocation index
let interpret_alloc_index = {
Expand All @@ -478,9 +468,24 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
n = new_n;
}
interpret_alloc_index
self.lazy_seq(interpret_alloc_index)
};

// Encode and index the items.
i = self.position();
let items = self.encode_info_for_items();
let item_bytes = self.position() - i;

i = self.position();
let index = items.write_index(&mut self.opaque.cursor);
let index_bytes = self.position() - i;

let link_meta = self.link_meta;
let is_proc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeProcMacro);
let has_default_lib_allocator =
attr::contains_name(tcx.hir.krate_attrs(), "default_lib_allocator");
let has_global_allocator = tcx.sess.has_global_allocator.get();

let root = self.lazy(&CrateRoot {
name: tcx.crate_name(LOCAL_CRATE),
triple: tcx.sess.opts.target_triple.clone(),
Expand Down Expand Up @@ -511,8 +516,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
impls,
exported_symbols,
wasm_custom_sections,
index,
interpret_alloc_index,
index,
});

let total_bytes = self.position();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub struct CrateRoot {
pub impls: LazySeq<TraitImpls>,
pub exported_symbols: LazySeq<(ExportedSymbol, SymbolExportLevel)>,
pub wasm_custom_sections: LazySeq<DefIndex>,
pub interpret_alloc_index: Vec<u32>,
pub interpret_alloc_index: LazySeq<u32>,

pub index: LazySeq<index::Index>,
}
Expand Down