refactor(ir): use u64 directly instead of spans for instructions

This commit is contained in:
multisn8 2024-01-19 14:26:20 +01:00
parent 87343f0a38
commit cdf42417da
Signed by untrusted user: multisamplednight
GPG key ID: 6D525AA147CBDAE2
3 changed files with 10 additions and 46 deletions

View file

@ -10,7 +10,7 @@
use serde::{Deserialize, Serialize};
use crate::{id, instruction, Map, Set, Span};
use crate::{id, instruction, Map, Set};
/// Semi-human-{read,writ}able [`crate::GraphIr`] with far less useful types.
///
@ -19,8 +19,7 @@ use crate::{id, instruction, Map, Set, Span};
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct GraphIr {
/// See [`crate::GraphIr::instructions`], just that a simple number is used for the ID instead
/// of a proper span.
pub(crate) instructions: Map<usize, instruction::Kind>,
pub(crate) instructions: Map<u64, instruction::Kind>,
/// See [`crate::GraphIr::edges`], the forward edges.
/// RON wants you to type the set as if it were a list.
pub(crate) edges: Map<Socket, Set<Socket>>,
@ -29,17 +28,14 @@ pub struct GraphIr {
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
pub struct Socket {
/// ID of the instruction this socket is on.
pub(crate) on: usize,
pub(crate) on: u64,
pub(crate) idx: u16,
}
impl From<Socket> for id::Socket {
fn from(source: Socket) -> Self {
Self {
belongs_to: (id::Instruction(Span {
from: source.on,
to: source.on,
})),
belongs_to: id::Instruction(source.on),
idx: id::SocketIdx(source.idx),
}
}
@ -52,7 +48,7 @@ impl From<GraphIr> for crate::GraphIr {
instructions: source
.instructions
.into_iter()
.map(|(id, kind)| (id::Instruction(Span { from: id, to: id }), kind))
.map(|(id, kind)| (id::Instruction(id), kind))
.collect(),
edges: type_edges(source.edges),
rev_edges: reverse_and_type_edges(edges),