mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Give Instance::expect_resolve a span
This commit is contained in:
parent
d3a742bde9
commit
9dc129ae82
@ -371,9 +371,14 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
|
||||
// Handle special calls like intrinsics and empty drop glue.
|
||||
let instance = if let ty::FnDef(def_id, fn_args) = *func.layout().ty.kind() {
|
||||
let instance =
|
||||
ty::Instance::expect_resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, fn_args)
|
||||
.polymorphize(fx.tcx);
|
||||
let instance = ty::Instance::expect_resolve(
|
||||
fx.tcx,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
def_id,
|
||||
fn_args,
|
||||
Some(source_info.span),
|
||||
)
|
||||
.polymorphize(fx.tcx);
|
||||
|
||||
if is_call_from_compiler_builtins_to_upstream_monomorphization(fx.tcx, instance) {
|
||||
if target.is_some() {
|
||||
|
@ -119,6 +119,7 @@ pub(crate) fn maybe_create_entry_wrapper(
|
||||
ParamEnv::reveal_all(),
|
||||
report.def_id,
|
||||
tcx.mk_args(&[GenericArg::from(main_ret_ty)]),
|
||||
None,
|
||||
)
|
||||
.polymorphize(tcx);
|
||||
|
||||
@ -144,6 +145,7 @@ pub(crate) fn maybe_create_entry_wrapper(
|
||||
ParamEnv::reveal_all(),
|
||||
start_def_id,
|
||||
tcx.mk_args(&[main_ret_ty.into()]),
|
||||
None,
|
||||
)
|
||||
.polymorphize(tcx);
|
||||
let start_func_id = import_function(tcx, m, start_instance);
|
||||
|
@ -479,6 +479,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
|
||||
ty::ParamEnv::reveal_all(),
|
||||
def_id,
|
||||
ty::List::empty(),
|
||||
None,
|
||||
);
|
||||
|
||||
let symbol_name = tcx.symbol_name(instance).name;
|
||||
|
@ -580,6 +580,7 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||
ty::ParamEnv::reveal_all(),
|
||||
def_id,
|
||||
ty::List::empty(),
|
||||
None,
|
||||
)),
|
||||
_ => {
|
||||
let name = name.unwrap_or("rust_eh_personality");
|
||||
|
@ -467,6 +467,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
ty::ParamEnv::reveal_all(),
|
||||
start_def_id,
|
||||
cx.tcx().mk_args(&[main_ret_ty.into()]),
|
||||
None,
|
||||
);
|
||||
let start_fn = cx.get_fn_addr(start_instance);
|
||||
|
||||
|
@ -842,6 +842,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
ty::ParamEnv::reveal_all(),
|
||||
def_id,
|
||||
args,
|
||||
Some(fn_span),
|
||||
)
|
||||
.polymorphize(bx.tcx()),
|
||||
),
|
||||
|
@ -253,6 +253,7 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
|
||||
ty::ParamEnv::reveal_all(),
|
||||
const_def_id,
|
||||
instance.args,
|
||||
Some(self.find_closest_untracked_caller_location()),
|
||||
);
|
||||
|
||||
return Ok(Some(new_instance));
|
||||
|
@ -13,7 +13,7 @@ use rustc_macros::{
|
||||
};
|
||||
use rustc_middle::ty::normalize_erasing_regions::NormalizationError;
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_span::{Span, Symbol};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use std::assert_matches::assert_matches;
|
||||
@ -513,10 +513,12 @@ impl<'tcx> Instance<'tcx> {
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
def_id: DefId,
|
||||
args: GenericArgsRef<'tcx>,
|
||||
span: Option<Span>,
|
||||
) -> Instance<'tcx> {
|
||||
match ty::Instance::resolve(tcx, param_env, def_id, args) {
|
||||
Ok(Some(instance)) => instance,
|
||||
instance => bug!(
|
||||
instance => span_bug!(
|
||||
span.unwrap_or(tcx.def_span(def_id)),
|
||||
"failed to resolve instance for {}: {instance:#?}",
|
||||
tcx.def_path_str_with_args(def_id, args)
|
||||
),
|
||||
@ -588,7 +590,7 @@ impl<'tcx> Instance<'tcx> {
|
||||
return Instance { def: InstanceKind::VTableShim(def_id), args };
|
||||
}
|
||||
|
||||
let mut resolved = Instance::expect_resolve(tcx, param_env, def_id, args);
|
||||
let mut resolved = Instance::expect_resolve(tcx, param_env, def_id, args, None);
|
||||
|
||||
let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::Vtable);
|
||||
match resolved.def {
|
||||
@ -665,13 +667,13 @@ impl<'tcx> 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 args = tcx.mk_args(&[ty.into()]);
|
||||
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args)
|
||||
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, None)
|
||||
}
|
||||
|
||||
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 args = tcx.mk_args(&[ty.into()]);
|
||||
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args)
|
||||
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, None)
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(tcx), ret)]
|
||||
|
@ -916,7 +916,13 @@ fn visit_fn_use<'tcx>(
|
||||
) {
|
||||
if let ty::FnDef(def_id, args) = *ty.kind() {
|
||||
let instance = if is_direct_call {
|
||||
ty::Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args)
|
||||
ty::Instance::expect_resolve(
|
||||
tcx,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
def_id,
|
||||
args,
|
||||
Some(source),
|
||||
)
|
||||
} else {
|
||||
match ty::Instance::resolve_for_fn_ptr(tcx, ty::ParamEnv::reveal_all(), def_id, args) {
|
||||
Some(instance) => instance,
|
||||
@ -1318,8 +1324,13 @@ fn visit_mentioned_item<'tcx>(
|
||||
match *item {
|
||||
MentionedItem::Fn(ty) => {
|
||||
if let ty::FnDef(def_id, args) = *ty.kind() {
|
||||
let instance =
|
||||
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args);
|
||||
let instance = Instance::expect_resolve(
|
||||
tcx,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
def_id,
|
||||
args,
|
||||
Some(span),
|
||||
);
|
||||
// `visit_instance_use` was written for "used" item collection but works just as well
|
||||
// for "mentioned" item collection.
|
||||
// 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> {
|
||||
ty::ParamEnv::reveal_all(),
|
||||
start_def_id,
|
||||
self.tcx.mk_args(&[main_ret_ty.into()]),
|
||||
None,
|
||||
);
|
||||
|
||||
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>(
|
||||
// As mentioned above, the method is legal to eagerly instantiate if it
|
||||
// only has lifetime generic parameters. This is validated by
|
||||
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);
|
||||
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args, None);
|
||||
|
||||
let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
|
||||
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, instance) {
|
||||
|
Loading…
Reference in New Issue
Block a user