Skip to content

IR: Taking function arg address and representing references as pointers #6967

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

Merged
merged 113 commits into from
Jun 13, 2025

Conversation

vaivaswatha
Copy link
Contributor

@vaivaswatha vaivaswatha commented Feb 27, 2025

Description

This is the third PR to address #6351. It allows safely taking addresses of function arguments, and represents references (&) as pointers in the IR.

Note: The entire function type_correction (in ir_generation.rs) and this edit in compile.rs, to handle return values, must be removed once we fix and finalize the syntax of references. Until then these two hacks need to stay. Ideally I wanted to put them both in one place (which is the type_correction pass), but the return type fix needs to happen, unfortunately, during IR gen.

vaivaswatha and others added 30 commits February 6, 2025 17:01
This is the third PR to address #6351. It allows safely
taking addresses of function arguments.
Copy link
Member

@ironcev ironcev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @vaivaswatha! 💪 🚀

To my comments, those regarding replacing asm code generated for slices, can IMO be addressed in a separate PR.

Looking forward to get this PR merged and to continue the work on references!

@ironcev ironcev changed the title Put function arguments into a local, to be optimised later IR: Taking function arg address and representing references as pointers Jun 11, 2025
@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 labels Jun 11, 2025
@vaivaswatha
Copy link
Contributor Author

Great job @vaivaswatha! 💪 🚀

Thank you @IGI-111 . This was a tough one !

To my comments, those regarding replacing asm code generated for slices, can IMO be addressed in a separate PR.

Yes, I agree with you about the comments, and that it's better done as a subsequent PR. Those ASM blocks were sources of multiple bugs that took me quite a while to get right, each time with me wondering why we have it like that.

Looking forward to get this PR merged and to continue the work on references!

Indeed !

I'll work on the other comments that you have and update the PR soon. From a first look, I agree with them all. Thank you.

Copy link
Member

@ironcev ironcev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thought, in the verify_ptr_to_int, I've enabled the check to make sure that we don't have any more semantically invalid PtrToInt casts, where the pointer argument is actually not the pointer.

Good news - looks like it is so 😄

"Bad" news - there are failing tests, but they all fail in the same case, on casting string slices to int. But this is more a conceptual thing because string<N> in IR is actually a pointer to the slice.

This is IMO a subject for an upcoming PR that will extend the verifyer.

Here is an example of such issues in tests, they are all essentially the same:

v6 = const string<4> "main"
v7 = ptr_to_int v6 to u64

The failing conversion will in this case be:

Internal compiler error: Verification failed: Pointer cast from non pointer string<4>.

@vaivaswatha
Copy link
Contributor Author

vaivaswatha commented Jun 11, 2025

@ironcev I've responded to all your comments (either made the changes or responded to the comment). Let me know if I missed any or if any other change needs to be done.

Thank you again @ironcev !

@ironcev ironcev requested a review from IGI-111 June 12, 2025 04:29
@vaivaswatha vaivaswatha merged commit e072442 into master Jun 13, 2025
41 checks passed
@vaivaswatha vaivaswatha deleted the vaivaswatha/ir2_pr3 branch June 13, 2025 00:12
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 General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants