Skip to content

Commit 6836b37

Browse files
committed
rdr: rename -Z separate_spans to -Z stable_crate_hash
1 parent c303ee9 commit 6836b37

File tree

29 files changed

+102
-103
lines changed

29 files changed

+102
-103
lines changed

compiler/rustc_interface/src/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl Linker {
6464
{
6565
let spans_path = path.with_extension("spans");
6666
let mut files: Vec<(&'static str, &Path)> = vec![("rmeta", path)];
67-
if sess.opts.unstable_opts.separate_spans && spans_path.exists() {
67+
if sess.opts.unstable_opts.stable_crate_hash && spans_path.exists() {
6868
files.push(("spans", &spans_path));
6969
}
7070
if let Some((id, product)) =

compiler/rustc_metadata/src/creader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,10 @@ impl CStore {
631631
None
632632
};
633633

634-
let has_separate_spans = crate_root.has_separate_spans();
634+
let has_stable_crate_hash = crate_root.has_stable_crate_hash();
635635
let crate_name = crate_root.name();
636636

637-
if has_separate_spans && source.spans.is_none() {
637+
if has_stable_crate_hash && source.spans.is_none() {
638638
return Err(CrateError::MissingSpanFile(crate_name, "file not found".to_string()));
639639
}
640640

@@ -652,7 +652,7 @@ impl CStore {
652652
host_hash,
653653
);
654654

655-
if has_separate_spans {
655+
if has_stable_crate_hash {
656656
crate_metadata
657657
.ensure_span_file_loaded()
658658
.map_err(|err| CrateError::MissingSpanFile(crate_name, err))?;

compiler/rustc_metadata/src/fs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
8787
None
8888
};
8989

90-
// When -Z separate-spans is enabled, encode spans to a separate .spans file
90+
// When -Z stable-crate-hash is enabled, encode spans to a separate .spans file
9191
let spans_tmp_filename = if let Some(required_source_files) = required_source_files
92-
&& tcx.sess.opts.unstable_opts.separate_spans
92+
&& tcx.sess.opts.unstable_opts.stable_crate_hash
9393
{
9494
let spans_tmp_filename = metadata_tmpdir.as_ref().join("lib.spans");
9595
encode_spans(tcx, &spans_tmp_filename, tcx.crate_hash(LOCAL_CRATE), required_source_files);
@@ -107,12 +107,12 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
107107
let (metadata_filename, metadata_tmpdir) = if need_metadata_file {
108108
let filename = match out_filename {
109109
OutFileName::Real(ref path) => {
110-
// RDR optimization: when -Z separate-spans is enabled, skip writing
110+
// RDR optimization: when -Z stable-crate-hash is enabled, skip writing
111111
// the .rmeta file if its content hash (SVH) hasn't changed. This
112112
// preserves the file's mtime, preventing cargo from rebuilding
113113
// dependent crates when only span positions changed.
114114
let new_hash = tcx.crate_hash(LOCAL_CRATE);
115-
let skip_write = tcx.sess.opts.unstable_opts.separate_spans
115+
let skip_write = tcx.sess.opts.unstable_opts.stable_crate_hash
116116
&& read_existing_metadata_hash(path).is_some_and(|old_hash| {
117117
let matches = old_hash == new_hash;
118118
if matches {

compiler/rustc_metadata/src/locator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ fn get_rmeta_metadata_section<'a, 'p>(filename: &'p Path) -> Result<OwnedSlice,
961961
Ok(slice_owned(mmap, Deref::deref))
962962
}
963963

964-
/// Loads a span metadata file (.spans) that accompanies rmeta files compiled with -Z separate_spans.
964+
/// Loads a span metadata file (.spans) that accompanies rmeta files compiled with -Z stable-crate-hash.
965965
pub(crate) fn get_span_metadata_section(filename: &Path) -> Result<SpanBlob, String> {
966966
// mmap the file, because only a small fraction of it is read.
967967
let file = std::fs::File::open(filename)

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ struct ImportedSourceFile {
229229
/// - `Some(imported)` means successfully imported
230230
///
231231
/// Note: Import failures now indicate a bug (either corrupted metadata or
232-
/// the crate was compiled with `-Z separate-spans` but the `.spans` file
232+
/// the crate was compiled with `-Z stable-crate-hash` but the `.spans` file
233233
/// is missing, which should have been caught at crate load time).
234234
235235
/// Decode context used when we just have a blob of metadata from which we have to decode a header
@@ -846,7 +846,7 @@ impl<'a, 'tcx> Decodable<MetadataDecodeContext<'a, 'tcx>> for SpanData {
846846
};
847847

848848
// Source file should always be available - missing files are caught at crate load time
849-
// for crates compiled with -Z separate-spans, and should never happen otherwise.
849+
// for crates compiled with -Z stable-crate-hash, and should never happen otherwise.
850850
let source_file = source_file.expect("source file should be available");
851851

852852
// Make sure our span is well-formed.
@@ -1181,8 +1181,8 @@ impl CrateRoot {
11811181
self.target_modifiers.decode(metadata)
11821182
}
11831183

1184-
pub(crate) fn has_separate_spans(&self) -> bool {
1185-
self.has_separate_spans
1184+
pub(crate) fn has_stable_crate_hash(&self) -> bool {
1185+
self.has_stable_crate_hash
11861186
}
11871187
}
11881188

@@ -1871,7 +1871,7 @@ impl<'a> CrateMetadataRef<'a> {
18711871
/// Returns `None` if the source file index doesn't exist in the source map table
18721872
/// (sparse table entry). This can happen when iterating through all indices.
18731873
///
1874-
/// Note: For crates compiled with `-Z separate-spans`, missing `.spans` files
1874+
/// Note: For crates compiled with `-Z stable-crate-hash`, missing `.spans` files
18751875
/// are detected and errored at crate load time, before this function is called.
18761876
fn imported_source_file(
18771877
self,
@@ -1986,10 +1986,11 @@ impl<'a> CrateMetadataRef<'a> {
19861986
return Some(cached.clone());
19871987
}
19881988

1989-
let source_file_to_import = if self.root.has_separate_spans() {
1990-
let span_data = self.cdata.span_file_data().expect(
1991-
"span file should be loaded for crate compiled with -Z separate-spans",
1992-
);
1989+
let source_file_to_import = if self.root.has_stable_crate_hash() {
1990+
let span_data = self
1991+
.cdata
1992+
.span_file_data()
1993+
.expect("span file should be loaded for crate compiled with -Z stable-crate-hash");
19931994
span_data
19941995
.source_map
19951996
.get_from_span_blob(&span_data.blob, source_file_index)
@@ -2009,7 +2010,7 @@ impl<'a> CrateMetadataRef<'a> {
20092010
// Return None for sparse table entries. This can happen when:
20102011
// - Searching through all source file indices (some may be empty)
20112012
//
2012-
// Note: For crates compiled with -Z separate-spans, missing .spans files
2013+
// Note: For crates compiled with -Z stable-crate-hash, missing .spans files
20132014
// are now detected and errored at crate load time, so that case no longer
20142015
// reaches here.
20152016
let Some(source_file_to_import) = source_file_to_import else {

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
673673
}
674674

675675
/// Encode source map using the provided set of required source files.
676-
/// This is used both for rmeta (when separate_spans is disabled) and
677-
/// for the span file (when separate_spans is enabled).
676+
/// This is used both for rmeta (when stable_crate_hash is disabled) and
677+
/// for the span file (when stable_crate_hash is enabled).
678678
fn encode_source_map_with(
679679
&mut self,
680680
required_source_files: FxIndexSet<usize>,
@@ -853,9 +853,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
853853

854854
// Encode source_map. This needs to be done last, because encoding `Span`s tells us which
855855
// `SourceFiles` we actually need to encode.
856-
// When separate_spans is enabled, source_map goes in the span file instead.
856+
// When stable_crate_hash is enabled, source_map goes in the span file instead.
857857
let source_map = stat!("source-map", || {
858-
if self.tcx.sess.opts.unstable_opts.separate_spans {
858+
if self.tcx.sess.opts.unstable_opts.stable_crate_hash {
859859
// Don't encode source_map in rmeta; it will be in the .spans file.
860860
// Keep required_source_files for the span file encoding.
861861
TableBuilder::default().encode(&mut self.opaque)
@@ -924,7 +924,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
924924
expn_hashes,
925925
def_path_hash_map,
926926
specialization_enabled_in: tcx.specialization_enabled_in(LOCAL_CRATE),
927-
has_separate_spans: tcx.sess.opts.unstable_opts.separate_spans,
927+
has_stable_crate_hash: tcx.sess.opts.unstable_opts.stable_crate_hash,
928928
})
929929
});
930930

@@ -2650,7 +2650,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
26502650
}
26512651

26522652
/// Encodes crate metadata to the given path.
2653-
/// Returns the set of required source files if `-Z separate_spans` is enabled,
2653+
/// Returns the set of required source files if `-Z stable-crate-hash` is enabled,
26542654
/// which is needed for encoding the span file.
26552655
#[instrument(level = "trace", skip(tcx))]
26562656
pub fn encode_metadata(
@@ -2697,7 +2697,7 @@ pub fn encode_metadata(
26972697
Ok(_) => {}
26982698
Err(err) => tcx.dcx().emit_fatal(FailCreateFileEncoder { err }),
26992699
};
2700-
if tcx.sess.opts.unstable_opts.separate_spans
2700+
if tcx.sess.opts.unstable_opts.stable_crate_hash
27012701
&& let Some(saved_spans) = work_product.saved_files.get("spans")
27022702
{
27032703
let span_source =
@@ -2778,7 +2778,7 @@ pub fn encode_spans(
27782778
}
27792779

27802780
/// Encodes metadata with standard header.
2781-
/// Returns the required_source_files if separate_spans is enabled (for span file encoding).
2781+
/// Returns the required_source_files if stable_crate_hash is enabled (for span file encoding).
27822782
fn with_encode_metadata_header(
27832783
tcx: TyCtxt<'_>,
27842784
path: &Path,
@@ -2832,8 +2832,12 @@ fn with_encode_metadata_header(
28322832
tcx.dcx().emit_fatal(FailWriteFile { path: ecx.opaque.path(), err });
28332833
}
28342834

2835-
// Return required_source_files if separate_spans is enabled (for span file encoding)
2836-
if tcx.sess.opts.unstable_opts.separate_spans { ecx.required_source_files.take() } else { None }
2835+
// Return required_source_files if stable_crate_hash is enabled (for span file encoding)
2836+
if tcx.sess.opts.unstable_opts.stable_crate_hash {
2837+
ecx.required_source_files.take()
2838+
} else {
2839+
None
2840+
}
28372841
}
28382842

28392843
fn with_encode_span_header(

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ pub(crate) struct CrateRoot {
344344

345345
specialization_enabled_in: bool,
346346

347-
/// Whether this crate was compiled with `-Z separate-spans`.
347+
/// Whether this crate was compiled with `-Z stable-crate-hash`.
348348
/// If true, span data is in a separate `.spans` file, not in this rmeta.
349-
has_separate_spans: bool,
349+
has_stable_crate_hash: bool,
350350
}
351351

352352
/// On-disk representation of `DefId`.

compiler/rustc_session/src/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct CrateSource {
2525
pub rlib: Option<PathBuf>,
2626
pub rmeta: Option<PathBuf>,
2727
pub sdylib_interface: Option<PathBuf>,
28-
/// Path to `.spans` file for crates compiled with `-Z separate-spans`.
28+
/// Path to `.spans` file for crates compiled with `-Z stable-crate-hash`.
2929
pub spans: Option<PathBuf>,
3030
}
3131

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,8 +2658,8 @@ written to standard error output)"),
26582658
for example: `-Z self-profile-events=default,query-keys`
26592659
all options: none, all, default, generic-activity, query-provider, query-cache-hit
26602660
query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm, artifact-sizes"),
2661-
separate_spans: bool = (false, parse_bool, [TRACKED],
2662-
"store span data in a separate .spans file for Relink, Don't Rebuild (RDR) (default: no)"),
2661+
stable_crate_hash: bool = (false, parse_bool, [TRACKED],
2662+
"stabilize the crate hash by storing spans separately, enabling relink-don't-rebuild (default: no)"),
26632663
share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED],
26642664
"make the current crate share its generic instantiations"),
26652665
shell_argfiles: bool = (false, parse_bool, [UNTRACKED],

compiler/rustc_session/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl Session {
286286
}
287287

288288
pub fn diagnostic_spans_hash(&self) -> Option<u64> {
289-
if !self.opts.unstable_opts.separate_spans {
289+
if !self.opts.unstable_opts.stable_crate_hash {
290290
return None;
291291
}
292292

0 commit comments

Comments
 (0)