about summary refs log tree commit diff
path: root/tvix/eval/src/opcode.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-26T17·46+0300
committertazjin <tazjin@tvl.su>2022-09-03T13·22+0000
commit4f00f75e31afc6bb1f163aa67e4b1cb0cadb2e12 (patch)
treea1d3d6c69841191901290a03d1e3c91a315dabf3 /tvix/eval/src/opcode.rs
parent3b64b7eb2ec178c11056d1e361def5b5b965ba43 (diff)
refactor(tvix/eval): add opcode::JumpOffset type for less ambiguity r/4619
This adds a transparent wrapper around `usize` used for jump offsets
in the opcodes. This is a step towards getting rid of ambiguous plain
`usize` usage in the opcode.

Change-Id: I21e35e67d94b32d68251908b96c7f62b6f56a8bb
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6282
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/opcode.rs')
-rw-r--r--tvix/eval/src/opcode.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/tvix/eval/src/opcode.rs b/tvix/eval/src/opcode.rs
index dadb2ecbf86f..220933f41ea9 100644
--- a/tvix/eval/src/opcode.rs
+++ b/tvix/eval/src/opcode.rs
@@ -1,12 +1,18 @@
 //! This module implements the instruction set running on the abstract
 //! machine implemented by tvix.
 
+#[repr(transparent)]
 #[derive(Clone, Copy, Debug)]
 pub struct ConstantIdx(pub usize);
 
+#[repr(transparent)]
 #[derive(Clone, Copy, Debug)]
 pub struct CodeIdx(pub usize);
 
+#[repr(transparent)]
+#[derive(Clone, Copy, Debug)]
+pub struct JumpOffset(pub usize);
+
 #[allow(clippy::enum_variant_names)]
 #[warn(variant_size_differences)]
 #[derive(Clone, Copy, Debug)]
@@ -40,10 +46,10 @@ pub enum OpCode {
     OpMoreOrEq,
 
     // Logical operators & generic jumps
-    OpJump(usize),
-    OpJumpIfTrue(usize),
-    OpJumpIfFalse(usize),
-    OpJumpIfNotFound(usize),
+    OpJump(JumpOffset),
+    OpJumpIfTrue(JumpOffset),
+    OpJumpIfFalse(JumpOffset),
+    OpJumpIfNotFound(JumpOffset),
 
     // Attribute sets
     OpAttrs(usize),