Skip to content

Commit 520de7c

Browse files
committed
remove FoldOutput
1 parent 8ee49da commit 520de7c

File tree

7 files changed

+13
-56
lines changed

7 files changed

+13
-56
lines changed

src/algorithm/const_fold.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
33
use crate::{
44
extension::ConstFoldResult,
5-
ops::{custom::ExternalOp, Const, LeafOp, OpType},
6-
values::Value,
7-
IncomingPort, OutgoingPort,
5+
ops::{Const, OpType},
6+
IncomingPort,
87
};
98

109
/// For a given op and consts, attempt to evaluate the op.
@@ -18,7 +17,7 @@ pub fn fold_const(op: &OpType, consts: &[(IncomingPort, Const)]) -> ConstFoldRes
1817
#[cfg(test)]
1918
mod test {
2019
use crate::{
21-
extension::{ExtensionRegistry, FoldOutput, PRELUDE, PRELUDE_REGISTRY},
20+
extension::{ExtensionRegistry, PRELUDE},
2221
ops::LeafOp,
2322
std_extensions::arithmetic::int_types::{ConstIntU, INT_TYPES},
2423
types::TypeArg,
@@ -57,18 +56,6 @@ mod test {
5756
let add_op: OpType = u64_add().into();
5857
let out = fold_const(&add_op, &consts).unwrap();
5958

60-
assert_eq!(&out[..], &[(0.into(), FoldOutput::Value(Box::new(i2c(c))))]);
61-
}
62-
63-
#[test]
64-
// a = a + 0
65-
fn test_zero_add() {
66-
for in_port in [0, 1] {
67-
let other_in = 1 - in_port;
68-
let consts = vec![(in_port.into(), i2c(0))];
69-
let add_op: OpType = u64_add().into();
70-
let out = fold_const(&add_op, &consts).unwrap();
71-
assert_eq!(&out[..], &[(0.into(), FoldOutput::Input(other_in.into()))]);
72-
}
59+
assert_eq!(&out[..], &[(0.into(), i2c(c))]);
7360
}
7461
}

src/extension.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub use type_def::{TypeDef, TypeDefBound};
3131
mod const_fold;
3232
pub mod prelude;
3333
pub mod validate;
34-
pub use const_fold::{ConstFold, ConstFoldResult, FoldOutput};
34+
pub use const_fold::{ConstFold, ConstFoldResult};
3535
pub use prelude::{PRELUDE, PRELUDE_REGISTRY};
3636

3737
/// Extension Registries store extensions to be looked up e.g. during validation.

src/extension/const_fold.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,9 @@ use crate::types::TypeArg;
66

77
use crate::OutgoingPort;
88

9-
use crate::IncomingPort;
10-
119
use crate::ops;
12-
use derive_more::From;
13-
14-
#[derive(From, Clone, PartialEq, Debug)]
15-
pub enum FoldOutput {
16-
/// Value from port can be replaced with a constant
17-
Value(Box<ops::Const>),
18-
/// Value from port corresponds to one of the incoming values.
19-
Input(IncomingPort),
20-
}
21-
22-
impl From<ops::Const> for FoldOutput {
23-
fn from(value: ops::Const) -> Self {
24-
Self::Value(Box::new(value))
25-
}
26-
}
2710

28-
pub type ConstFoldResult = Option<Vec<(OutgoingPort, FoldOutput)>>;
11+
pub type ConstFoldResult = Option<Vec<(OutgoingPort, ops::Const)>>;
2912

3013
pub trait ConstFold: Send + Sync {
3114
fn fold(

src/extension/op_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::{
1313

1414
use crate::types::type_param::{check_type_args, TypeArg, TypeParam};
1515
use crate::types::{FunctionType, PolyFuncType};
16-
use crate::{ops, Hugr, IncomingPort};
16+
use crate::Hugr;
1717

1818
/// Trait necessary for binary computations of OpDef signature
1919
pub trait CustomSignatureFunc: Send + Sync {

src/ops/custom.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::extension::{ConstFoldResult, ExtensionId, ExtensionRegistry, OpDef, S
88
use crate::hugr::hugrmut::sealed::HugrMutInternals;
99
use crate::hugr::{HugrView, NodeType};
1010
use crate::types::{type_param::TypeArg, FunctionType};
11-
use crate::{ops, Hugr, IncomingPort, Node, OutgoingPort};
11+
use crate::{ops, Hugr, IncomingPort, Node};
1212

1313
use super::tag::OpTag;
1414
use super::{LeafOp, OpTrait, OpType};

src/std_extensions/arithmetic/int_ops.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
33
use super::int_types::{get_log_width, int_type_var, ConstIntU, INT_TYPES, LOG_WIDTH_TYPE_PARAM};
44
use crate::extension::prelude::{sum_with_error, BOOL_T};
5-
use crate::extension::{ConstFoldResult, CustomValidator, FoldOutput, ValidateJustArgs};
5+
use crate::extension::{ConstFoldResult, CustomValidator, ValidateJustArgs};
66
use crate::types::{FunctionType, PolyFuncType};
77
use crate::utils::collect_array;
8-
use crate::values::Value;
8+
99
use crate::{
1010
extension::{ExtensionId, ExtensionSet, SignatureError},
1111
types::{type_param::TypeArg, Type, TypeRow},
@@ -72,22 +72,10 @@ fn idivmod_sig() -> PolyFuncType {
7272
int_polytype(2, intpair.clone(), vec![Type::new_tuple(intpair)])
7373
}
7474

75-
fn zero(width: u8) -> ops::Const {
76-
ops::Const::new(
77-
ConstIntU::new(width, 0).unwrap().into(),
78-
INT_TYPES[5].to_owned(),
79-
)
80-
.unwrap()
81-
}
82-
8375
fn iadd_fold(consts: &[(IncomingPort, ops::Const)]) -> ConstFoldResult {
8476
// TODO get width from const
8577
let width = 5;
8678
match consts {
87-
[(p, c)] if c == &zero(width) => {
88-
let other_port: IncomingPort = if &IncomingPort::from(0) == p { 1 } else { 0 }.into();
89-
Some(vec![(0.into(), other_port.into())])
90-
}
9179
[(_, c1), (_, c2)] => {
9280
let [c1, c2]: [&ConstIntU; 2] = [c1, c2].map(|c| c.get_custom_value().unwrap());
9381

@@ -99,8 +87,7 @@ fn iadd_fold(consts: &[(IncomingPort, ops::Const)]) -> ConstFoldResult {
9987
.into(),
10088
INT_TYPES[5].to_owned(),
10189
)
102-
.unwrap()
103-
.into(),
90+
.unwrap(),
10491
)])
10592
}
10693

src/values.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use downcast_rs::{impl_downcast, Downcast};
99
use smol_str::SmolStr;
1010

1111
use crate::macros::impl_box_clone;
12-
use crate::ops::OpType;
13-
use crate::{Hugr, HugrView, IncomingPort, OutgoingPort};
12+
13+
use crate::{Hugr, HugrView};
1414

1515
use crate::types::{CustomCheckFailure, CustomType};
1616

0 commit comments

Comments
 (0)