about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_trans/debuginfo/mod.rs9
-rw-r--r--src/librustc_trans/debuginfo/source_loc.rs26
-rw-r--r--src/librustc_trans/mir/block.rs7
-rw-r--r--src/librustc_trans/mir/mod.rs48
-rw-r--r--src/librustc_trans/mir/statement.rs2
5 files changed, 54 insertions, 38 deletions
diff --git a/src/librustc_trans/debuginfo/mod.rs b/src/librustc_trans/debuginfo/mod.rs
index b22bb080d05..e984edacaf8 100644
--- a/src/librustc_trans/debuginfo/mod.rs
+++ b/src/librustc_trans/debuginfo/mod.rs
@@ -28,7 +28,6 @@ use rustc::ty::subst::Substs;
 
 use abi::Abi;
 use common::{CrateContext, BlockAndBuilder};
-use mir::MirContext;
 use monomorphize::{self, Instance};
 use rustc::ty::{self, Ty};
 use rustc::mir;
@@ -434,7 +433,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 }
 
 pub fn declare_local<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
-                               mir: &MirContext,
+                               dbg_context: &FunctionDebugContext,
                                variable_name: ast::Name,
                                variable_type: Ty<'tcx>,
                                scope_metadata: DIScope,
@@ -476,7 +475,7 @@ pub fn declare_local<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
                     align as u64,
                 )
             };
