Skip to content

Commit 9dc129a

Browse files
Give Instance::expect_resolve a span
1 parent d3a742b commit 9dc129a

File tree

9 files changed

+38
-12
lines changed

9 files changed

+38
-12
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,14 @@ pub(crate) fn codegen_terminator_call<'tcx>(
371371

372372
// Handle special calls like intrinsics and empty drop glue.
373373
let instance = if let ty::FnDef(def_id, fn_args) = *func.layout().ty.kind() {
374-
let instance =
375-
ty::Instance::expect_resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, fn_args)
376-
.polymorphize(fx.tcx);
374+
let instance = ty::Instance::expect_resolve(
375+
fx.tcx,
376+
ty::ParamEnv::reveal_all(),
377+
def_id,
378+
fn_args,
379+
Some(source_info.span),
380+
)
381+
.polymorphize(fx.tcx);
377382

378383
if is_call_from_compiler_builtins_to_upstream_monomorphization(fx.tcx, instance) {
379384
if target.is_some() {

compiler/rustc_codegen_cranelift/src/main_shim.rs

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub(crate) fn maybe_create_entry_wrapper(
119119
ParamEnv::reveal_all(),
120120
report.def_id,
121121
tcx.mk_args(&[GenericArg::from(main_ret_ty)]),
122+
None,
122123
)
123124
.polymorphize(tcx);
124125

@@ -144,6 +145,7 @@ pub(crate) fn maybe_create_entry_wrapper(
144145
ParamEnv::reveal_all(),
145146
start_def_id,
146147
tcx.mk_args(&[main_ret_ty.into()]),
148+
None,
147149
)
148150
.polymorphize(tcx);
149151
let start_func_id = import_function(tcx, m, start_instance);

compiler/rustc_codegen_gcc/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
479479
ty::ParamEnv::reveal_all(),
480480
def_id,
481481
ty::List::empty(),
482+
None,
482483
);
483484

484485
let symbol_name = tcx.symbol_name(instance).name;

compiler/rustc_codegen_llvm/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
580580
ty::ParamEnv::reveal_all(),
581581
def_id,
582582
ty::List::empty(),
583+
None,
583584
)),
584585
_ => {
585586
let name = name.unwrap_or("rust_eh_personality");

compiler/rustc_codegen_ssa/src/base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
467467
ty::ParamEnv::reveal_all(),
468468
start_def_id,
469469
cx.tcx().mk_args(&[main_ret_ty.into()]),
470+
None,
470471
);
471472
let start_fn = cx.get_fn_addr(start_instance);
472473

compiler/rustc_codegen_ssa/src/mir/block.rs

+1
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
842842
ty::ParamEnv::reveal_all(),
843843
def_id,
844844
args,
845+
Some(fn_span),
845846
)
846847
.polymorphize(bx.tcx()),
847848
),

compiler/rustc_const_eval/src/const_eval/machine.rs

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
253253
ty::ParamEnv::reveal_all(),
254254
const_def_id,
255255
instance.args,
256+
Some(self.find_closest_untracked_caller_location()),
256257
);
257258

258259
return Ok(Some(new_instance));

compiler/rustc_middle/src/ty/instance.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_macros::{
1313
};
1414
use rustc_middle::ty::normalize_erasing_regions::NormalizationError;
1515
use rustc_span::def_id::LOCAL_CRATE;
16-
use rustc_span::Symbol;
16+
use rustc_span::{Span, Symbol};
1717
use tracing::{debug, instrument};
1818

1919
use std::assert_matches::assert_matches;
@@ -513,10 +513,12 @@ impl<'tcx> Instance<'tcx> {
513513
param_env: ty::ParamEnv<'tcx>,
514514
def_id: DefId,
515515
args: GenericArgsRef<'tcx>,
516+
span: Option<Span>,
516517
) -> Instance<'tcx> {
517518
match ty::Instance::resolve(tcx, param_env, def_id, args) {
518519
Ok(Some(instance)) => instance,
519-
instance => bug!(
520+
instance => span_bug!(
521+
span.unwrap_or(tcx.def_span(def_id)),
520522
"failed to resolve instance for {}: {instance:#?}",
521523
tcx.def_path_str_with_args(def_id, args)
522524
),
@@ -588,7 +590,7 @@ impl<'tcx> Instance<'tcx> {
588590
return Instance { def: InstanceKind::VTableShim(def_id), args };
589591
}
590592

591-
let mut resolved = Instance::expect_resolve(tcx, param_env, def_id, args);
593+
let mut resolved = Instance::expect_resolve(tcx, param_env, def_id, args, None);
592594

593595
let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::Vtable);
594596
match resolved.def {
@@ -665,13 +667,13 @@ impl<'tcx> Instance<'tcx> {
665667
pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
666668
let def_id = tcx.require_lang_item(LangItem::DropInPlace, None);
667669
let args = tcx.mk_args(&[ty.into()]);
668-
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args)
670+
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, None)
669671
}
670672

671673
pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
672674
let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, None);
673675
let args = tcx.mk_args(&[ty.into()]);
674-
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args)
676+
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, None)
675677
}
676678

677679
#[instrument(level = "debug", skip(tcx), ret)]

compiler/rustc_monomorphize/src/collector.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,13 @@ fn visit_fn_use<'tcx>(
916916
) {
917917
if let ty::FnDef(def_id, args) = *ty.kind() {
918918
let instance = if is_direct_call {
919-
ty::Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args)
919+
ty::Instance::expect_resolve(
920+
tcx,
921+
ty::ParamEnv::reveal_all(),
922+
def_id,
923+
args,
924+
Some(source),
925+
)
920926
} else {
921927
match ty::Instance::resolve_for_fn_ptr(tcx, ty::ParamEnv::reveal_all(), def_id, args) {
922928
Some(instance) => instance,
@@ -1318,8 +1324,13 @@ fn visit_mentioned_item<'tcx>(
13181324
match *item {
13191325
MentionedItem::Fn(ty) => {
13201326
if let ty::FnDef(def_id, args) = *ty.kind() {
1321-
let instance =
1322-
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args);
1327+
let instance = Instance::expect_resolve(
1328+
tcx,
1329+
ty::ParamEnv::reveal_all(),
1330+
def_id,
1331+
args,
1332+
Some(span),
1333+
);
13231334
// `visit_instance_use` was written for "used" item collection but works just as well
13241335
// for "mentioned" item collection.
13251336
// We can set `is_direct_call`; that just means we'll skip a bunch of shims that anyway
@@ -1544,6 +1555,7 @@ impl<'v> RootCollector<'_, 'v> {
15441555
ty::ParamEnv::reveal_all(),
15451556
start_def_id,
15461557
self.tcx.mk_args(&[main_ret_ty.into()]),
1558+
None,
15471559
);
15481560

15491561
self.output.push(create_fn_mono_item(self.tcx, start_instance, DUMMY_SP));
@@ -1614,7 +1626,7 @@ fn create_mono_items_for_default_impls<'tcx>(
16141626
// As mentioned above, the method is legal to eagerly instantiate if it
16151627
// only has lifetime generic parameters. This is validated by
16161628
let args = trait_ref.args.extend_to(tcx, method.def_id, only_region_params);
1617-
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args);
1629+
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args, None);
16181630

16191631
let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
16201632
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, instance) {

0 commit comments

Comments
 (0)