about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMark-Simulacrum <mark.simulacrum@gmail.com>2016-12-16 13:25:18 -0700
committerMark Simulacrum <mark.simulacrum@gmail.com>2016-12-20 20:03:24 -0700
commit820164582dc22e8d31283da377825331bfc06da9 (patch)
tree6a4a9a4d4f270c615b2f2a44f2b89f3ae545e1a0 /src
parentbe981dce80f6d115b04a6898bb2d6bf316dc402d (diff)
downloadrust-820164582dc22e8d31283da377825331bfc06da9.tar.gz
rust-820164582dc22e8d31283da377825331bfc06da9.zip
Remove DebugLoc.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trans/adt.rs4
-rw-r--r--src/librustc_trans/base.rs5
-rw-r--r--src/librustc_trans/common.rs5
-rw-r--r--src/librustc_trans/debuginfo/mod.rs19
-rw-r--r--src/librustc_trans/debuginfo/source_loc.rs27
-rw-r--r--src/librustc_trans/intrinsic.rs13
-rw-r--r--src/librustc_trans/mir/block.rs13
-rw-r--r--src/librustc_trans/mir/mod.rs32
-rw-r--r--src/librustc_trans/mir/statement.rs5
9 files changed, 38 insertions, 85 deletions
diff --git a/src/librustc_trans/adt.rs b/src/librustc_trans/adt.rs
index 7f8eef5a51d..5482200f13e 100644
--- a/src/librustc_trans/adt.rs
+++ b/src/librustc_trans/adt.rs
@@ -49,7 +49,6 @@ use llvm::{ValueRef, True, IntEQ, IntNE};
 use rustc::ty::layout;
 use rustc::ty::{self, Ty, AdtKind};
 use common::*;
-use debuginfo::DebugLoc;
 use glue;
 use base;
 use machine;
@@ -595,8 +594,6 @@ fn struct_field_ptr<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
         return bcx.struct_gep(ptr_val, ix);
     }
 
-    let dbloc = DebugLoc::None;
-
     // We need to get the pointer manually now.
     // We do this by casting to a *i8, then offsetting it by the appropriate amount.
     // We do this instead of, say, simply adjusting the pointer from the result of a GEP
@@ -627,7 +624,6 @@ fn struct_field_ptr<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
     //   (unaligned offset + (align - 1)) & -align
 
     // Calculate offset
-    dbloc.apply(bcx.fcx());
     let align_sub_1 = bcx.sub(align, C_uint(bcx.ccx(), 1u64));
     let offset = bcx.and(bcx.add(unaligned_offset, align_sub_1),
                          bcx.neg(align));
diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs
index 4f346f8897e..b1be2e4abe6 100644
--- a/src/librustc_trans/base.rs
+++ b/src/librustc_trans/base.rs
@@ -60,7 +60,7 @@ use common::{type_is_zero_size, val_ty};
 use common;
 use consts;
 use context::{SharedCrateContext, CrateContextList};
-use debuginfo::{self, DebugLoc};
+use debuginfo;
 use declare;
 use machine;
 use machine::{llalign_of_min, llsize_of};
@@ -649,7 +649,6 @@ pub fn alloc_ty<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
 }
 
 pub fn alloca(cx: &BlockAndBuilder, ty: Type, name: &str) -> ValueRef {
-    DebugLoc::None.apply(cx.fcx());
     cx.fcx().alloca(ty, name)
 }
 
@@ -658,8 +657,6 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
     /// and builds the return block.
     pub fn finish(&'blk self, ret_cx: &BlockAndBuilder<'blk, 'tcx>) {
         self.build_return_block(ret_cx);
-
-        DebugLoc::None.apply(self);
         self.cleanup();
     }
 
diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs
index 1025f9d4051..7aceb0b88bb 100644
--- a/src/librustc_trans/common.rs
+++ b/src/librustc_trans/common.rs
@@ -16,6 +16,7 @@ use session::Session;
 use llvm;
 use llvm::{ValueRef, BasicBlockRef, BuilderRef, ContextRef, TypeKind};
 use llvm::{True, False, Bool, OperandBundleDef, get_param};
+use llvm::debuginfo::DIScope;
 use monomorphize::Instance;
 use rustc::hir::def::Def;
 use rustc::hir::def_id::DefId;
@@ -578,6 +579,10 @@ impl<'blk, 'tcx> BlockAndBuilder<'blk, 'tcx> {
         }
     }
 
