@@ -38,6 +38,7 @@ const TAG_FULL_SPAN: u8 = 0;
38
38
// A partial span with no location information, encoded only with a `SyntaxContext`
39
39
const TAG_PARTIAL_SPAN : u8 = 1 ;
40
40
const TAG_RELATIVE_SPAN : u8 = 2 ;
41
+ const TAG_RELATIVE_OUTER_SPAN : u8 = 3 ;
41
42
42
43
const TAG_SYNTAX_CONTEXT : u8 = 0 ;
43
44
const TAG_EXPN_DATA : u8 = 1 ;
@@ -654,6 +655,17 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> {
654
655
let enclosing = self . tcx . source_span_untracked ( parent. unwrap ( ) ) . data_untracked ( ) ;
655
656
( enclosing. lo + BytePos :: from_u32 ( dlo) , enclosing. lo + BytePos :: from_u32 ( dto) )
656
657
}
658
+ TAG_RELATIVE_OUTER_SPAN => {
659
+ let dlo = isize:: decode ( self ) ;
660
+ let dto = isize:: decode ( self ) ;
661
+
662
+ let enclosing = self . tcx . source_span_untracked ( parent. unwrap ( ) ) . data_untracked ( ) ;
663
+ let reference = enclosing. lo . to_u32 ( ) as isize ;
664
+ (
665
+ BytePos :: from_usize ( ( reference + dlo) as usize ) ,
666
+ BytePos :: from_usize ( ( reference + dto) as usize ) ,
667
+ )
668
+ }
657
669
TAG_FULL_SPAN => {
658
670
let file_lo_index = SourceFileIndex :: decode ( self ) ;
659
671
let line_lo = usize:: decode ( self ) ;
@@ -664,6 +676,7 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> {
664
676
let lo = file_lo. lines ( ) [ line_lo - 1 ] + col_lo;
665
677
let lo = file_lo. absolute_position ( lo) ;
666
678
let hi = lo + len;
679
+
667
680
( lo, hi)
668
681
}
669
682
_ => unreachable ! ( ) ,
@@ -892,30 +905,33 @@ impl<'a, 'tcx> SpanEncoder for CacheEncoder<'a, 'tcx> {
892
905
return TAG_PARTIAL_SPAN . encode ( self ) ;
893
906
}
894
907
895
- if let Some ( parent) = span_data. parent {
896
- let enclosing = self . tcx . source_span_untracked ( parent) . data_untracked ( ) ;
897
- if enclosing. contains ( span_data) {
898
- TAG_RELATIVE_SPAN . encode ( self ) ;
899
- ( span_data. lo - enclosing. lo ) . to_u32 ( ) . encode ( self ) ;
900
- ( span_data. hi - enclosing. lo ) . to_u32 ( ) . encode ( self ) ;
901
- return ;
902
- }
908
+ let parent =
909
+ span_data. parent . map ( |parent| self . tcx . source_span_untracked ( parent) . data_untracked ( ) ) ;
910
+ if let Some ( parent) = parent
911
+ && parent. contains ( span_data)
912
+ {
913
+ TAG_RELATIVE_SPAN . encode ( self ) ;
914
+ ( span_data. lo - parent. lo ) . to_u32 ( ) . encode ( self ) ;
915
+ ( span_data. hi - parent. lo ) . to_u32 ( ) . encode ( self ) ;
916
+ return ;
903
917
}
904
918
905
- let pos = self . source_map . byte_pos_to_line_and_col ( span_data . lo ) ;
906
- let partial_span = match & pos {
907
- Some ( ( file_lo , _ , _ ) ) => !file_lo . contains ( span_data . hi ) ,
908
- None => true ,
919
+ let Some ( ( file_lo , line_lo , col_lo ) ) =
920
+ self . source_map . byte_pos_to_line_and_col ( span_data . lo )
921
+ else {
922
+ return TAG_PARTIAL_SPAN . encode ( self ) ;
909
923
} ;
910
924
911
- if partial_span {
912
- return TAG_PARTIAL_SPAN . encode ( self ) ;
925
+ if let Some ( parent) = parent
926
+ && file_lo. contains ( parent. lo )
927
+ {
928
+ TAG_RELATIVE_OUTER_SPAN . encode ( self ) ;
929
+ ( span_data. lo . to_u32 ( ) as isize - parent. lo . to_u32 ( ) as isize ) . encode ( self ) ;
930
+ ( span_data. hi . to_u32 ( ) as isize - parent. lo . to_u32 ( ) as isize ) . encode ( self ) ;
931
+ return ;
913
932
}
914
933
915
- let ( file_lo, line_lo, col_lo) = pos. unwrap ( ) ;
916
-
917
934
let len = span_data. hi - span_data. lo ;
918
-
919
935
let source_file_index = self . source_file_index ( file_lo) ;
920
936
921
937
TAG_FULL_SPAN . encode ( self ) ;
0 commit comments