mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Revert "write the root position at the end"
This reverts commit 44f66429e1fdba2cd167b4033f04f462a368b717.
This commit is contained in:
parent
ec64b4c90e
commit
34e44e5774
@ -688,7 +688,7 @@ impl MetadataBlob {
|
|||||||
|
|
||||||
pub(crate) fn get_root(&self) -> CrateRoot {
|
pub(crate) fn get_root(&self) -> CrateRoot {
|
||||||
let slice = &self.blob()[..];
|
let slice = &self.blob()[..];
|
||||||
let offset = slice.len() - 4;
|
let offset = METADATA_HEADER.len();
|
||||||
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)
|
||||||
|
@ -733,7 +733,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
assert_eq!(total_bytes, computed_total_bytes);
|
assert_eq!(total_bytes, computed_total_bytes);
|
||||||
|
|
||||||
if tcx.sess.meta_stats() {
|
if tcx.sess.meta_stats() {
|
||||||
self.opaque.flush().unwrap();
|
self.opaque.flush();
|
||||||
|
|
||||||
let pos_before_rewind = self.opaque.file().stream_position().unwrap();
|
let pos_before_rewind = self.opaque.file().stream_position().unwrap();
|
||||||
let mut zero_bytes = 0;
|
let mut zero_bytes = 0;
|
||||||
@ -2225,10 +2225,8 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &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);
|
||||||
|
|
||||||
// Though we had holded the root position historically in this place, we moved it to the end
|
// Will be filled with the root position after encoding everything.
|
||||||
// of all emitted bytes by #96544. Therefore, now these 4 bytes are just a dummy to avoid the
|
encoder.emit_raw_bytes(&[0, 0, 0, 0]);
|
||||||
// breaking change.
|
|
||||||
encoder.emit_raw_bytes(&[0, 0, 0, 0]).unwrap();
|
|
||||||
|
|
||||||
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);
|
||||||
@ -2259,20 +2257,25 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &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)
|
||||||
|
.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();
|
||||||
ecx.opaque.emit_raw_bytes(&[
|
file.write_all(&[(pos >> 24) as u8, (pos >> 16) as u8, (pos >> 8) as u8, (pos >> 0) as u8])
|
||||||
(pos >> 24) as u8,
|
.unwrap_or_else(|err| tcx.sess.fatal(&format!("failed to write to the file: {}", err)));
|
||||||
(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",
|
||||||
ecx.opaque.file().metadata().unwrap().len() as u64,
|
file.metadata().unwrap().len() as u64,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user