Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using IrType::Pointer for raw pointers and references #5964

Open
ironcev opened this issue May 6, 2024 · 0 comments
Open

Consider using IrType::Pointer for raw pointers and references #5964

ironcev opened this issue May 6, 2024 · 0 comments
Assignees
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

Comments

@ironcev
Copy link
Member

ironcev commented May 6, 2024

Currently, both raw pointers (raw_ptr) and references (&T) are treated as u64 addresses in the IR, obtained by ptr_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 as Pointer to an IrType instead of being u64.

The obvious benefit of having them modeled as Pointers, 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:

local u64 my_ref

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 plain u64 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.

@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: ir IRgen and sway-ir including optimization passes compiler: optimization IR Optimization Passes labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants