Skip to content

Commit 86c5944

Browse files
authored
Merge pull request #1144 from bjorn3/dynamic_module
Use dynamic dispatch for the inner Module
2 parents c247446 + 73d3a1c commit 86c5944

28 files changed

+172
-229
lines changed

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/abi/comments.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ use cranelift_codegen::entity::EntityRef;
1010

1111
use crate::prelude::*;
1212

13-
pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
13+
pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, '_>) {
1414
fx.add_global_comment(
1515
"kind loc.idx param pass mode ty".to_string(),
1616
);
1717
}
1818

1919
pub(super) fn add_arg_comment<'tcx>(
20-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
20+
fx: &mut FunctionCx<'_, '_, 'tcx>,
2121
kind: &str,
2222
local: Option<mir::Local>,
2323
local_field: Option<usize>,
@@ -62,15 +62,15 @@ pub(super) fn add_arg_comment<'tcx>(
6262
));
6363
}
6464

65-
pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
65+
pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, '_>) {
6666
fx.add_global_comment(String::new());
6767
fx.add_global_comment(
6868
"kind local ty size align (abi,pref)".to_string(),
6969
);
7070
}
7171

7272
pub(super) fn add_local_place_comments<'tcx>(
73-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
73+
fx: &mut FunctionCx<'_, '_, 'tcx>,
7474
place: CPlace<'tcx>,
7575
local: Local,
7676
) {

src/abi/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub(crate) fn get_function_sig<'tcx>(
7373
/// Instance must be monomorphized
7474
pub(crate) fn import_function<'tcx>(
7575
tcx: TyCtxt<'tcx>,
76-
module: &mut impl Module,
76+
module: &mut dyn Module,
7777
inst: Instance<'tcx>,
7878
) -> FuncId {
7979
let name = tcx.symbol_name(inst).name.to_string();
@@ -83,10 +83,10 @@ pub(crate) fn import_function<'tcx>(
8383
.unwrap()
8484
}
8585

86-
impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
86+
impl<'tcx> FunctionCx<'_, '_, 'tcx> {
8787
/// Instance must be monomorphized
8888
pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
89-
let func_id = import_function(self.tcx, &mut self.cx.module, inst);
89+
let func_id = import_function(self.tcx, self.cx.module, inst);
9090
let func_ref = self
9191
.cx
9292
.module
@@ -167,7 +167,7 @@ impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
167167

168168
/// Make a [`CPlace`] capable of holding value of the specified type.
169169
fn make_local_place<'tcx>(
170-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
170+
fx: &mut FunctionCx<'_, '_, 'tcx>,
171171
local: Local,
172172
layout: TyAndLayout<'tcx>,
173173
is_ssa: bool,
@@ -188,10 +188,7 @@ fn make_local_place<'tcx>(
188188
place
189189
}
190190

191-
pub(crate) fn codegen_fn_prelude<'tcx>(
192-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
193-
start_block: Block,
194-
) {
191+
pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_block: Block) {
195192
fx.bcx.append_block_params_for_function_params(start_block);
196193

197194
fx.bcx.switch_to_block(start_block);
@@ -344,7 +341,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
344341
}
345342

346343
pub(crate) fn codegen_terminator_call<'tcx>(
347-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
344+
fx: &mut FunctionCx<'_, '_, 'tcx>,
348345
span: Span,
349346
current_block: Block,
350347
func: &Operand<'tcx>,
@@ -572,7 +569,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
572569
}
573570

574571
pub(crate) fn codegen_drop<'tcx>(
575-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
572+
fx: &mut FunctionCx<'_, '_, 'tcx>,
576573
span: Span,
577574
drop_place: CPlace<'tcx>,
578575
) {

src/abi/pass_mode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
199199
}
200200

201201
pub(super) fn to_casted_value<'tcx>(
202-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
202+
fx: &mut FunctionCx<'_, '_, 'tcx>,
203203
arg: CValue<'tcx>,
204204
cast: CastTarget,
205205
) -> SmallVec<[Value; 2]> {
@@ -219,7 +219,7 @@ pub(super) fn to_casted_value<'tcx>(
219219
}
220220

