Skip to content

Commit d97f0ce

Browse files
committed
Refactors reducing compile times.
1 parent bb92cbb commit d97f0ce

File tree

12 files changed

+94
-145
lines changed

12 files changed

+94
-145
lines changed

cilly/src/v2/builtins/atomics.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ pub fn emulate_uint8_cmp_xchng(asm: &mut Assembly, patcher: &mut MissingMethodPa
1414
asm,
1515
patcher,
1616
"cmpxchng8",
17-
|asm, prev, arg, _| {
17+
Box::new(|asm, prev, arg, _| {
1818
// 1st, mask the previous value
1919
let prev_mask = asm.alloc_node(Const::I32(0xFFFF_FF00_u32 as i32));
2020
let prev = asm.alloc_node(CILNode::BinOp(prev, prev_mask, BinOp::And));
2121

2222
asm.alloc_node(CILNode::BinOp(prev, arg, BinOp::Or))
23-
},
23+
}),
2424
Int::I32,
2525
);
2626
generate_atomic(
2727
asm,
2828
patcher,
2929
"cmpxchng16",
30-
|asm, prev, arg, _| {
30+
Box::new(|asm, prev, arg, _| {
3131
// 1st, mask the previous value
3232
let prev_mask = asm.alloc_node(Const::I32(0xFFFF_0000_u32 as i32));
3333
let prev = asm.alloc_node(CILNode::BinOp(prev, prev_mask, BinOp::And));
3434

3535
asm.alloc_node(CILNode::BinOp(prev, arg, BinOp::Or))
36-
},
36+
}),
3737
Int::I32,
3838
);
3939
let name = asm.alloc_string("atomic_xchng_u8");
@@ -134,7 +134,7 @@ pub fn generate_atomic(
134134
asm: &mut Assembly,
135135
patcher: &mut MissingMethodPatcher,
136136
op_name: &str,
137-
op: impl Fn(&mut Assembly, NodeIdx, NodeIdx, Int) -> NodeIdx + 'static,
137+
op: Box<(dyn Fn(&mut Assembly, NodeIdx, NodeIdx, Int) -> NodeIdx)>,
138138
int: Int,
139139
) {
140140
let name = asm.alloc_string(format!("atomic_{op_name}_{int}", int = int.name()));
@@ -197,7 +197,7 @@ pub fn generate_atomic_for_ints(
197197
Int::ISize,
198198
];
199199
for int in ATOMIC_INTS {
200-
generate_atomic(asm, patcher, op_name, op.clone(), int);
200+
generate_atomic(asm, patcher, op_name, Box::new(op.clone()), int);
201201
}
202202
}
203203
/// Adds all the builitn atomic functions to the patcher, allowing for their use.
@@ -228,21 +228,21 @@ pub fn generate_all_atomics(asm: &mut Assembly, patcher: &mut MissingMethodPatch
228228
asm,
229229
patcher,
230230
"or",
231-
|asm, lhs, rhs, _| asm.alloc_node(CILNode::BinOp(lhs, rhs, BinOp::Or)),
231+
Box:: new(|asm, lhs, rhs, _| asm.alloc_node(CILNode::BinOp(lhs, rhs, BinOp::Or))),
232232
int,
233233
);
234234
generate_atomic(
235235
asm,
236236
patcher,
237237
"and",
238-
|asm, lhs, rhs, _| asm.alloc_node(CILNode::BinOp(lhs, rhs, BinOp::And)),
238+
Box:: new(|asm, lhs, rhs, _| asm.alloc_node(CILNode::BinOp(lhs, rhs, BinOp::And))),
239239
int,
240240
);
241241
generate_atomic(
242242
asm,
243243
patcher,
244244
"add",
245-
|asm, lhs, rhs, _| asm.alloc_node(CILNode::BinOp(lhs, rhs, BinOp::Add)),
245+
Box:: new(|asm, lhs, rhs, _| asm.alloc_node(CILNode::BinOp(lhs, rhs, BinOp::Add))),
246246
int,
247247
);
248248
}

