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

Type annotations on switch #76

Closed
tlively opened this issue Aug 28, 2024 · 3 comments · Fixed by #81
Closed

Type annotations on switch #76

tlively opened this issue Aug 28, 2024 · 3 comments · Fixed by #81

Comments

@tlively
Copy link
Member

tlively commented Aug 28, 2024

The explainer currently has switch taking two type annotations, but the second can be computed from the first, so it seems we should only need one. Is there any reason to prefer having both?

@dhil
Copy link
Member

dhil commented Aug 28, 2024

All the instructions are annotated with their continuation types (notably cont.bind has two annotations too as its typing rule involves two continuations). I don't think any of these annotations are strictly necessary as I believe they are computable (maybe I am missing an edge case). However, in my experience the type annotations make the implementation simpler as you simply have to verify/check a producer provided type against what's on the stack rather than first constructing the type and then checking. To me there is a philosophical discussion to be had here: do we want the engine to compute evidence as much as possible or simply have it verify/check provided evidence? (personally I am lean towards the latter.)

That said, I think it may be the case that in practice switch will end up with the same type annotation twice, e.g. switch $ct $ct $tag, because my current belief is that practical use-cases will fix some universal type for switching in order to allow any stack to switch to any other stack. Though, it is possible to imagine use-cases where the heterogeneity provided by the current typing rule could be useful (e.g. static encoding of transaction protocols).

@rossberg
Copy link
Member

In the case of cont.bind, the second annotation cannot be derived easily — validation would have to construct a new deftype, and there generally is no principal way of doing so, e.g., because of type recursion. In the case of switch, however, the second type can simply be read off the definition of the first. So the annotation should indeed be unnecessary and we should remove it. That actually simplifies validation, since it avoids an extra comparison with the annotation.

@dhil
Copy link
Member

dhil commented Aug 28, 2024

OK, I will revert the reference interpreter to the single type annotation.

dhil added a commit that referenced this issue Aug 28, 2024
This patch redefines the `switch` instruction such that it only takes a single immediate type (in addition to the tag).

Resolves #76.
@dhil dhil closed this as completed in #81 Aug 29, 2024
@dhil dhil closed this as completed in c2f9449 Aug 29, 2024
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 a pull request may close this issue.

3 participants