-
Notifications
You must be signed in to change notification settings - Fork 57
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
The following code fails, due to how lifetimes are encoded in melior, I think this should be valid code given MLIR ownership right?
The problem when dealing with BlockRefs and operation result values is they are wrongly tied to the BlockRef itself and not the block the blockref references i think
#[test]
fn lifetimes() {
let context = Context::new();
let region = Region::new();
let blockref = region.append_block(Block::new(&[]));
fn do_stuff<'ctx: 'region, 'region>(
context: &'ctx Context,
_region: &'region Region<'ctx>,
block: BlockRef<'ctx, 'region>,
) -> Value<'ctx, 'region> {
block.append_operation(arith::constant(
context,
IntegerAttribute::new(IntegerType::new(context, 64).into(), 1).into(),
Location::unknown(context),
)).result(0).unwrap().into()
}
let value = do_stuff(&context, ®ion, blockref);
}error[E0515]: cannot return value referencing function parameter `block`
--> melior/src/ir/block.rs:580:13
|
580 | block.append_operation(arith::constant(
| ^----
| |
| _____________`block` is borrowed here
| |
581 | | context,
582 | | IntegerAttribute::new(IntegerType::new(context, 64).into(), 1).into(),
583 | | Location::unknown(context),
584 | | )).result(0).unwrap().into()
| |________________________________________^ returns a value referencing data owned by the current function
Some errors have detailed explanations: E0432, E0515.
For more information about an error, try `rustc --explain E0432`.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working