simulator WIP: use petgraph for topological sort over assignments
All checks were successful
/ deps (push) Successful in 18s
/ test (push) Successful in 4m50s

This commit is contained in:
Jacob Lifshay 2024-11-13 04:14:04 -08:00
parent f780e31622
commit d7d8e2e7ce
Signed by: programmerjake
SSH key fingerprint: SHA256:B1iRVvUJkvd7upMIiMqn6OyxvD2SgJkAH3ZnUOj6z+c
5 changed files with 887 additions and 145 deletions

17
Cargo.lock generated
View file

@ -315,6 +315,7 @@ dependencies = [
"num-bigint",
"num-traits",
"os_pipe",
"petgraph",
"serde",
"serde_json",
"tempfile",
@ -358,6 +359,12 @@ dependencies = [
"thiserror",
]
[[package]]
name = "fixedbitset"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "funty"
version = "2.0.0"
@ -515,6 +522,16 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "petgraph"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db"
dependencies = [
"fixedbitset",
"indexmap",
]
[[package]]
name = "prettyplease"
version = "0.2.20"

View file

@ -29,6 +29,7 @@ jobslot = "0.2.19"
num-bigint = "0.4.6"
num-traits = "0.2.16"
os_pipe = "1.2.1"
petgraph = "0.6.5"
prettyplease = "0.2.20"
proc-macro2 = "1.0.83"
quote = "1.0.36"

View file

@ -25,6 +25,7 @@ jobslot.workspace = true
num-bigint.workspace = true
num-traits.workspace = true
os_pipe.workspace = true
petgraph.workspace = true
serde_json.workspace = true
serde.workspace = true
tempfile.workspace = true

File diff suppressed because it is too large Load diff

View file

@ -362,6 +362,12 @@ pub(crate) struct Insns<BK: InsnsBuildingKind> {
state_layout: StateLayout<BK>,
}
impl<BK: InsnsBuildingKind> Insns<BK> {
pub(crate) fn state_layout(&self) -> &StateLayout<BK> {
&self.state_layout
}
}
struct InsnsDebug<'a> {
insns: &'a [Insn],
insn_source_locations: &'a [SourceLocation],
@ -564,13 +570,13 @@ macro_rules! make_state_part_kinds {
impl Copy for StateLayout<InsnsBuildingDone> {}
impl<BK: InsnsBuildingKind> StateLayout<BK> {
pub(crate) fn len(self) -> StateLen {
pub(crate) fn len(&self) -> StateLen {
StateLen {
ty: self.ty.len(),
$($state_field: self.$state_field.len(),)*
}
}
pub(crate) fn is_empty(self) -> bool {
pub(crate) fn is_empty(&self) -> bool {
self.ty.is_empty() $(&& self.$state_field.is_empty())*
}
pub(crate) fn empty() -> Self {
@ -652,12 +658,12 @@ macro_rules! make_state_part_kinds {
impl Copy for TypeLayout<InsnsBuildingDone> {}
impl<BK: InsnsBuildingKind> TypeLayout<BK> {
pub(crate) fn len(self) -> TypeLen {
pub(crate) fn len(&self) -> TypeLen {
TypeLen {
$($type_field: self.$type_field.len(),)*
}
}
pub(crate) fn is_empty(self) -> bool {
pub(crate) fn is_empty(&self) -> bool {
$(self.$type_field.is_empty())&&+
}
pub(crate) fn empty() -> Self {
@ -762,6 +768,14 @@ macro_rules! make_state_part_kinds {
}
impl State {
pub(crate) fn new(insns: Interned<Insns<InsnsBuildingDone>>) -> Self {
Self {
insns,
pc: 0,
$($state_field: StatePart::new(insns.state_layout.$state_field.len()),)*
$($type_field: StatePart::new(insns.state_layout.ty.$type_field.len()),)*
}
}
pub(crate) fn borrow(&mut self) -> BorrowedState<'_> {
BorrowedState {
orig_insns: self.insns,
@ -1494,6 +1508,13 @@ impl<K: StatePartKind, V: fmt::Debug> fmt::Debug for StatePartIndexMap<K, V> {
}
}
impl<K: StatePartKind, V> Extend<(StatePartIndex<K>, V)> for StatePartIndexMap<K, V> {
fn extend<T: IntoIterator<Item = (StatePartIndex<K>, V)>>(&mut self, iter: T) {
self.map
.extend(iter.into_iter().map(|(k, v)| (k.as_usize(), v)));
}
}
impl<K: StatePartKind, V> StatePartIndexMap<K, V> {
pub(crate) fn new() -> Self {
Self {
@ -1834,6 +1855,17 @@ impl_insns! {
}
next!();
}
CastBigToArrayIndex {
#[kind = Output]
dest: StatePartIndex<StatePartKindSmallSlots>,
#[kind = Input]
src: StatePartIndex<StatePartKindBigSlots>,
} => {
let src = &state.big_slots[src];
let value = src.try_into().unwrap_or(SmallUInt::MAX);
state.small_slots[dest] = value;
next!();
}
CastToSInt {
#[kind = Output]
dest: StatePartIndex<StatePartKindBigSlots>,
@ -2055,6 +2087,20 @@ impl_insns! {
state.big_slots[dest] = value;
next!();
}
SliceInt {
#[kind = Output]
dest: StatePartIndex<StatePartKindBigSlots>,
#[kind = Input]
src: StatePartIndex<StatePartKindBigSlots>,
#[kind = Immediate]
start: usize,
#[kind = Immediate]
len: usize,
} => {
let value = &state.big_slots[src] >> start;
state.big_slots[dest] = value & &*bigint_mask(len);
next!();
}
CmpEq {
#[kind = Output]
dest: StatePartIndex<StatePartKindBigSlots>,