Skip to content

Commit

Permalink
Use SpanId in MIR.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed May 12, 2020
1 parent 988eee9 commit aad6039
Show file tree
Hide file tree
Showing 73 changed files with 723 additions and 604 deletions.
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_middle::ty::layout::{HasParamEnv, LayoutError, TyAndLayout};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::config::{CFGuard, CrateType, DebugInfo};
use rustc_session::Session;
use rustc_span::source_map::{Span, DUMMY_SP};
use rustc_span::source_map::{SpanId, DUMMY_SPID};
use rustc_span::symbol::Symbol;
use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx};
use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
Expand Down Expand Up @@ -820,10 +820,10 @@ impl LayoutOf for CodegenCx<'ll, 'tcx> {
type TyAndLayout = TyAndLayout<'tcx>;

fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
self.spanned_layout_of(ty, DUMMY_SP)
self.spanned_layout_of(ty, DUMMY_SPID)
}

fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyAndLayout {
fn spanned_layout_of(&self, ty: Ty<'tcx>, span: SpanId) -> Self::TyAndLayout {
self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)).unwrap_or_else(|e| {
if let LayoutError::SizeOverflow(_) = e {
self.sess().span_fatal(span, &e.to_string())
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn make_mir_scope(
debug_context.scopes[parent]
} else {
// The root is the function itself.
let loc = cx.lookup_debug_loc(mir.span.lo());
let loc = cx.lookup_debug_loc(cx.tcx.reify_span(mir.span).lo());
debug_context.scopes[scope] = DebugScope {
scope_metadata: Some(fn_metadata),
file_start_pos: loc.file.start_pos,
Expand All @@ -75,7 +75,7 @@ fn make_mir_scope(
return;
}

let loc = cx.lookup_debug_loc(scope_data.span.lo());
let loc = cx.lookup_debug_loc(cx.tcx.reify_span(scope_data.span).lo());
let file_metadata = file_metadata(cx, &loc.file, debug_context.defining_crate);

let scope_metadata = unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
return None;
}

let span = mir.span;
let span = self.tcx().reify_span(mir.span);

// This can be the case for functions inlined from another crate
if span.is_dummy() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
if let Some(index) = place.as_local() {
self.assign(index, location);
let decl_span = self.fx.mir.local_decls[index].source_info.span;
if !self.fx.rvalue_creates_operand(rvalue, decl_span) {
if !self.fx.rvalue_creates_operand(rvalue, self.fx.cx.tcx().reify_span(decl_span)) {
self.not_ssa(index);
}
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
self.set_debug_loc(&mut bx, terminator.source_info);

// Get the location information.
let span = bx.tcx().reify_span(span);
let location = self.get_caller_location(&mut bx, span).immediate();

// Put together the arguments to the panic entry point.
Expand Down Expand Up @@ -606,6 +607,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bug!("`miri_start_panic` should never end up in compiled code");
}

let span = bx.tcx().reify_span(span);
if self.codegen_panic_intrinsic(
&helper,
&mut bx,
Expand Down Expand Up @@ -670,7 +672,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let c = self.eval_mir_constant(constant);
let (llval, ty) = self.simd_shuffle_indices(
&bx,
constant.span,
bx.tcx().reify_span(constant.span),
constant.literal.ty,
c,
);
Expand All @@ -689,7 +691,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&fn_abi,
&args,
dest,
terminator.source_info.span,
bx.tcx().reify_span(terminator.source_info.span),
);

if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
Expand Down
20 changes: 13 additions & 7 deletions src/librustc_codegen_ssa/mir/debuginfo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::rustc_middle::ty::layout::HasTyCtxt;
use crate::traits::*;
use rustc_hir::def_id::CrateNum;
use rustc_index::vec::IndexVec;
Expand Down Expand Up @@ -60,23 +61,28 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}

pub fn debug_loc(&self, source_info: mir::SourceInfo) -> (Option<Bx::DIScope>, Span) {
let source_span = self.cx.tcx().reify_span(source_info.span);

// Bail out if debug info emission is not enabled.
match self.debug_context {
None => return (None, source_info.span),
None => return (None, source_span),
Some(_) => {}
}

// In order to have a good line stepping behavior in debugger, we overwrite debug
// locations of macro expansions with that of the outermost expansion site
// (unless the crate is being compiled with `-Z debug-macros`).
if !source_info.span.from_expansion() || self.cx.sess().opts.debugging_opts.debug_macros {
let scope = self.scope_metadata_for_loc(source_info.scope, source_info.span.lo());
(scope, source_info.span)
if !source_span.from_expansion() || self.cx.sess().opts.debugging_opts.debug_macros {
let scope = self.scope_metadata_for_loc(source_info.scope, source_span.lo());
(scope, source_span)
} else {
// Walk up the macro expansion chain until we reach a non-expanded span.
// We also stop at the function body level because no line stepping can occur
// at the level above that.
let span = rustc_span::hygiene::walk_chain(source_info.span, self.mir.span.ctxt());
let span = rustc_span::hygiene::walk_chain(
source_span,
self.cx.tcx().reify_span(self.mir.span).ctxt(),
);
let scope = self.scope_metadata_for_loc(source_info.scope, span.lo());
// Use span of the outermost expansion site, while keeping the original lexical scope.
(scope, span)
Expand Down Expand Up @@ -149,7 +155,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let (scope, span) = if full_debug_info {
self.debug_loc(decl.source_info)
} else {
(None, decl.source_info.span)
(None, self.cx.tcx().reify_span(decl.source_info.span))
};
let dbg_var = scope.map(|scope| {
// FIXME(eddyb) is this `+ 1` needed at all?
Expand Down Expand Up @@ -312,7 +318,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let (scope, span) = if full_debug_info {
self.debug_loc(var.source_info)
} else {
(None, var.source_info.span)
(None, self.cx.tcx().reify_span(var.source_info.span))
};
let dbg_var = scope.map(|scope| {
let place = var.place;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::Rvalue::Aggregate(..) => {
let ty = rvalue.ty(self.mir, self.cx.tcx());
let ty = self.monomorphize(&ty);
self.cx.spanned_layout_of(ty, span).is_zst()
self.cx.spanned_layout_of(ty, span.into()).is_zst()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&asm.asm,
outputs,
input_vals,
statement.source_info.span,
bx.tcx().reify_span(statement.source_info.span),
);
if !res {
struct_span_err!(
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_middle/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_hir as hir;
use rustc_hir::definitions::DefPathData;
use rustc_macros::HashStable;
use rustc_session::CtfeBacktrace;
use rustc_span::{def_id::DefId, Pos, Span, SpanId};
use rustc_span::{def_id::DefId, Pos, SpanId};
use rustc_target::abi::{Align, Size};
use std::{any::Any, backtrace::Backtrace, fmt, mem};

Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct ConstEvalErr<'tcx> {
#[derive(Debug)]
pub struct FrameInfo<'tcx> {
pub instance: ty::Instance<'tcx>,
pub span: Span,
pub span: SpanId,
pub lint_root: Option<hir::HirId>,
}

Expand All @@ -59,7 +59,8 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
write!(f, "inside `{}`", self.instance)?;
}
if !self.span.is_dummy() {
let lo = tcx.sess.source_map().lookup_char_pos(self.span.lo());
let span = tcx.reify_span(self.span);
let lo = tcx.sess.source_map().lookup_char_pos(span.lo());
write!(f, " at {}:{}:{}", lo.file.name, lo.line, lo.col.to_usize() + 1)?;
}
Ok(())
Expand Down
Loading

0 comments on commit aad6039

Please sign in to comment.