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

Handle closures that are invalid for Aleo. #28417

Merged
merged 1 commit into from
Oct 23, 2024
Merged

Handle closures that are invalid for Aleo. #28417

merged 1 commit into from
Oct 23, 2024

Conversation

mikebenfield
Copy link
Collaborator

In particular,

  1. Insert a dummy instruction for empty closures. SnarkVM won't parse closures with no instructions.

  2. Give a parse error for Leo functions with no parameters (rather than just generating
    an invalid Aleo closure).

Fixes #28401

@mikebenfield mikebenfield requested a review from d0cd October 22, 2024 22:59
@mikebenfield mikebenfield force-pushed the empty-closure branch 3 times, most recently from 0f818b0 to 5cadd8c Compare October 23, 2024 00:17
Copy link
Collaborator

@d0cd d0cd left a comment

Choose a reason for hiding this comment

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

LGTM!

In particular,

1. Insert a dummy instruction for empty closures
and finalizers. SnarkVM won't parse these with no instructions.

2. Give an error for Leo functions with
no parameters (rather than just generating
an invalid Aleo closure).

Fixes #28401
@mikebenfield
Copy link
Collaborator Author

I made the error into a compiler error as you suggested; that makes a little more sense.

One other change to note: previously async functions with no body gave an error during typechecking. I've removed this error, and instead they now also have a dummy instruction inserted. My thinking for this is that in principle dead code elimination could remove all the code a user wrote, so we have to be able to handle the empty function case anyway. But let me know if you prefer otherwise.

@d0cd
Copy link
Collaborator

d0cd commented Oct 23, 2024

Do you have an opinion on issuing a warning to the user, whenever a dummy instruction is inserted?

@mikebenfield
Copy link
Collaborator Author

I lean towards thinking we shouldn't. Other programming languages treat empty functions as a normal thing that doesn't need to be warned about, and why would Leo need to be different? But it's not a very strong preference. What do you think?

@d0cd
Copy link
Collaborator

d0cd commented Oct 23, 2024

I'm in agreement. If users are conscious about their emitted code, then it is available to them.

Copy link
Collaborator

@d0cd d0cd left a comment

Choose a reason for hiding this comment

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

LGTM!

@d0cd d0cd merged commit c505dda into mainnet Oct 23, 2024
12 of 13 checks passed
@d0cd d0cd deleted the empty-closure branch October 23, 2024 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Leo generates invalid Aleo code for empty functions / closures
2 participants