From ea658481413b0ba5d9ccf39218efa39aa9e28502 Mon Sep 17 00:00:00 2001 From: tjjfvi Date: Tue, 5 Mar 2024 09:24:03 -0500 Subject: [PATCH] document invariants --- src/run/def.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/run/def.rs b/src/run/def.rs index 7319ea75..0c947def 100644 --- a/src/run/def.rs +++ b/src/run/def.rs @@ -199,8 +199,10 @@ impl<'a, M: Mode> Net<'a, M> { /// [`Def`]s, when not pre-compiled, are represented as lists of instructions. #[derive(Debug, Default, Clone)] pub struct InterpretedDef { - pub instr: Vec, - pub trgs: usize, + pub(crate) instr: Vec, + /// The number of targets used in the def; must be greater than all of the + /// `TrgId` indices in `instr`. + pub(crate) trgs: usize, } impl AsDef for InterpretedDef { @@ -214,6 +216,12 @@ impl AsDef for InterpretedDef { let mut trgs = Trgs(&mut net.trgs[..] as *mut _ as *mut _); + /// Points to an array of `Trg`s of length at least `def.trgs`. The `Trg`s + /// may not all be initialized. + /// + /// Only `TrgId`s with index less than `def.trgs` may be passed to `get_trg` + /// and `set_trg`, and `get_trg` can only be called after `set_trg` was + /// called with the same `TrgId`. struct Trgs(*mut Trg); impl Trgs {