cilly/src/v2/cilnode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ impl CILNode {
868868
pub fn map(
869869
self,
870870
asm: &mut Assembly,
871-
map: &mut impl FnMut(Self, &mut Assembly) -> Self,
871+
map: &mut dyn FnMut(Self, &mut Assembly) -> Self,
872872
) -> Self {
873873
match self {
874874
CILNode::Const(_)

cilly/src/v2/cilroot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ impl CILRoot {
493493
pub fn map(
494494
self,
495495
asm: &mut Assembly,
496-
root_map: &mut impl FnMut(Self, &mut Assembly) -> Self,
497-
node_map: &mut impl FnMut(CILNode, &mut Assembly) -> CILNode,
496+
root_map: &mut dyn FnMut(Self, &mut Assembly) -> Self,
497+
node_map: &mut dyn FnMut(CILNode, &mut Assembly) -> CILNode,
498498
) -> Self {
499499
match self {
500500
CILRoot::Unreachable(_) => root_map(self, asm),

src/assembly.rs

-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,6 @@ pub fn add_const_value(asm: &mut cilly::v2::Assembly, bytes: u128) -> StaticFiel
866866
field_desc
867867
}
868868

869-
870869
pub(crate) fn span_source_info(tcx: TyCtxt, span: rustc_span::Span) -> CILRoot {
871870
let (file, lstart, cstart, lend, mut cend) = tcx.sess.source_map().span_to_location_info(span);
872871
let file = file.map_or(String::new(), |file| {

src/call_info.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use crate::fn_ctx::MethodCompileCtx;
2+
use crate::r#type::get_type;
13
use cilly::v2::FnSig;
4+
use rustc_abi::ExternAbi as TargetAbi;
25
use rustc_middle::ty::{Instance, List, PseudoCanonicalInput, TyKind};
36
use rustc_target::callconv::Conv;
4-
use rustc_abi::ExternAbi as TargetAbi;
5-
use crate::fn_ctx::MethodCompileCtx;
6-
use crate::r#type::get_type;
77
pub struct CallInfo {
88
sig: FnSig,
99
split_last_tuple: bool,

src/function_sig.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::codegen_error::CodegenError;
22
use crate::fn_ctx::MethodCompileCtx;
33
use crate::r#type::get_type;
44
use cilly::{v2::FnSig, Type};
5+
use rustc_abi::ExternAbi as TargetAbi;
56
use rustc_middle::ty::{Instance, List, Ty, TyCtxt, TyKind};
67
use rustc_target::callconv::Conv;
7-
use rustc_abi::ExternAbi as TargetAbi;
88

99
/// Creates a `FnSig` from ` `. May not match the result of `sig_from_instance_`!
1010
/// Use ONLY for function pointers!

src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ extern crate rustc_target;
9797
extern crate rustc_ty_utils;
9898
extern crate stable_mir;
9999

100-
101100
// Modules
102101
/// Code handling the creation of aggreate values (Arrays, enums,structs,tuples,etc.)
103102
mod aggregate;
@@ -115,7 +114,6 @@ mod casts;
115114
mod fn_ctx;
116115
pub mod native_pastrough;
117116

118-
119117
/// Runtime errors and utlity functions/macros related to them
120118
mod codegen_error;
121119
/// Test harnesses.

src/place/adress.rs

+23-44
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ pub fn address_last_dereference<'tcx>(
4545
// Enums don't require any special handling
4646
PlaceTy::EnumVariant(_, _) => return addr_calc,
4747
};
48-
//eprintln!("target_type:{target_type:?} curr_type:{curr_type:?}");
4948
// Get the type curr_type points to!
5049
let curr_points_to = super::pointed_type(curr_type.into());
5150
let curr_type = ctx.type_from_cache(curr_type);
@@ -77,20 +76,6 @@ pub fn address_last_dereference<'tcx>(
7776
obj: Box::new(curr_type),
7877
},
7978
}
80-
/*match (curr_points_to.kind(), target_type.kind()) {
81-
(TyKind::Slice(_), TyKind::Slice(_)) => addr_calc,
82-
(TyKind::Slice(_), _) => CILNode::LDField {
83-
field: FieldDesc::new(
84-
curr_type.as_class_ref().unwrap(),
85-
ctx.nptr(Type::Void.into()),
86-
ctx.alloc_string(crate::DATA_PTR),
87-
)
88-
.into(),
89-
addr: addr_calc.into(),
90-
},
91-
_ => addr_calc,
92-
}*/
93-
//println!("casting {source:?} source_pointed_to:{source_pointed_to:?} to {target:?} target_pointed_to:{target_pointed_to:?}. ops:{ops:?}");
9479
}
9580
fn field_address<'a>(
9681
curr_type: super::PlaceTy<'a>,
@@ -220,24 +205,12 @@ pub fn place_elem_adress<'tcx>(
220205
(ld_field!(addr_calc.clone(), desc)).cast_ptr(ctx.nptr(inner_type))
221206
+ CILNode::V2(ctx.alloc_node(offset))
222207
}
223-
TyKind::Array(element, _length) => {
224-
let element = ctx.monomorphize(*element);
225-
let element_type = ctx.type_from_cache(element);
226-
let array_type = ctx.type_from_cache(curr_ty);
227-
let array_dotnet = array_type.as_class_ref().expect("Non array type");
228-
let arr_ref = ctx.nref(array_type);
229-
let element_ptr = ctx.nptr(element_type);
230-
let mref = MethodRef::new(
231-
array_dotnet,
232-
ctx.alloc_string("get_Address"),
233-
ctx.sig([arr_ref, Type::Int(Int::USize)], element_ptr),
234-
MethodKind::Instance,
235-
vec![].into(),
236-
);
208+
TyKind::Array(element, _) => {
209+
let mref = array_get_address(ctx, *element, curr_ty);
237210
call!(ctx.alloc_methodref(mref), [addr_calc, CILNode::V2(index)])
238211
}
239212
_ => {
240-
rustc_middle::ty::print::with_no_trimmed_paths! {todo!("Can't index into {curr_ty}!")}
213+
todo!("Can't index into {curr_ty}!")
241214
}
242215
}
243216
}
@@ -311,20 +284,7 @@ pub fn place_elem_adress<'tcx>(
311284
+ (index * conv_usize!(CILNode::V2(ctx.size_of(inner_type).into_idx(ctx))))
312285
}
313286
TyKind::Array(element, _) => {
314-
let element_ty = ctx.monomorphize(*element);
315-
316-
let element = ctx.type_from_cache(element_ty);
317-
let array_type = ctx.type_from_cache(curr_ty);
318-
let array_dotnet = array_type.as_class_ref().expect("Non array type");
319-
let arr_ref = ctx.nref(array_type);
320-
let element_ptr = ctx.nptr(element);
321-
let mref = MethodRef::new(
322-
array_dotnet,
323-
ctx.alloc_string("get_Address"),
324-
ctx.sig([arr_ref, Type::Int(Int::USize)], element_ptr),
325-
MethodKind::Instance,
326-
vec![].into(),
327-
);
287+
let mref = array_get_address(ctx, *element, curr_ty);
328288
if *from_end {
329289
todo!("Can't index array from end!");
330290
} else {
@@ -347,3 +307,22 @@ pub fn place_elem_adress<'tcx>(
347307
}
348308
}
349309
}
310+
pub fn array_get_address<'tcx>(
311+
ctx: &mut MethodCompileCtx<'tcx, '_>,
312+
element: Ty<'tcx>,
313+
curr_ty: Ty<'tcx>,
314+
) -> MethodRef {
315+
let element = ctx.monomorphize(element);
316+
let element = ctx.type_from_cache(element);
317+
let array_type = ctx.type_from_cache(curr_ty);
318+
let array_dotnet = array_type.as_class_ref().expect("Non array type");
319+
let arr_ref = ctx.nref(array_type);
320+
let element_ptr = ctx.nptr(element);
321+
MethodRef::new(
322+
array_dotnet,
323+
ctx.alloc_string("get_Address"),
324+
ctx.sig([arr_ref, Type::Int(Int::USize)], element_ptr),
325+
MethodKind::Instance,
326+
vec![].into(),
327+
)
328+
}