221221
pub(super) fn from_casted_value<'tcx>(
222-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
222+
fx: &mut FunctionCx<'_, '_, 'tcx>,
223223
block_params: &[Value],
224224
layout: TyAndLayout<'tcx>,
225225
cast: CastTarget,
@@ -258,7 +258,7 @@ pub(super) fn from_casted_value<'tcx>(
258258

259259
/// Get a set of values to be passed as function arguments.
260260
pub(super) fn adjust_arg_for_abi<'tcx>(
261-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
261+
fx: &mut FunctionCx<'_, '_, 'tcx>,
262262
arg: CValue<'tcx>,
263263
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
264264
) -> SmallVec<[Value; 2]> {
@@ -281,7 +281,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
281281
/// Create a [`CValue`] containing the value of a function parameter adding clif function parameters
282282
/// as necessary.
283283
pub(super) fn cvalue_for_param<'tcx>(
284-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
284+
fx: &mut FunctionCx<'_, '_, 'tcx>,
285285
#[cfg_attr(not(debug_assertions), allow(unused_variables))] local: Option<mir::Local>,
286286
#[cfg_attr(not(debug_assertions), allow(unused_variables))] local_field: Option<usize>,
287287
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,

src/abi/returning.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use smallvec::{smallvec, SmallVec};
88

99
/// Can the given type be returned into an ssa var or does it need to be returned on the stack.
1010
pub(crate) fn can_return_to_ssa_var<'tcx>(
11-
fx: &FunctionCx<'_, 'tcx, impl Module>,
11+
fx: &FunctionCx<'_, '_, 'tcx>,
1212
func: &mir::Operand<'tcx>,
1313
args: &[mir::Operand<'tcx>],
1414
) -> bool {
@@ -58,7 +58,7 @@ pub(crate) fn can_return_to_ssa_var<'tcx>(
5858
/// Return a place where the return value of the current function can be written to. If necessary
5959
/// this adds an extra parameter pointing to where the return value needs to be stored.
6060
pub(super) fn codegen_return_param<'tcx>(
61-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
61+
fx: &mut FunctionCx<'_, '_, 'tcx>,
6262
ssa_analyzed: &rustc_index::vec::IndexVec<Local, crate::analyze::SsaKind>,
6363
block_params_iter: &mut impl Iterator<Item = Value>,
6464
) -> CPlace<'tcx> {
@@ -120,11 +120,11 @@ pub(super) fn codegen_return_param<'tcx>(
120120

121121
/// Invokes the closure with if necessary a value representing the return pointer. When the closure
122122
/// returns the call return value(s) if any are written to the correct place.
123-
pub(super) fn codegen_with_call_return_arg<'tcx, M: Module, T>(
124-
fx: &mut FunctionCx<'_, 'tcx, M>,
123+
pub(super) fn codegen_with_call_return_arg<'tcx, T>(
124+
fx: &mut FunctionCx<'_, '_, 'tcx>,
125125
ret_arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
126126
ret_place: Option<CPlace<'tcx>>,
127-
f: impl FnOnce(&mut FunctionCx<'_, 'tcx, M>, Option<Value>) -> (Inst, T),
127+
f: impl FnOnce(&mut FunctionCx<'_, '_, 'tcx>, Option<Value>) -> (Inst, T),
128128
) -> (Inst, T) {
129129
let return_ptr = match ret_arg_abi.mode {
130130
PassMode::Ignore => None,
@@ -193,7 +193,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, M: Module, T>(
193193
}
194194

195195
/// Codegen a return instruction with the right return value(s) if any.
196-
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, impl Module>) {
196+
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) {
197197
match fx.fn_abi.as_ref().unwrap().ret.mode {
198198
PassMode::Ignore
199199
| PassMode::Indirect {

src/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) enum SsaKind {
1111
Ssa,
1212
}
1313

14-
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Module>) -> IndexVec<Local, SsaKind> {
14+
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
1515
let mut flag_map = fx
1616
.mir
1717
.local_decls

src/base.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_target::abi::call::FnAbi;
88
use crate::prelude::*;
99

1010
pub(crate) fn codegen_fn<'tcx>(
11-
cx: &mut crate::CodegenCx<'tcx, impl Module>,
11+
cx: &mut crate::CodegenCx<'_, 'tcx>,
1212
instance: Instance<'tcx>,
1313
linkage: Linkage,
1414
) {
@@ -209,7 +209,7 @@ pub(crate) fn verify_func(
209209
});
210210
}
211211

212-
fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
212+
fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) {
213213
for (bb, bb_data) in fx.mir.basic_blocks().iter_enumerated() {
214214
let block = fx.get_block(bb);
215215
fx.bcx.switch_to_block(block);
@@ -453,7 +453,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
453453
}
454454

455455
fn codegen_stmt<'tcx>(
456-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
456+
fx: &mut FunctionCx<'_, '_, 'tcx>,
457457
#[allow(unused_variables)] cur_block: Block,
458458
stmt: &Statement<'tcx>,
459459
) {
@@ -595,10 +595,7 @@ fn codegen_stmt<'tcx>(
595595
let from_ty = operand.layout().ty;
596596
let to_ty = fx.monomorphize(to_ty);
597597

598-
fn is_fat_ptr<'tcx>(
599-
fx: &FunctionCx<'_, 'tcx, impl Module>,
600-
ty: Ty<'tcx>,
601-
) -> bool {
598+
fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
602599
ty.builtin_deref(true)
603600
.map(
604601
|ty::TypeAndMut {
@@ -895,10 +892,7 @@ fn codegen_stmt<'tcx>(
895892
}
896893
}
897894

898-
fn codegen_array_len<'tcx>(
899-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
900-
place: CPlace<'tcx>,
901-
) -> Value {
895+
fn codegen_array_len<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx>) -> Value {
902896
match *place.layout().ty.kind() {
903897
ty::Array(_elem_ty, len) => {
904898
let len = fx
@@ -915,7 +909,7 @@ fn codegen_array_len<'tcx>(
915909
}
916910

917911
pub(crate) fn codegen_place<'tcx>(
918-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
912+
fx: &mut FunctionCx<'_, '_, 'tcx>,
919913
place: Place<'tcx>,
920914
) -> CPlace<'tcx> {
921915
let mut cplace = fx.get_local_place(place.local);
@@ -987,7 +981,7 @@ pub(crate) fn codegen_place<'tcx>(
987981
}
988982

989983
pub(crate) fn codegen_operand<'tcx>(
990-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
984+
fx: &mut FunctionCx<'_, '_, 'tcx>,
991985
operand: &Operand<'tcx>,
992986
) -> CValue<'tcx> {
993987
match operand {
@@ -999,11 +993,7 @@ pub(crate) fn codegen_operand<'tcx>(
999993
}
1000994
}
1001995

