diff --git a/macro/tests/operand.rs b/macro/tests/operand.rs index 9c669a9206..8379e97bb0 100644 --- a/macro/tests/operand.rs +++ b/macro/tests/operand.rs @@ -1,6 +1,6 @@ mod utility; -use melior::ir::{block::BlockApi, Block, Location, Type}; +use melior::ir::{block::BlockLike, Block, Location, Type}; use utility::*; melior_macro::dialect! { diff --git a/melior/src/dialect/arith.rs b/melior/src/dialect/arith.rs index deac34b89c..c55b888eb1 100644 --- a/melior/src/dialect/arith.rs +++ b/melior/src/dialect/arith.rs @@ -174,7 +174,7 @@ mod tests { dialect::func, ir::{ attribute::{StringAttribute, TypeAttribute}, - block::BlockApi, + block::BlockLike, r#type::FunctionType, Attribute, Block, Location, Module, Region, Type, }, diff --git a/melior/src/dialect/cf.rs b/melior/src/dialect/cf.rs index e4d39336c0..03b6b06b80 100644 --- a/melior/src/dialect/cf.rs +++ b/melior/src/dialect/cf.rs @@ -5,7 +5,7 @@ use crate::{ attribute::{ DenseElementsAttribute, DenseI32ArrayAttribute, IntegerAttribute, StringAttribute, }, - block::BlockApi, + block::BlockLike, operation::OperationBuilder, r#type::RankedTensorType, Block, Identifier, Location, Operation, Type, Value, diff --git a/melior/src/dialect/func.rs b/melior/src/dialect/func.rs index 7c5c26d4c2..97d45d3a5f 100644 --- a/melior/src/dialect/func.rs +++ b/melior/src/dialect/func.rs @@ -87,7 +87,7 @@ pub fn r#return<'c>(operands: &[Value<'c, '_>], location: Location<'c>) -> Opera mod tests { use super::*; use crate::{ - ir::{block::BlockApi, Block, Module, Type}, + ir::{block::BlockLike, Block, Module, Type}, test::create_test_context, }; diff --git a/melior/src/dialect/index.rs b/melior/src/dialect/index.rs index 2d6e8c0333..88994129d2 100644 --- a/melior/src/dialect/index.rs +++ b/melior/src/dialect/index.rs @@ -75,7 +75,7 @@ mod tests { dialect::func, ir::{ attribute::{StringAttribute, TypeAttribute}, - block::BlockApi, + block::BlockLike, r#type::{FunctionType, IntegerType}, Block, Location, Module, Region, Type, }, diff --git a/melior/src/dialect/llvm.rs b/melior/src/dialect/llvm.rs index eef4f9b649..fff8c120a0 100644 --- a/melior/src/dialect/llvm.rs +++ b/melior/src/dialect/llvm.rs @@ -381,7 +381,7 @@ mod tests { }, ir::{ attribute::{IntegerAttribute, StringAttribute, TypeAttribute}, - block::BlockApi, + block::BlockLike, r#type::{FunctionType, IntegerType}, Block, Module, Region, }, diff --git a/melior/src/dialect/memref.rs b/melior/src/dialect/memref.rs index c710e77c48..a0e1eeaa8f 100644 --- a/melior/src/dialect/memref.rs +++ b/melior/src/dialect/memref.rs @@ -324,7 +324,7 @@ mod tests { dialect::{func, index}, ir::{ attribute::{DenseElementsAttribute, StringAttribute, TypeAttribute}, - block::BlockApi, + block::BlockLike, r#type::{FunctionType, IntegerType, RankedTensorType}, Block, Module, Region, Type, }, diff --git a/melior/src/dialect/ods.rs b/melior/src/dialect/ods.rs index cc0c64f18b..05d741071d 100644 --- a/melior/src/dialect/ods.rs +++ b/melior/src/dialect/ods.rs @@ -140,7 +140,7 @@ mod tests { dialect, ir::{ attribute::{IntegerAttribute, StringAttribute, TypeAttribute}, - block::BlockApi, + block::BlockLike, r#type::{FunctionType, IntegerType}, Block, Location, Module, Region, Type, }, diff --git a/melior/src/dialect/scf.rs b/melior/src/dialect/scf.rs index c8e62a8bc3..7744250daf 100644 --- a/melior/src/dialect/scf.rs +++ b/melior/src/dialect/scf.rs @@ -114,7 +114,7 @@ mod tests { dialect::{arith, func}, ir::{ attribute::{FloatAttribute, IntegerAttribute, StringAttribute, TypeAttribute}, - block::BlockApi, + block::BlockLike, r#type::{FunctionType, IntegerType, Type}, Attribute, Block, Module, }, diff --git a/melior/src/ir/block.rs b/melior/src/ir/block.rs index 54ffbe1d68..2130be63a5 100644 --- a/melior/src/ir/block.rs +++ b/melior/src/ir/block.rs @@ -23,53 +23,54 @@ use std::{ ops::Deref, }; -pub trait BlockApi<'c, 'v> { +pub trait BlockLike<'c, 'a> { /// Returns an argument at a position. - fn argument(&self, index: usize) -> Result, Error>; + fn argument(self, index: usize) -> Result, Error>; + /// Returns a number of arguments. - fn argument_count(&self) -> usize; + fn argument_count(self) -> usize; /// Returns a reference to the first operation. - fn first_operation(&self) -> Option>; + fn first_operation(self) -> Option>; /// Returns a mutable reference to the first operation. - fn first_operation_mut(&mut self) -> Option>; + fn first_operation_mut(self) -> Option>; /// Returns a reference to a terminator operation. - fn terminator(&self) -> Option>; + fn terminator(self) -> Option>; /// Returns a mutable reference to a terminator operation. - fn terminator_mut(&mut self) -> Option>; + fn terminator_mut(self) -> Option>; /// Returns a parent region. // TODO Store lifetime of regions in blocks, or create another type like // `InsertedBlockRef`? - fn parent_region(&self) -> Option>; + fn parent_region(self) -> Option>; /// Returns a parent operation. - fn parent_operation(&self) -> Option>; + fn parent_operation(self) -> Option>; /// Adds an argument. - fn add_argument(&self, r#type: Type<'c>, location: Location<'c>) -> Value<'c, 'v>; + fn add_argument(self, r#type: Type<'c>, location: Location<'c>) -> Value<'c, 'a>; /// Appends an operation. - fn append_operation(&self, operation: Operation<'c>) -> OperationRef<'c, 'v>; + fn append_operation(self, operation: Operation<'c>) -> OperationRef<'c, 'a>; /// Inserts an operation. // TODO How can we make those update functions take `&mut self`? // TODO Use cells? - fn insert_operation(&self, position: usize, operation: Operation<'c>) -> OperationRef<'c, 'v>; + fn insert_operation(self, position: usize, operation: Operation<'c>) -> OperationRef<'c, 'a>; /// Inserts an operation after another. fn insert_operation_after( - &self, - one: OperationRef<'c, 'v>, + self, + one: OperationRef<'c, 'a>, other: Operation<'c>, - ) -> OperationRef<'c, 'v>; + ) -> OperationRef<'c, 'a>; /// Inserts an operation before another. fn insert_operation_before( - &self, - one: OperationRef<'c, 'v>, + self, + one: OperationRef<'c, 'a>, other: Operation<'c>, - ) -> OperationRef<'c, 'v>; + ) -> OperationRef<'c, 'a>; /// Returns a next block in a region. - fn next_in_region(&self) -> Option>; + fn next_in_region(self) -> Option>; } /// A block. @@ -143,8 +144,8 @@ impl<'c> Block<'c> { } } -impl<'c, 'v> BlockApi<'c, 'v> for &'v Block<'c> { - fn argument(&self, index: usize) -> Result, Error> { +impl<'c, 'v> BlockLike<'c, 'v> for &'v Block<'c> { + fn argument(self, index: usize) -> Result, Error> { unsafe { if index < self.argument_count() { Ok(BlockArgument::from_raw(mlirBlockGetArgument( @@ -161,35 +162,35 @@ impl<'c, 'v> BlockApi<'c, 'v> for &'v Block<'c> { } } - fn argument_count(&self) -> usize { + fn argument_count(self) -> usize { unsafe { mlirBlockGetNumArguments(self.raw) as usize } } - fn first_operation(&self) -> Option> { + fn first_operation(self) -> Option> { unsafe { OperationRef::from_option_raw(mlirBlockGetFirstOperation(self.raw)) } } - fn first_operation_mut(&mut self) -> Option> { + fn first_operation_mut(self) -> Option> { unsafe { OperationRefMut::from_option_raw(mlirBlockGetFirstOperation(self.raw)) } } - fn terminator(&self) -> Option> { + fn terminator(self) -> Option> { unsafe { OperationRef::from_option_raw(mlirBlockGetTerminator(self.raw)) } } - fn terminator_mut(&mut self) -> Option> { + fn terminator_mut(self) -> Option> { unsafe { OperationRefMut::from_option_raw(mlirBlockGetTerminator(self.raw)) } } - fn parent_region(&self) -> Option> { + fn parent_region(self) -> Option> { unsafe { RegionRef::from_option_raw(mlirBlockGetParentRegion(self.raw)) } } - fn parent_operation(&self) -> Option> { + fn parent_operation(self) -> Option> { unsafe { OperationRef::from_option_raw(mlirBlockGetParentOperation(self.raw)) } } - fn add_argument(&self, r#type: Type<'c>, location: Location<'c>) -> Value<'c, 'v> { + fn add_argument(self, r#type: Type<'c>, location: Location<'c>) -> Value<'c, 'v> { unsafe { Value::from_raw(mlirBlockAddArgument( self.raw, @@ -199,7 +200,7 @@ impl<'c, 'v> BlockApi<'c, 'v> for &'v Block<'c> { } } - fn append_operation(&self, operation: Operation<'c>) -> OperationRef<'c, 'v> { + fn append_operation(self, operation: Operation<'c>) -> OperationRef<'c, 'v> { unsafe { let operation = operation.into_raw(); @@ -209,7 +210,7 @@ impl<'c, 'v> BlockApi<'c, 'v> for &'v Block<'c> { } } - fn insert_operation(&self, position: usize, operation: Operation<'c>) -> OperationRef<'c, 'v> { + fn insert_operation(self, position: usize, operation: Operation<'c>) -> OperationRef<'c, 'v> { unsafe { let operation = operation.into_raw(); @@ -220,7 +221,7 @@ impl<'c, 'v> BlockApi<'c, 'v> for &'v Block<'c> { } fn insert_operation_after( - &self, + self, one: OperationRef<'c, 'v>, other: Operation<'c>, ) -> OperationRef<'c, 'v> { @@ -234,7 +235,7 @@ impl<'c, 'v> BlockApi<'c, 'v> for &'v Block<'c> { } fn insert_operation_before( - &self, + self, one: OperationRef<'c, 'v>, other: Operation<'c>, ) -> OperationRef<'c, 'v> { @@ -247,7 +248,7 @@ impl<'c, 'v> BlockApi<'c, 'v> for &'v Block<'c> { } } - fn next_in_region(&self) -> Option> { + fn next_in_region(self) -> Option> { unsafe { BlockRef::from_option_raw(mlirBlockGetNextInRegion(self.raw)) } } } @@ -324,78 +325,78 @@ impl BlockRef<'_, '_> { } } -impl<'c, 'v> BlockApi<'c, 'v> for BlockRef<'c, 'v> { - fn argument(&self, index: usize) -> Result, Error> { +impl<'c, 'v> BlockLike<'c, 'v> for BlockRef<'c, 'v> { + fn argument(self, index: usize) -> Result, Error> { let block = unsafe { Block::from_raw(self.raw) }; let result = block.argument(index); Block::into_raw(block); result } - fn argument_count(&self) -> usize { + fn argument_count(self) -> usize { let block = unsafe { Block::from_raw(self.raw) }; let result = block.argument_count(); Block::into_raw(block); result } - fn first_operation(&self) -> Option> { + fn first_operation(self) -> Option> { let block = unsafe { Block::from_raw(self.raw) }; let result = block.first_operation(); Block::into_raw(block); result } - fn first_operation_mut(&mut self) -> Option> { + fn first_operation_mut(self) -> Option> { let mut block = unsafe { Block::from_raw(self.raw) }; let result = block.first_operation_mut(); Block::into_raw(block); result } - fn terminator(&self) -> Option> { + fn terminator(self) -> Option> { let block = unsafe { Block::from_raw(self.raw) }; let result = block.terminator(); Block::into_raw(block); result } - fn terminator_mut(&mut self) -> Option> { + fn terminator_mut(self) -> Option> { let mut block = unsafe { Block::from_raw(self.raw) }; let result = block.terminator_mut(); Block::into_raw(block); result } - fn parent_region(&self) -> Option> { + fn parent_region(self) -> Option> { let block = unsafe { Block::from_raw(self.raw) }; let result = block.parent_region(); Block::into_raw(block); result } - fn parent_operation(&self) -> Option> { + fn parent_operation(self) -> Option> { let block = unsafe { Block::from_raw(self.raw) }; let result = block.parent_operation(); Block::into_raw(block); result } - fn add_argument(&self, r#type: Type<'c>, location: Location<'c>) -> Value<'c, 'v> { + fn add_argument(self, r#type: Type<'c>, location: Location<'c>) -> Value<'c, 'v> { let block = unsafe { Block::from_raw(self.raw) }; let result = block.add_argument(r#type, location); Block::into_raw(block); result } - fn append_operation(&self, operation: Operation<'c>) -> OperationRef<'c, 'v> { + fn append_operation(self, operation: Operation<'c>) -> OperationRef<'c, 'v> { let block = unsafe { Block::from_raw(self.raw) }; let result = block.append_operation(operation); Block::into_raw(block); result } - fn insert_operation(&self, position: usize, operation: Operation<'c>) -> OperationRef<'c, 'v> { + fn insert_operation(self, position: usize, operation: Operation<'c>) -> OperationRef<'c, 'v> { let block = unsafe { Block::from_raw(self.raw) }; let result = block.insert_operation(position, operation); Block::into_raw(block); @@ -403,7 +404,7 @@ impl<'c, 'v> BlockApi<'c, 'v> for BlockRef<'c, 'v> { } fn insert_operation_after( - &self, + self, one: OperationRef<'c, 'v>, other: Operation<'c>, ) -> OperationRef<'c, 'v> { @@ -414,7 +415,7 @@ impl<'c, 'v> BlockApi<'c, 'v> for BlockRef<'c, 'v> { } fn insert_operation_before( - &self, + self, one: OperationRef<'c, 'v>, other: Operation<'c>, ) -> OperationRef<'c, 'v> { @@ -424,7 +425,7 @@ impl<'c, 'v> BlockApi<'c, 'v> for BlockRef<'c, 'v> { result } - fn next_in_region(&self) -> Option> { + fn next_in_region(self) -> Option> { let block = unsafe { Block::from_raw(self.raw) }; let result = block.next_in_region(); Block::into_raw(block); diff --git a/melior/src/ir/block/argument.rs b/melior/src/ir/block/argument.rs index 4218c79a2c..fe175bb62d 100644 --- a/melior/src/ir/block/argument.rs +++ b/melior/src/ir/block/argument.rs @@ -71,7 +71,7 @@ mod tests { use super::*; use crate::{ context::Context, - ir::{block::BlockApi, Block, Location}, + ir::{block::BlockLike, Block, Location}, }; #[test] diff --git a/melior/src/ir/operation.rs b/melior/src/ir/operation.rs index 02f70536e0..09a28159a9 100644 --- a/melior/src/ir/operation.rs +++ b/melior/src/ir/operation.rs @@ -521,7 +521,7 @@ mod tests { use super::*; use crate::{ context::Context, - ir::{attribute::StringAttribute, block::BlockApi, Block, Location, Region, Type}, + ir::{attribute::StringAttribute, block::BlockLike, Block, Location, Region, Type}, test::create_test_context, }; use pretty_assertions::assert_eq; diff --git a/melior/src/ir/operation/builder.rs b/melior/src/ir/operation/builder.rs index 0429bafb1a..efacc898b4 100644 --- a/melior/src/ir/operation/builder.rs +++ b/melior/src/ir/operation/builder.rs @@ -137,7 +137,7 @@ impl<'c> OperationBuilder<'c> { mod tests { use super::*; use crate::{ - ir::{block::BlockApi, Block, ValueLike}, + ir::{block::BlockLike, Block, ValueLike}, test::create_test_context, }; diff --git a/melior/src/ir/operation/result.rs b/melior/src/ir/operation/result.rs index e92a2e5b0b..c3eec9bd25 100644 --- a/melior/src/ir/operation/result.rs +++ b/melior/src/ir/operation/result.rs @@ -61,7 +61,7 @@ impl<'c, 'a> TryFrom> for OperationResult<'c, 'a> { #[cfg(test)] mod tests { use crate::{ - ir::{block::BlockApi, operation::OperationBuilder, Block, Location, Type}, + ir::{block::BlockLike, operation::OperationBuilder, Block, Location, Type}, test::create_test_context, }; diff --git a/melior/src/lib.rs b/melior/src/lib.rs index c4e2ccf03d..9b9d2e0ace 100644 --- a/melior/src/lib.rs +++ b/melior/src/lib.rs @@ -36,7 +36,7 @@ mod tests { dialect::{self, arith, func, scf}, ir::{ attribute::{IntegerAttribute, StringAttribute, TypeAttribute}, - block::BlockApi, + block::BlockLike, operation::OperationBuilder, r#type::{FunctionType, IntegerType}, Block, Location, Module, Region, Type, Value, diff --git a/melior/src/pass/external.rs b/melior/src/pass/external.rs index 218292d878..b01f7645fb 100644 --- a/melior/src/pass/external.rs +++ b/melior/src/pass/external.rs @@ -216,7 +216,7 @@ mod tests { dialect::func, ir::{ attribute::{StringAttribute, TypeAttribute}, - block::BlockApi, + block::BlockLike, r#type::FunctionType, Block, Identifier, Location, Module, Region, },