Skip to content

Commit a66f0e5

Browse files
committed
Misc fixes
1 parent f899e39 commit a66f0e5

File tree

15 files changed

+185
-338
lines changed

15 files changed

+185
-338
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ rustc-demangle = "0.1.23"
2020
cilly = {path = "./cilly"}
2121
serde = { version = "1.0.183", features = ["derive"] }
2222
strsim = "0.11.1"
23-
regex = "1.10.5"
23+
2424
fxhash = "0.2.1"
25-
ordered-float = { version = "4.2.1", features = ["serde"] }
25+
2626
[profile.dev.package.fxhash]
2727
opt-level = 3
2828
[lib]

cilly/Cargo.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ lazy_static = "1.4.0"
1212
postcard = { version = "1.0.6", features = ["use-std"] }
1313
ar = "0.9.0"
1414
fxhash = "0.2.1"
15-
name-variant = "0.1.0"
16-
internment = { version = "0.8.4", features = ["arc", "serde"] }
17-
ordered-float = { version = "4.2.1", features = ["serde"] }
18-
string-interner = { version = "*", features = ["serde"] }
19-
interner = "0.2.1"
20-
streaming-iterator = "0.1.9"
2115
[[bin]]
2216
name = "linker"
2317
test = false

cilly/src/cil_iter.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{call_site::CallSite, cil_node::CILNode, cil_root::CILRoot};
1+
use crate::{call_site::CallSite, cil_node::CILNode, cil_root::CILRoot, v2::hashable::HashableF32};
22

33
#[derive(Debug, Clone, Copy)]
44
pub enum CILIterElem<'a> {
@@ -576,11 +576,7 @@ fn iter() {
576576
FnSig::new(&[Type::I32, Type::F32], Type::Void),
577577
true,
578578
)),
579-
args: [
580-
CILNode::LdcI32(-77),
581-
CILNode::LdcF32(ordered_float::OrderedFloat(3.119765)),
582-
]
583-
.into(),
579+
args: [CILNode::LdcI32(-77), CILNode::LdcF32(HashableF32(3.119765))].into(),
584580
};
585581
let mut iter = root.into_iter();
586582
assert!(matches!(
@@ -593,9 +589,7 @@ fn iter() {
593589
));
594590
assert!(matches!(
595591
iter.next(),
596-
Some(CILIterElem::Node(CILNode::LdcF32(
597-
ordered_float::OrderedFloat(3.119765)
598-
)))
592+
Some(CILIterElem::Node(CILNode::LdcF32(HashableF32(3.119765))))
599593
));
600594
assert!(iter.next().is_none());
601595
}

cilly/src/cil_iter_mut.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::marker::PhantomData;
22

3-
use ordered_float::OrderedFloat;
4-
5-
use crate::{cil_node::CILNode, cil_root::CILRoot};
3+
use crate::{cil_node::CILNode, cil_root::CILRoot, v2::hashable::HashableF32};
64

75
#[derive(Debug)]
86
enum CILIterElemUnsafe<'a> {
@@ -615,11 +613,7 @@ fn iter() {
615613
FnSig::new(&[Type::I32, Type::F32], Type::Void),
616614
true,
617615
)),
618-
args: [
619-
CILNode::LdcI32(-77),
620-
CILNode::LdcF32(OrderedFloat(3.119765)),
621-
]
622-
.into(),
616+
args: [CILNode::LdcI32(-77), CILNode::LdcF32(HashableF32(3.119765))].into(),
623617
};
624618
let mut iter = (&mut root).into_iter();
625619
assert!(matches!(
@@ -632,9 +626,7 @@ fn iter() {
632626
));
633627
assert!(matches!(
634628
iter.next(),
635-
Some(CILIterElemMut::Node(CILNode::LdcF32(OrderedFloat(
636-
3.119765
637-
))))
629+
Some(CILIterElemMut::Node(CILNode::LdcF32(HashableF32(3.119765))))
638630
));
639631
assert!(iter.next().is_none());
640632
}