1002-
pub(crate) fn codegen_panic<'tcx>(
1003-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
1004-
msg_str: &str,
1005-
span: Span,
1006-
) {
996+
pub(crate) fn codegen_panic<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, msg_str: &str, span: Span) {
1007997
let location = fx.get_caller_location(span).load_scalar(fx);
1008998

1009999
let msg_ptr = fx.anonymous_str("assert", msg_str);
@@ -1017,7 +1007,7 @@ pub(crate) fn codegen_panic<'tcx>(
10171007
}
10181008

10191009
pub(crate) fn codegen_panic_inner<'tcx>(
1020-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
1010+
fx: &mut FunctionCx<'_, '_, 'tcx>,
10211011
lang_item: rustc_hir::LangItem,
10221012
args: &[Value],
10231013
span: Span,

src/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::prelude::*;
44

55
pub(crate) fn clif_intcast(
6-
fx: &mut FunctionCx<'_, '_, impl Module>,
6+
fx: &mut FunctionCx<'_, '_, '_>,
77
val: Value,
88
to: Type,
99
signed: bool,
@@ -51,7 +51,7 @@ pub(crate) fn clif_intcast(
5151
}
5252

5353
pub(crate) fn clif_int_or_float_cast(
54-
fx: &mut FunctionCx<'_, '_, impl Module>,
54+
fx: &mut FunctionCx<'_, '_, '_>,
5555
from: Value,
5656
from_signed: bool,
5757
to_ty: Type,

src/codegen_i128.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use cranelift_codegen::ir::ArgumentPurpose;
55
use crate::prelude::*;
66

77
pub(crate) fn maybe_codegen<'tcx>(
8-
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
8+
fx: &mut FunctionCx<'_, '_, 'tcx>,
99
bin_op: BinOp,
1010
checked: bool,
1111
lhs: CValue<'tcx>,

0 commit comments

Comments
 (0)