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

[DMS-55] Add Prim.Ret primitive that acts like var:return #34

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

DK318
Copy link
Member

@DK318 DK318 commented Jun 26, 2024

Problem

Sometimes we want to reference a return variable in predicates. It's not possible because Prim.forall/Prim.exists accepts a lambda that shadows the outer var:return.

Example

func foo(): T {
  ...
  assert:system Prim.forall<T>(func tt = (tt == var:return));
  ...
};

var:return in the example refers to the result of the lambda inside Prim.forall but we want it to be referenced to the result of foo.

Solution

Introduce new primitive Prim.Ret with <T>() -> T type that is translated to $Res Viper variable.

Possible Problems

Since Prim.Ret is a regular Motoko's primitive then the user may do some inappropriate actions. For example:

let arr = Prim.Ret<[var Nat]>();
arr[0] := 42;

We don't restrict such actions. We suppose that Prim.Ret would be used only inside assertions. Using it in other places could lead to undefined behavior.

@GoPavel
Copy link

GoPavel commented Jun 27, 2024

LGTM,
Could you also revert changes of #11?

We've introduced a new workaround with `Prim.Ret<T>` primitive.
`var:return` syntax became redundant. Let's revert it.
@DK318 DK318 merged commit af6e934 into master Jun 27, 2024
1 of 4 checks passed
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.

2 participants