mirror of https://github.com/rust-lang/rust.git
Revert "Use CachingSourceMapView::byte_pos_to_line_and_col instead of SourceMap::lookup_char_pos"
This reverts commit eb4fc45310
.
It caused a panic while compiling simple-raytracer
This commit is contained in:
parent
eb4fc45310
commit
fbe36ad68a
|
@ -3,7 +3,7 @@ use std::path::{Component, Path};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use rustc_span::{CachingSourceMapView, FileName};
|
use rustc_span::FileName;
|
||||||
|
|
||||||
use cranelift_codegen::binemit::CodeOffset;
|
use cranelift_codegen::binemit::CodeOffset;
|
||||||
|
|
||||||
|
@ -74,12 +74,12 @@ fn line_program_add_file(
|
||||||
|
|
||||||
impl<'tcx> DebugContext<'tcx> {
|
impl<'tcx> DebugContext<'tcx> {
|
||||||
pub(super) fn emit_location(&mut self, entry_id: UnitEntryId, span: Span) {
|
pub(super) fn emit_location(&mut self, entry_id: UnitEntryId, span: Span) {
|
||||||
let (file, line, col) = self.source_map.byte_pos_to_line_and_col(span.lo()).unwrap();
|
let loc = self.tcx.sess.source_map().lookup_char_pos(span.lo());
|
||||||
|
|
||||||
let file_id = line_program_add_file(
|
let file_id = line_program_add_file(
|
||||||
&mut self.dwarf.unit.line_program,
|
&mut self.dwarf.unit.line_program,
|
||||||
&mut self.dwarf.line_strings,
|
&mut self.dwarf.line_strings,
|
||||||
&file.name,
|
&loc.file.name,
|
||||||
);
|
);
|
||||||
|
|
||||||
let entry = self.dwarf.unit.get_mut(entry_id);
|
let entry = self.dwarf.unit.get_mut(entry_id);
|
||||||
|
@ -90,12 +90,12 @@ impl<'tcx> DebugContext<'tcx> {
|
||||||
);
|
);
|
||||||
entry.set(
|
entry.set(
|
||||||
gimli::DW_AT_decl_line,
|
gimli::DW_AT_decl_line,
|
||||||
AttributeValue::Udata(line as u64),
|
AttributeValue::Udata(loc.line as u64),
|
||||||
);
|
);
|
||||||
// FIXME: probably omit this
|
// FIXME: probably omit this
|
||||||
entry.set(
|
entry.set(
|
||||||
gimli::DW_AT_decl_column,
|
gimli::DW_AT_decl_column,
|
||||||
AttributeValue::Udata(col.to_usize() as u64),
|
AttributeValue::Udata(loc.col.to_usize() as u64),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,6 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
|
||||||
source_info_set: &indexmap::IndexSet<SourceInfo>,
|
source_info_set: &indexmap::IndexSet<SourceInfo>,
|
||||||
) -> CodeOffset {
|
) -> CodeOffset {
|
||||||
let tcx = self.debug_context.tcx;
|
let tcx = self.debug_context.tcx;
|
||||||
let mut source_map = CachingSourceMapView::new(tcx.sess.source_map());
|
|
||||||
|
|
||||||
let line_program = &mut self.debug_context.dwarf.unit.line_program;
|
let line_program = &mut self.debug_context.dwarf.unit.line_program;
|
||||||
|
|
||||||
|
@ -125,25 +124,25 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
|
||||||
let line_strings = &mut self.debug_context.dwarf.line_strings;
|
let line_strings = &mut self.debug_context.dwarf.line_strings;
|
||||||
let mut last_file = None;
|
let mut last_file = None;
|
||||||
let mut create_row_for_span = |line_program: &mut LineProgram, span: Span| {
|
let mut create_row_for_span = |line_program: &mut LineProgram, span: Span| {
|
||||||
let (file, line, col) = source_map.byte_pos_to_line_and_col(span.lo()).unwrap();
|
let loc = tcx.sess.source_map().lookup_char_pos(span.lo());
|
||||||
|
|
||||||
// line_program_add_file is very slow.
|
// line_program_add_file is very slow.
|
||||||
// Optimize for the common case of the current file not being changed.
|
// Optimize for the common case of the current file not being changed.
|
||||||
let current_file_changed = if let Some(last_file) = &mut last_file {
|
let current_file_changed = if let Some(last_file) = &mut last_file {
|
||||||
// If the allocations are not equal, then the files may still be equal, but that
|
// If the allocations are not equal, then the files may still be equal, but that
|
||||||
// is not a problem, as this is just an optimization.
|
// is not a problem, as this is just an optimization.
|
||||||
!Lrc::ptr_eq(last_file, &file)
|
!Lrc::ptr_eq(last_file, &loc.file)
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
};
|
};
|
||||||
if current_file_changed {
|
if current_file_changed {
|
||||||
let file_id = line_program_add_file(line_program, line_strings, &file.name);
|
let file_id = line_program_add_file(line_program, line_strings, &loc.file.name);
|
||||||
line_program.row().file = file_id;
|
line_program.row().file = file_id;
|
||||||
last_file = Some(file.clone());
|
last_file = Some(loc.file.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
line_program.row().line = line as u64;
|
line_program.row().line = loc.line as u64;
|
||||||
line_program.row().column = col.to_u32() as u64 + 1;
|
line_program.row().column = loc.col.to_u32() as u64 + 1;
|
||||||
line_program.generate_row();
|
line_program.generate_row();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,6 @@ mod line_info;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use rustc_span::CachingSourceMapView;
|
|
||||||
|
|
||||||
use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc};
|
use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc};
|
||||||
use cranelift_codegen::isa::RegUnit;
|
use cranelift_codegen::isa::RegUnit;
|
||||||
use cranelift_codegen::ValueLocRange;
|
use cranelift_codegen::ValueLocRange;
|
||||||
|
@ -36,8 +34,6 @@ pub struct DebugContext<'tcx> {
|
||||||
unit_range_list: RangeList,
|
unit_range_list: RangeList,
|
||||||
|
|
||||||
types: HashMap<Ty<'tcx>, UnitEntryId>,
|
types: HashMap<Ty<'tcx>, UnitEntryId>,
|
||||||
|
|
||||||
source_map: CachingSourceMapView<'tcx>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> DebugContext<'tcx> {
|
impl<'tcx> DebugContext<'tcx> {
|
||||||
|
@ -102,8 +98,6 @@ impl<'tcx> DebugContext<'tcx> {
|
||||||
unit_range_list: RangeList(Vec::new()),
|
unit_range_list: RangeList(Vec::new()),
|
||||||
|
|
||||||
types: HashMap::new(),
|
types: HashMap::new(),
|
||||||
|
|
||||||
source_map: CachingSourceMapView::new(tcx.sess.source_map()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue