Skip to content

Commit a6b07f9

Browse files
committed
Reworked handling of statics to preserve more info.
1 parent 97c4fa5 commit a6b07f9

File tree

28 files changed

+534
-513
lines changed

28 files changed

+534
-513
lines changed

cilly/src/bin/asmedit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ fn misolate(asm: &mut Assembly, isolate_id: Interned<MethodRef>) {
360360
}
361361
fn parse_id(id: &str, asm: &Assembly) -> Interned<MethodRef> {
362362
if let Ok(id) = id.parse::<u32>() {
363-
unsafe { Interned::from_index(NonZeroU32::new(id).unwrap()) }
363+
Interned::from_index(NonZeroU32::new(id).unwrap())
364364
} else {
365365
let Some(mut iter) = asm.find_methods_matching(id) else {
366366
panic!("{id:?} is neithier a method name nor a method id")

cilly/src/v2/asm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ impl Assembly {
185185
let method_def_idxs: Box<[_]> = self.method_defs.keys().copied().collect();
186186
for method in method_def_idxs {
187187
let mut tmp_method = self.method_def(method).clone();
188-
tmp_method.typecheck(self);
188+
if let Err(err) = tmp_method.typecheck(self) {
189+
eprintln!("{err:?}");
190+
};
189191
}
190192
}
191193
#[must_use]

cilly/src/v2/asm_link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ impl Assembly {
108108
super::Const::Null(cref) => super::Const::Null(self.translate_class_ref(source, *cref)),
109109
super::Const::ByteBuffer { data, tpe } => {
110110
let tpe = self.translate_type(source, source[*tpe]);
111-
(super::Const::ByteBuffer {
111+
super::Const::ByteBuffer {
112112
data: self.alloc_const_data(&source.const_data[*data]),
113113
tpe: self.alloc_type(tpe),
114-
})
114+
}
115115
}
116116
_ => cst.clone(),
117117
}

cilly/src/v2/builtins/atomics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
asm::MissingMethodPatcher,
33
bimap::Interned,
4-
cilnode::{ExtendKind, MethodKind, PtrCastRes},
4+
cilnode::{ExtendKind, MethodKind},
55
cilroot::BranchCond,
66
BasicBlock, BinOp, CILNode, CILRoot, ClassRef, Const, Int, MethodImpl, MethodRef, Type,
77
};

cilly/src/v2/builtins/int128/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
asm::MissingMethodPatcher, cilnode::UnOp, Assembly, BasicBlock, BinOp, BranchCond, CILNode,
3-
CILRoot, ClassRef, Const, Int, MethodImpl, Type,
2+
asm::MissingMethodPatcher, Assembly, BasicBlock, BinOp, BranchCond, CILNode, CILRoot, ClassRef,
3+
Const, Int, MethodImpl, Type,
44
};
55

66
fn op_direct(

cilly/src/v2/builtins/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ pub fn insert_exeception_stub(asm: &mut Assembly, patcher: &mut MissingMethodPat
429429
Some(NonZeroU32::new(8).unwrap()),
430430
None,
431431
true,
432-
));
432+
))
433+
.unwrap();
433434
insert_catch_unwind_stub(asm, patcher);
434435
}
435436
pub fn insert_exception(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {

cilly/src/v2/builtins/simd/binop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
asm::MissingMethodPatcher, tpe::simd::SIMDElem, Assembly, BasicBlock, BinOp, CILNode, CILRoot,
3-
Const, Int, Interned, MethodImpl, MethodRef, Type,
3+
Const, Interned, MethodImpl, MethodRef, Type,
44
};
55
macro_rules! binop {
66
($op_name:ident,$op_dotnet:literal) => {
@@ -108,7 +108,7 @@ fn simd_binop(
108108
}
109109
pub fn fallback_simd(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {
110110
simd_binop(
111-
|asm, lhs, rhs, elem, res_tpe| {
111+
|asm, lhs, rhs, _, res_tpe| {
112112
let res = asm.biop(lhs, rhs, BinOp::Lt);
113113
asm.int_cast(
114114
res,
@@ -121,7 +121,7 @@ pub fn fallback_simd(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {
121121
patcher,
122122
);
123123
simd_binop(
124-
|asm, lhs, rhs, elem, res_tpe| {
124+
|asm, lhs, rhs, _, res_tpe| {
125125
let res = asm.biop(lhs, rhs, BinOp::Eq);
126126
asm.int_cast(
127127
res,

cilly/src/v2/builtins/simd/eq.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::{
2-
asm::MissingMethodPatcher,
3-
bimap::Interned,
4-
tpe::simd::{SIMDElem, SIMDVector},
5-
Assembly, BasicBlock, BinOp, CILNode, CILRoot, Const, MethodImpl, MethodRef, Type,
2+
asm::MissingMethodPatcher, bimap::Interned, Assembly, BasicBlock, CILNode, CILRoot, MethodImpl,
3+
MethodRef, Type,
64
};
75

86
use super::dotnet_vec_cast;

cilly/src/v2/c_exporter/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,13 +715,15 @@ impl CExporter {
715715
CILNode::LdStaticField(static_field_idx) => {
716716
let field = asm[static_field_idx];
717717
let class = asm[field.owner()].clone();
718-
let fname = class_member_name(&asm[class.name()], &asm[field.name()]);
718+
let fname =
719+
class_member_name(&asm[class.name()], &escape_nonfn_name(&asm[field.name()]));
719720
fname.to_string()
720721
}
721722
CILNode::LdStaticFieldAdress(static_field_idx) => {
722723
let field = asm[static_field_idx];
723724
let class = asm[field.owner()].clone();
724-
let fname = class_member_name(&asm[class.name()], &asm[field.name()]);
725+
let fname =
726+
class_member_name(&asm[class.name()], &escape_nonfn_name(&asm[field.name()]));
725727
format!("&{}", fname)
726728
}
727729
CILNode::LdFtn(method) => mref_to_name(&asm[method], asm),
@@ -951,7 +953,8 @@ impl CExporter {
951953
CILRoot::SetStaticField { field, val } => {
952954
let field = asm[field];
953955
let class = asm[field.owner()].clone();
954-
let fname = class_member_name(&asm[class.name()], &asm[field.name()]);
956+
let fname =
957+
class_member_name(&asm[class.name()], &escape_nonfn_name(&asm[field.name()]));
955958
let val = Self::node_to_string(asm[val].clone(), asm, locals, inputs, sig)?;
956959
format!("{fname} = {val};")
957960
}

cilly/src/v2/cilroot.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use serde::{Deserialize, Serialize};
22

33
use super::{
4-
bimap::{BiMapIndex, Interned, IntoBiMapIndex},
5-
cilnode::IsPure,
6-
Assembly, CILNode, FieldDesc, Float, FnSig, Int, MethodRef, StaticFieldDesc, Type,
4+
bimap::Interned, cilnode::IsPure, Assembly, CILNode, FieldDesc, Float, FnSig, Int, MethodRef,
5+
StaticFieldDesc, Type,
76
};
87
use crate::{cil_root::CILRoot as V1Root, IString};
98
//use crate::cil_node::CILNode as V1Node;

cilly/src/v2/class.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use super::{
2-
bimap::{BiMapIndex, Interned, IntoBiMapIndex},
3-
Assembly, Const, IntoAsmIndex, MethodDefIdx, MethodRef, Type,
4-
};
1+
use super::{bimap::Interned, Assembly, Const, MethodDefIdx, MethodRef, Type};
52
use crate::Access;
63
use crate::{utilis::assert_unique, IString};
74
use serde::{Deserialize, Serialize};
@@ -859,7 +856,8 @@ fn type_gc() {
859856
None,
860857
None,
861858
true,
862-
));
859+
))
860+
.unwrap();
863861
let name: Interned<IString> = asm.alloc_string("Gone");
864862
asm.class_def(ClassDef::new(
865863
name,
@@ -872,7 +870,8 @@ fn type_gc() {
872870
None,
873871
None,
874872
true,
875-
));
873+
))
874+
.unwrap();
876875
assert_eq!(asm.class_defs().len(), 2);
877876
asm.eliminate_dead_types();
878877
assert_eq!(asm.class_defs().len(), 1);

cilly/src/v2/field.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize};
22

33
use crate::IString;
44

5-
use super::bimap::{BiMapIndex, Interned};
6-
use super::{bimap::IntoBiMapIndex, Type};
5+
use super::bimap::Interned;
6+
use super::Type;
77
use super::{ClassRef, Int, IntoAsmIndex};
88

99
impl Interned<FieldDesc> {

cilly/src/v2/fnsig.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
use super::{
4-
bimap::{BiMapIndex, IntoBiMapIndex},
5-
Type,
6-
};
3+
use super::Type;
74
#[derive(Hash, PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
85
pub struct FnSig {
96
inputs: Box<[Type]>,

cilly/src/v2/method.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ use fxhash::{FxHashMap, FxHashSet};
22
use serde::{Deserialize, Serialize};
33

44
use super::{
5-
bimap::{BiMapIndex, Interned, IntoBiMapIndex},
5+
bimap::Interned,
66
cilnode::{IsPure, MethodKind},
77
class::ClassDefIdx,
8-
Access, Assembly, BasicBlock, CILIterElem, CILNode, ClassDef, ClassRef, FnSig, Int,
9-
IntoAsmIndex, Type,
8+
Access, Assembly, BasicBlock, CILIterElem, CILNode, ClassRef, FnSig, Int, IntoAsmIndex, Type,
109
};
11-
use crate::{cil_node::CallOpArgs, cilnode::PtrCastRes, iter::TpeIter};
10+
use crate::{cilnode::PtrCastRes, iter::TpeIter};
1211
use crate::{CILRoot, IString};
1312
pub type LocalId = u32;
1413
#[derive(Hash, PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
@@ -143,7 +142,7 @@ impl MethodRef {
143142
)
144143
}
145144

146-
pub(crate) fn aligned_free(asm: &mut Assembly) -> Interned<MethodRef> {
145+
pub fn aligned_free(asm: &mut Assembly) -> Interned<MethodRef> {
147146
let void_ptr = asm.nptr(Type::Void);
148147
let sig = asm.sig([void_ptr], Type::Void);
149148
let aligned_free = asm.alloc_string("AlignedFree");
@@ -764,7 +763,7 @@ impl MethodImpl {
764763
let val = asm.alloc_node(CILNode::Call(Box::new((alloc, args, IsPure::NOT))));
765764
if asm[mref.sig()].output() != sig.output() {
766765
match (asm[mref.sig()].output(), sig.output()) {
767-
(Type::Ptr(a), Type::Ptr(b)) => {
766+
(Type::Ptr(a), Type::Ptr(_)) => {
768767
let val =
769768
asm.alloc_node(CILNode::PtrCast(val, Box::new(PtrCastRes::Ptr(*a))));
770769
vec![asm.alloc_root(CILRoot::Ret(val))]

cilly/src/v2/mod.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(clippy::module_name_repetitions)]
33
// This lint includes tests for some bizzare reason, so ignoring it seems like the best course of action
44
#![allow(clippy::missing_panics_doc)]
5-
#![warn(missing_docs)]
5+
//#![warn(missing_docs)]
66
pub use super::bimap::Interned;
77
use std::path::Path;
88

@@ -24,31 +24,48 @@ pub use tpe::int::Int;
2424
pub use tpe::Type;
2525

2626
use crate::IString;
27-
27+
/// Assembly
2828
pub mod asm;
29+
/// Linker-related code
2930
pub mod asm_link;
31+
/// Basic block - the building block of control-flow
3032
pub mod basic_block;
33+
/// Interning code
3134
pub mod bimap;
35+
/// Builtin intrinsics
3236
pub mod builtins;
37+
/// Code exporting C source files
3338
pub mod c_exporter;
34-
39+
/// Exports modules to IR builders. Used for quickly implementing intrinsics
3540
pub mod cillyir_exporter;
3641
pub mod cilnode;
3742
pub mod cilroot;
43+
/// Definitons of a value / byref type
3844
pub mod class;
45+
/// IR constant
3946
pub mod cst;
47+
/// IR field
4048
pub mod field;
49+
/// IR functions signature
4150
pub mod fnsig;
4251
/// Defines hashable and equable floating point types. All NaNs are compared by bits, and -0.0 != 0.0.
4352
pub mod hashable;
53+
/// Exports IR to .NET bytecode
4454
pub mod il_exporter;
55+
/// IR iterator
4556
pub mod iter;
57+
/// Exports IR to JVM bytecode
4658
pub mod java_exporter;
4759
pub mod macros;
60+
/// IR functions
4861
pub mod method;
62+
/// IR function builder
4963
pub mod method_builder;
64+
/// IR optimization functions
5065
pub mod opt;
66+
/// IR type repr
5167
pub mod tpe;
68+
/// IR typechecker
5269
pub mod typecheck;
5370
#[test]
5471
fn types() {
@@ -58,7 +75,7 @@ fn types() {
5875
assert_eq!(*tpe.deref(&asm).deref(&asm), Type::Int(Int::U8));
5976
}
6077
#[test]
61-
pub fn nodes() {
78+
fn nodes() {
6279
let mut asm = Assembly::default();
6380
let add = asm.biop(Const::I8(2), Const::I8(1), BinOp::Add);
6481
let mut iter = CILIter::new(asm[add].clone(), &asm);
@@ -83,7 +100,9 @@ pub fn nodes() {
83100
));
84101
assert!(iter.next().is_none());
85102
}
103+
/// IL exporter
86104
pub trait Exporter {
105+
/// Export error
87106
type Error: std::fmt::Debug;
88107
/// # Errors
89108
/// Returns an error if the export process failed.

cilly/src/v2/opt/mod.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -710,37 +710,7 @@ impl MethodDef {
710710
cache: &mut SideEffectInfoCache,
711711
) {
712712
if let MethodImpl::MethodBody { blocks, .. } = self.implementation_mut() {
713-
/*let has_targets: FxHashMap<_, bool> = blocks
714-
.iter()
715-
.map(|block| (block.block_id(), block.targets(asm).next().is_some()))
716-
.collect();
717-
let blocks_copy: FxHashMap<_, _> = blocks
718-
.iter()
719-
.map(|block| (block.block_id(), block.clone()))
720-
.collect();*/
721713
for block in blocks.iter_mut() {
722-
/* if let CILRoot::Branch(info) =
723-
&asm[*block.roots().last().expect("Blocks can't be empty")]
724-
{
725-
if block.roots().iter().all(|root| match &asm[*root] {
726-
CILRoot::StLoc(_, _)
727-
| CILRoot::SourceFileInfo { .. }
728-
| CILRoot::Nop
729-
| CILRoot::SetField(_) => true,
730-
CILRoot::Branch(info) => is_branch_unconditional(&info),
731-
_ => false,
732-
}) {
733-
let (target, _, None) = info.as_ref() else {
734-
continue;
735-
};
736-
// Ret or throw
737-
if !has_targets[target] && blocks_copy[target].roots().len() < 60 {
738-
let roots = block.roots_mut();
739-
roots.pop();
740-
roots.extend(blocks_copy[target].roots());
741-
}
742-
}
743-
}*/
744714
let Some(handler) = block.handler() else {
745715
continue;
746716
};

cilly/src/v2/tpe/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use std::num::NonZeroU8;
33
use serde::{Deserialize, Serialize};
44
use simd::SIMDVector;
55

6-
use super::{
7-
bimap::{BiMapIndex, Interned, IntoBiMapIndex},
8-
Assembly, ClassRef, Float, FnSig, Int,
9-
};
6+
use super::{bimap::Interned, Assembly, ClassRef, Float, FnSig, Int};
107

118
pub mod float;
129
pub mod int;

cilly/src/v2/typecheck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ pub enum TypeCheckError {
137137
/// Index of the local.
138138
loc: u32,
139139
/// Recived type.
140-
got: Type,
140+
got: String,
141141
/// Expected type
142-
expected: Type,
142+
expected: String,
143143
},
144144
/// A comparison of non-prmitive types.
145145
ValueTypeCompare {
@@ -1006,8 +1006,8 @@ impl CILRoot {
10061006
if !got.is_assignable_to(expected, asm) {
10071007
Err(TypeCheckError::LocalAssigementWrong {
10081008
loc: *loc,
1009-
got,
1010-
expected,
1009+
got: got.mangle(asm),
1010+
expected: expected.mangle(asm),
10111011
})
10121012
} else {
10131013
Ok(())

src/aggregate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
};
55
use cilly::{
66
cil_node::CILNode, cil_root::CILRoot, cilnode::MethodKind, ClassRef, Const, FieldDesc, FnSig,
7-
Int, Interned, MethodRef, Type,
7+
Int, MethodRef, Type,
88
};
99
use rustc_abi::FieldIdx;
1010
use rustc_codegen_clr_place::{place_adress, place_get, place_set};

0 commit comments

Comments
 (0)