Consider using IrType::Pointer
for raw pointers and references
#5964
Labels
compiler: ir
IRgen and sway-ir including optimization passes
compiler: optimization
IR Optimization Passes
compiler
General compiler. Should eventually become more specific as the issue is triaged
Currently, both raw pointers (
raw_ptr
) and references (&T
) are treated asu64
addresses in the IR, obtained byptr_to_int
from the original pointer. Since the references were introduced, there is a TODO comment in the IR generation asking if this conversion step is actually needed and if we can have raw pointers and references modeled asPointer
to anIrType
instead of beingu64
.The obvious benefit of having them modeled as
Pointer
s, beside the clearly communicating the semantics, is knowing that certain locals are actually pointing to other values, and conserving the pointee types. E.g., currently, pointer and reference locals are emitted like:This results in a cumbersome and also cognitively demanding treatment of pointers and references in e.q. optimizations, because the only way to know if
my_ref
in the above example is a reference/pointer or a plainu64
number, is to look at the certain usage patterns specific for pointers and references, which is difficult and in a general case very likely never a 100% valid heuristics.That's why I propose, as the mentioned TODO comment says, to explore if we can use
IrType::Pointer
instead.The reason why the current design of having pointers modeled as plain
u64
was originally chosen is not known to me.The text was updated successfully, but these errors were encountered: