Fix spans

This commit is contained in:
Michael Goulet 2024-07-01 16:32:32 -04:00
parent 0f7f3f4045
commit 3273ccea4b
11 changed files with 36 additions and 36 deletions

View file

@ -376,7 +376,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
def_id, def_id,
fn_args, fn_args,
Some(source_info.span), source_info.span,
) )
.polymorphize(fx.tcx); .polymorphize(fx.tcx);

View file

@ -4,6 +4,7 @@ use rustc_middle::ty::AssocKind;
use rustc_middle::ty::GenericArg; use rustc_middle::ty::GenericArg;
use rustc_session::config::{sigpipe, EntryFnType}; use rustc_session::config::{sigpipe, EntryFnType};
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use rustc_span::DUMMY_SP;
use crate::prelude::*; use crate::prelude::*;
@ -119,7 +120,7 @@ pub(crate) fn maybe_create_entry_wrapper(
ParamEnv::reveal_all(), ParamEnv::reveal_all(),
report.def_id, report.def_id,
tcx.mk_args(&[GenericArg::from(main_ret_ty)]), tcx.mk_args(&[GenericArg::from(main_ret_ty)]),
None, DUMMY_SP,
) )
.polymorphize(tcx); .polymorphize(tcx);
@ -145,7 +146,7 @@ pub(crate) fn maybe_create_entry_wrapper(
ParamEnv::reveal_all(), ParamEnv::reveal_all(),
start_def_id, start_def_id,
tcx.mk_args(&[main_ret_ty.into()]), tcx.mk_args(&[main_ret_ty.into()]),
None, DUMMY_SP,
) )
.polymorphize(tcx); .polymorphize(tcx);
let start_func_id = import_function(tcx, m, start_instance); let start_func_id = import_function(tcx, m, start_instance);

View file

@ -17,7 +17,7 @@ use rustc_middle::ty::layout::{
}; };
use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
use rustc_session::Session; use rustc_session::Session;
use rustc_span::{source_map::respan, Span}; use rustc_span::{source_map::respan, Span, DUMMY_SP};
use rustc_target::abi::{ use rustc_target::abi::{
call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx, call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx,
}; };
@ -479,7 +479,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
def_id, def_id,
ty::List::empty(), ty::List::empty(),
None, DUMMY_SP,
); );
let symbol_name = tcx.symbol_name(instance).name; let symbol_name = tcx.symbol_name(instance).name;

View file

@ -28,7 +28,7 @@ use rustc_session::config::{BranchProtection, CFGuard, CFProtection};
use rustc_session::config::{CrateType, DebugInfo, PAuthKey, PacRet}; use rustc_session::config::{CrateType, DebugInfo, PAuthKey, PacRet};
use rustc_session::Session; use rustc_session::Session;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
use rustc_span::Span; use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{call::FnAbi, HasDataLayout, TargetDataLayout, VariantIdx}; use rustc_target::abi::{call::FnAbi, HasDataLayout, TargetDataLayout, VariantIdx};
use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel}; use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
use smallvec::SmallVec; use smallvec::SmallVec;
@ -580,7 +580,7 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
def_id, def_id,
ty::List::empty(), ty::List::empty(),
None, DUMMY_SP,
)), )),
_ => { _ => {
let name = name.unwrap_or("rust_eh_personality"); let name = name.unwrap_or("rust_eh_personality");

View file

@ -37,7 +37,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::config::{self, CrateType, EntryFnType, OptLevel, OutputType}; use rustc_session::config::{self, CrateType, EntryFnType, OptLevel, OutputType};
use rustc_session::Session; use rustc_session::Session;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::Symbol; use rustc_span::{Symbol, DUMMY_SP};
use rustc_target::abi::FIRST_VARIANT; use rustc_target::abi::FIRST_VARIANT;
use std::cmp; use std::cmp;
@ -467,7 +467,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
start_def_id, start_def_id,
cx.tcx().mk_args(&[main_ret_ty.into()]), cx.tcx().mk_args(&[main_ret_ty.into()]),
None, DUMMY_SP,
); );
let start_fn = cx.get_fn_addr(start_instance); let start_fn = cx.get_fn_addr(start_instance);

