Skip to content

Commit 0132738

Browse files
committed
Reifying callers of Instance::resolve use resolve_for_fn_ptr.
1 parent f5f67e7 commit 0132738

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

src/librustc/ty/instance.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// use crate::hir::CodegenFnAttrFlags;
12
use crate::hir::Unsafety;
23
use crate::hir::def::Namespace;
34
use crate::hir::def_id::DefId;
@@ -304,12 +305,8 @@ impl<'tcx> Instance<'tcx> {
304305
substs: SubstsRef<'tcx>,
305306
) -> Option<Instance<'tcx>> {
306307
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
307-
let fn_sig = tcx.fn_sig(def_id);
308-
// let is_reify_shim = fn_sig.inputs().skip_binder().len() > 0
309-
// && fn_sig.input(0).skip_binder().is_param(0)
310-
// && tcx.generics_of(def_id).has_self;
311-
if is_reify_shim {
312-
debug!(" => fn ptr with implicit caller location");
308+
if false {
309+
debug!(" => fn pointer created for function with #[track_caller]");
313310
Some(Instance {
314311
def: InstanceDef::ReifyShim(def_id),
315312
substs,

src/librustc_codegen_ssa/callee.rs

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ pub fn resolve_and_get_fn<'tcx, Cx: CodegenMethods<'tcx>>(
1818
)
1919
}
2020

21+
pub fn resolve_and_get_fn_for_ptr<'tcx,
22+
Cx: Backend<'tcx> + MiscMethods<'tcx> + TypeMethods<'tcx>
23+
>(
24+
cx: &Cx,
25+
def_id: DefId,
26+
substs: SubstsRef<'tcx>,
27+
) -> Cx::Value {
28+
cx.get_fn(
29+
ty::Instance::resolve_for_fn_ptr(
30+
cx.tcx(),
31+
ty::ParamEnv::reveal_all(),
32+
def_id,
33+
substs
34+
).unwrap()
35+
)
36+
}
37+
2138
pub fn resolve_and_get_fn_for_vtable<'tcx,
2239
Cx: Backend<'tcx> + MiscMethods<'tcx> + TypeMethods<'tcx>
2340
>(

src/librustc_codegen_ssa/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
190190
bug!("reifying a fn ptr that requires const arguments");
191191
}
192192
OperandValue::Immediate(
193-
callee::resolve_and_get_fn(bx.cx(), def_id, substs))
193+
callee::resolve_and_get_fn_for_ptr(bx.cx(), def_id, substs))
194194
}
195195
_ => {
196196
bug!("{} cannot be reified to a fn ptr", operand.layout.ty)

src/librustc_mir/monomorphize/collector.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -721,10 +721,12 @@ fn visit_fn_use<'tcx>(
721721
output: &mut Vec<MonoItem<'tcx>>,
722722
) {
723723
if let ty::FnDef(def_id, substs) = ty.kind {
724-
let instance = ty::Instance::resolve(tcx,
725-
ty::ParamEnv::reveal_all(),
726-
def_id,
727-
substs).unwrap();
724+
let resolver = if is_direct_call {
725+
ty::Instance::resolve
726+
} else {
727+
ty::Instance::resolve_for_fn_ptr
728+
};
729+
let instance = resolver(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap();
728730
visit_instance_use(tcx, instance, is_direct_call, output);
729731
}
730732
}

src/librustc_mir/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
4545
build_call_shim(
4646
tcx,
4747
def_id,
48-
Adjustment::DerefMove,
48+
Adjustment::Identity, // TODO(anp) is this the right kind of adjustment?
4949
CallKind::Direct(def_id),
5050
None,
5151
)

0 commit comments

Comments
 (0)