Skip to content

Commit f6163bf

Browse files
authored
feat!: Remove description on opaque ops. (#2197)
This PR removes the description field on opaque operations. The description can and should be derived when resolving the operation; there is no need for every instance of an operation to carry its own individual copy of an operation's documentation. BREAKING CHANGE: - Removed `description` parameter from `OpaqueOp::new`.
1 parent 187c885 commit f6163bf

File tree

8 files changed

+6
-52
lines changed

8 files changed

+6
-52
lines changed

hugr-core/src/import.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,7 @@ impl<'a> Context<'a> {
568568
// to declare operations as a node, in which case the description will be attached
569569
// to that node as metadata.
570570

571-
let optype = OpType::OpaqueOp(OpaqueOp::new(
572-
extension,
573-
name,
574-
String::default(),
575-
args,
576-
signature,
577-
));
571+
let optype = OpType::OpaqueOp(OpaqueOp::new(extension, name, args, signature));
578572

579573
let node = self.make_node(node_id, optype, parent)?;
580574

hugr-core/src/ops/custom.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ use std::sync::Arc;
66
use thiserror::Error;
77
#[cfg(test)]
88
use {
9-
crate::extension::test::SimpleOpDef,
10-
crate::proptest::{any_nonempty_smolstr, any_nonempty_string},
11-
::proptest::prelude::*,
12-
::proptest_derive::Arbitrary,
9+
crate::extension::test::SimpleOpDef, crate::proptest::any_nonempty_smolstr,
10+
::proptest::prelude::*, ::proptest_derive::Arbitrary,
1311
};
1412

1513
use crate::core::HugrNode;
@@ -114,7 +112,6 @@ impl ExtensionOp {
114112
OpaqueOp {
115113
extension: self.def.extension_id().clone(),
116114
name: self.def.name().clone(),
117-
description: self.def.description().into(),
118115
args: self.args.clone(),
119116
signature: self.signature.clone(),
120117
}
@@ -168,7 +165,6 @@ impl From<ExtensionOp> for OpaqueOp {
168165
OpaqueOp {
169166
extension: def.extension_id().clone(),
170167
name: def.name().clone(),
171-
description: def.description().into(),
172168
args,
173169
signature,
174170
}
@@ -239,8 +235,6 @@ pub struct OpaqueOp {
239235
extension: ExtensionId,
240236
#[cfg_attr(test, proptest(strategy = "any_nonempty_smolstr()"))]
241237
name: OpName,
242-
#[cfg_attr(test, proptest(strategy = "any_nonempty_string()"))]
243-
description: String, // cache in advance so description() can return &str
244238
args: Vec<TypeArg>,
245239
// note that the `signature` field might not include `extension`. Thus this must
246240
// remain private, and should be accessed through
@@ -257,14 +251,12 @@ impl OpaqueOp {
257251
pub fn new(
258252
extension: ExtensionId,
259253
name: impl Into<OpName>,
260-
description: String,
261254
args: impl Into<Vec<TypeArg>>,
262255
signature: Signature,
263256
) -> Self {
264257
Self {
265258
extension,
266259
name: name.into(),
267-
description,
268260
args: args.into(),
269261
signature,
270262
}
@@ -317,7 +309,7 @@ impl DataflowOpTrait for OpaqueOp {
317309
const TAG: OpTag = OpTag::Leaf;
318310

319311
fn description(&self) -> &str {
320-
&self.description
312+
"Opaque operation"
321313
}
322314

323315
fn signature(&self) -> Cow<'_, Signature> {
@@ -414,12 +406,10 @@ mod test {
414406
let op = OpaqueOp::new(
415407
"res".try_into().unwrap(),
416408
"op",
417-
"desc".into(),
418409
vec![TypeArg::Type { ty: usize_t() }],
419410
sig.clone(),
420411
);
421412
assert_eq!(op.name(), "OpaqueOp:res.op");
422-
assert_eq!(DataflowOpTrait::description(&op), "desc");
423413
assert_eq!(op.args(), &[TypeArg::Type { ty: usize_t() }]);
424414
assert_eq!(op.signature().as_ref(), &sig);
425415
}
@@ -431,7 +421,6 @@ mod test {
431421
let opaque = OpaqueOp::new(
432422
conversions::EXTENSION_ID,
433423
"itobool",
434-
"description".into(),
435424
vec![],
436425
Signature::new(i0.clone(), bool_t()),
437426
);
@@ -472,14 +461,8 @@ mod test {
472461

473462
let registry = ExtensionRegistry::new([ext]);
474463
registry.validate().unwrap();
475-
let opaque_val = OpaqueOp::new(
476-
ext_id.clone(),
477-
val_name,
478-
String::new(),
479-
vec![],
480-
endo_sig.clone(),
481-
);
482-
let opaque_comp = OpaqueOp::new(ext_id.clone(), comp_name, String::new(), vec![], endo_sig);
464+
let opaque_val = OpaqueOp::new(ext_id.clone(), val_name, vec![], endo_sig.clone());
465+
let opaque_comp = OpaqueOp::new(ext_id.clone(), comp_name, vec![], endo_sig);
483466
let mut resolved_val = opaque_val.into();
484467
resolve_op_extensions(
485468
Node::from(portgraph::NodeIndex::new(1)),

hugr-py/src/hugr/_serialization/ops.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ class ExtensionOp(DataflowOp):
498498
extension: ExtensionId
499499
name: str
500500
signature: stys.FunctionType = Field(default_factory=stys.FunctionType.empty)
501-
description: str = ""
502501
args: list[stys.TypeArg] = Field(default_factory=list)
503502

504503
def insert_port_types(self, in_types: TypeRow, out_types: TypeRow) -> None:

hugr-py/src/hugr/ops.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ class Custom(DataflowOp):
315315

316316
op_name: str
317317
signature: tys.FunctionType = field(default_factory=tys.FunctionType.empty)
318-
description: str = ""
319318
extension: tys.ExtensionId = ""
320319
args: list[tys.TypeArg] = field(default_factory=list)
321320

@@ -325,7 +324,6 @@ def _to_serial(self, parent: Node) -> sops.ExtensionOp:
325324
extension=self.extension,
326325
name=self.op_name,
327326
signature=self.signature._to_serial(),
328-
description=self.description,
329327
args=ser_it(self.args),
330328
)
331329

specification/schema/hugr_schema_live.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,6 @@
537537
"signature": {
538538
"$ref": "#/$defs/FunctionType"
539539
},
540-
"description": {
541-
"default": "",
542-
"title": "Description",
543-
"type": "string"
544-
},
545540
"args": {
546541
"items": {
547542
"$ref": "#/$defs/TypeArg"

specification/schema/hugr_schema_strict_live.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,6 @@
537537
"signature": {
538538
"$ref": "#/$defs/FunctionType"
539539
},
540-
"description": {
541-
"default": "",
542-
"title": "Description",
543-
"type": "string"
544-
},
545540
"args": {
546541
"items": {
547542
"$ref": "#/$defs/TypeArg"

specification/schema/testing_hugr_schema_live.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,6 @@
537537
"signature": {
538538
"$ref": "#/$defs/FunctionType"
539539
},
540-
"description": {
541-
"default": "",
542-
"title": "Description",
543-
"type": "string"
544-
},
545540
"args": {
546541
"items": {
547542
"$ref": "#/$defs/TypeArg"

specification/schema/testing_hugr_schema_strict_live.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,6 @@
537537
"signature": {
538538
"$ref": "#/$defs/FunctionType"
539539
},
540-
"description": {
541-
"default": "",
542-
"title": "Description",
543-
"type": "string"
544-
},
545540
"args": {
546541
"items": {
547542
"$ref": "#/$defs/TypeArg"

0 commit comments

Comments
 (0)