validate that tied outputs are equivalent to their corresponding input
authorJacob Lifshay <programmerjake@gmail.com>
Tue, 1 Nov 2022 01:51:36 +0000 (18:51 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Tue, 1 Nov 2022 01:51:36 +0000 (18:51 -0700)
src/bigint_presentation_code/compiler_ir2.py

index 382d66c457f5dacbe45561f262e464b1b9fa84f6..7109e776d23ce08fc70d1ec2e44b01cde4e77d44 100644 (file)
@@ -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):