+    pub fn set_source_location(&self, scope: DIScope, sp: Span) {
+        debuginfo::set_source_location(self.fcx(), self, scope, sp)
+    }
+
     pub fn at_start<F, R>(&self, f: F) -> R
         where F: FnOnce(&BlockAndBuilder<'blk, 'tcx>) -> R
     {
diff --git a/src/librustc_trans/debuginfo/mod.rs b/src/librustc_trans/debuginfo/mod.rs
index 1bf3c0acec5..f915f60c294 100644
--- a/src/librustc_trans/debuginfo/mod.rs
+++ b/src/librustc_trans/debuginfo/mod.rs
@@ -27,7 +27,7 @@ use rustc::hir::def_id::DefId;
 use rustc::ty::subst::Substs;
 
 use abi::Abi;
-use common::{CrateContext, FunctionContext, BlockAndBuilder};
+use common::{CrateContext, BlockAndBuilder};
 use monomorphize::{self, Instance};
 use rustc::ty::{self, Ty};
 use rustc::mir;
@@ -55,6 +55,7 @@ pub use self::create_scope_map::{create_mir_scopes, MirDebugScope};
 pub use self::source_loc::start_emitting_source_locations;
 pub use self::metadata::create_global_var_metadata;
 pub use self::metadata::extend_scope_to_file;
+pub use self::source_loc::set_source_location;
 
 #[allow(non_upper_case_globals)]
 const DW_TAG_auto_variable: c_uint = 0x100;
@@ -507,19 +508,3 @@ pub fn declare_local<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
         _ => { /* nothing to do */ }
     }
 }
-
-#[derive(Copy, Clone, PartialEq, Eq, Debug)]
-pub enum DebugLoc {
-    ScopeAt(DIScope, Span),
-    None
-}
-
-impl DebugLoc {
-    pub fn apply(self, fcx: &FunctionContext) {
-        source_loc::set_source_location(fcx, None, self);
-    }
-
-    pub fn apply_to_bcx(self, bcx: &BlockAndBuilder) {
-        source_loc::set_source_location(bcx.fcx(), Some(bcx), self);
-    }
-}
diff --git a/src/librustc_trans/debuginfo/source_loc.rs b/src/librustc_trans/debuginfo/source_loc.rs
index 86ecc0e65a9..e03ad1a8c8f 100644
--- a/src/librustc_trans/debuginfo/source_loc.rs
+++ b/src/librustc_trans/debuginfo/source_loc.rs
@@ -11,8 +11,8 @@
 use self::InternalDebugLocation::*;
 
 use super::utils::{debug_context, span_start};
-use super::metadata::{UNKNOWN_COLUMN_NUMBER};
-use super::{FunctionDebugContext, DebugLoc};
+use super::metadata::UNKNOWN_COLUMN_NUMBER;
+use super::FunctionDebugContext;
 
 use llvm;
 use llvm::debuginfo::DIScope;
@@ -21,41 +21,30 @@ use common::{CrateContext, FunctionContext};
 
 use libc::c_uint;
 use std::ptr;
-use syntax_pos::Pos;
+use syntax_pos::{Span, Pos};
 
 /// Sets the current debug location at the beginning of the span.
 ///
 /// Maps to a call to llvm::LLVMSetCurrentDebugLocation(...).
