]> git.lizzy.rs Git - rust.git/commitdiff
Revert "Use CachingSourceMapView::byte_pos_to_line_and_col instead of SourceMap:...
authorbjorn3 <bjorn3@users.noreply.github.com>
Mon, 3 Feb 2020 20:36:36 +0000 (21:36 +0100)
committerbjorn3 <bjorn3@users.noreply.github.com>
Mon, 3 Feb 2020 20:36:36 +0000 (21:36 +0100)
This reverts commit eb4fc45310c70513d73d893616cd6735465680ca.

It caused a panic while compiling simple-raytracer

src/debuginfo/line_info.rs
src/debuginfo/mod.rs

index 66a12091ecda9f61e61fdb6f6e72979949b42a48..3152e4812f75839045039478a0afb36f487581be 100644 (file)
@@ -3,7 +3,7 @@
 
 use crate::prelude::*;
 
-use rustc_span::{CachingSourceMapView, FileName};
+use rustc_span::FileName;
 
 use cranelift_codegen::binemit::CodeOffset;
 
@@ -74,12 +74,12 @@ fn line_program_add_file(
 
 impl<'tcx> DebugContext<'tcx> {
     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(
             &mut self.dwarf.unit.line_program,
             &mut self.dwarf.line_strings,
-            &file.name,
+            &loc.file.name,
         );
 
         let entry = self.dwarf.unit.get_mut(entry_id);
@@ -90,12 +90,12 @@ pub(super) fn emit_location(&mut self, entry_id: UnitEntryId, span: Span) {
         );
         entry.set(
             gimli::DW_AT_decl_line,
-            AttributeValue::Udata(line as u64),
+            AttributeValue::Udata(loc.line as u64),
         );
         // FIXME: probably omit this
         entry.set(
             gimli::DW_AT_decl_column,
-            AttributeValue::Udata(col.to_usize() as u64),
+            AttributeValue::Udata(loc.col.to_usize() as u64),
         );
     }
 }
@@ -108,7 +108,6 @@ pub(super) fn create_debug_lines(
         source_info_set: &indexmap::IndexSet<SourceInfo>,
     ) -> CodeOffset {
         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;
 
@@ -125,25 +124,25 @@ pub(super) fn create_debug_lines(
         let line_strings = &mut self.debug_context.dwarf.line_strings;
         let mut last_file = None;
         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.
             // Optimize for the common case of the current file not being changed.
             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
                 // is not a problem, as this is just an optimization.
-                !Lrc::ptr_eq(last_file, &file)
+                !Lrc::ptr_eq(last_file, &loc.file)
             } else {
                 true
             };
             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;
-                last_file = Some(file.clone());
+                last_file = Some(loc.file.clone());
             }
 
-            line_program.row().line = line as u64;
-            line_program.row().column = col.to_u32() as u64 + 1;
+            line_program.row().line = loc.line as u64;
+            line_program.row().column = loc.col.to_u32() as u64 + 1;
             line_program.generate_row();
         };
 
index f007cb1265dea12fa3225ad3ae42e0c9cd1e901f..d4be26885a042a195666846d906501e874547290 100644 (file)
@@ -3,8 +3,6 @@
 
 use crate::prelude::*;
 
-use rustc_span::CachingSourceMapView;
-
 use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc};
 use cranelift_codegen::isa::RegUnit;
 use cranelift_codegen::ValueLocRange;
@@ -36,8 +34,6 @@ pub struct DebugContext<'tcx> {
     unit_range_list: RangeList,
 
     types: HashMap<Ty<'tcx>, UnitEntryId>,
-
-    source_map: CachingSourceMapView<'tcx>,
 }
 
 impl<'tcx> DebugContext<'tcx> {
@@ -102,8 +98,6 @@ pub fn new(tcx: TyCtxt<'tcx>, address_size: u8) -> Self {
             unit_range_list: RangeList(Vec::new()),
 
             types: HashMap::new(),
-
-            source_map: CachingSourceMapView::new(tcx.sess.source_map()),
         }
     }