bug! with a better error message for failing Instance::resolve
This commit is contained in:
parent
d137783642
commit
bc293ed53e
4 changed files with 34 additions and 15 deletions
|
@ -349,10 +349,9 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
|
|
||||||
// Handle special calls like intrinsics and empty drop glue.
|
// Handle special calls like intrinsics and empty drop glue.
|
||||||
let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() {
|
let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() {
|
||||||
let instance = ty::Instance::resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs)
|
let instance =
|
||||||
.unwrap()
|
ty::Instance::expect_resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs)
|
||||||
.unwrap()
|
.polymorphize(fx.tcx);
|
||||||
.polymorphize(fx.tcx);
|
|
||||||
|
|
||||||
if fx.tcx.symbol_name(instance).name.starts_with("llvm.") {
|
if fx.tcx.symbol_name(instance).name.starts_with("llvm.") {
|
||||||
crate::intrinsics::codegen_llvm_intrinsic_call(
|
crate::intrinsics::codegen_llvm_intrinsic_call(
|
||||||
|
|
|
@ -751,10 +751,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
let (instance, mut llfn) = match *callee.layout.ty.kind() {
|
let (instance, mut llfn) = match *callee.layout.ty.kind() {
|
||||||
ty::FnDef(def_id, substs) => (
|
ty::FnDef(def_id, substs) => (
|
||||||
Some(
|
Some(
|
||||||
ty::Instance::resolve(bx.tcx(), ty::ParamEnv::reveal_all(), def_id, substs)
|
ty::Instance::expect_resolve(
|
||||||
.unwrap()
|
bx.tcx(),
|
||||||
.unwrap()
|
ty::ParamEnv::reveal_all(),
|
||||||
.polymorphize(bx.tcx()),
|
def_id,
|
||||||
|
substs,
|
||||||
|
)
|
||||||
|
.polymorphize(bx.tcx()),
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
|
|
|
@ -385,6 +385,21 @@ impl<'tcx> Instance<'tcx> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn expect_resolve(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
|
def_id: DefId,
|
||||||
|
substs: SubstsRef<'tcx>,
|
||||||
|
) -> Instance<'tcx> {
|
||||||
|
match ty::Instance::resolve(tcx, param_env, def_id, substs) {
|
||||||
|
Ok(Some(instance)) => instance,
|
||||||
|
_ => bug!(
|
||||||
|
"failed to resolve instance for {}",
|
||||||
|
tcx.def_path_str_with_substs(def_id, substs)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This should be kept up to date with `resolve`.
|
// This should be kept up to date with `resolve`.
|
||||||
pub fn resolve_opt_const_arg(
|
pub fn resolve_opt_const_arg(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
@ -525,7 +540,7 @@ 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 substs = tcx.intern_substs(&[ty.into()]);
|
let substs = tcx.intern_substs(&[ty.into()]);
|
||||||
Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap().unwrap()
|
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(tcx), ret)]
|
#[instrument(level = "debug", skip(tcx), ret)]
|
||||||
|
|
|
@ -931,10 +931,13 @@ fn visit_fn_use<'tcx>(
|
||||||
) {
|
) {
|
||||||
if let ty::FnDef(def_id, substs) = *ty.kind() {
|
if let ty::FnDef(def_id, substs) = *ty.kind() {
|
||||||
let instance = if is_direct_call {
|
let instance = if is_direct_call {
|
||||||
ty::Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap().unwrap()
|
ty::Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs)
|
||||||
} else {
|
} else {
|
||||||
ty::Instance::resolve_for_fn_ptr(tcx, ty::ParamEnv::reveal_all(), def_id, substs)
|
match ty::Instance::resolve_for_fn_ptr(tcx, ty::ParamEnv::reveal_all(), def_id, substs)
|
||||||
.unwrap()
|
{
|
||||||
|
Some(instance) => instance,
|
||||||
|
_ => bug!("failed to resolve instance for {ty}"),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
visit_instance_use(tcx, instance, is_direct_call, source, output);
|
visit_instance_use(tcx, instance, is_direct_call, source, output);
|
||||||
}
|
}
|
||||||
|
@ -1369,9 +1372,8 @@ fn create_mono_items_for_default_impls<'tcx>(
|
||||||
trait_ref.substs[param.index as usize]
|
trait_ref.substs[param.index as usize]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let instance = ty::Instance::resolve(tcx, param_env, method.def_id, substs)
|
let instance =
|
||||||
.unwrap()
|
ty::Instance::expect_resolve(tcx, param_env, method.def_id, substs);
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue