construct EncodedMetadata in encode_and_write_metadata
This commit is contained in:
parent
bb75c4b46a
commit
c26c461c0c
2 changed files with 17 additions and 12 deletions
|
@ -68,11 +68,9 @@ pub fn encode_and_write_metadata(
|
||||||
.unwrap_or_else(|err| tcx.sess.fatal(&format!("couldn't create a temp dir: {}", err)));
|
.unwrap_or_else(|err| tcx.sess.fatal(&format!("couldn't create a temp dir: {}", err)));
|
||||||
let metadata_tmpdir = MaybeTempDir::new(metadata_tmpdir, tcx.sess.opts.cg.save_temps);
|
let metadata_tmpdir = MaybeTempDir::new(metadata_tmpdir, tcx.sess.opts.cg.save_temps);
|
||||||
let metadata_filename = metadata_tmpdir.as_ref().join(METADATA_FILENAME);
|
let metadata_filename = metadata_tmpdir.as_ref().join(METADATA_FILENAME);
|
||||||
let metadata = match metadata_kind {
|
match metadata_kind {
|
||||||
MetadataKind::None => {
|
MetadataKind::None => {
|
||||||
let metadata = EncodedMetadata::new();
|
let _ = emit_metadata(tcx.sess, &[], &metadata_tmpdir);
|
||||||
let _ = emit_metadata(tcx.sess, metadata.raw_data(), &metadata_tmpdir);
|
|
||||||
metadata
|
|
||||||
}
|
}
|
||||||
MetadataKind::Uncompressed | MetadataKind::Compressed => {
|
MetadataKind::Uncompressed | MetadataKind::Compressed => {
|
||||||
encode_metadata(tcx, &metadata_filename)
|
encode_metadata(tcx, &metadata_filename)
|
||||||
|
@ -82,7 +80,7 @@ pub fn encode_and_write_metadata(
|
||||||
let _prof_timer = tcx.sess.prof.generic_activity("write_crate_metadata");
|
let _prof_timer = tcx.sess.prof.generic_activity("write_crate_metadata");
|
||||||
|
|
||||||
let need_metadata_file = tcx.sess.opts.output_types.contains_key(&OutputType::Metadata);
|
let need_metadata_file = tcx.sess.opts.output_types.contains_key(&OutputType::Metadata);
|
||||||
if need_metadata_file {
|
let metadata_filename = if need_metadata_file {
|
||||||
if let Err(e) = non_durable_rename(&metadata_filename, &out_filename) {
|
if let Err(e) = non_durable_rename(&metadata_filename, &out_filename) {
|
||||||
tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
|
tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
|
||||||
}
|
}
|
||||||
|
@ -92,7 +90,12 @@ pub fn encode_and_write_metadata(
|
||||||
.span_diagnostic
|
.span_diagnostic
|
||||||
.emit_artifact_notification(&out_filename, "metadata");
|
.emit_artifact_notification(&out_filename, "metadata");
|
||||||
}
|
}
|
||||||
}
|
out_filename
|
||||||
|
} else {
|
||||||
|
metadata_filename
|
||||||
|
};
|
||||||
|
let raw_data = std::fs::read(metadata_filename).unwrap();
|
||||||
|
let metadata = EncodedMetadata::from_raw_data(raw_data);
|
||||||
|
|
||||||
let need_metadata_module = metadata_kind == MetadataKind::Compressed;
|
let need_metadata_module = metadata_kind == MetadataKind::Compressed;
|
||||||
|
|
||||||
|
|
|
@ -2146,13 +2146,18 @@ impl EncodedMetadata {
|
||||||
EncodedMetadata { raw_data: Vec::new() }
|
EncodedMetadata { raw_data: Vec::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn from_raw_data(raw_data: Vec<u8>) -> Self {
|
||||||
|
Self { raw_data }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn raw_data(&self) -> &[u8] {
|
pub fn raw_data(&self) -> &[u8] {
|
||||||
&self.raw_data
|
&self.raw_data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_metadata(tcx: TyCtxt<'_>, path: impl AsRef<Path>) -> EncodedMetadata {
|
pub fn encode_metadata(tcx: TyCtxt<'_>, path: impl AsRef<Path>) {
|
||||||
let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata");
|
let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata");
|
||||||
|
|
||||||
// Since encoding metadata is not in a query, and nothing is cached,
|
// Since encoding metadata is not in a query, and nothing is cached,
|
||||||
|
@ -2170,11 +2175,10 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: impl AsRef<Path>) -> EncodedMetada
|
||||||
// It can be removed if it turns out to cause trouble or be detrimental to performance.
|
// It can be removed if it turns out to cause trouble or be detrimental to performance.
|
||||||
join(|| prefetch_mir(tcx), || tcx.exported_symbols(LOCAL_CRATE));
|
join(|| prefetch_mir(tcx), || tcx.exported_symbols(LOCAL_CRATE));
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_metadata_impl(tcx: TyCtxt<'_>, path: impl AsRef<Path>) -> EncodedMetadata {
|
fn encode_metadata_impl(tcx: TyCtxt<'_>, path: impl AsRef<Path>) {
|
||||||
let mut encoder = opaque::FileEncoder::new(path.as_ref())
|
let mut encoder = opaque::FileEncoder::new(path.as_ref())
|
||||||
.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);
|
||||||
|
@ -2226,8 +2230,6 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: impl AsRef<Path>) -> EncodedMetad
|
||||||
|
|
||||||
// Record metadata size for self-profiling
|
// Record metadata size for self-profiling
|
||||||
tcx.prof.artifact_size("crate_metadata", "crate_metadata", result.len() as u64);
|
tcx.prof.artifact_size("crate_metadata", "crate_metadata", result.len() as u64);
|
||||||
|
|
||||||
EncodedMetadata { raw_data: result }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn provide(providers: &mut Providers) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue