Skip to content

Commit 9e3d79b

Browse files
committed
add flag to split sourcemap into a secondary rmeta file
1 parent c65bc6c commit 9e3d79b

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
436436
assert!(
437437
last_pos <= position,
438438
"make sure that the calls to `lazy*` \
439-
are in the same order as the metadata fields",
439+
are in the same order as the metadata fields",
440440
);
441441
position.get() - last_pos.get()
442442
}
@@ -603,6 +603,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
603603
adapted.encode(&mut self.opaque)
604604
}
605605

606+
fn dont_encode_source_map(
607+
&mut self,
608+
) -> LazyTable<u32, Option<LazyValue<rustc_span::SourceFile>>> {
609+
let adapted = TableBuilder::default();
610+
adapted.encode(&mut self.opaque)
611+
}
612+
606613
fn encode_crate_root(&mut self) -> LazyValue<CrateRoot> {
607614
let tcx = self.tcx;
608615
let mut stats: Vec<(&'static str, usize)> = Vec::with_capacity(32);
@@ -708,7 +715,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
708715

709716
// Encode source_map. This needs to be done last, because encoding `Span`s tells us which
710717
// `SourceFiles` we actually need to encode.
711-
let source_map = stat!("source-map", || self.encode_source_map());
718+
let source_map = if tcx.sess.is_split_rmeta_enabled() {
719+
stat!("source-map", || self.dont_encode_source_map())
720+
} else {
721+
stat!("source-map", || self.encode_source_map())
722+
};
712723
let target_modifiers = stat!("target-modifiers", || self.encode_target_modifiers());
713724

714725
let root = stat!("final", || {
@@ -1706,7 +1717,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17061717

17071718
record_array!(self.tables.module_children_non_reexports[def_id] <-
17081719
module_children.iter().filter(|child| child.reexport_chain.is_empty())
1709-
.map(|child| child.res.def_id().index));
1720+
.map(|child| child.res.def_id().index));
17101721

17111722
record_defaulted_array!(self.tables.module_children_reexports[def_id] <-
17121723
module_children.iter().filter(|child| !child.reexport_chain.is_empty()));
@@ -1755,7 +1766,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17551766
if matches!(rpitit_info, ty::ImplTraitInTraitData::Trait { .. }) {
17561767
record_array!(
17571768
self.tables.assumed_wf_types_for_rpitit[def_id]
1758-
<- self.tcx.assumed_wf_types_for_rpitit(def_id)
1769+
<- self.tcx.assumed_wf_types_for_rpitit(def_id)
17591770
);
17601771
self.encode_precise_capturing_args(def_id);
17611772
}
@@ -1838,7 +1849,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18381849
for &local_def_id in tcx.mir_keys(()) {
18391850
if let DefKind::AssocFn | DefKind::Fn = tcx.def_kind(local_def_id) {
18401851
record_array!(self.tables.deduced_param_attrs[local_def_id.to_def_id()] <-
1841-
self.tcx.deduced_param_attrs(local_def_id.to_def_id()));
1852+
self.tcx.deduced_param_attrs(local_def_id.to_def_id()));
18421853
}
18431854
}
18441855
}

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,8 @@ written to standard error output)"),
25372537
by the linker"),
25382538
split_lto_unit: Option<bool> = (None, parse_opt_bool, [TRACKED],
25392539
"enable LTO unit splitting (default: no)"),
2540+
split_rmeta: Option<bool> = (None, parse_opt_bool, [TRACKED],
2541+
"split extra rmeta data that isn't relevant rlib ABI into a separate file"),
25402542
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
25412543
"hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"),
25422544
#[rustc_lint_opt_deny_field_access("use `Session::stack_protector` instead of this field")]

compiler/rustc_session/src/session.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ impl Session {
400400
self.opts.unstable_opts.split_lto_unit == Some(true)
401401
}
402402

403+
pub fn is_split_rmeta_enabled(&self) -> bool {
404+
self.opts.unstable_opts.split_rmeta == Some(true)
405+
}
406+
403407
/// Check whether this compile session and crate type use static crt.
404408
pub fn crt_static(&self, crate_type: Option<CrateType>) -> bool {
405409
if !self.target.crt_static_respected {
2.23 KB
Binary file not shown.
2.23 KB
Binary file not shown.

tests/run-make/rdr-ignores-comments/rmake.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
// tests that changing the content of a comment will cause a change in the rmeta of a file
2-
use run_make_support::{rfs, rustc};
1+
// tests that changing the content of a comment will not cause a change in the rmeta of a library if -Zsplit-rmeta is enabled
32
use std::hash::{Hash, Hasher};
43
use std::path::Path;
54

5+
use run_make_support::{rfs, rustc};
6+
67
fn main() {
78
let before = check_and_hash("before.rs");
89
let after = check_and_hash("after.rs");
910
dbg!(before, after);
10-
assert_neq!(before, after);
11+
assert_eq!(before, after);
1112
}
1213

1314
fn check_and_hash<P>(filename: P) -> u64
1415
where
1516
P: AsRef<Path>,
1617
{
1718
rfs::rename(filename, "foo.rs");
18-
rustc().input("foo.rs").emit("metadata").run();
19+
rustc().input("foo.rs").emit("metadata").arg("-Zsplit-rmeta").run();
1920
// hash the output
2021
let bytes = rfs::read("libfoo.rmeta");
2122
let mut hasher = std::hash::DefaultHasher::new();

0 commit comments

Comments
 (0)