Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defunctionalize spans for diagnostics #72142

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl CodegenCx<'ll, 'tcx> {
debug!("get_static: sym={} item_attr={:?}", sym, self.tcx.item_attrs(def_id));

let attrs = self.tcx.codegen_fn_attrs(def_id);
let span = self.tcx.def_span(def_id);
let span = self.tcx.real_def_span(def_id);
let g = check_and_apply_linkage(&self, &attrs, ty, sym, span);

// Thread-local statics in some other crate need to *always* be linked
Expand Down
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/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
// We may want to remove the namespace scope if we're in an extern block (see
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952).
let var_scope = get_namespace_for_item(cx, def_id);
let span = tcx.def_span(def_id);
let span = tcx.real_def_span(def_id);

let (file_metadata, line_number) = if !span.is_dummy() {
let loc = cx.lookup_debug_loc(span.lo());
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
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ impl SharedEmitter {
}

impl Emitter for SharedEmitter {
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
fn emit_diagnostic(&mut self, diag: &rustc_errors::RealDiagnostic) {
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
msg: diag.message(),
code: diag.code.clone(),
Expand Down Expand Up @@ -1612,7 +1612,7 @@ impl SharedEmitterMain {
if let Some(code) = diag.code {
d.code(code);
}
handler.emit_diagnostic(&d);
handler.emit_diagnostic(d);
}
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => {
sess.span_err(ExpnId::from_u32(cookie).expn_data().call_site, &msg)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::cgu_reuse_tracker::CguReuse;
use rustc_session::config::{self, EntryFnType};
use rustc_session::Session;
use rustc_span::Span;
use rustc_span::SpanId;
use rustc_symbol_mangling::test as symbol_names_test;
use rustc_target::abi::{Abi, Align, LayoutOf, Scalar, VariantIdx};

Expand Down Expand Up @@ -414,7 +414,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(

fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
cx: &'a Bx::CodegenCx,
sp: Span,
sp: SpanId,
rust_main: Bx::Value,
rust_main_def_id: LocalDefId,
use_start_lang_item: bool,
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
8 changes: 4 additions & 4 deletions src/librustc_codegen_ssa/traits/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::common::TypeKind;
use crate::mir::place::PlaceRef;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::ty::{self, Ty};
use rustc_span::DUMMY_SP;
use rustc_span::DUMMY_SPID;
use rustc_target::abi::call::{ArgAbi, CastTarget, FnAbi, Reg};
use rustc_target::abi::Integer;

Expand Down Expand Up @@ -70,16 +70,16 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
}

fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
ty.is_sized(self.tcx().at(DUMMY_SP), ty::ParamEnv::reveal_all())
ty.is_sized(self.tcx().at(DUMMY_SPID), ty::ParamEnv::reveal_all())
}

fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
ty.is_freeze(self.tcx(), ty::ParamEnv::reveal_all(), DUMMY_SP)
ty.is_freeze(self.tcx(), ty::ParamEnv::reveal_all(), DUMMY_SPID)
}

fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
let param_env = ty::ParamEnv::reveal_all();
if ty.is_sized(self.tcx().at(DUMMY_SP), param_env) {
if ty.is_sized(self.tcx().at(DUMMY_SPID), param_env) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
// it wants to print.
if !info.payload().is::<rustc_errors::ExplicitBug>() {
let d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
handler.emit_diagnostic(&d);
handler.emit_diagnostic(d);
}

let mut xs: Vec<Cow<'static, str>> = vec![
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_errors/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

use crate::emitter::FileWithAnnotatedLines;
use crate::snippet::Line;
use crate::{CodeSuggestion, Diagnostic, DiagnosticId, Emitter, Level, SubDiagnostic};
use crate::{CodeSuggestion, DiagnosticId, Emitter, Level, RealDiagnostic, RealSubDiagnostic};
use annotate_snippets::display_list::DisplayList;
use annotate_snippets::formatter::DisplayListFormatter;
use annotate_snippets::snippet::*;
use rustc_data_structures::sync::Lrc;
use rustc_span::source_map::SourceMap;
use rustc_span::{Loc, MultiSpan, SourceFile};
use rustc_span::{Loc, MultiSpan, SourceFile, Span};

/// Generates diagnostics using annotate-snippet
pub struct AnnotateSnippetEmitterWriter {
Expand All @@ -28,7 +28,7 @@ pub struct AnnotateSnippetEmitterWriter {

impl Emitter for AnnotateSnippetEmitterWriter {
/// The entry point for the diagnostics generation
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
fn emit_diagnostic(&mut self, diag: &RealDiagnostic) {
let mut children = diag.children.clone();
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);

Expand Down Expand Up @@ -68,9 +68,9 @@ struct DiagnosticConverter<'a> {
code: Option<DiagnosticId>,
msp: MultiSpan,
#[allow(dead_code)]
children: &'a [SubDiagnostic],
children: &'a [RealSubDiagnostic],
#[allow(dead_code)]
suggestions: &'a [CodeSuggestion],
suggestions: &'a [CodeSuggestion<Span>],
}

impl<'a> DiagnosticConverter<'a> {
Expand Down Expand Up @@ -191,8 +191,8 @@ impl AnnotateSnippetEmitterWriter {
message: String,
code: &Option<DiagnosticId>,
msp: &MultiSpan,
children: &[SubDiagnostic],
suggestions: &[CodeSuggestion],
children: &[RealSubDiagnostic],
suggestions: &[CodeSuggestion<Span>],
) {
let converter = DiagnosticConverter {
source_map: self.source_map.clone(),
Expand Down
Loading