Skip to content

Commit

Permalink
Deprecate StringRef::from_str (#357)
Browse files Browse the repository at this point in the history
Part of #348.
  • Loading branch information
raviqqe authored Oct 18, 2023
1 parent f11e9c4 commit 46439ee
Show file tree
Hide file tree
Showing 31 changed files with 227 additions and 394 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.body().append_operation(func::func(
location
));

block.append_operation(func::r#return(&context, &[sum.result(0).unwrap().into()], location));
block.append_operation(func::r#return( &[sum.result(0).unwrap().into()], location));

let region = Region::new();
region.append_block(block);
Expand Down
14 changes: 7 additions & 7 deletions 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(context, #attribute_name)?
.attribute(#attribute_name)?
)?;
let start = (0..#index)
.map(|index| attribute.element(index))
Expand Down Expand Up @@ -154,11 +154,11 @@ impl<'a> OperationField<'a> {
let name = &self.name;

Some(if constraint.is_unit()? {
quote! { self.operation.attribute(context, #name).is_some() }
quote! { self.operation.attribute(#name).is_some() }
} else {
quote! {
self.operation
.attribute(context, #name)?
.attribute(#name)?
.try_into()
.map_err(::melior::Error::from)
}
Expand All @@ -174,7 +174,7 @@ impl<'a> OperationField<'a> {

if constraint.is_unit()? || constraint.is_optional()? {
Some(quote! {
self.operation.remove_attribute(context, #name)
self.operation.remove_attribute(#name)
})
} else {
None
Expand All @@ -193,14 +193,14 @@ impl<'a> OperationField<'a> {
Ok(Some(if constraint.is_unit()? {
quote! {
if value {
self.operation.set_attribute(context, #name, Attribute::unit(&self.operation.context()));
self.operation.set_attribute(#name, Attribute::unit(&self.operation.context()));
} else {
self.operation.remove_attribute(context, #name)
self.operation.remove_attribute(#name)
}
}
} else {
quote! {
self.operation.set_attribute(context, #name, &value.into());
self.operation.set_attribute(#name, &value.into());
}
}))
}
Expand Down
2 changes: 1 addition & 1 deletion macro/src/dialect/operation/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<'o> OperationBuilder<'o> {
pub fn new(context: &'c ::melior::Context, location: ::melior::ir::Location<'c>) -> Self {
Self {
context,
builder: ::melior::ir::operation::OperationBuilder::new(&context, #name, location),
builder: ::melior::ir::operation::OperationBuilder::new( #name, location),
#(#phantoms),*
}
}
Expand Down
6 changes: 3 additions & 3 deletions macro/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn generate_binary(dialect: &Ident, names: &[Ident]) -> Result<TokenStream,
rhs: crate::ir::Value<'c, '_>,
location: crate::ir::Location<'c>,
) -> crate::ir::Operation<'c> {
crate::ir::operation::OperationBuilder::new(&context, name, location)
crate::ir::operation::OperationBuilder::new( name, location)
.add_operands(&[lhs, rhs])
.enable_result_type_inference()
.build()
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn generate_unary(dialect: &Ident, names: &[Ident]) -> Result<TokenStream, B
value: crate::ir::Value<'c, '_>,
location: crate::ir::Location<'c>,
) -> crate::ir::Operation<'c> {
crate::ir::operation::OperationBuilder::new(&context, name, location)
crate::ir::operation::OperationBuilder::new( name, location)
.add_operands(&[value])
.enable_result_type_inference()
.build()
Expand Down Expand Up @@ -110,7 +110,7 @@ pub fn generate_typed_unary(
r#type: crate::ir::Type<'c>,
location: crate::ir::Location<'c>,
) -> crate::ir::Operation<'c> {
crate::ir::operation::OperationBuilder::new(&context, name, location)
crate::ir::operation::OperationBuilder::new( name, location)
.add_operands(&[value])
.add_results(&[r#type])
.build()
Expand Down
2 changes: 2 additions & 0 deletions melior/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn string_ref_create(bencher: &mut Bencher) {

bencher.iter(|| {
for string in &strings {
#[allow(deprecated)]
let _ = StringRef::from_str(&context, string.as_str());
}
});
Expand All @@ -25,6 +26,7 @@ fn string_ref_create_cached(bencher: &mut Bencher) {

bencher.iter(|| {
for _ in 0..ITERATION_COUNT {
#[allow(deprecated)]
let _ = StringRef::from_str(&context, "foo");
}
});
Expand Down
21 changes: 5 additions & 16 deletions melior/src/dialect/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn constant<'c>(
value: Attribute<'c>,
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, "arith.constant", location)
OperationBuilder::new("arith.constant", location)
.add_attributes(&[(Identifier::new(context, "value"), value)])
.enable_result_type_inference()
.build()
Expand Down Expand Up @@ -87,7 +87,7 @@ fn cmp<'c>(
rhs: Value<'c, '_>,
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, name, location)
OperationBuilder::new(name, location)
.add_attributes(&[(
Identifier::new(context, "predicate"),
IntegerAttribute::new(predicate, IntegerType::new(context, 64).into()).into(),
Expand All @@ -100,13 +100,12 @@ fn cmp<'c>(

/// Creates an `arith.select` operation.
pub fn select<'c>(
context: &'c Context,
condition: Value<'c, '_>,
true_value: Value<'c, '_>,
false_value: Value<'c, '_>,
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, "arith.select", location)
OperationBuilder::new("arith.select", location)
.add_operands(&[condition, true_value, false_value])
.add_results(&[true_value.r#type()])
.build()
Expand Down Expand Up @@ -209,7 +208,6 @@ mod tests {
let name = name.as_string_ref().as_str().unwrap();

block.append_operation(func::r#return(
context,
&[block.append_operation(operation).result(0).unwrap().into()],
location,
));
Expand Down Expand Up @@ -599,11 +597,7 @@ mod tests {
location,
));

block.append_operation(func::r#return(
&context,
&[sum.result(0).unwrap().into()],
location,
));
block.append_operation(func::r#return(&[sum.result(0).unwrap().into()], location));

let region = Region::new();
region.append_block(block);
Expand Down Expand Up @@ -646,18 +640,13 @@ mod tests {
]);

let val = block.append_operation(select(
&context,
block.argument(0).unwrap().into(),
block.argument(1).unwrap().into(),
block.argument(2).unwrap().into(),
location,
));

block.append_operation(func::r#return(
&context,
&[val.result(0).unwrap().into()],
location,
));
block.append_operation(func::r#return(&[val.result(0).unwrap().into()], location));

let region = Region::new();
region.append_block(block);
Expand Down
25 changes: 12 additions & 13 deletions melior/src/dialect/cf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn assert<'c>(
message: &str,
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, "cf.assert", location)
OperationBuilder::new("cf.assert", location)
.add_attributes(&[(
Identifier::new(context, "msg"),
StringAttribute::new(context, message).into(),
Expand All @@ -31,12 +31,11 @@ pub fn assert<'c>(

/// Creates a `cf.br` operation.
pub fn br<'c>(
context: &'c Context,
successor: &Block<'c>,
destination_operands: &[Value<'c, '_>],
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, "cf.br", location)
OperationBuilder::new("cf.br", location)
.add_operands(destination_operands)
.add_successors(&[successor])
.build()
Expand All @@ -53,7 +52,7 @@ pub fn cond_br<'c>(
false_successor_operands: &[Value<'c, '_>],
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, "cf.cond_br", location)
OperationBuilder::new("cf.cond_br", location)
.add_attributes(&[(
Identifier::new(context, "operand_segment_sizes"),
DenseI32ArrayAttribute::new(
Expand Down Expand Up @@ -93,7 +92,7 @@ pub fn switch<'c>(
.chain(case_destinations.iter().copied())
.unzip();

Ok(OperationBuilder::new(context, "cf.switch", location)
Ok(OperationBuilder::new("cf.switch", location)
.add_attributes(&[
(
Identifier::new(context, "case_values"),
Expand Down Expand Up @@ -188,7 +187,7 @@ mod tests {

block.append_operation(assert(&context, operand, "assert message", location));

block.append_operation(func::r#return(&context, &[], location));
block.append_operation(func::r#return(&[], location));

let region = Region::new();
region.append_block(block);
Expand Down Expand Up @@ -227,9 +226,9 @@ mod tests {
.result(0)
.unwrap();

block.append_operation(br(&context, &dest_block, &[operand.into()], location));
block.append_operation(br(&dest_block, &[operand.into()], location));

dest_block.append_operation(func::r#return(&context, &[], location));
dest_block.append_operation(func::r#return(&[], location));

let region = Region::new();
region.append_block(block);
Expand Down Expand Up @@ -294,8 +293,8 @@ mod tests {
location,
));

true_block.append_operation(func::r#return(&context, &[], location));
false_block.append_operation(func::r#return(&context, &[], location));
true_block.append_operation(func::r#return(&[], location));
false_block.append_operation(func::r#return(&[], location));

let region = Region::new();
region.append_block(block);
Expand Down Expand Up @@ -353,9 +352,9 @@ mod tests {
.unwrap(),
);

default_block.append_operation(func::r#return(&context, &[], location));
first_block.append_operation(func::r#return(&context, &[], location));
second_block.append_operation(func::r#return(&context, &[], location));
default_block.append_operation(func::r#return(&[], location));
first_block.append_operation(func::r#return(&[], location));
second_block.append_operation(func::r#return(&[], location));

let region = Region::new();
region.append_block(block);
Expand Down
28 changes: 9 additions & 19 deletions melior/src/dialect/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn call<'c>(
result_types: &[Type<'c>],
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, "func.call", location)
OperationBuilder::new("func.call", location)
.add_attributes(&[(Identifier::new(context, "callee"), function.into())])
.add_operands(arguments)
.add_results(result_types)
Expand All @@ -28,13 +28,12 @@ pub fn call<'c>(

/// Create a `func.call_indirect` operation.
pub fn call_indirect<'c>(
context: &'c Context,
function: Value<'c, '_>,
arguments: &[Value<'c, '_>],
result_types: &[Type<'c>],
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, "func.call_indirect", location)
OperationBuilder::new("func.call_indirect", location)
.add_operands(&[function])
.add_operands(arguments)
.add_results(result_types)
Expand All @@ -49,7 +48,7 @@ pub fn constant<'c>(
r#type: FunctionType<'c>,
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, "func.constant", location)
OperationBuilder::new("func.constant", location)
.add_attributes(&[(Identifier::new(context, "value"), function.into())])
.add_results(&[r#type.into()])
.build()
Expand All @@ -65,7 +64,7 @@ pub fn func<'c>(
attributes: &[(Identifier<'c>, Attribute<'c>)],
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, "func.func", location)
OperationBuilder::new("func.func", location)
.add_attributes(&[
(Identifier::new(context, "sym_name"), name.into()),
(Identifier::new(context, "function_type"), r#type.into()),
Expand All @@ -77,12 +76,8 @@ pub fn func<'c>(
}

/// Create a `func.return` operation.
pub fn r#return<'c>(
context: &'c Context,
operands: &[Value<'c, '_>],
location: Location<'c>,
) -> Operation<'c> {
OperationBuilder::new(context, "func.return", location)
pub fn r#return<'c>(operands: &[Value<'c, '_>], location: Location<'c>) -> Operation<'c> {
OperationBuilder::new("func.return", location)
.add_operands(operands)
.build()
.expect("valid operation")
Expand Down Expand Up @@ -123,7 +118,7 @@ mod tests {
.result(0)
.unwrap()
.into();
block.append_operation(r#return(&context, &[value], location));
block.append_operation(r#return(&[value], location));

let region = Region::new();
region.append_block(block);
Expand Down Expand Up @@ -163,7 +158,6 @@ mod tests {
));
let value = block
.append_operation(call_indirect(
&context,
function.result(0).unwrap().into(),
&[block.argument(0).unwrap().into()],
&[index_type],
Expand All @@ -172,7 +166,7 @@ mod tests {
.result(0)
.unwrap()
.into();
block.append_operation(r#return(&context, &[value], location));
block.append_operation(r#return(&[value], location));

let region = Region::new();
region.append_block(block);
Expand Down Expand Up @@ -200,11 +194,7 @@ mod tests {
let function = {
let block = Block::new(&[(integer_type, location)]);

block.append_operation(r#return(
&context,
&[block.argument(0).unwrap().into()],
location,
));
block.append_operation(r#return(&[block.argument(0).unwrap().into()], location));

let region = Region::new();
region.append_block(block);
Expand Down
Loading

0 comments on commit 46439ee

Please sign in to comment.