Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe committed Oct 14, 2023
1 parent 262dd0c commit bcdab4a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion macro/src/dialect/operation/accessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<'a> OperationField<'a> {
let attribute =
::melior::ir::attribute::DenseI32ArrayAttribute::<'c>::try_from(
self.operation
.attribute(#attribute_name)?
.attribute(context, #attribute_name)?
)?;
let start = (0..#index)
.map(|index| attribute.element(index))
Expand Down
23 changes: 17 additions & 6 deletions macro/tests/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ fn simple() {
let r#type = Type::parse(&context, "i32").unwrap();
let block = Block::new(&[(r#type, location), (r#type, location)]);
let op = operand_test::simple(
&context,
r#type,
block.argument(0).unwrap().into(),
block.argument(1).unwrap().into(),
location,
);

assert_eq!(op.lhs().unwrap(), block.argument(0).unwrap().into());
assert_eq!(op.rhs().unwrap(), block.argument(1).unwrap().into());
assert_eq!(op.lhs(&context).unwrap(), block.argument(0).unwrap().into());
assert_eq!(op.rhs(&context).unwrap(), block.argument(1).unwrap().into());
assert_eq!(op.operation().operand_count(), 2);
}

Expand All @@ -39,6 +40,7 @@ fn variadic_after_single() {
let r#type = Type::parse(&context, "i32").unwrap();
let block = Block::new(&[(r#type, location), (r#type, location), (r#type, location)]);
let op = operand_test::variadic(
&context,
r#type,
block.argument(0).unwrap().into(),
&[
Expand All @@ -48,9 +50,18 @@ fn variadic_after_single() {
location,
);

assert_eq!(op.first().unwrap(), block.argument(0).unwrap().into());
assert_eq!(op.others().next(), Some(block.argument(2).unwrap().into()));
assert_eq!(op.others().nth(1), Some(block.argument(1).unwrap().into()));
assert_eq!(
op.first(&context).unwrap(),
block.argument(0).unwrap().into()
);
assert_eq!(
op.others(&context).next(),
Some(block.argument(2).unwrap().into())
);
assert_eq!(
op.others(&context).nth(1),
Some(block.argument(1).unwrap().into())
);
assert_eq!(op.operation().operand_count(), 3);
assert_eq!(op.others().count(), 2);
assert_eq!(op.others(&context).count(), 2);
}
26 changes: 18 additions & 8 deletions macro/tests/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ fn single() {
let block = Block::new(&[]);
let r1 = Region::new();
r1.append_block(block);
region_test::single(r1, location)
region_test::single(&context, r1, location)
};

assert!(op.default_region().unwrap().first_block().is_some());
assert!(op.default_region(&context).unwrap().first_block().is_some());
}

#[test]
Expand All @@ -36,23 +36,33 @@ fn variadic_after_single() {
let block = Block::new(&[]);
let (r1, r2, r3) = (Region::new(), Region::new(), Region::new());
r2.append_block(block);
region_test::variadic(r1, vec![r2, r3], location)
region_test::variadic(&context, r1, vec![r2, r3], location)
};

let op2 = {
let block = Block::new(&[]);
let (r1, r2, r3) = (Region::new(), Region::new(), Region::new());
r2.append_block(block);
region_test::VariadicOp::builder(location)
region_test::VariadicOp::builder(&context, location)
.default_region(r1)
.other_regions(vec![r2, r3])
.build()
};

assert_eq!(op.operation().to_string(), op2.operation().to_string());

assert!(op.default_region().unwrap().first_block().is_none());
assert_eq!(op.other_regions().count(), 2);
assert!(op.other_regions().next().unwrap().first_block().is_some());
assert!(op.other_regions().nth(1).unwrap().first_block().is_none());
assert!(op.default_region(&context).unwrap().first_block().is_none());
assert_eq!(op.other_regions(&context).count(), 2);
assert!(op
.other_regions(&context)
.next()
.unwrap()
.first_block()
.is_some());
assert!(op
.other_regions(&context)
.nth(1)
.unwrap()
.first_block()
.is_none());
}

0 comments on commit bcdab4a

Please sign in to comment.