Skip to content

Commit b52522a

Browse files
committedJul 21, 2020
Auto merge of #69749 - davidtwco:issue-46477-polymorphization, r=eddyb
Polymorphization This PR implements an analysis to detect when functions could remain polymorphic during code generation. Fixes #46477 r? @eddyb cc @rust-lang/wg-mir-opt @nikomatsakis @pnkfelix
2 parents 734233d + 4b99699 commit b52522a

File tree

67 files changed

+2034
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2034
-191
lines changed
 

‎src/librustc_codegen_llvm/callee.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use log::debug;
1313
use rustc_codegen_ssa::traits::*;
1414

1515
use rustc_middle::ty::layout::{FnAbiExt, HasTyCtxt};
16-
use rustc_middle::ty::{Instance, TypeFoldable};
16+
use rustc_middle::ty::{self, Instance, TypeFoldable};
1717

1818
/// Codegens a reference to a fn/method item, monomorphizing and
1919
/// inlining as it goes.
@@ -29,14 +29,18 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
2929

3030
assert!(!instance.substs.needs_infer());
3131
assert!(!instance.substs.has_escaping_bound_vars());
32-
assert!(!instance.substs.has_param_types_or_consts());
3332

3433
if let Some(&llfn) = cx.instances.borrow().get(&instance) {
3534
return llfn;
3635
}
3736

3837
let sym = tcx.symbol_name(instance).name;
39-
debug!("get_fn({:?}: {:?}) => {}", instance, instance.monomorphic_ty(cx.tcx()), sym);
38+
debug!(
39+
"get_fn({:?}: {:?}) => {}",
40+
instance,
41+
instance.ty(cx.tcx(), ty::ParamEnv::reveal_all()),
42+
sym
43+
);
4044

4145
let fn_abi = FnAbi::of_instance(cx, instance, &[]);
4246

‎src/librustc_codegen_llvm/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl CodegenCx<'ll, 'tcx> {
203203
def_id
204204
);
205205

206-
let ty = instance.monomorphic_ty(self.tcx);
206+
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
207207
let sym = self.tcx.symbol_name(instance).name;
208208

209209
debug!("get_static: sym={} instance={:?}", sym, instance);
@@ -361,7 +361,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
361361
};
362362

363363
let instance = Instance::mono(self.tcx, def_id);
364-
let ty = instance.monomorphic_ty(self.tcx);
364+
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
365365
let llty = self.layout_of(ty).llvm_type(self);
366366
let g = if val_llty == llty {
367367
g

0 commit comments

Comments
 (0)