Skip to content

Commit

Permalink
feat: Automatically add the custom op's extension to its 'runtime_req…
Browse files Browse the repository at this point in the history
…s' set (#1787)

Ignores custom operations that are missing their own extension as a
runtime req when validating.

drive-by: Update doc that still refered to `extension_requirements`
  • Loading branch information
aborgna-q authored Dec 16, 2024
1 parent 7cf7bb6 commit 3ef5bd9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions hugr-core/src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ impl SignatureFunc {
SignatureFunc::MissingValidateFunc(ts) => (ts, args),
};
let mut res = pf.instantiate(args)?;

// Automatically add the extensions where the operation is defined to
// the runtime requirements of the op.
res.runtime_reqs.insert(def.extension.clone());

// If there are any row variables left, this will fail with an error:
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/extension/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! required across the HUGR.
//!
//! This is distinct from _runtime_ extension requirements, which are defined
//! more granularly in each function signature by the `required_extensions`
//! more granularly in each function signature by the `runtime_reqs`
//! field. See the `extension_inference` feature and related modules for that.
//!
//! Note: These procedures are only temporary until `hugr-model` is stabilized.
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/extension/resolution/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub(crate) fn resolve_op_extensions<'e>(
cause: e,
})?;

if opaque.signature() != ext_op.signature() {
if opaque.signature().io() != ext_op.signature().io() {
return Err(OpaqueOpError::SignatureMismatch {
node,
extension: opaque.extension().clone(),
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl Hugr {
///
/// This is distinct from _runtime_ extension requirements computed in
/// [`Hugr::infer_extensions`], which are computed more granularly in each
/// function signature by the `required_extensions` field and define the set
/// function signature by the `runtime_reqs` field and define the set
/// of capabilities required by the runtime to execute each function.
///
/// Updates the internal extension registry with the extensions used in the
Expand Down
7 changes: 7 additions & 0 deletions hugr-py/src/hugr/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ def instantiate(
concrete_signature: Concrete function type of the operation, only required
if the operation is polymorphic.
"""
# Add the extension where the operation is defined as a runtime requirement.
# We don't store this in the json definition as it is redundant information.
if concrete_signature is not None:
concrete_signature = concrete_signature.with_runtime_reqs(
[self.get_extension().name]
)

return ops.ExtOp(self, concrete_signature, list(args or []))


Expand Down

0 comments on commit 3ef5bd9

Please sign in to comment.