Skip to content

Commit

Permalink
refactor: use MakeOpDef for int_ops (#724)
Browse files Browse the repository at this point in the history
Co-authored-by: Alec Edgington <[email protected]>
  • Loading branch information
ss2165 and cqc-alec authored Dec 1, 2023
1 parent 5e549f2 commit 39599d8
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 407 deletions.
17 changes: 15 additions & 2 deletions src/ops/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::hugr::{HugrView, NodeType};
use crate::types::{type_param::TypeArg, FunctionType};
use crate::{Hugr, Node};

use super::dataflow::DataflowOpTrait;
use super::tag::OpTag;
use super::{LeafOp, OpTrait, OpType};

Expand Down Expand Up @@ -74,7 +75,7 @@ impl ExternalOp {
pub fn description(&self) -> &str {
match self {
Self::Opaque(op) => op.description.as_str(),
Self::Extension(ExtensionOp { def, .. }) => def.description(),
Self::Extension(ext_op) => DataflowOpTrait::description(ext_op),
}
}

Expand All @@ -86,7 +87,7 @@ impl ExternalOp {
.signature
.clone()
.expect("Op should have been serialized with signature."),
Self::Extension(ExtensionOp { signature, .. }) => signature.clone(),
Self::Extension(ext_op) => ext_op.signature(),
}
}
}
Expand Down Expand Up @@ -170,6 +171,18 @@ impl PartialEq for ExtensionOp {
}
}

impl DataflowOpTrait for ExtensionOp {
const TAG: OpTag = OpTag::Leaf;

fn description(&self) -> &str {
self.def().description()
}

fn signature(&self) -> FunctionType {
self.signature.clone()
}
}

impl Eq for ExtensionOp {}

/// An opaquely-serialized op that refers to an as-yet-unresolved [`OpDef`]
Expand Down
9 changes: 3 additions & 6 deletions src/std_extensions/arithmetic/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
Extension,
};

use super::int_types::int_type_var;
use super::int_types::int_tv;
use super::{float_types::FLOAT64_TYPE, int_types::LOG_WIDTH_TYPE_PARAM};

/// The extension identifier.
Expand All @@ -17,15 +17,12 @@ pub const EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("arithmetic.con
pub fn extension() -> Extension {
let ftoi_sig = PolyFuncType::new(
vec![LOG_WIDTH_TYPE_PARAM],
FunctionType::new(
type_row![FLOAT64_TYPE],
vec![sum_with_error(int_type_var(0))],
),
FunctionType::new(type_row![FLOAT64_TYPE], vec![sum_with_error(int_tv(0))]),
);

let itof_sig = PolyFuncType::new(
vec![LOG_WIDTH_TYPE_PARAM],
FunctionType::new(vec![int_type_var(0)], type_row![FLOAT64_TYPE]),
FunctionType::new(vec![int_tv(0)], type_row![FLOAT64_TYPE]),
);

let mut extension = Extension::new_with_reqs(
Expand Down
Loading

0 comments on commit 39599d8

Please sign in to comment.