| 7874 | |
| 7875 | |
| 7876 | def _validate_expr(circuit_scope: CircuitScopeInterface, node: expr.Expr) -> expr.Expr: |
| 7877 | # This takes the `circuit_scope` object as an argument rather than being a circuit method and |
| 7878 | # inferring it because we may want to call this several times, and we almost invariably already |
| 7879 | # need the interface implementation for something else anyway. |
| 7880 | # If we're not in a capturing scope (i.e. we're in the root scope), then the |
| 7881 | # `use_{var,stretch}` calls are no-ops. |
| 7882 | for ident in set(expr.iter_identifiers(node)): |
| 7883 | if isinstance(ident, expr.Stretch): |
| 7884 | circuit_scope.use_stretch(ident) |
| 7885 | elif ident.standalone: |
| 7886 | circuit_scope.use_var(ident) |
| 7887 | else: |
| 7888 | circuit_scope.resolve_classical_resource(ident.var) |
| 7889 | return node |
| 7890 | |
| 7891 | |
| 7892 | def _copy_metadata(original, cpy): |