From da998d8fa19a8c888f7e55e4dd5432fb39d7167d Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 31 Oct 2022 18:51:36 -0700 Subject: [PATCH] validate that tied outputs are equivalent to their corresponding input --- src/bigint_presentation_code/compiler_ir2.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bigint_presentation_code/compiler_ir2.py b/src/bigint_presentation_code/compiler_ir2.py index 382d66c..7109e77 100644 --- a/src/bigint_presentation_code/compiler_ir2.py +++ b/src/bigint_presentation_code/compiler_ir2.py @@ -661,9 +661,13 @@ class GenericOpProperties: self.outputs = tuple(outputs) fixed_locs = [] # type: list[tuple[Loc, int]] for idx, out in enumerate(self.outputs): - if out.tied_input_index is not None \ - and out.tied_input_index >= len(self.inputs): - raise ValueError(f"tied_input_index out of range: {out}") + if out.tied_input_index is not None: + if out.tied_input_index >= len(self.inputs): + raise ValueError(f"tied_input_index out of range: {out}") + tied_inp = self.inputs[out.tied_input_index] + if tied_inp.tied_to_input(out.tied_input_index) != out: + raise ValueError(f"output can't be tied to non-equivalent " + f"input: {out} tied to {tied_inp}") if out.fixed_loc is not None: for other_fixed_loc, other_idx in fixed_locs: if not other_fixed_loc.conflicts(out.fixed_loc): -- 2.30.2