View file

@ -842,7 +842,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
def_id, def_id,
args, args,
Some(fn_span), fn_span,
) )
.polymorphize(bx.tcx()), .polymorphize(bx.tcx()),
), ),

View file

@ -253,7 +253,7 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
const_def_id, const_def_id,
instance.args, instance.args,
Some(self.find_closest_untracked_caller_location()), self.cur_span(),
); );
return Ok(Some(new_instance)); return Ok(Some(new_instance));

View file

@ -888,6 +888,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
self.param_env, self.param_env,
def_id, def_id,
instance.args.rebase_onto(tcx, trait_def_id, concrete_trait_ref.args), instance.args.rebase_onto(tcx, trait_def_id, concrete_trait_ref.args),
self.cur_span(),
); );
assert_eq!(fn_inst, concrete_method); assert_eq!(fn_inst, concrete_method);
} }

View file

@ -547,8 +547,14 @@ impl<'tcx> Instance<'tcx> {
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
def_id: DefId, def_id: DefId,
args: GenericArgsRef<'tcx>, args: GenericArgsRef<'tcx>,
span: Option<Span>, span: Span,
) -> Instance<'tcx> { ) -> Instance<'tcx> {
// We compute the span lazily, to avoid unnecessary query calls.
// If `span` is a DUMMY_SP, and the def id is local, then use the
// def span of the def id.
let span_or_local_def_span =
|| if span.is_dummy() && def_id.is_local() { tcx.def_span(def_id) } else { span };
match ty::Instance::resolve(tcx, param_env, def_id, args) { match ty::Instance::resolve(tcx, param_env, def_id, args) {
Ok(Some(instance)) => instance, Ok(Some(instance)) => instance,
Ok(None) => { Ok(None) => {
@ -567,7 +573,7 @@ impl<'tcx> Instance<'tcx> {
// We don't use `def_span(def_id)` so that diagnostics point // We don't use `def_span(def_id)` so that diagnostics point
// to the crate root during mono instead of to foreign items. // to the crate root during mono instead of to foreign items.
// This is arguably better. // This is arguably better.
span: span.unwrap_or(DUMMY_SP), span: span_or_local_def_span(),
shrunk, shrunk,
was_written, was_written,
path, path,
@ -575,14 +581,14 @@ impl<'tcx> Instance<'tcx> {
}); });
} else { } else {
span_bug!( span_bug!(
span.unwrap_or(tcx.def_span(def_id)), span_or_local_def_span(),
"failed to resolve instance for {}", "failed to resolve instance for {}",
tcx.def_path_str_with_args(def_id, args) tcx.def_path_str_with_args(def_id, args)
) )
} }
} }
instance => span_bug!( instance => span_bug!(
span.unwrap_or(tcx.def_span(def_id)), span_or_local_def_span(),
"failed to resolve instance for {}: {instance:#?}", "failed to resolve instance for {}: {instance:#?}",
tcx.def_path_str_with_args(def_id, args) tcx.def_path_str_with_args(def_id, args)
), ),
@ -642,6 +648,7 @@ impl<'tcx> Instance<'tcx> {
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
def_id: DefId, def_id: DefId,
args: GenericArgsRef<'tcx>, args: GenericArgsRef<'tcx>,
span: Span,
) -> Instance<'tcx> { ) -> Instance<'tcx> {
debug!("resolve_for_vtable(def_id={:?}, args={:?})", def_id, args); debug!("resolve_for_vtable(def_id={:?}, args={:?})", def_id, args);
let fn_sig = tcx.fn_sig(def_id).instantiate_identity(); let fn_sig = tcx.fn_sig(def_id).instantiate_identity();
@ -654,7 +661,7 @@ impl<'tcx> Instance<'tcx> {
return Instance { def: InstanceKind::VTableShim(def_id), args }; return Instance { def: InstanceKind::VTableShim(def_id), args };
} }
let mut resolved = Instance::expect_resolve(tcx, param_env, def_id, args, None); let mut resolved = Instance::expect_resolve(tcx, param_env, def_id, args, span);
let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::Vtable); let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::Vtable);
match resolved.def { match resolved.def {
@ -731,13 +738,13 @@ impl<'tcx> Instance<'tcx> {
pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> { pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
let def_id = tcx.require_lang_item(LangItem::DropInPlace, None); let def_id = tcx.require_lang_item(LangItem::DropInPlace, None);
let args = tcx.mk_args(&[ty.into()]); let args = tcx.mk_args(&[ty.into()]);
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, None) Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, DUMMY_SP)
} }
pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> { pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, None); let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, None);
let args = tcx.mk_args(&[ty.into()]); let args = tcx.mk_args(&[ty.into()]);
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, None) Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, DUMMY_SP)
} }
#[instrument(level = "debug", skip(tcx), ret)] #[instrument(level = "debug", skip(tcx), ret)]

