[Mlir-commits] [mlir] [mlir] Make single value `ValueRange`s memory safer (PR #121996)

Markus Böck llvmlistbot at llvm.org
Tue Jan 7 13:46:42 PST 2025


zero9178 wrote:

> I am conflicted about this. On one hand, it seems like it's not a bad thing to have. On the other hand, I already think about `ValueRange` and friends like `ArrayRef<Value>`, and it's not valid to do
> 
> ```c++
> ArrayRef<Value> stuff = getTemporary();
> ```

I like to see the world  not for what it appears to be, but for what it could be :slightly_smiling_face: 

Jokes aside, I think there is an argument to be made that the underlying thing the `Value` "refers" to, either a `BlockArgument` or an `OpResult`, is owned by the corresponding operation/block. 
In that sense I think it is non-intuitive that currently the lifetime of the "wrapper" (`Value`) matters, rather than the lifetime of the actual underlying concept (the result or block argument). The constructors from `OperandRange` and `ResultRange`  arguably do something similar.

https://github.com/llvm/llvm-project/pull/121996


More information about the Mlir-commits mailing list