-            source_loc::set_debug_location(cx, bcx,
+            source_loc::set_debug_location(bcx,
                 InternalDebugLocation::new(scope_metadata, loc.line, loc.col.to_usize()));
             unsafe {
                 let debug_loc = llvm::LLVMGetCurrentDebugLocation(bcx.llbuilder);
@@ -496,8 +495,8 @@ pub fn declare_local<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
 
     match variable_kind {
         ArgumentVariable(_) | CapturedVariable => {
-            assert!(!mir.debug_context.get_ref(span).source_locations_enabled.get());
-            source_loc::set_debug_location(cx, bcx, UnknownLocation);
+            assert!(!dbg_context.get_ref(span).source_locations_enabled.get());
+            source_loc::set_debug_location(bcx, UnknownLocation);
         }
         _ => { /* nothing to do */ }
     }
diff --git a/src/librustc_trans/debuginfo/source_loc.rs b/src/librustc_trans/debuginfo/source_loc.rs
index 16b32f2e3d6..e02c8be19a2 100644
--- a/src/librustc_trans/debuginfo/source_loc.rs
+++ b/src/librustc_trans/debuginfo/source_loc.rs
@@ -17,8 +17,6 @@ use super::FunctionDebugContext;
 use llvm;
 use llvm::debuginfo::DIScope;
 use builder::Builder;
-use common::CrateContext;
-use mir::MirContext;
 
 use libc::c_uint;
 use std::ptr;
@@ -27,24 +25,26 @@ 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(mir: &MirContext, builder: &Builder, scope: DIScope, span: Span) {
-    let function_debug_context = match mir.debug_context {
+pub fn set_source_location(
+    debug_context: &FunctionDebugContext, builder: &Builder, scope: DIScope, span: Span
+) {
+    let function_debug_context = match *debug_context {
         FunctionDebugContext::DebugInfoDisabled => return,
         FunctionDebugContext::FunctionWithoutDebugInfo => {
-            set_debug_location(mir.ccx(), builder, UnknownLocation);
+            set_debug_location(builder, UnknownLocation);
             return;
         }
         FunctionDebugContext::RegularContext(ref data) => data
     };
 
     let dbg_loc = if function_debug_context.source_locations_enabled.get() {
-        debug!("set_source_location: {}", mir.ccx().sess().codemap().span_to_string(span));
-        let loc = span_start(mir.ccx(), span);
+        debug!("set_source_location: {}", builder.ccx.sess().codemap().span_to_string(span));
+        let loc = span_start(builder.ccx, span);
         InternalDebugLocation::new(scope, loc.line, loc.col.to_usize())
     } else {
         UnknownLocation
     };
-    set_debug_location(mir.ccx(), builder, dbg_loc);
+    set_debug_location(builder, dbg_loc);
 }
 
 /// Enables emitting source locations for the given functions.
@@ -53,8 +53,8 @@ pub fn set_source_location(mir: &MirContext, builder: &Builder, scope: DIScope,
 /// they are disabled when beginning to translate a new function. This functions
 /// switches source location emitting on and must therefore be called before the
 /// first real statement/expression of the function is translated.
-pub fn start_emitting_source_locations(mir: &MirContext) {
-    match mir.debug_context {
+pub fn start_emitting_source_locations(dbg_context: &FunctionDebugContext) {
+    match *dbg_context {
         FunctionDebugContext::RegularContext(ref data) => {
             data.source_locations_enabled.set(true)
         },
@@ -79,9 +79,7 @@ impl InternalDebugLocation {
     }
 }
 
-pub fn set_debug_location(cx: &CrateContext,
-                          builder: &Builder,
-                          debug_location: InternalDebugLocation) {
+pub fn set_debug_location(builder: &Builder, debug_location: InternalDebugLocation) {
     let metadata_node = match debug_location {
         KnownLocation { scope, line, .. } => {
             // Always set the column to zero like Clang and GCC
@@ -90,7 +88,7 @@ pub fn set_debug_location(cx: &CrateContext,
 
             unsafe {
                 llvm::LLVMRustDIBuilderCreateDebugLocation(
-                    debug_context(cx).llcontext,
+                    debug_context(builder.ccx).llcontext,
                     line as c_uint,
                     col as c_uint,
                     scope,
diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs
index e259f7c20f2..6b6ca1a98a3 100644
--- a/src/librustc_trans/mir/block.rs
+++ b/src/librustc_trans/mir/block.rs
@@ -115,7 +115,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
 
         let span = terminator.source_info.span;
         let (scope, debug_span) = self.debug_loc(terminator.source_info);
-        debuginfo::set_source_location(self, &bcx, scope, debug_span);
+        debuginfo::set_source_location(&self.debug_context, &bcx, scope, debug_span);
         match terminator.kind {
             mir::TerminatorKind::Resume => {
                 if let Some(cleanup_pad) = cleanup_pad {
@@ -327,7 +327,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
 
                 // After this point, bcx is the block for the call to panic.
                 bcx = panic_block;
-                debuginfo::set_source_location(self, &bcx, scope, debug_span);
+                debuginfo::set_source_location(&self.debug_context, &bcx, scope, debug_span);
 
                 // Get the location information.
                 let loc = bcx.sess().codemap().lookup_char_pos(span.lo);
@@ -643,7 +643,8 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
                     if let Some((_, target)) = *destination {
                         let ret_bcx = self.build_block(target);
                         ret_bcx.at_start(|ret_bcx| {
-                            debuginfo::set_source_location(self, &ret_bcx, scope, debug_span);
+                            debuginfo::set_source_location(&self.debug_context,
+                                &ret_bcx, scope, debug_span);
                             let op = OperandRef {
                                 val: Immediate(invokeret),
                                 ty: sig.output(),
diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs
index f8bd087b0da..d0123d6e6f7 100644
--- a/src/librustc_trans/mir/mod.rs
+++ b/src/librustc_trans/mir/mod.rs
@@ -44,9 +44,9 @@ use self::operand::{OperandRef, OperandValue};
 
 /// Master context for translating MIR.
 pub struct MirContext<'a, 'tcx:'a> {
-    pub mir: &'a mir::Mir<'tcx>,
+    mir: &'a mir::Mir<'tcx>,
 
-    pub debug_context: debuginfo::FunctionDebugContext,
+    debug_context: debuginfo::FunctionDebugContext,
 
     /// Function context
     fcx: &'a common::FunctionContext<'a, 'tcx>,
@@ -276,7 +276,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
                 let lvalue = LvalueRef::alloca(&bcx, ty, &name.as_str());
                 if dbg {
                     let (scope, span) = mircx.debug_loc(source_info);
-                    declare_local(&bcx, &mircx, name, ty, scope,
+                    declare_local(&bcx, &mircx.debug_context, name, ty, scope,
                         VariableAccess::DirectVariable { alloca: lvalue.llval },
                         VariableKind::LocalVariable, span);
                 }
@@ -314,7 +314,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
     // Up until here, IR instructions for this function have explicitly not been annotated with
     // source code location, so we don't step into call setup code. From here on, source location
     // emitting should be enabled.
-    debuginfo::start_emitting_source_locations(&mircx);
+    debuginfo::start_emitting_source_locations(&mircx.debug_context);
 
     let mut funclets: IndexVec<mir::BasicBlock, Option<Funclet>> =
         IndexVec::from_elem(None, mir.basic_blocks());
@@ -418,10 +418,15 @@ fn arg_local_refs<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
                 let variable_access = VariableAccess::DirectVariable {
                     alloca: lltemp
                 };
-                declare_local(bcx, mircx, arg_decl.name.unwrap_or(keywords::Invalid.name()),
-                              arg_ty, scope, variable_access,
-                              VariableKind::ArgumentVariable(arg_index + 1),
-                              DUMMY_SP);
+                declare_local(
+                    bcx,
+                    &mircx.debug_context,
+                    arg_decl.name.unwrap_or(keywords::Invalid.name()),
+                    arg_ty, scope,
+                    variable_access,
+                    VariableKind::ArgumentVariable(arg_index + 1),
+                    DUMMY_SP
+                );
             });
 
             return LocalRef::Lvalue(LvalueRef::new_sized(lltemp, LvalueTy::from_ty(arg_ty)));
@@ -490,10 +495,16 @@ fn arg_local_refs<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
         arg_scope.map(|scope| {
             // Is this a regular argument?
             if arg_index > 0 || mir.upvar_decls.is_empty() {
-                declare_local(bcx, mircx, arg_decl.name.unwrap_or(keywords::Invalid.name()), arg_ty,
-                              scope, VariableAccess::DirectVariable { alloca: llval },
-                              VariableKind::ArgumentVariable(arg_index + 1),
-                              DUMMY_SP);
+                declare_local(
+                    bcx,
+                    &mircx.debug_context,
+                    arg_decl.name.unwrap_or(keywords::Invalid.name()),
+                    arg_ty,
+                    scope,
+                    VariableAccess::DirectVariable { alloca: llval },
+                    VariableKind::ArgumentVariable(arg_index + 1),
+                    DUMMY_SP
+                );
                 return;
             }
 
@@ -558,9 +569,16 @@ fn arg_local_refs<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
                     alloca: env_ptr,
                     address_operations: &ops
                 };
-                declare_local(bcx, mircx, decl.debug_name, ty, scope, variable_access,
-                              VariableKind::CapturedVariable,
-                              DUMMY_SP);
+                declare_local(
+                    bcx,
+                    &mircx.debug_context,
+                    decl.debug_name,
+                    ty,
+                    scope,
+                    variable_access,
+                    VariableKind::CapturedVariable,
+                    DUMMY_SP
+                );
             }
         });
         LocalRef::Lvalue(LvalueRef::new_sized(llval, LvalueTy::from_ty(arg_ty)))
diff --git a/src/librustc_trans/mir/statement.rs b/src/librustc_trans/mir/statement.rs
index 62ee768ab07..6fc5d7db676 100644
--- a/src/librustc_trans/mir/statement.rs
+++ b/src/librustc_trans/mir/statement.rs
@@ -27,7 +27,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
         debug!("trans_statement(statement={:?})", statement);
 
         let (scope, span) = self.debug_loc(statement.source_info);
-        debuginfo::set_source_location(self, &bcx, scope, span);
+        debuginfo::set_source_location(&self.debug_context, &bcx, scope, span);
         match statement.kind {
             mir::StatementKind::Assign(ref lvalue, ref rvalue) => {
                 if let mir::Lvalue::Local(index) = *lvalue {