You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The MIR backend has a couple of commands that produce a reference value with the same mutability as something else:
The mir_static function (see mir_static and mir_static_initializer #1941) produces a reference to a static value. If the static value is immutable, then the reference will be immutable, and if the static value is mutable, then the reference will be mutable.
The mir_slice_value and mir_slice_range_value functions (see mir_slice_value and mir_slice_range_value #1948) produces a slice reference from an array reference. Similarly, the slice reference will have the same mutability as the array reference.
What is missing from these designs is a way to cast from a mutable reference to an immutable one, which is something that is allowed in Rust. We could envision variants of all the commands above that expect a mutable reference and return an immutable one, but this would result in an explosion of different variants of each command.
A somewhat nicer alternative would be to introduce a standalone mir_cast_to_immut_ref : MIRValue -> MIRValue function that performs this cast. That way, we can consolidate all of the logic needed to do the cast into a single command. In fact, this idea shares some similarities with the existing llvm_cast_pointer command, so perhaps there is a way to design this such that llvm_cast_pointer and mir_cast_to_immut_ref share the same underlying machinery.
The text was updated successfully, but these errors were encountered:
The MIR backend has a couple of commands that produce a reference value with the same mutability as something else:
mir_static
function (seemir_static
andmir_static_initializer
#1941) produces a reference to astatic
value. If thestatic
value is immutable, then the reference will be immutable, and if thestatic
value is mutable, then the reference will be mutable.mir_slice_value
andmir_slice_range_value
functions (seemir_slice_value
andmir_slice_range_value
#1948) produces a slice reference from an array reference. Similarly, the slice reference will have the same mutability as the array reference.What is missing from these designs is a way to cast from a mutable reference to an immutable one, which is something that is allowed in Rust. We could envision variants of all the commands above that expect a mutable reference and return an immutable one, but this would result in an explosion of different variants of each command.
A somewhat nicer alternative would be to introduce a standalone
mir_cast_to_immut_ref : MIRValue -> MIRValue
function that performs this cast. That way, we can consolidate all of the logic needed to do the cast into a single command. In fact, this idea shares some similarities with the existingllvm_cast_pointer
command, so perhaps there is a way to design this such thatllvm_cast_pointer
andmir_cast_to_immut_ref
share the same underlying machinery.The text was updated successfully, but these errors were encountered: