Skip to content

Commit

Permalink
feat: instantiate method for OpDef (#1576)
Browse files Browse the repository at this point in the history
Closes #1512

drive-by: typos
  • Loading branch information
ss2165 authored Oct 11, 2024
1 parent f8bf61a commit 36548ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions hugr-py/src/hugr/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ def qualified_name(self) -> str:
return f"{ext_name}.{self.name}"
return self.name

def instantiate(
self,
args: Sequence[tys.TypeArg] | None = None,
concrete_signature: tys.FunctionType | None = None,
) -> ops.ExtOp:
"""Instantiate an operation from this definition.
Args:
args: Type arguments corresponding to the type parameters of the definition.
concrete_signature: Concrete function type of the operation, only required
if the operation is polymorphic.
"""
return ops.ExtOp(self, concrete_signature, list(args or []))


@dataclass
class ExtensionValue(ExtensionObject):
Expand Down
6 changes: 3 additions & 3 deletions hugr-py/src/hugr/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def ext_op(self) -> ExtOp:
Computed once using :meth:`op_def` :meth:`type_args` and :meth:`type_args`.
Each of those methods should be deterministic.
"""
return ExtOp(self.op_def(), self.cached_signature(), self.type_args())
return self.op_def().instantiate(self.type_args(), self.cached_signature())

def op_def(self) -> ext.OpDef:
"""The :class:`tys.OpDef` for this operation.
Expand Down Expand Up @@ -657,7 +657,7 @@ def name(self) -> str:
class DataflowBlock(DfParentOp):
"""Parent of non-entry basic block in a control flow graph."""

#: Inputs types of the innner dataflow graph.
#: Inputs types of the inner dataflow graph.
inputs: tys.TypeRow
_sum: tys.Sum | None = None
_other_outputs: tys.TypeRow | None = field(default=None, repr=False)
Expand Down Expand Up @@ -879,7 +879,7 @@ def name(self) -> str:
class Case(DfParentOp):
"""Parent of a dataflow graph that is a branch of a :class:`Conditional`."""

#: Inputs types of the innner dataflow graph.
#: Inputs types of the inner dataflow graph.
inputs: tys.TypeRow
_outputs: tys.TypeRow | None = field(default=None, repr=False)
num_out: int = field(default=0, repr=False)
Expand Down

0 comments on commit 36548ab

Please sign in to comment.