Skip to content

Commit 011760c

Browse files
Auto merge of #144930 - cjgillot:untracked-end-point, r=<try>
[EXPERIMENT] Avoid tracking span to compute `end_point`.
2 parents 0060d5a + 08260ee commit 011760c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

compiler/rustc_span/src/source_map.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -911,12 +911,14 @@ impl SourceMap {
911911

912912
/// Returns a new span representing just the last character of this span.
913913
pub fn end_point(&self, sp: Span) -> Span {
914-
let pos = sp.hi().0;
914+
// We restrict the current span, so we cannot look around. Using the untracked data is ok.
915+
let sp = sp.data_untracked();
916+
let pos = sp.hi.0;
915917

916918
let width = self.find_width_of_character_at_span(sp, false);
917919
let corrected_end_position = pos.checked_sub(width).unwrap_or(pos);
918920

919-
let end_point = BytePos(cmp::max(corrected_end_position, sp.lo().0));
921+
let end_point = BytePos(cmp::max(corrected_end_position, sp.lo.0));
920922
sp.with_lo(end_point)
921923
}
922924

@@ -930,8 +932,9 @@ impl SourceMap {
930932
if sp.is_dummy() {
931933
return sp;
932934
}
933-
let start_of_next_point = sp.hi().0;
934935

936+
let sp = sp.data();
937+
let start_of_next_point = sp.hi.0;
935938
let width = self.find_width_of_character_at_span(sp, true);
936939
// If the width is 1, then the next span should only contain the next char besides current ending.
937940
// However, in the case of a multibyte character, where the width != 1, the next span should
@@ -940,7 +943,7 @@ impl SourceMap {
940943
start_of_next_point.checked_add(width).unwrap_or(start_of_next_point);
941944

942945
let end_of_next_point = BytePos(cmp::max(start_of_next_point + 1, end_of_next_point));
943-
Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt(), None)
946+
Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt, None)
944947
}
945948

946949
/// Check whether span is followed by some specified expected string in limit scope
@@ -963,9 +966,7 @@ impl SourceMap {
963966
/// Finds the width of the character, either before or after the end of provided span,
964967
/// depending on the `forwards` parameter.
965968
#[instrument(skip(self, sp))]
966-
fn find_width_of_character_at_span(&self, sp: Span, forwards: bool) -> u32 {
967-
let sp = sp.data();
968-
969+
fn find_width_of_character_at_span(&self, sp: SpanData, forwards: bool) -> u32 {
969970
if sp.lo == sp.hi && !forwards {
970971
debug!("early return empty span");
971972
return 1;

compiler/rustc_span/src/span_encoding.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ use crate::{BytePos, SPAN_TRACK, SpanData};
7474
/// because `parent` isn't currently used by default.
7575
///
7676
/// In order to reliably use parented spans in incremental compilation,
77-
/// the dependency to the parent definition's span. This is performed
78-
/// using the callback `SPAN_TRACK` to access the query engine.
79-
///
77+
/// accesses to `lo` and `hi` must introduce a dependency to the parent definition's span.
78+
/// This is performed using the callback `SPAN_TRACK` to access the query engine.
8079
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
8180
#[rustc_pass_by_value]
8281
pub struct Span {

0 commit comments

Comments
 (0)