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

motoko-san: Update README.md #19

Merged
merged 1 commit into from
May 30, 2024
Merged

motoko-san: Update README.md #19

merged 1 commit into from
May 30, 2024

Conversation

int-index
Copy link
Member

Update the README.md to describe features implemented by Serokell for Milestone 1 and Milestone 2

Milestone 1

  1. Arguments and return values
  2. The return statement, early exit
  3. Loop invariants
  4. Method calls in let/var declarations, assignments
  5. The Nat data type (translated to Int)
  6. Arrays of primitive types
  7. Monomorphisation of private methods (new pass: prep.ml)
  8. Assertions on the result (the var:return syntax)

Milestone 2

  1. Tuples of primitive types, matching on tuples in let
  2. Option types
  3. Variant types using the ADT Viper plugin (nominative typing, generics supported)
  4. switch statements to match on tuples, options, variants

Copy link

@GoPavel GoPavel left a comment

Choose a reason for hiding this comment

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

LGTM
Only one thing: I think that it's useful to mention that loop invariant should hold before and after loop. Sometimes you might come up with invariant that holds only after at least one iteration and be confused.

src/viper/README.md Outdated Show resolved Hide resolved
@int-index int-index force-pushed the motoko-san/readme branch from e9e075f to b2bf7db Compare May 27, 2024 17:34
Instead of using `{ #A; #B }` in type signatures, one must always
refer to this variant by its name `N`.
* Furthermore, given two identical variant declarations, they are
treated as distinct in the translation:
Copy link

Choose a reason for hiding this comment

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

Idea: We could alternatively use an uninterpreted function eq(x: Tuple, y:: Tuple) that is axiomatized as

forall x, y :: eq(x, y) <==> x.0 == y.0 && x.1 == y.1

etc.

This goes, however, into the direction of program-specific preamble generation (as we don't know which tuple types we would need to compare for equality), which is not what we're currently doing.

Copy link

Choose a reason for hiding this comment

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

@aterga, I'm not sure why your comment is relevant here - I think they are talking about type equality being structural, not value equality.

Copy link

Choose a reason for hiding this comment

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

IIUC, they are saying "Motoko equality is structural, but we translate it to Viper using ==, which reduces the completeness of the translation." Did I get it wrongly?

If not, then I'm merely suggesting that there could be a straightforward, yet more complete translation. Although I'm not suggesting that it's implemented it in the scope of the current Serokell grant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe I phrased it poorly, but I meant to talk about type equality here, as @crusso points out.


Supporting `async` types is _hard_.

Supporting `Float`, function types, co-inductive, mutually recursive, and sub-typing is _hard_.

Supporting container types and generic types, e.g., arrays (`[var T]`) and `HashMap<K, V>`, is _hard_.
Supporting container types and generic types, e.g. `HashMap<K, V>`, is _hard_.
Copy link

Choose a reason for hiding this comment

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

Do you think this is conceptually harder than what we do for Arrays, or about the same complexity?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we find the right axioms, it should be possible, but we won't know until we try. For arrays there was an example in Viper's documentation, a hashmap would require more tinkering

Copy link

Choose a reason for hiding this comment

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

Thanks, this is just my curiosity.

We do have some drafts for translating HashMap from Motoko to Viper from a very long time ago (even before Motoko-san was created). But let's keep working on concrete examples, and I don't think we need to add anything with HashMaps into this project (there's enough interesting canisters with arrays, ADTs and things that we already support — we should utilize those before expanding).

return a; // conditional early exit
};
return a; // normal exit
```
Copy link

Choose a reason for hiding this comment

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

Would the following work, too?

      if (length == 0) {
        return a;   // conditional early exit
      };
      a     // normal exit

Copy link
Member Author

Choose a reason for hiding this comment

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

We could make it work, but at the moment it doesn't.

src/viper/README.md Outdated Show resolved Hide resolved
src/viper/README.md Outdated Show resolved Hide resolved
```

* Motoko's type checker has not been modified to account for
nominative equality of variants, so type inference is not reliable:
Copy link

Choose a reason for hiding this comment

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

Suggested change
nominative equality of variants, so type inference is not reliable:
nominal equality of variants, so type inference is not reliable:

I guess we will just have to live with this fundamental difference between Viper and Motoko. @aterga is there any way to teach Viper about structural type equivalence (and subtyping)?

Copy link

@aterga aterga May 28, 2024

Choose a reason for hiding this comment

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

Yes.

The Viper language is designed to be simple, and to allow modeling programs in many different (imperative) languages. So while we cannot translate many statement from Motoko into Viper 1:1, of course there are multiple ways we could model those cases in Viper and still support them.

That is where I was going with this comment, btw: #19 (comment)

Copy link

Choose a reason for hiding this comment

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

For example Prusti encode all Rust types as predicates. I think in that approach subtyping is not a big deal, but there will be other drawbacks e.g. folding/unfolding Viper isorecursive predicates.

Copy link

Choose a reason for hiding this comment

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

Correct. I would not recommend using separation logic predicates in Motoko-san, as they would require generating ghost statements to fold / unfold the definitions, and they are limited to tree structures (so, e.g., an array cannot be expressed this way).

@int-index int-index force-pushed the motoko-san/readme branch from b2bf7db to 9057948 Compare May 28, 2024 09:53
@int-index int-index merged commit 150c958 into master May 30, 2024
2 of 5 checks passed
@delete-merged-branch delete-merged-branch bot deleted the motoko-san/readme branch May 30, 2024 10:19
* `if-[else]` statements


Supporting pattern-matching is conceptually _simple_.
Copy link

Choose a reason for hiding this comment

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

We could perhaps remove this line now

Copy link
Member Author

Choose a reason for hiding this comment

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

We would first have to add support for nested pattern matching, I imagine?

Copy link

Choose a reason for hiding this comment

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

Indeed, but then the line could be "Supporting general pattern-matching is conceptually simple." :-)

This is a very, very minor issue, so feel free to ignore

Copy link

Choose a reason for hiding this comment

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

We can take it into account when we will update README after the 3rd Milestone

Copy link

Choose a reason for hiding this comment

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

Done

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.

4 participants