From cdf42417da31b20da833d9ffe3754cddb35cc6eb Mon Sep 17 00:00:00 2001 From: MultisampledNight Date: Fri, 19 Jan 2024 14:26:20 +0100 Subject: [PATCH] refactor(ir): use u64 directly instead of spans for instructions --- crates/ir/src/id.rs | 20 ++++---------------- crates/ir/src/lib.rs | 22 +--------------------- crates/ir/src/semi_human.rs | 14 +++++--------- 3 files changed, 10 insertions(+), 46 deletions(-) diff --git a/crates/ir/src/id.rs b/crates/ir/src/id.rs index 315bc6f..a55806e 100644 --- a/crates/ir/src/id.rs +++ b/crates/ir/src/id.rs @@ -6,10 +6,8 @@ //! //! Instead, this module offers an alternative way to refer to specific instances: //! -//! - [`Instruction`]s are referred to as their **byte [`Span`]s** in the source code, -//! so effectively where they are written in the source code. -//! (Or if coming from [`crate::semi_human::GraphIr`], -//! it's just a fictional number floating in space.) +//! - [`Instruction`]s are effectively just a number floating in space, +//! incremented each time a new instruction is referred to. //! - [`Socket`]s contain //! - what [`Instruction`] they belong to //! - which index they occupy on it @@ -19,22 +17,12 @@ use serde::{Deserialize, Serialize}; -use crate::Span; - -/// One specific instruction, and where it is found in code. +/// One specific instruction. /// /// It does **not** contain what kind of instruction this is. /// Refer to [`crate::instruction::Kind`] for this instead. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] -pub struct Instruction(pub(super) Span); - -impl Instruction { - /// Where this instruction is written down. - #[must_use] - pub fn span(&self) -> &Span { - &self.0 - } -} +pub struct Instruction(pub(super) u64); /// On an **instruction**, accepts incoming data. /// diff --git a/crates/ir/src/lib.rs b/crates/ir/src/lib.rs index 3865d64..ef7a23d 100644 --- a/crates/ir/src/lib.rs +++ b/crates/ir/src/lib.rs @@ -1,4 +1,4 @@ -use std::{num::NonZeroUsize, ops::RangeInclusive}; +use std::num::NonZeroUsize; use instruction::SocketCount; use serde::{Deserialize, Serialize}; @@ -268,26 +268,6 @@ impl<'ir> Instruction<'ir> { } } -/// Some part referred to in source code. -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] -pub struct Span { - // would love to use an actual [`std::ops::RangeInclusive`], but those don't implement - // `PartialOrd` and `Ord` unfortunately - /// At which byte this span starts, inclusively. - pub from: usize, - /// At which byte this span ends, inclusively. - pub to: usize, -} - -impl From> for Span { - fn from(range: RangeInclusive) -> Self { - Self { - from: *range.start(), - to: *range.end(), - } - } -} - /// Constructs an [`id::Socket`] a bit more tersely. fn socket(id: &id::Instruction, idx: u16) -> id::Socket { id::Socket { diff --git a/crates/ir/src/semi_human.rs b/crates/ir/src/semi_human.rs index 64dae43..7d7ff83 100644 --- a/crates/ir/src/semi_human.rs +++ b/crates/ir/src/semi_human.rs @@ -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, + pub(crate) instructions: Map, /// See [`crate::GraphIr::edges`], the forward edges. /// RON wants you to type the set as if it were a list. pub(crate) edges: Map>, @@ -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 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 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),