Skip to content

Commit b7cd0f7

Browse files
committed
Auto merge of rust-lang#93681 - Mark-Simulacrum:rlink-binary, r=davidtwco,bjorn3
Store rlink data in opaque binary format on disk This removes one of the only uses of JSON decoding (to Rust structs) from the compiler, and fixes the FIXME comment. It's not clear to me what the reason for using JSON here originally was, and from what I can tell nothing outside of rustc expects to read the emitted information, so it seems like a reasonable step to move it to the metadata-encoding format (rustc_serialize::opaque). Mostly intended as a FIXME fix, though potentially a stepping stone to dropping the support for Decodable to be used to decode JSON entirely (allowing for better/faster APIs on the Decoder trait). cc rust-lang#64191
2 parents 1f0a968 + a1c261c commit b7cd0f7

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

Diff for: compiler/rustc_driver/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_log::stdout_isatty;
2929
use rustc_metadata::locator;
3030
use rustc_save_analysis as save;
3131
use rustc_save_analysis::DumpHandler;
32-
use rustc_serialize::json::{self, ToJson};
32+
use rustc_serialize::json::ToJson;
3333
use rustc_session::config::{nightly_options, CG_OPTIONS, DB_OPTIONS};
3434
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, TrimmedDefPaths};
3535
use rustc_session::cstore::MetadataLoader;
@@ -595,10 +595,12 @@ impl RustcDefaultCalls {
595595
// FIXME: #![crate_type] and #![crate_name] support not implemented yet
596596
sess.init_crate_types(collect_crate_types(sess, &[]));
597597
let outputs = compiler.build_output_filenames(sess, &[]);
598-
let rlink_data = fs::read_to_string(file).unwrap_or_else(|err| {
598+
let rlink_data = fs::read(file).unwrap_or_else(|err| {
599599
sess.fatal(&format!("failed to read rlink file: {}", err));
600600
});
601-
let codegen_results: CodegenResults = json::decode(&rlink_data);
601+
let mut decoder = rustc_serialize::opaque::Decoder::new(&rlink_data, 0);
602+
let codegen_results: CodegenResults =
603+
rustc_serialize::Decodable::decode(&mut decoder);
602604
let result = compiler.codegen_backend().link(sess, codegen_results, &outputs);
603605
abort_on_err(result, sess);
604606
} else {

Diff for: compiler/rustc_interface/src/queries.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_middle::arena::Arena;
1313
use rustc_middle::dep_graph::DepGraph;
1414
use rustc_middle::ty::{GlobalCtxt, TyCtxt};
1515
use rustc_query_impl::Queries as TcxQueries;
16-
use rustc_serialize::json;
1716
use rustc_session::config::{self, OutputFilenames, OutputType};
1817
use rustc_session::{output::find_crate_name, Session};
1918
use rustc_span::symbol::sym;
@@ -367,12 +366,10 @@ impl Linker {
367366
}
368367

369368
if sess.opts.debugging_opts.no_link {
370-
// FIXME: use a binary format to encode the `.rlink` file
371-
let rlink_data = json::encode(&codegen_results).map_err(|err| {
372-
sess.fatal(&format!("failed to encode rlink: {}", err));
373-
})?;
369+
let mut encoder = rustc_serialize::opaque::Encoder::new(Vec::new());
370+
rustc_serialize::Encodable::encode(&codegen_results, &mut encoder).unwrap();
374371
let rlink_file = self.prepare_outputs.with_extension(config::RLINK_EXT);
375-
std::fs::write(&rlink_file, rlink_data).map_err(|err| {
372+
std::fs::write(&rlink_file, encoder.into_inner()).map_err(|err| {
376373
sess.fatal(&format!("failed to write file {}: {}", rlink_file.display(), err));
377374
})?;
378375
return Ok(());

0 commit comments

Comments
 (0)