Skip to content

Commit

Permalink
Fix regions method (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe authored Jul 26, 2023
1 parent 851cb29 commit f83d518
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions melior/src/ir/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'c> Operation<'c> {

/// Gets all regions.
pub fn regions(&self) -> impl Iterator<Item = RegionRef<'c, '_>> {
(0..self.result_count()).map(|index| self.region(index).expect("valid result index"))
(0..self.region_count()).map(|index| self.region(index).expect("valid result index"))
}

/// Gets the number of successors.
Expand Down Expand Up @@ -416,7 +416,7 @@ mod tests {
use super::*;
use crate::{
context::Context,
ir::{attribute::StringAttribute, Block, Location, Type},
ir::{attribute::StringAttribute, Block, Location, Region, Type},
test::create_test_context,
};
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -507,14 +507,29 @@ mod tests {
let block = Block::new(&[(r#type, location)]);
let argument: Value = block.argument(0).unwrap().into();

let operands = vec![argument.clone(), argument.clone(), argument.clone()];
let operands = vec![argument, argument, argument];
let operation = OperationBuilder::new("foo", Location::unknown(&context))
.add_operands(&operands)
.build();

assert_eq!(
operation.operands().skip(1).collect::<Vec<_>>(),
vec![argument.clone(), argument.clone()]
vec![argument, argument]
);
}

#[test]
fn regions() {
let context = create_test_context();
context.set_allow_unregistered_dialects(true);

let operation = OperationBuilder::new("foo", Location::unknown(&context))
.add_regions(vec![Region::new()])
.build();

assert_eq!(
operation.regions().collect::<Vec<_>>(),
vec![operation.region(0).unwrap()]
);
}

Expand Down

0 comments on commit f83d518

Please sign in to comment.