Skip to content

Commit 8be7f80

Browse files
committed
Remove monomorphize methods.
1 parent c9100f2 commit 8be7f80

17 files changed

Lines changed: 52 additions & 107 deletions

File tree

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
269269
.mir
270270
.args_iter()
271271
.map(|local| {
272-
let arg_ty = fx.monomorphize(fx.mir.local_decls[local].ty);
272+
let arg_ty = fx.mir.local_decls[local].ty;
273273

274274
// Adapted from https://github.com/rust-lang/rust/blob/145155dc96757002c7b2e9de8489416e2fdbbd57/src/librustc_codegen_llvm/mir/mod.rs#L442-L482
275275
if Some(local) == fx.mir.spread_arg {
@@ -372,7 +372,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
372372
}
373373

374374
for local in fx.mir.vars_and_temps_iter() {
375-
let ty = fx.monomorphize(fx.mir.local_decls[local].ty);
375+
let ty = fx.mir.local_decls[local].ty;
376376
let layout = fx.layout_of(ty);
377377

378378
let is_ssa = ssa_analyzed[local].is_ssa(fx, ty);
@@ -481,9 +481,9 @@ pub(crate) fn codegen_terminator_call<'tcx>(
481481
};
482482

483483
let extra_args = &args[fn_sig.inputs().skip_binder().len()..];
484-
let extra_args = fx.tcx.mk_type_list_from_iter(
485-
extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.node.ty(fx.mir, fx.tcx))),
486-
);
484+
let extra_args = fx
485+
.tcx
486+
.mk_type_list_from_iter(extra_args.iter().map(|op_arg| op_arg.node.ty(fx.mir, fx.tcx)));
487487
let fn_abi = if let Some(instance) = instance {
488488
FullyMonomorphizedLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args)
489489
} else {

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,8 @@ fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func
281281
}
282282

