Skip to content

Commit aad6039

Browse files
committed
Use SpanId in MIR.
1 parent 988eee9 commit aad6039

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+723
-604
lines changed

src/librustc_codegen_llvm/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::ty::layout::{HasParamEnv, LayoutError, TyAndLayout};
1818
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
1919
use rustc_session::config::{CFGuard, CrateType, DebugInfo};
2020
use rustc_session::Session;
21-
use rustc_span::source_map::{Span, DUMMY_SP};
21+
use rustc_span::source_map::{SpanId, DUMMY_SPID};
2222
use rustc_span::symbol::Symbol;
2323
use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx};
2424
use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
@@ -820,10 +820,10 @@ impl LayoutOf for CodegenCx<'ll, 'tcx> {
820820
type TyAndLayout = TyAndLayout<'tcx>;
821821

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

826-
fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyAndLayout {
826+
fn spanned_layout_of(&self, ty: Ty<'tcx>, span: SpanId) -> Self::TyAndLayout {
827827
self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)).unwrap_or_else(|e| {
828828
if let LayoutError::SizeOverflow(_) = e {
829829
self.sess().span_fatal(span, &e.to_string())

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn make_mir_scope(
5959
debug_context.scopes[parent]
6060
} else {
6161
// The root is the function itself.
62-
let loc = cx.lookup_debug_loc(mir.span.lo());
62+
let loc = cx.lookup_debug_loc(cx.tcx.reify_span(mir.span).lo());
6363
debug_context.scopes[scope] = DebugScope {
6464
scope_metadata: Some(fn_metadata),
6565
file_start_pos: loc.file.start_pos,
@@ -75,7 +75,7 @@ fn make_mir_scope(
7575
return;
7676
}
7777

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

8181
let scope_metadata = unsafe {

src/librustc_codegen_llvm/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
237237
return None;
238238
}
239239

240-
let span = mir.span;
240+
let span = self.tcx().reify_span(mir.span);
241241

242242
// This can be the case for functions inlined from another crate
243243
if span.is_dummy() {

src/librustc_codegen_ssa/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
224224
if let Some(index) = place.as_local() {
225225
self.assign(index, location);
226226
let decl_span = self.fx.mir.local_decls[index].source_info.span;
227-
if !self.fx.rvalue_creates_operand(rvalue, decl_span) {
227+
if !self.fx.rvalue_creates_operand(rvalue, self.fx.cx.tcx().reify_span(decl_span)) {
228228
self.not_ssa(index);
229229
}
230230
} else {

src/librustc_codegen_ssa/mir/block.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
406406
self.set_debug_loc(&mut bx, terminator.source_info);
407407

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

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

610+
let span = bx.tcx().reify_span(span);
609611
if self.codegen_panic_intrinsic(
610612
&helper,
611613
&mut bx,
@@ -670,7 +672,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
670672
let c = self.eval_mir_constant(constant);
671673
let (llval, ty) = self.simd_shuffle_indices(
672674
&bx,
673-
constant.span,
675+
bx.tcx().reify_span(constant.span),
674676
constant.literal.ty,
675677
c,
676678
);
@@ -689,7 +691,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
689691
&fn_abi,
690692
&args,
691693
dest,
692-
terminator.source_info.span,
694+
bx.tcx().reify_span(terminator.source_info.span),
693695
);
694696

695697
if let ReturnDest::IndirectOperand(dst, _) = ret_dest {

src/librustc_codegen_ssa/mir/debuginfo.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::rustc_middle::ty::layout::HasTyCtxt;
12
use crate::traits::*;
23
use rustc_hir::def_id::CrateNum;
34
use rustc_index::vec::IndexVec;
@@ -60,23 +61,28 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6061
}
6162

6263
pub fn debug_loc(&self, source_info: mir::SourceInfo) -> (Option<Bx::DIScope>, Span) {
64+
let source_span = self.cx.tcx().reify_span(source_info.span);
65+
6366
// Bail out if debug info emission is not enabled.
6467
match self.debug_context {
65-
None => return (None, source_info.span),
68+
None => return (None, source_span),
6669
Some(_) => {}
6770
}
6871

6972
// In order to have a good line stepping behavior in debugger, we overwrite debug
7073
// locations of macro expansions with that of the outermost expansion site
7174
// (unless the crate is being compiled with `-Z debug-macros`).
72-
if !source_info.span.from_expansion() || self.cx.sess().opts.debugging_opts.debug_macros {
73-
let scope = self.scope_metadata_for_loc(source_info.scope, source_info.span.lo());
74-
(scope, source_info.span)
75+
if !source_span.from_expansion() || self.cx.sess().opts.debugging_opts.debug_macros {
76+
let scope = self.scope_metadata_for_loc(source_info.scope, source_span.lo());
77+
(scope, source_span)
7578
} else {
7679
// Walk up the macro expansion chain until we reach a non-expanded span.
7780
// We also stop at the function body level because no line stepping can occur
7881
// at the level above that.
79-
let span = rustc_span::hygiene::walk_chain(source_info.span, self.mir.span.ctxt());
82+
let span = rustc_span::hygiene::walk_chain(
83+
source_span,
84+
self.cx.tcx().reify_span(self.mir.span).ctxt(),
85+
);
8086
let scope = self.scope_metadata_for_loc(source_info.scope, span.lo());
8187
// Use span of the outermost expansion site, while keeping the original lexical scope.
8288
(scope, span)
@@ -149,7 +155,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
149155
let (scope, span) = if full_debug_info {
150156
self.debug_loc(decl.source_info)
151157
} else {
152-
(None, decl.source_info.span)
158+
(None, self.cx.tcx().reify_span(decl.source_info.span))
153159
};
154160
let dbg_var = scope.map(|scope| {
155161
// FIXME(eddyb) is this `+ 1` needed at all?
@@ -312,7 +318,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
312318
let (scope, span) = if full_debug_info {
313319
self.debug_loc(var.source_info)
314320
} else {
315-
(None, var.source_info.span)
321+
(None, self.cx.tcx().reify_span(var.source_info.span))
316322
};
317323
let dbg_var = scope.map(|scope| {
318324
let place = var.place;

src/librustc_codegen_ssa/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
751751
mir::Rvalue::Aggregate(..) => {
752752
let ty = rvalue.ty(self.mir, self.cx.tcx());
753753
let ty = self.monomorphize(&ty);
754-
self.cx.spanned_layout_of(ty, span).is_zst()
754+
self.cx.spanned_layout_of(ty, span.into()).is_zst()
755755
}
756756
}
757757

src/librustc_codegen_ssa/mir/statement.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9797
&asm.asm,
9898
outputs,
9999
input_vals,
100-
statement.source_info.span,
100+
bx.tcx().reify_span(statement.source_info.span),
101101
);
102102
if !res {
103103
struct_span_err!(

src/librustc_middle/mir/interpret/error.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir as hir;
1111
use rustc_hir::definitions::DefPathData;
1212
use rustc_macros::HashStable;
1313
use rustc_session::CtfeBacktrace;
14-
use rustc_span::{def_id::DefId, Pos, Span, SpanId};
14+
use rustc_span::{def_id::DefId, Pos, SpanId};
1515
use rustc_target::abi::{Align, Size};
1616
use std::{any::Any, backtrace::Backtrace, fmt, mem};
1717

@@ -44,7 +44,7 @@ pub struct ConstEvalErr<'tcx> {
4444
#[derive(Debug)]
4545
pub struct FrameInfo<'tcx> {
4646
pub instance: ty::Instance<'tcx>,
47-
pub span: Span,
47+
pub span: SpanId,
4848
pub lint_root: Option<hir::HirId>,
4949
}
5050

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

0 commit comments

Comments
 (0)