Skip to content

Commit 10728a7

Browse files
refactor: remove InvalidOpsWithReturn entirely and replace with test::add
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
1 parent 9d4bc0e commit 10728a7

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

hir/src/derive.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ mod tests {
148148

149149
use crate::{
150150
attributes::Overflow,
151-
dialects::test::{self, Add, InvalidOpsWithReturn},
151+
dialects::test::{self, Add},
152152
pass::{Nesting, PassManager},
153-
Builder, BuilderExt, Context, Op, Operation, Report, Spanned,
153+
Builder, BuilderExt, Context, Op, Operation, Report, Spanned, Value,
154154
};
155155

156156
derive! {
@@ -255,12 +255,20 @@ mod tests {
255255
let mut builder = context.clone().builder();
256256
builder.set_insertion_point_to_end(block);
257257

258-
let op_builder = builder.create::<InvalidOpsWithReturn, _>(SourceSpan::default());
259-
let op = op_builder(lhs, rhs);
260-
let op = op.unwrap();
258+
let op_builder = builder.create::<Add, _>(SourceSpan::default());
259+
let op = op_builder(lhs, rhs, Overflow::Wrapping);
260+
let mut op = op.unwrap();
261+
262+
// NOTE: We override the result's type in order to force the SameOperandsAndResultType
263+
// verification function to trigger an error
264+
{
265+
let mut binding = op.borrow_mut();
266+
let mut result = binding.result_mut();
267+
result.set_type(Type::U64);
268+
}
261269

262270
// Construct a pass manager with the default pass pipeline
263-
let mut pm = PassManager::on::<InvalidOpsWithReturn>(context.clone(), Nesting::Implicit);
271+
let mut pm = PassManager::on::<Add>(context.clone(), Nesting::Implicit);
264272
// Run pass pipeline
265273
pm.run(op.as_operation_ref()).unwrap();
266274
}

hir/src/dialects/test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ impl DialectRegistration for TestDialect {
115115

116116
fn register_operations(info: &mut DialectInfo) {
117117
info.register_operation::<ops::Add>();
118-
info.register_operation::<ops::InvalidOpsWithReturn>();
119118
info.register_operation::<ops::Mul>();
120119
info.register_operation::<ops::Shl>();
121120
info.register_operation::<ops::Ret>();

hir/src/dialects/test/ops/binary.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,3 @@ impl InferTypeOpInterface for Shl {
7474
Ok(())
7575
}
7676
}
77-
78-
/// Invalid operation that breaks the SameOperandsAndResultType trait (used for testing).
79-
#[operation(
80-
dialect = TestDialect,
81-
traits(BinaryOp, SameTypeOperands, SameOperandsAndResultType),
82-
implements(InferTypeOpInterface)
83-
)]
84-
pub struct InvalidOpsWithReturn {
85-
#[operand]
86-
lhs: AnyInteger,
87-
#[operand]
88-
rhs: AnyInteger,
89-
#[result]
90-
result: AnyUnsignedInteger,
91-
}
92-
93-
impl InferTypeOpInterface for InvalidOpsWithReturn {
94-
fn infer_return_types(&mut self, _context: &Context) -> Result<(), Report> {
95-
self.result_mut().set_type(Type::U64);
96-
Ok(())
97-
}
98-
}

0 commit comments

Comments
 (0)