283283
fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
284-
let arg_uninhabited = fx
285-
.mir
286-
.args_iter()
287-
.any(|arg| fx.layout_of(fx.monomorphize(fx.mir.local_decls[arg].ty)).is_uninhabited());
284+
let arg_uninhabited =
285+
fx.mir.args_iter().any(|arg| fx.layout_of(fx.mir.local_decls[arg].ty).is_uninhabited());
288286
if arg_uninhabited {
289287
fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]);
290288
fx.bcx.switch_to_block(fx.block_map[START_BLOCK]);
@@ -688,8 +686,8 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
688686
ref operand,
689687
to_ty,
690688
) => {
691-
let from_ty = fx.monomorphize(operand.ty(&fx.mir.local_decls, fx.tcx));
692-
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
689+
let from_ty = operand.ty(&fx.mir.local_decls, fx.tcx);
690+
let to_layout = fx.layout_of(to_ty);
693691
match *from_ty.kind() {
694692
ty::FnDef(def_id, args) => {
695693
let func_ref = fx.get_function_ref(
@@ -712,7 +710,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
712710
ref operand,
713711
to_ty,
714712
) => {
715-
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
713+
let to_layout = fx.layout_of(to_ty);
716714
let operand = codegen_operand(fx, operand);
717715
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
718716
}
@@ -742,7 +740,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
742740
) => {
743741
let operand = codegen_operand(fx, operand);
744742
let from_ty = operand.layout().ty;
745-
let to_ty = fx.monomorphize(to_ty);
746743

747744
fn is_wide_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
748745
ty.builtin_deref(true).is_some_and(|pointee_ty| {
@@ -814,8 +811,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
814811
}
815812
Rvalue::Repeat(ref operand, times) => {
816813
let operand = codegen_operand(fx, operand);
817-
let times = fx
818-
.monomorphize(times)
814+
let times = times
819815
.try_to_target_usize(fx.tcx)
820816
.expect("expected monomorphic const in codegen");
821817
if operand.layout().size.bytes() == 0 {
@@ -852,7 +848,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
852848
if matches!(**kind, AggregateKind::RawPtr(..)) =>
853849
{
854850
let ty = to_place_and_rval.1.ty(&fx.mir.local_decls, fx.tcx);
855-
let layout = fx.layout_of(fx.monomorphize(ty));
851+
let layout = fx.layout_of(ty);
856852
let [data, meta] = &*operands.raw else {
857853
bug!("RawPtr fields: {operands:?}");
858854
};
@@ -947,8 +943,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
947943
fn codegen_array_len<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx>) -> Value {
948944
match *place.layout().ty.kind() {
949945
ty::Array(_elem_ty, len) => {
950-
let len = fx
951-
.monomorphize(len)
946+
let len = len
952947
.try_to_target_usize(fx.tcx)
953948
.expect("expected monomorphic const in codegen") as i64;
954949
fx.bcx.ins().iconst(fx.pointer_type, len)
@@ -971,7 +966,7 @@ pub(crate) fn codegen_place<'tcx>(
971966
}
972967
PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"),
973968
PlaceElem::UnwrapUnsafeBinder(ty) => {
974-
cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty));
969+
cplace = cplace.place_transmute_type(fx, ty);
975970
}
976971
PlaceElem::Field(field, _ty) => {
977972
cplace = cplace.place_field(fx, field);

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use cranelift_codegen::isa::TargetFrontendConfig;
22
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
33
use rustc_abi::{Float, Integer, Primitive};
44
use rustc_index::IndexVec;
5-
use rustc_middle::ty::TypeFoldable;
65
use rustc_middle::ty::layout::{
76
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers,
87
};
@@ -342,13 +341,6 @@ impl<'tcx> HasTargetSpec for FunctionCx<'_, '_, 'tcx> {
342341
}
343342

344343
impl<'tcx> FunctionCx<'_, '_, 'tcx> {
345-
pub(crate) fn monomorphize<T>(&self, value: T) -> T
346-
where
347-
T: TypeFoldable<TyCtxt<'tcx>> + Copy,
348-
{
349-
value
350-
}
351-
352344
pub(crate) fn clif_type(&self, ty: Ty<'tcx>) -> Option<Type> {
353345
clif_type_from_ty(self.tcx, ty)
354346
}

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
7878
fx: &FunctionCx<'_, '_, 'tcx>,
7979
constant: &ConstOperand<'tcx>,
8080
) -> (ConstValue, Ty<'tcx>) {
81-
let cv = fx.monomorphize(constant.const_);
81+
let cv = constant.const_;
8282
// This cannot fail because we checked all required_consts in advance.
8383
let val = cv
8484
.eval(fx.tcx, ty::TypingEnv::fully_monomorphized(), constant.span)

compiler/rustc_codegen_cranelift/src/inline_asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
111111
.span_err(span, "asm! and global_asm! sym operands are not yet supported");
112112
}
113113

114-
let const_ = fx.monomorphize(value.const_);
114+
let const_ = value.const_;
115115
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
116116
let instance = ty::Instance::resolve_for_fn_ptr(
117117
fx.tcx,

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
180180
}
181181

182182
// Make sure this is actually a SIMD vector.
183-
let idx_ty = fx.monomorphize(idx.node.ty(fx.mir, fx.tcx));
183+
let idx_ty = idx.node.ty(fx.mir, fx.tcx);
184184
if !idx_ty.is_simd()
185185
|| !matches!(idx_ty.simd_size_and_type(fx.tcx).1.kind(), ty::Uint(ty::UintTy::U32))
186186
{

compiler/rustc_codegen_ssa/src/mir/analyze.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ pub(crate) fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2424
.local_decls
2525
.iter()
2626
.map(|decl| {
27-
let ty = fx.monomorphize(decl.ty);
28-
let layout = fx.cx.spanned_layout_of(ty, decl.source_info.span);
27+
let layout = fx.cx.spanned_layout_of(decl.ty, decl.source_info.span);
2928
if layout.is_zst() { LocalKind::ZST } else { LocalKind::Unused }
3029
})
3130
.collect();
@@ -81,8 +80,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'b, 'tcx>> LocalAnalyzer<'a, 'b, 'tcx, Bx>
8180
LocalKind::ZST => {}
8281
LocalKind::Memory => {}
8382
LocalKind::Unused => {
84-
let ty = fx.monomorphize(decl.ty);
85-
let layout = fx.cx.spanned_layout_of(ty, decl.source_info.span);
83+
let layout = fx.cx.spanned_layout_of(decl.ty, decl.source_info.span);
8684
*kind =
8785
if fx.cx.is_backend_immediate(layout) || fx.cx.is_backend_scalar_pair(layout) {
8886
LocalKind::SSA(location)
@@ -138,7 +136,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'b, 'tcx>> LocalAnalyzer<'a, 'b, 'tcx, Bx>
138136

139137
// Scan through to ensure the only projections are those which
140138
// `FunctionCx::maybe_codegen_consume_direct` can handle.
141-
let base_ty = self.fx.monomorphized_place_ty(mir::PlaceRef::from(place_ref.local));
139+
let base_ty = self.fx.mir.local_decls[place_ref.local].ty;
142140
let mut layout = self.fx.cx.layout_of(base_ty);
143141
for elem in place_ref.projection {
144142
layout = match *elem {
@@ -256,7 +254,6 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'b, 'tcx>> Visitor<'tcx> for LocalAnalyzer
256254
let kind = &mut self.locals[local];
257255
if *kind != LocalKind::Memory {
258256
let ty = self.fx.mir.local_decls[local].ty;
259-
let ty = self.fx.monomorphize(ty);
260257
if self.fx.cx.type_needs_drop(ty) {
261258
// Only need the place if we're actually dropping it.
262259
*kind = LocalKind::Memory;

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
609609
mergeable_succ: bool,
610610
) -> MergingSucc {
611611
let ty = location.ty(self.mir, bx.tcx()).ty;
612-
let ty = self.monomorphize(ty);
613612
let drop_fn = Instance::resolve_drop_glue(bx.tcx(), ty);
614613

615614
if let ty::InstanceKind::DropGlue(_, None) = drop_fn.def {
@@ -949,7 +948,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
949948
}
950949

951950
let result_layout =
952-
self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
951+
self.cx.layout_of(destination.ty(self.mir, self.cx.tcx()).ty);
953952

954953
let (result_place, store_in_local) =
955954
if let Some(local) = destination.as_local() {
@@ -1094,8 +1093,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10941093
assert!(!instance.args.has_infer());
10951094
assert!(!instance.args.has_escaping_bound_vars());
10961095

1097-
let result_layout =
1098-
self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
1096+
let result_layout = self.cx.layout_of(destination.ty(self.mir, self.cx.tcx()).ty);
10991097

11001098
let return_dest = if result_layout.is_zst() {
11011099
ReturnDest::Nothing
@@ -1142,10 +1140,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11421140
let sig = callee.layout.ty.fn_sig(bx.tcx());
11431141

11441142
let extra_args = &args[sig.inputs().skip_binder().len()..];
1145-
let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| {
1146-
let op_ty = op_arg.node.ty(self.mir, bx.tcx());
1147-
self.monomorphize(op_ty)
1148-
}));
1143+
let extra_args = bx.tcx().mk_type_list_from_iter(
1144+
extra_args.iter().map(|op_arg| op_arg.node.ty(self.mir, bx.tcx())),
1145+
);
11491146

11501147
let fn_abi = match instance {
11511148
Some(instance) => bx.fn_abi_of_instance(instance, extra_args),
@@ -1445,7 +1442,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14451442
InlineAsmOperandRef::Const { string }
14461443
}
14471444
mir::InlineAsmOperand::SymFn { ref value } => {
1448-
let const_ = self.monomorphize(value.const_);
1445+
let const_ = value.const_;
14491446
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
14501447
let instance = ty::Instance::resolve_for_fn_ptr(
14511448
bx.tcx(),

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1616
constant: &mir::ConstOperand<'tcx>,
1717
) -> OperandRef<'tcx, Bx::Value> {
1818
let val = self.eval_mir_constant(constant);
19-
let ty = self.monomorphize(constant.ty());
19+
let ty = constant.ty();
2020
OperandRef::from_const(bx, val, ty)
2121
}
2222

2323
pub fn eval_mir_constant(&self, constant: &mir::ConstOperand<'tcx>) -> mir::ConstValue {
2424
// `MirUsedCollector` visited all required_consts before codegen began, so if we got here
2525
// there can be no more constants that fail to evaluate.
26-
self.monomorphize(constant.const_)
26+
constant
27+
.const_
2728
.eval(self.cx.tcx(), self.cx.typing_env(), constant.span)
2829
.expect("erroneous constant missed by mono item collection")
2930
}
@@ -39,7 +40,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3940
constant: &mir::ConstOperand<'tcx>,
4041
) -> Result<Result<ty::ValTree<'tcx>, Ty<'tcx>>, ErrorHandled> {
4142
let tcx = self.cx.tcx();
42-
let uv = match self.monomorphize(constant.const_) {
43+
let uv = match constant.const_ {
4344
mir::Const::Unevaluated(uv, _) => uv.shrink(tcx),
4445
mir::Const::Ty(_, c) => match c.kind() {
4546
// A constant that came from a const generic but was then used as an argument to
@@ -57,7 +58,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5758
// real const generic, and get rid of this entire function.
5859
other => span_bug!(constant.span, "{other:#?}"),
5960
};
60-
let uv = self.monomorphize(uv);
6161
tcx.const_eval_resolve_for_typeck(self.cx.typing_env(), uv, constant.span)
6262
}
6363

@@ -67,7 +67,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6767
bx: &Bx,
6868
constant: &mir::ConstOperand<'tcx>,
6969
) -> (Bx::Value, Ty<'tcx>) {
70-
let ty = self.monomorphize(constant.ty());
70+
let ty = constant.ty();
7171
assert!(ty.is_simd());
7272
let field_ty = ty.simd_size_and_type(bx.tcx()).1;
7373

compiler/rustc_codegen_ssa/src/mir/coverageinfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
88
pub(crate) fn codegen_coverage(&self, bx: &mut Bx, kind: &CoverageKind, scope: SourceScope) {
99
// Determine the instance that coverage data was originally generated for.
1010
let instance = if let Some(inlined) = scope.inlined_instance(&self.mir.source_scopes) {
11-
self.monomorphize(inlined)
11+
inlined
1212
} else {
1313
self.instance
1414
};

0 commit comments

Comments
 (0)