cilly/src/cil_node.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
use crate::{
2-
call, call_site::CallSite, cil_iter::CILIterTrait, cil_root::CILRoot,
3-
field_desc::FieldDescriptor, fn_sig::FnSig, ptr, static_field_desc::StaticFieldDescriptor,
2+
call,
3+
call_site::CallSite,
4+
cil_iter::CILIterTrait,
5+
cil_root::CILRoot,
6+
field_desc::FieldDescriptor,
7+
fn_sig::FnSig,
8+
ptr,
9+
static_field_desc::StaticFieldDescriptor,
10+
v2::hashable::{HashableF32, HashableF64},
411
DotnetTypeRef, IString, Type,
512
};
6-
use ordered_float::OrderedFloat;
13+
714
use serde::{Deserialize, Serialize};
815
/// A container for the arguments of a call, callvirt, or newobj instruction.
916
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Hash, Debug)]
@@ -134,8 +141,8 @@ pub enum CILNode {
134141
LdcU32(u32),
135142
LdcI8(i8),
136143
LdcI16(i16),
137-
LdcF64(OrderedFloat<f64>),
138-
LdcF32(OrderedFloat<f32>),
144+
LdcF64(HashableF64),
145+
LdcF32(HashableF32),
139146
LoadGlobalAllocPtr {
140147
alloc_id: u64,
141148
},

cilly/src/v2/class.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@ impl ClassDef {
271271
// Merge the static fields, removing duplicates
272272
self.static_fields_mut().extend(translated.static_fields());
273273
make_unique(&mut self.static_fields);
274-
// Merge the static fields, removing duplicates
275-
self.static_fields_mut().extend(translated.static_fields());
276-
make_unique(self.static_fields_mut());
277274
// Merge the methods, removing duplicates
278275
self.methods_mut().extend(translated.methods());
279276
make_unique(self.methods_mut());

cilly/src/v2/cst.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
use ordered_float::OrderedFloat;
21
use serde::{Deserialize, Serialize};
32

4-
use super::{CILNode, Float, Int, StringIdx, Type};
3+
use super::{
4+
hashable::{HashableF32, HashableF64},
5+
CILNode, Float, Int, StringIdx, Type,
6+
};
57

68
#[derive(PartialEq, Eq, Clone, Debug, Hash, Serialize, Deserialize)]
79
pub enum Const {
@@ -17,8 +19,8 @@ pub enum Const {
1719
USize(u64),
1820
PlatformString(StringIdx),
1921
Bool(bool),
20-
F32(OrderedFloat<f32>),
21-
F64(OrderedFloat<f64>),
22+
F32(HashableF32),
23+
F64(HashableF64),
2224
}
2325
impl Const {
2426
pub(crate) fn get_type(&self) -> Type {

cilly/src/v2/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub mod cst;
3030
pub mod field;
3131
pub mod float;
3232
pub mod fnsig;
33+
/// Defines hashable and equable floating point types. All NaNs are compared by bits, and -0.0 != 0.0.
34+
pub mod hashable;
3335
pub mod il_exporter;
3436
pub mod int;
3537
pub mod iter;

src/assembly.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::{
3030
mono::MonoItem,
3131
Local, LocalDecl, Statement, Terminator,
3232
},
33-
ty::{Instance, ParamEnv, Ty, TyCtxt, TyKind},
33+
ty::{Instance, ParamEnv, TyCtxt, TyKind},
3434
};
3535
type LocalDefList = Vec<(Option<IString>, Type)>;
3636
type ArgsDebugInfo = Vec<Option<IString>>;
@@ -639,14 +639,14 @@ pub fn add_allocation(
639639
}
640640
GlobalAlloc::VTable(..) => {
641641
//TODO: handle VTables
642-
let alloc_fld: IString = format!("alloc_{alloc_id:x}").into();
642+
let alloc_fld: IString = format!("al_{alloc_id:x}").into();
643643
let field_desc = StaticFieldDescriptor::new(None, ptr!(Type::U8), alloc_fld.clone());
644644
asm.add_static(ptr!(Type::U8), &alloc_fld, false);
645645
return CILNode::LDStaticField(Box::new(field_desc));
646646
}
647647
GlobalAlloc::Function { .. } => {
648648
//TODO: handle constant functions
649-
let alloc_fld: IString = format!("alloc_{alloc_id:x}").into();
649+
let alloc_fld: IString = format!("al_{alloc_id:x}").into();
650650
let field_desc = StaticFieldDescriptor::new(None, ptr!(Type::U8), alloc_fld.clone());
651651
asm.add_static(ptr!(Type::U8), &alloc_fld, false);
652652

@@ -662,7 +662,7 @@ pub fn add_allocation(
662662
// Alloc ids are *not* unique across all crates. Adding the hash here ensures we don't overwrite allocations during linking
663663
// TODO:consider using something better here / making the hashes stable.
664664
let byte_hash = calculate_hash(&bytes);
665-
let alloc_fld: IString = format!("a_{}{}", encode(alloc_id), encode(byte_hash)).into();
665+
let alloc_fld: IString = format!("al_{}_{}", encode(alloc_id), encode(byte_hash)).into();
666666
let field_desc = StaticFieldDescriptor::new(None, ptr!(Type::U8), alloc_fld.clone());
667667
if !asm.static_fields().contains_key(&alloc_fld) {
668668
let init_method =

0 commit comments

Comments
 (0)