View file

@ -853,13 +853,7 @@ fn visit_fn_use<'tcx>(
) { ) {
if let ty::FnDef(def_id, args) = *ty.kind() { if let ty::FnDef(def_id, args) = *ty.kind() {
let instance = if is_direct_call { let instance = if is_direct_call {
ty::Instance::expect_resolve( ty::Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, source)
tcx,
ty::ParamEnv::reveal_all(),
def_id,
args,
Some(source),
)
} else { } else {
match ty::Instance::resolve_for_fn_ptr(tcx, ty::ParamEnv::reveal_all(), def_id, args) { match ty::Instance::resolve_for_fn_ptr(tcx, ty::ParamEnv::reveal_all(), def_id, args) {
Some(instance) => instance, Some(instance) => instance,
@ -1261,13 +1255,8 @@ fn visit_mentioned_item<'tcx>(
match *item { match *item {
MentionedItem::Fn(ty) => { MentionedItem::Fn(ty) => {
if let ty::FnDef(def_id, args) = *ty.kind() { if let ty::FnDef(def_id, args) = *ty.kind() {
let instance = Instance::expect_resolve( let instance =
tcx, Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, span);
ty::ParamEnv::reveal_all(),
def_id,
args,
Some(span),
);
// `visit_instance_use` was written for "used" item collection but works just as well // `visit_instance_use` was written for "used" item collection but works just as well
// for "mentioned" item collection. // for "mentioned" item collection.
// We can set `is_direct_call`; that just means we'll skip a bunch of shims that anyway // We can set `is_direct_call`; that just means we'll skip a bunch of shims that anyway
@ -1492,7 +1481,7 @@ impl<'v> RootCollector<'_, 'v> {
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
start_def_id, start_def_id,
self.tcx.mk_args(&[main_ret_ty.into()]), self.tcx.mk_args(&[main_ret_ty.into()]),
None, DUMMY_SP,
); );
self.output.push(create_fn_mono_item(self.tcx, start_instance, DUMMY_SP)); self.output.push(create_fn_mono_item(self.tcx, start_instance, DUMMY_SP));
@ -1561,9 +1550,10 @@ fn create_mono_items_for_default_impls<'tcx>(
} }
// As mentioned above, the method is legal to eagerly instantiate if it // As mentioned above, the method is legal to eagerly instantiate if it
// only has lifetime generic parameters. This is validated by // only has lifetime generic parameters. This is validated by calling
// `own_requires_monomorphization` on both the impl and method.
let args = trait_ref.args.extend_to(tcx, method.def_id, only_region_params); let args = trait_ref.args.extend_to(tcx, method.def_id, only_region_params);
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args, None); let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args, DUMMY_SP);
let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP); let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, instance) { if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, instance) {

View file

@ -6,7 +6,7 @@ use rustc_middle::bug;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt, Upcast, VtblEntry}; use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt, Upcast, VtblEntry};
use rustc_middle::ty::{GenericArgs, TypeVisitableExt}; use rustc_middle::ty::{GenericArgs, TypeVisitableExt};
use rustc_span::{sym, Span}; use rustc_span::{sym, Span, DUMMY_SP};
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use std::fmt::Debug; use std::fmt::Debug;
@ -290,6 +290,7 @@ fn vtable_entries<'tcx>(
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
def_id, def_id,
args, args,
DUMMY_SP,
); );
VtblEntry::Method(instance) VtblEntry::Method(instance)