@@ -3,7 +3,7 @@ use std::path::{Component, Path};
3
3
4
4
use crate :: prelude:: * ;
5
5
6
- use rustc_span:: FileName ;
6
+ use rustc_span:: { CachingSourceMapView , FileName } ;
7
7
8
8
use cranelift_codegen:: binemit:: CodeOffset ;
9
9
@@ -74,12 +74,12 @@ fn line_program_add_file(
74
74
75
75
impl < ' tcx > DebugContext < ' tcx > {
76
76
pub ( super ) fn emit_location ( & mut self , entry_id : UnitEntryId , span : Span ) {
77
- let loc = self . tcx . sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
77
+ let ( file , line , col ) = self . source_map . byte_pos_to_line_and_col ( span. lo ( ) ) . unwrap ( ) ;
78
78
79
79
let file_id = line_program_add_file (
80
80
& mut self . dwarf . unit . line_program ,
81
81
& mut self . dwarf . line_strings ,
82
- & loc . file . name ,
82
+ & file. name ,
83
83
) ;
84
84
85
85
let entry = self . dwarf . unit . get_mut ( entry_id) ;
@@ -90,12 +90,12 @@ impl<'tcx> DebugContext<'tcx> {
90
90
) ;
91
91
entry. set (
92
92
gimli:: DW_AT_decl_line ,
93
- AttributeValue :: Udata ( loc . line as u64 ) ,
93
+ AttributeValue :: Udata ( line as u64 ) ,
94
94
) ;
95
95
// FIXME: probably omit this
96
96
entry. set (
97
97
gimli:: DW_AT_decl_column ,
98
- AttributeValue :: Udata ( loc . col . to_usize ( ) as u64 ) ,
98
+ AttributeValue :: Udata ( col. to_usize ( ) as u64 ) ,
99
99
) ;
100
100
}
101
101
}
@@ -108,6 +108,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
108
108
source_info_set : & indexmap:: IndexSet < SourceInfo > ,
109
109
) -> CodeOffset {
110
110
let tcx = self . debug_context . tcx ;
111
+ let mut source_map = CachingSourceMapView :: new ( tcx. sess . source_map ( ) ) ;
111
112
112
113
let line_program = & mut self . debug_context . dwarf . unit . line_program ;
113
114
@@ -124,25 +125,25 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
124
125
let line_strings = & mut self . debug_context . dwarf . line_strings ;
125
126
let mut last_file = None ;
126
127
let mut create_row_for_span = |line_program : & mut LineProgram , span : Span | {
127
- let loc = tcx . sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
128
+ let ( file , line , col ) = source_map. byte_pos_to_line_and_col ( span. lo ( ) ) . unwrap ( ) ;
128
129
129
130
// line_program_add_file is very slow.
130
131
// Optimize for the common case of the current file not being changed.
131
132
let current_file_changed = if let Some ( last_file) = & mut last_file {
132
133
// If the allocations are not equal, then the files may still be equal, but that
133
134
// is not a problem, as this is just an optimization.
134
- !Lrc :: ptr_eq ( last_file, & loc . file )
135
+ !Lrc :: ptr_eq ( last_file, & file)
135
136
} else {
136
137
true
137
138
} ;
138
139
if current_file_changed {
139
- let file_id = line_program_add_file ( line_program, line_strings, & loc . file . name ) ;
140
+ let file_id = line_program_add_file ( line_program, line_strings, & file. name ) ;
140
141
line_program. row ( ) . file = file_id;
141
- last_file = Some ( loc . file . clone ( ) ) ;
142
+ last_file = Some ( file. clone ( ) ) ;
142
143
}
143
144
144
- line_program. row ( ) . line = loc . line as u64 ;
145
- line_program. row ( ) . column = loc . col . to_u32 ( ) as u64 + 1 ;
145
+ line_program. row ( ) . line = line as u64 ;
146
+ line_program. row ( ) . column = col. to_u32 ( ) as u64 + 1 ;
146
147
line_program. generate_row ( ) ;
147
148
} ;
148
149
0 commit comments