-pub fn set_source_location(fcx: &FunctionContext,
-                           builder: Option<&Builder>,
-                           debug_loc: DebugLoc) {
-    let builder = builder.map(|b| b.llbuilder);
+pub fn set_source_location(fcx: &FunctionContext, builder: &Builder, scope: DIScope, span: Span) {
+    let builder = builder.llbuilder;
     let function_debug_context = match fcx.debug_context {
         FunctionDebugContext::DebugInfoDisabled => return,
         FunctionDebugContext::FunctionWithoutDebugInfo => {
-            set_debug_location(fcx.ccx, builder, UnknownLocation);
+            set_debug_location(fcx.ccx, Some(builder), UnknownLocation);
             return;
         }
         FunctionDebugContext::RegularContext(ref data) => data
     };
 
     let dbg_loc = if function_debug_context.source_locations_enabled.get() {
-        let (scope, span) = match debug_loc {
-            DebugLoc::ScopeAt(scope, span) => (scope, span),
-            DebugLoc::None => {
-                set_debug_location(fcx.ccx, builder, UnknownLocation);
-                return;
-            }
-        };
-
-        debug!("set_source_location: {}",
-               fcx.ccx.sess().codemap().span_to_string(span));
+        debug!("set_source_location: {}", fcx.ccx.sess().codemap().span_to_string(span));
         let loc = span_start(fcx.ccx, span);
         InternalDebugLocation::new(scope, loc.line, loc.col.to_usize())
     } else {
         UnknownLocation
     };
-    set_debug_location(fcx.ccx, builder, dbg_loc);
+    set_debug_location(fcx.ccx, Some(builder), dbg_loc);
 }
 
 /// Enables emitting source locations for the given functions.
diff --git a/src/librustc_trans/intrinsic.rs b/src/librustc_trans/intrinsic.rs
index b70a1d119de..84a6406c8e7 100644
--- a/src/librustc_trans/intrinsic.rs
+++ b/src/librustc_trans/intrinsic.rs
@@ -18,7 +18,6 @@ use abi::{Abi, FnType};
 use adt;
 use base::*;
 use common::*;
-use debuginfo::DebugLoc;
 use declare;
 use glue;
 use type_of;
@@ -31,7 +30,7 @@ use syntax::ast;
 use syntax::symbol::Symbol;
 
 use rustc::session::Session;
-use syntax_pos::{Span, DUMMY_SP};
+use syntax_pos::Span;
 
 use std::cmp::Ordering;
 use std::iter;
@@ -90,7 +89,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
                                             fn_ty: &FnType,
                                             llargs: &[ValueRef],
                                             llresult: ValueRef,
-                                            call_debug_location: DebugLoc) {
+                                            span: Span) {
     let fcx = bcx.fcx();
     let ccx = fcx.ccx;
     let tcx = bcx.tcx();
@@ -105,14 +104,6 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
     let ret_ty = sig.output();
     let name = &*tcx.item_name(def_id).as_str();
 
-    let span = match call_debug_location {
-        DebugLoc::ScopeAt(_, span) => span,
-        DebugLoc::None => {
-            span_bug!(fcx.span.unwrap_or(DUMMY_SP),
-                      "intrinsic `{}` called with missing span", name);
-        }
-    };
-
     // These are the only intrinsic functions that diverge.
     if name == "abort" {
         let llfn = ccx.get_intrinsic(&("llvm.trap"));
diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs
index d76385b8bfe..88e623f1ecc 100644
--- a/src/librustc_trans/mir/block.rs
+++ b/src/librustc_trans/mir/block.rs
@@ -20,7 +20,6 @@ use callee::{Callee, CalleeData, Fn, Intrinsic, NamedTupleConstructor, Virtual};
 use common::{self, BlockAndBuilder, Funclet};
 use common::{C_bool, C_str_slice, C_struct, C_u32, C_undef};
 use consts;
-use debuginfo::DebugLoc;
 use Disr;
 use machine::{llalign_of_min, llbitsize_of_real};
 use meth;
@@ -115,9 +114,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
         debug!("trans_block: terminator: {:?}", terminator);
 
         let span = terminator.source_info.span;
-        let debug_loc = self.debug_loc(terminator.source_info);
-        debug_loc.apply_to_bcx(&bcx);
-        debug_loc.apply(bcx.fcx());
+        let (scope, debug_span) = self.debug_loc(terminator.source_info);
+        bcx.set_source_location(scope, debug_span);
         match terminator.kind {
             mir::TerminatorKind::Resume => {
                 if let Some(cleanup_pad) = cleanup_pad {
@@ -329,7 +327,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
 
                 // After this point, bcx is the block for the call to panic.
                 bcx = panic_block;
-                debug_loc.apply_to_bcx(&bcx);
+                bcx.set_source_location(scope, debug_span);
 
                 // Get the location information.
                 let loc = bcx.sess().codemap().lookup_char_pos(span.lo);
@@ -605,7 +603,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
                                 bug!("Cannot use direct operand with an intrinsic call")
                         };
 
-                        trans_intrinsic_call(&bcx, callee.ty, &fn_ty, &llargs, dest, debug_loc);
+                        trans_intrinsic_call(&bcx, callee.ty, &fn_ty, &llargs, dest, debug_span);
 
                         if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
                             // Make a fake operand for store_return
@@ -645,7 +643,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
                     if let Some((_, target)) = *destination {
                         let ret_bcx = self.build_block(target);
                         ret_bcx.at_start(|ret_bcx| {
-                            debug_loc.apply_to_bcx(ret_bcx);
+                            bcx.set_source_location(scope, debug_span);
                             let op = OperandRef {
                                 val: Immediate(invokeret),
                                 ty: sig.output(),
@@ -885,7 +883,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
             }
             CleanupKind::Funclet => {
                 bcx.set_personality_fn(self.fcx.eh_personality());
-                DebugLoc::None.apply_to_bcx(&bcx);
                 let cleanup_pad = bcx.cleanup_pad(None, &[]);
                 funclets[bb] = Funclet::msvc(cleanup_pad);
             }
diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs
index c3cc5a7a9b3..7ceba69c371 100644
--- a/src/librustc_trans/mir/mod.rs
+++ b/src/librustc_trans/mir/mod.rs
@@ -10,16 +10,18 @@
 
 use libc::c_uint;
 use llvm::{self, ValueRef, BasicBlockRef};
+use llvm::debuginfo::DIScope;
 use rustc::ty;
 use rustc::mir;
 use rustc::mir::tcx::LvalueTy;
 use session::config::FullDebugInfo;
 use base;
 use common::{self, BlockAndBuilder, CrateContext, FunctionContext, C_null, Funclet};
-use debuginfo::{self, declare_local, DebugLoc, VariableAccess, VariableKind, FunctionDebugContext};
+use debuginfo::{self, declare_local, VariableAccess, VariableKind, FunctionDebugContext};
+use machine;
 use type_of;
 
-use syntax_pos::{DUMMY_SP, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos};
+use syntax_pos::{DUMMY_SP, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos, Span};
 use syntax::symbol::keywords;
 
 use std::cell::Ref;
@@ -88,15 +90,12 @@ pub struct MirContext<'bcx, 'tcx:'bcx> {
 }
 
 impl<'blk, 'tcx> MirContext<'blk, 'tcx> {
-    pub fn debug_loc(&mut self, source_info: mir::SourceInfo) -> DebugLoc {
+    pub fn debug_loc(&mut self, source_info: mir::SourceInfo) -> (DIScope, Span) {
         // Bail out if debug info emission is not enabled.
         match self.fcx.debug_context {
             FunctionDebugContext::DebugInfoDisabled |
             FunctionDebugContext::FunctionWithoutDebugInfo => {
-                // Can't return DebugLoc::None here because intrinsic::trans_intrinsic_call()
-                // relies on debug location to obtain span of the call site.
-                return DebugLoc::ScopeAt(self.scopes[source_info.scope].scope_metadata,
-                                         source_info.span);
+                return (self.scopes[source_info.scope].scope_metadata, source_info.span);
             }
             FunctionDebugContext::RegularContext(_) =>{}
         }
@@ -109,8 +108,8 @@ impl<'blk, 'tcx> MirContext<'blk, 'tcx> {
             self.fcx.ccx.sess().opts.debugging_opts.debug_macros {
 
             let scope_metadata = self.scope_metadata_for_loc(source_info.scope,
-                                                             source_info.span.lo);
-            DebugLoc::ScopeAt(scope_metadata, source_info.span)
+                source_info.span.lo);
+            (scope_metadata, source_info.span)
         } else {
             let cm = self.fcx.ccx.sess().codemap();
             // Walk up the macro expansion chain until we reach a non-expanded span.
@@ -125,7 +124,7 @@ impl<'blk, 'tcx> MirContext<'blk, 'tcx> {
             }
             let scope_metadata = self.scope_metadata_for_loc(source_info.scope, span.lo);
             // Use span of the outermost call site, while keeping the original lexical scope
-            DebugLoc::ScopeAt(scope_metadata, span)
+            (scope_metadata, span)
         }
     }
 
@@ -236,14 +235,10 @@ pub fn trans_mir<'blk, 'tcx: 'blk>(fcx: &'blk FunctionContext<'blk, 'tcx>) {
                 debug!("alloc: {:?} ({}) -> lvalue", local, name);
                 let lvalue = LvalueRef::alloca(&bcx, ty, &name.as_str());
                 if dbg {
-                    let dbg_loc = mircx.debug_loc(source_info);
-                    if let DebugLoc::ScopeAt(scope, span) = dbg_loc {
-                        declare_local(&bcx, name, ty, scope,
-                            VariableAccess::DirectVariable { alloca: lvalue.llval },
-                            VariableKind::LocalVariable, span);
-                    } else {
-                        panic!("Unexpected");
-                    }
+                    let (scope, span) = mircx.debug_loc(source_info);
+                    declare_local(&bcx, name, ty, scope,
+                        VariableAccess::DirectVariable { alloca: lvalue.llval },
+                        VariableKind::LocalVariable, span);
                 }
                 LocalRef::Lvalue(lvalue)
             } else {
@@ -312,7 +307,6 @@ pub fn trans_mir<'blk, 'tcx: 'blk>(fcx: &'blk FunctionContext<'blk, 'tcx>) {
         }
     }
 
-    DebugLoc::None.apply(fcx);
     fcx.cleanup();
 }
 
diff --git a/src/librustc_trans/mir/statement.rs b/src/librustc_trans/mir/statement.rs
index 47537c830dc..6cc3f6aad9f 100644
--- a/src/librustc_trans/mir/statement.rs
+++ b/src/librustc_trans/mir/statement.rs
@@ -25,9 +25,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
                            -> BlockAndBuilder<'bcx, 'tcx> {
         debug!("trans_statement(statement={:?})", statement);
 
-        let debug_loc = self.debug_loc(statement.source_info);
-        debug_loc.apply_to_bcx(&bcx);
-        debug_loc.apply(bcx.fcx());
+        let (scope, span) = self.debug_loc(statement.source_info);
+        bcx.set_source_location(scope, span);
         match statement.kind {
             mir::StatementKind::Assign(ref lvalue, ref rvalue) => {
                 if let mir::Lvalue::Local(index) = *lvalue {