write the root position at the end
This commit is contained in:
parent
b28b7c90cb
commit
c8e49e4b25
2 changed files with 10 additions and 18 deletions
|
@ -682,13 +682,13 @@ impl MetadataBlob {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_rustc_version(&self) -> String {
|
pub(crate) fn get_rustc_version(&self) -> String {
|
||||||
LazyValue::<String>::from_position(NonZeroUsize::new(METADATA_HEADER.len() + 4).unwrap())
|
LazyValue::<String>::from_position(NonZeroUsize::new(METADATA_HEADER.len()).unwrap())
|
||||||
.decode(self)
|
.decode(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_root(&self) -> CrateRoot {
|
pub(crate) fn get_root(&self) -> CrateRoot {
|
||||||
let slice = &self.blob()[..];
|
let slice = &self.blob()[..];
|
||||||
let offset = METADATA_HEADER.len();
|
let offset = slice.len() - 4;
|
||||||
let pos = (((slice[offset + 0] as u32) << 24)
|
let pos = (((slice[offset + 0] as u32) << 24)
|
||||||
| ((slice[offset + 1] as u32) << 16)
|
| ((slice[offset + 1] as u32) << 16)
|
||||||
| ((slice[offset + 2] as u32) << 8)
|
| ((slice[offset + 2] as u32) << 8)
|
||||||
|
|
|
@ -40,7 +40,7 @@ use rustc_span::{
|
||||||
use rustc_target::abi::VariantIdx;
|
use rustc_target::abi::VariantIdx;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::io::{Read, Seek, Write};
|
use std::io::{Read, Write};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
@ -2215,9 +2215,6 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: impl AsRef<Path>) {
|
||||||
.unwrap_or_else(|err| tcx.sess.fatal(&format!("failed to create file encoder: {}", err)));
|
.unwrap_or_else(|err| tcx.sess.fatal(&format!("failed to create file encoder: {}", err)));
|
||||||
encoder.emit_raw_bytes(METADATA_HEADER);
|
encoder.emit_raw_bytes(METADATA_HEADER);
|
||||||
|
|
||||||
// Will be filled with the root position after encoding everything.
|
|
||||||
encoder.emit_raw_bytes(&[0, 0, 0, 0]);
|
|
||||||
|
|
||||||
let source_map_files = tcx.sess.source_map().files();
|
let source_map_files = tcx.sess.source_map().files();
|
||||||
let source_file_cache = (source_map_files[0].clone(), 0);
|
let source_file_cache = (source_map_files[0].clone(), 0);
|
||||||
let required_source_files = Some(GrowableBitSet::with_capacity(source_map_files.len()));
|
let required_source_files = Some(GrowableBitSet::with_capacity(source_map_files.len()));
|
||||||
|
@ -2247,25 +2244,20 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: impl AsRef<Path>) {
|
||||||
// culminating in the `CrateRoot` which points to all of it.
|
// culminating in the `CrateRoot` which points to all of it.
|
||||||
let root = ecx.encode_crate_root();
|
let root = ecx.encode_crate_root();
|
||||||
|
|
||||||
ecx.opaque.flush();
|
|
||||||
let mut file = std::fs::OpenOptions::new()
|
|
||||||
.write(true)
|
|
||||||
.open(path.as_ref())
|
|
||||||
.unwrap_or_else(|err| tcx.sess.fatal(&format!("failed to open the file: {}", err)));
|
|
||||||
|
|
||||||
// Encode the root position.
|
// Encode the root position.
|
||||||
let header = METADATA_HEADER.len();
|
|
||||||
file.seek(std::io::SeekFrom::Start(header as u64))
|
|
||||||
.unwrap_or_else(|err| tcx.sess.fatal(&format!("failed to seek the file: {}", err)));
|
|
||||||
let pos = root.position.get();
|
let pos = root.position.get();
|
||||||
file.write_all(&[(pos >> 24) as u8, (pos >> 16) as u8, (pos >> 8) as u8, (pos >> 0) as u8])
|
ecx.opaque.emit_raw_bytes(&[
|
||||||
.unwrap_or_else(|err| tcx.sess.fatal(&format!("failed to write to the file: {}", err)));
|
(pos >> 24) as u8,
|
||||||
|
(pos >> 16) as u8,
|
||||||
|
(pos >> 8) as u8,
|
||||||
|
(pos >> 0) as u8,
|
||||||
|
]);
|
||||||
|
|
||||||
// Record metadata size for self-profiling
|
// Record metadata size for self-profiling
|
||||||
tcx.prof.artifact_size(
|
tcx.prof.artifact_size(
|
||||||
"crate_metadata",
|
"crate_metadata",
|
||||||
"crate_metadata",
|
"crate_metadata",
|
||||||
file.metadata().unwrap().len() as u64,
|
ecx.opaque.file().metadata().unwrap().len() as u64,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue