Mmap the incremental data instead of reading it.
This commit is contained in:
parent
05cccdc9b3
commit
4afdeaaabd
@ -14,6 +14,7 @@
|
||||
use std::io::{self, Read};
|
||||
use std::path::Path;
|
||||
|
||||
use rustc_data_structures::memmap::Mmap;
|
||||
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
|
||||
use rustc_serialize::Encoder;
|
||||
|
||||
@ -54,14 +55,15 @@ pub fn read_file(
|
||||
report_incremental_info: bool,
|
||||
path: &Path,
|
||||
nightly_build: bool,
|
||||
) -> io::Result<Option<(Vec<u8>, usize)>> {
|
||||
let data = match fs::read(path) {
|
||||
Ok(data) => data,
|
||||
) -> io::Result<Option<(Mmap, usize)>> {
|
||||
let file = match fs::File::open(path) {
|
||||
Ok(file) => file,
|
||||
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(None),
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
let mmap = unsafe { Mmap::map(file) }?;
|
||||
|
||||
let mut file = io::Cursor::new(data);
|
||||
let mut file = io::Cursor::new(&*mmap);
|
||||
|
||||
// Check FILE_MAGIC
|
||||
{
|
||||
@ -103,7 +105,7 @@ pub fn read_file(
|
||||
}
|
||||
|
||||
let post_header_start_pos = file.position() as usize;
|
||||
Ok(Some((file.into_inner(), post_header_start_pos)))
|
||||
Ok(Some((mmap, post_header_start_pos)))
|
||||
}
|
||||
|
||||
fn report_format_mismatch(report_incremental_info: bool, file: &Path, message: &str) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
//! Code to save/load the dep-graph from files.
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::memmap::Mmap;
|
||||
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
|
||||
use rustc_middle::ty::OnDiskCache;
|
||||
use rustc_serialize::opaque::Decoder;
|
||||
@ -48,7 +49,7 @@ fn load_data(
|
||||
report_incremental_info: bool,
|
||||
path: &Path,
|
||||
nightly_build: bool,
|
||||
) -> LoadResult<(Vec<u8>, usize)> {
|
||||
) -> LoadResult<(Mmap, usize)> {
|
||||
match file_format::read_file(report_incremental_info, path, nightly_build) {
|
||||
Ok(Some(data_and_pos)) => LoadResult::Ok { data: data_and_pos },
|
||||
Ok(None) => {
|
||||
|
@ -27,6 +27,7 @@
|
||||
use rustc_ast as ast;
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::memmap::Mmap;
|
||||
use rustc_data_structures::profiling::SelfProfilerRef;
|
||||
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
@ -71,7 +72,7 @@
|
||||
|
||||
pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
|
||||
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
|
||||
fn new(sess: &'tcx Session, data: Vec<u8>, start_pos: usize) -> Self
|
||||
fn new(sess: &'tcx Session, data: Mmap, start_pos: usize) -> Self
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::QueryCtxt;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
|
||||
use rustc_data_structures::memmap::Mmap;
|
||||
use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, OnceCell};
|
||||
use rustc_data_structures::unhash::UnhashMap;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, StableCrateId, LOCAL_CRATE};
|
||||
@ -42,7 +43,7 @@
|
||||
/// any side effects that have been emitted during a query.
|
||||
pub struct OnDiskCache<'sess> {
|
||||
// The complete cache data in serialized form.
|
||||
serialized_data: Vec<u8>,
|
||||
serialized_data: Option<Mmap>,
|
||||
|
||||
// Collects all `QuerySideEffects` created during the current compilation
|
||||
// session.
|
||||
@ -182,7 +183,8 @@ fn new(tcx: TyCtxt<'_>, file: &SourceFile) -> EncodedSourceFileId {
|
||||
}
|
||||
|
||||
impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
|
||||
fn new(sess: &'sess Session, data: Vec<u8>, start_pos: usize) -> Self {
|
||||
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
|
||||
fn new(sess: &'sess Session, data: Mmap, start_pos: usize) -> Self {
|
||||
debug_assert!(sess.opts.incremental.is_some());
|
||||
|
||||
// Wrap in a scope so we can borrow `data`.
|
||||
@ -204,7 +206,7 @@ fn new(sess: &'sess Session, data: Vec<u8>, start_pos: usize) -> Self {
|
||||
};
|
||||
|
||||
Self {
|
||||
serialized_data: data,
|
||||
serialized_data: Some(data),
|
||||
file_index_to_stable_id: footer.file_index_to_stable_id,
|
||||
file_index_to_file: Default::default(),
|
||||
cnum_map: OnceCell::new(),
|
||||
@ -225,7 +227,7 @@ fn new(sess: &'sess Session, data: Vec<u8>, start_pos: usize) -> Self {
|
||||
|
||||
fn new_empty(source_map: &'sess SourceMap) -> Self {
|
||||
Self {
|
||||
serialized_data: Vec::new(),
|
||||
serialized_data: None,
|
||||
file_index_to_stable_id: Default::default(),
|
||||
file_index_to_file: Default::default(),
|
||||
cnum_map: OnceCell::new(),
|
||||
@ -577,7 +579,10 @@ fn with_decoder<'a, 'tcx, T, F: FnOnce(&mut CacheDecoder<'sess, 'tcx>) -> T>(
|
||||
|
||||
let mut decoder = CacheDecoder {
|
||||
tcx,
|
||||
opaque: opaque::Decoder::new(&self.serialized_data[..], pos.to_usize()),
|
||||
opaque: opaque::Decoder::new(
|
||||
self.serialized_data.as_deref().unwrap_or(&[]),
|
||||
pos.to_usize(),
|
||||
),
|
||||
source_map: self.source_map,
|
||||
cnum_map,
|
||||
file_index_to_file: &self.file_index_to_file,
|
||||
|
Loading…
Reference in New Issue
Block a user