Skip to content

Commit fbe36ad

Browse files
committed
Revert "Use CachingSourceMapView::byte_pos_to_line_and_col instead of SourceMap::lookup_char_pos"
This reverts commit eb4fc45. It caused a panic while compiling simple-raytracer
1 parent eb4fc45 commit fbe36ad

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/debuginfo/line_info.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::{Component, Path};
33

44
use crate::prelude::*;
55

6-
use rustc_span::{CachingSourceMapView, FileName};
6+
use rustc_span::FileName;
77

88
use cranelift_codegen::binemit::CodeOffset;
99

@@ -74,12 +74,12 @@ fn line_program_add_file(
7474

7575
impl<'tcx> DebugContext<'tcx> {
7676
pub(super) fn emit_location(&mut self, entry_id: UnitEntryId, span: Span) {
77-
let (file, line, col) = self.source_map.byte_pos_to_line_and_col(span.lo()).unwrap();
77+
let loc = self.tcx.sess.source_map().lookup_char_pos(span.lo());
7878

7979
let file_id = line_program_add_file(
8080
&mut self.dwarf.unit.line_program,
8181
&mut self.dwarf.line_strings,
82-
&file.name,
82+
&loc.file.name,
8383
);
8484

8585
let entry = self.dwarf.unit.get_mut(entry_id);
@@ -90,12 +90,12 @@ impl<'tcx> DebugContext<'tcx> {
9090
);
9191
entry.set(
9292
gimli::DW_AT_decl_line,
93-
AttributeValue::Udata(line as u64),
93+
AttributeValue::Udata(loc.line as u64),
9494
);
9595
// FIXME: probably omit this
9696
entry.set(
9797
gimli::DW_AT_decl_column,
98-
AttributeValue::Udata(col.to_usize() as u64),
98+
AttributeValue::Udata(loc.col.to_usize() as u64),
9999
);
100100
}
101101
}
@@ -108,7 +108,6 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
108108
source_info_set: &indexmap::IndexSet<SourceInfo>,
109109
) -> CodeOffset {
110110
let tcx = self.debug_context.tcx;
111-
let mut source_map = CachingSourceMapView::new(tcx.sess.source_map());
112111

113112
let line_program = &mut self.debug_context.dwarf.unit.line_program;
114113

@@ -125,25 +124,25 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
125124
let line_strings = &mut self.debug_context.dwarf.line_strings;
126125
let mut last_file = None;
127126
let mut create_row_for_span = |line_program: &mut LineProgram, span: Span| {
128-
let (file, line, col) = source_map.byte_pos_to_line_and_col(span.lo()).unwrap();
127+
let loc = tcx.sess.source_map().lookup_char_pos(span.lo());
129128

130129
// line_program_add_file is very slow.
131130
// Optimize for the common case of the current file not being changed.
132131
let current_file_changed = if let Some(last_file) = &mut last_file {
133132
// If the allocations are not equal, then the files may still be equal, but that
134133
// is not a problem, as this is just an optimization.
135-
!Lrc::ptr_eq(last_file, &file)
134+
!Lrc::ptr_eq(last_file, &loc.file)
136135
} else {
137136
true
138137
};
139138
if current_file_changed {
140-
let file_id = line_program_add_file(line_program, line_strings, &file.name);
139+
let file_id = line_program_add_file(line_program, line_strings, &loc.file.name);
141140
line_program.row().file = file_id;
142-
last_file = Some(file.clone());
141+
last_file = Some(loc.file.clone());
143142
}
144143

145-
line_program.row().line = line as u64;
146-
line_program.row().column = col.to_u32() as u64 + 1;
144+
line_program.row().line = loc.line as u64;
145+
line_program.row().column = loc.col.to_u32() as u64 + 1;
147146
line_program.generate_row();
148147
};
149148

src/debuginfo/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ mod line_info;
33

44
use crate::prelude::*;
55

6-
use rustc_span::CachingSourceMapView;
7-
86
use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc};
97
use cranelift_codegen::isa::RegUnit;
108
use cranelift_codegen::ValueLocRange;
@@ -36,8 +34,6 @@ pub struct DebugContext<'tcx> {
3634
unit_range_list: RangeList,
3735

3836
types: HashMap<Ty<'tcx>, UnitEntryId>,
39-
40-
source_map: CachingSourceMapView<'tcx>,
4137
}
4238

4339
impl<'tcx> DebugContext<'tcx> {
@@ -102,8 +98,6 @@ impl<'tcx> DebugContext<'tcx> {
10298
unit_range_list: RangeList(Vec::new()),
10399

104100
types: HashMap::new(),
105-
106-
source_map: CachingSourceMapView::new(tcx.sess.source_map()),
107101
}
108102
}
109103

0 commit comments

Comments
 (0)