Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regions method #269

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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