Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: instantiate method for OpDef #1576

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading