Skip to content

Commit 5f38582

Browse files
committed
refactor(span): rename source_len to normalized_source_len
This is a preparation for introducing a unnormalized source length field
1 parent b6d7ff3 commit 5f38582

File tree

7 files changed

+26
-27
lines changed

7 files changed

+26
-27
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
596596
.map(|fmap| {
597597
(
598598
escape_dep_filename(&fmap.name.prefer_local().to_string()),
599-
fmap.source_len.0 as u64,
599+
fmap.normalized_source_len.0 as u64,
600600
fmap.checksum_hash,
601601
)
602602
})

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ impl<'a> CrateMetadataRef<'a> {
17441744
src_hash,
17451745
checksum_hash,
17461746
start_pos: original_start_pos,
1747-
source_len,
1747+
normalized_source_len,
17481748
lines,
17491749
multibyte_chars,
17501750
normalized_pos,
@@ -1804,7 +1804,7 @@ impl<'a> CrateMetadataRef<'a> {
18041804
src_hash,
18051805
checksum_hash,
18061806
stable_id,
1807-
source_len.to_u32(),
1807+
normalized_source_len.to_u32(),
18081808
self.cnum,
18091809
lines,
18101810
multibyte_chars,
@@ -1817,9 +1817,9 @@ impl<'a> CrateMetadataRef<'a> {
18171817
translated (start_pos {:?} source_len {:?})",
18181818
local_version.name,
18191819
original_start_pos,
1820-
source_len,
1820+
normalized_source_len,
18211821
local_version.start_pos,
1822-
local_version.source_len
1822+
local_version.normalized_source_len
18231823
);
18241824

18251825
ImportedSourceFile {

compiler/rustc_query_system/src/ich/impls_syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
5454
checksum_hash: _,
5555
external_src: _,
5656
start_pos: _,
57-
source_len: _,
57+
normalized_source_len: _,
5858
lines: _,
5959
ref multibyte_chars,
6060
ref normalized_pos,

compiler/rustc_span/src/lib.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,8 +1723,8 @@ pub struct SourceFile {
17231723
pub external_src: FreezeLock<ExternalSource>,
17241724
/// The start position of this source in the `SourceMap`.
17251725
pub start_pos: BytePos,
1726-
/// The byte length of this source.
1727-
pub source_len: RelativeBytePos,
1726+
/// The byte length of this source after normalization.
1727+
pub normalized_source_len: RelativeBytePos,
17281728
/// Locations of lines beginnings in the source code.
17291729
pub lines: FreezeLock<SourceFileLines>,
17301730
/// Locations of multi-byte characters in the source code.
@@ -1748,7 +1748,7 @@ impl Clone for SourceFile {
17481748
checksum_hash: self.checksum_hash,
17491749
external_src: self.external_src.clone(),
17501750
start_pos: self.start_pos,
1751-
source_len: self.source_len,
1751+
normalized_source_len: self.normalized_source_len,
17521752
lines: self.lines.clone(),
17531753
multibyte_chars: self.multibyte_chars.clone(),
17541754
normalized_pos: self.normalized_pos.clone(),
@@ -1764,7 +1764,7 @@ impl<S: SpanEncoder> Encodable<S> for SourceFile {
17641764
self.src_hash.encode(s);
17651765
self.checksum_hash.encode(s);
17661766
// Do not encode `start_pos` as it's global state for this session.
1767-
self.source_len.encode(s);
1767+
self.normalized_source_len.encode(s);
17681768

17691769
// We are always in `Lines` form by the time we reach here.
17701770
assert!(self.lines.read().is_lines());
@@ -1837,7 +1837,7 @@ impl<D: SpanDecoder> Decodable<D> for SourceFile {
18371837
let name: FileName = Decodable::decode(d);
18381838
let src_hash: SourceFileHash = Decodable::decode(d);
18391839
let checksum_hash: Option<SourceFileHash> = Decodable::decode(d);
1840-
let source_len: RelativeBytePos = Decodable::decode(d);
1840+
let normalized_source_len: RelativeBytePos = Decodable::decode(d);
18411841
let lines = {
18421842
let num_lines: u32 = Decodable::decode(d);
18431843
if num_lines > 0 {
@@ -1859,7 +1859,7 @@ impl<D: SpanDecoder> Decodable<D> for SourceFile {
18591859
SourceFile {
18601860
name,
18611861
start_pos: BytePos::from_u32(0),
1862-
source_len,
1862+
normalized_source_len,
18631863
src: None,
18641864
src_hash,
18651865
checksum_hash,
@@ -1962,9 +1962,8 @@ impl SourceFile {
19621962
let normalized_pos = normalize_src(&mut src);
19631963

19641964
let stable_id = StableSourceFileId::from_filename_in_current_crate(&name);
1965-
let source_len = src.len();
1966-
let source_len = u32::try_from(source_len).map_err(|_| OffsetOverflowError)?;
1967-
if source_len > Self::MAX_FILE_SIZE {
1965+
let normalized_source_len = u32::try_from(src.len()).map_err(|_| OffsetOverflowError)?;
1966+
if normalized_source_len > Self::MAX_FILE_SIZE {
19681967
return Err(OffsetOverflowError);
19691968
}
19701969

@@ -1977,7 +1976,7 @@ impl SourceFile {
19771976
checksum_hash,
19781977
external_src: FreezeLock::frozen(ExternalSource::Unneeded),
19791978
start_pos: BytePos::from_u32(0),
1980-
source_len: RelativeBytePos::from_u32(source_len),
1979+
normalized_source_len: RelativeBytePos::from_u32(normalized_source_len),
19811980
lines: FreezeLock::frozen(SourceFileLines::Lines(lines)),
19821981
multibyte_chars,
19831982
normalized_pos,
@@ -2161,7 +2160,7 @@ impl SourceFile {
21612160

21622161
#[inline]
21632162
pub fn end_position(&self) -> BytePos {
2164-
self.absolute_position(self.source_len)
2163+
self.absolute_position(self.normalized_source_len)
21652164
}
21662165

21672166
/// Finds the line containing the given position. The return value is the
@@ -2197,7 +2196,7 @@ impl SourceFile {
21972196

21982197
#[inline]
21992198
pub fn is_empty(&self) -> bool {
2200-
self.source_len.to_u32() == 0
2199+
self.normalized_source_len.to_u32() == 0
22012200
}
22022201

22032202
/// Calculates the original byte position relative to the start of the file

compiler/rustc_span/src/source_map.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl SourceMap {
262262
bytes,
263263
Span::new(
264264
file.start_pos,
265-
BytePos(file.start_pos.0 + file.source_len.0),
265+
BytePos(file.start_pos.0 + file.normalized_source_len.0),
266266
SyntaxContext::root(),
267267
None,
268268
),
@@ -353,14 +353,14 @@ impl SourceMap {
353353
src_hash: SourceFileHash,
354354
checksum_hash: Option<SourceFileHash>,
355355
stable_id: StableSourceFileId,
356-
source_len: u32,
356+
normalized_source_len: u32,
357357
cnum: CrateNum,
358358
file_local_lines: FreezeLock<SourceFileLines>,
359359
multibyte_chars: Vec<MultiByteChar>,
360360
normalized_pos: Vec<NormalizedPos>,
361361
metadata_index: u32,
362362
) -> Arc<SourceFile> {
363-
let source_len = RelativeBytePos::from_u32(source_len);
363+
let normalized_source_len = RelativeBytePos::from_u32(normalized_source_len);
364364

365365
let source_file = SourceFile {
366366
name: filename,
@@ -372,7 +372,7 @@ impl SourceMap {
372372
metadata_index,
373373
}),
374374
start_pos: BytePos(0),
375-
source_len,
375+
normalized_source_len,
376376
lines: file_local_lines,
377377
multibyte_chars,
378378
normalized_pos,
@@ -566,7 +566,7 @@ impl SourceMap {
566566

567567
let start_index = local_begin.pos.to_usize();
568568
let end_index = local_end.pos.to_usize();
569-
let source_len = local_begin.sf.source_len.to_usize();
569+
let source_len = local_begin.sf.normalized_source_len.to_usize();
570570

571571
if start_index > end_index || end_index > source_len {
572572
return Err(SpanSnippetError::MalformedForSourcemap(MalformedSourceMapPositions {
@@ -997,7 +997,7 @@ impl SourceMap {
997997
return 1;
998998
}
999999

1000-
let source_len = local_begin.sf.source_len.to_usize();
1000+
let source_len = local_begin.sf.normalized_source_len.to_usize();
10011001
debug!("source_len=`{:?}`", source_len);
10021002
// Ensure indexes are also not malformed.
10031003
if start_index > end_index || end_index > source_len - 1 {

compiler/rustc_span/src/source_map/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ fn t10() {
230230
name,
231231
src_hash,
232232
checksum_hash,
233-
source_len,
233+
normalized_source_len,
234234
lines,
235235
multibyte_chars,
236236
normalized_pos,
@@ -243,7 +243,7 @@ fn t10() {
243243
src_hash,
244244
checksum_hash,
245245
stable_id,
246-
source_len.to_u32(),
246+
normalized_source_len.to_u32(),
247247
CrateNum::ZERO,
248248
FreezeLock::new(lines.read().clone()),
249249
multibyte_chars,

src/tools/clippy/clippy_config/src/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct ConfError {
108108

109109
impl ConfError {
110110
fn from_toml(file: &SourceFile, error: &toml::de::Error) -> Self {
111-
let span = error.span().unwrap_or(0..file.source_len.0 as usize);
111+
let span = error.span().unwrap_or(0..file.normalized_source_len.0 as usize);
112112
Self::spanned(file, error.message(), None, span)
113113
}
114114

0 commit comments

Comments
 (0)