src/place/body.rs

+12-52
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{pointed_type, PlaceTy};
1+
use super::{array_get_address, array_get_item, pointed_type, PlaceTy};
22

33
use crate::{
44
assembly::MethodCompileCtx,
@@ -164,39 +164,19 @@ pub fn place_elem_body_index<'tcx>(
164164
)
165165
}
166166
}
167-
TyKind::Array(element, _length) => {
168-
let element = ctx.monomorphize(*element);
169-
let element_type = ctx.type_from_cache(element);
170-
let array_type = ctx.type_from_cache(curr_ty);
171-
let array_dotnet = array_type.as_class_ref().expect("Non array type");
172-
let arr_ref = ctx.nref(array_type);
167+
TyKind::Array(element, _length) => {
173168
let index = ctx.alloc_node(cilly::CILNode::IntCast {
174169
input: index,
175170
target: Int::USize,
176171
extend: cilly::cilnode::ExtendKind::ZeroExtend,
177172
});
178173
let index = CILNode::V2(index);
179-
if body_ty_is_by_adress(element, ctx) {
180-
let elem_ptr = ctx.nptr(element_type);
181-
let mref = MethodRef::new(
182-
array_dotnet,
183-
ctx.alloc_string("get_Address"),
184-
ctx.sig([arr_ref, Type::Int(Int::USize)], elem_ptr),
185-
MethodKind::Instance,
186-
vec![].into(),
187-
);
188-
let ops = call!(ctx.alloc_methodref(mref), [parrent_node, index]);
189-
((element).into(), ops)
174+
if body_ty_is_by_adress(*element, ctx) {
175+
let mref = array_get_address(ctx,*element,curr_ty);
176+
((*element).into(), call!(ctx.alloc_methodref(mref), [parrent_node, index]))
190177
} else {
191-
let mref = MethodRef::new(
192-
array_dotnet,
193-
ctx.alloc_string("get_Item"),
194-
ctx.sig([arr_ref, Type::Int(Int::USize)], element_type),
195-
MethodKind::Instance,
196-
vec![].into(),
197-
);
198-
let ops = call!(ctx.alloc_methodref(mref), [parrent_node, index]);
199-
((element).into(), ops)
178+
let mref = array_get_item(ctx,*element,curr_ty);
179+
((*element).into(), call!(ctx.alloc_methodref(mref), [parrent_node, index]))
200180
}
201181
}
202182
_ => {
@@ -287,32 +267,12 @@ pub fn place_elem_body<'tcx>(
287267
}
288268
}
289269
TyKind::Array(element, _length) => {
290-
let element_ty = ctx.monomorphize(*element);
291-
let element = ctx.type_from_cache(element_ty);
292-
let array_type = ctx.type_from_cache(curr_ty);
293-
let array_dotnet = array_type.as_class_ref().expect("Non array type");
294-
let arr_ref = ctx.nref(array_type);
295-
if body_ty_is_by_adress(element_ty, ctx) {
296-
let elem_ptr = ctx.nptr(element);
297-
let mref = MethodRef::new(
298-
array_dotnet,
299-
ctx.alloc_string("get_Address"),
300-
ctx.sig([arr_ref, Type::Int(Int::USize)], elem_ptr),
301-
MethodKind::Instance,
302-
vec![].into(),
303-
);
304-
let ops = call!(ctx.alloc_methodref(mref), [parrent_node, index]);
305-
((element_ty).into(), ops)
270+
if body_ty_is_by_adress(*element, ctx) {
271+
let mref = array_get_address(ctx,*element,curr_ty);
272+
((*element).into(), call!(ctx.alloc_methodref(mref), [parrent_node, index]))
306273
} else {
307-
let mref = MethodRef::new(
308-
array_dotnet,
309-
ctx.alloc_string("get_Item"),
310-
ctx.sig([arr_ref, Type::Int(Int::USize)], element),
311-
MethodKind::Instance,
312-
vec![].into(),
313-
);
314-
let ops = call!(ctx.alloc_methodref(mref), [parrent_node, index]);
315-
((element_ty).into(), ops)
274+
let mref = array_get_item(ctx,*element,curr_ty);
275+
((*element).into(), call!(ctx.alloc_methodref(mref), [parrent_node, index]))
316276
}
317277
}
318278
_ => {

0 commit comments

Comments
 (0)