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

Check that definitions from modes respect their scope #62

Closed
bugarela opened this issue Mar 31, 2022 · 5 comments · Fixed by #228
Closed

Check that definitions from modes respect their scope #62

bugarela opened this issue Mar 31, 2022 · 5 comments · Fixed by #228
Assignees
Labels
effect system Quint effects checker

Comments

@bugarela
Copy link
Collaborator

TNT has modes that define what expressions can be used inside a definition. We are currently ignoring this and everything is allowed in any mode. We should make a pass after name resolution that checks semantically if definitions of a mode contain only expressions allowed in that mode.

@bugarela bugarela added the alpha label Mar 31, 2022
@bugarela bugarela self-assigned this Mar 31, 2022
@bugarela
Copy link
Collaborator Author

There's currently no way of differentiating state and stateless modes. One idea is to add the pure keyword as a prefix to any stateless definitions.

@bugarela
Copy link
Collaborator Author

state and stateless operators can be used as parameters to high order operators. However, without specification of which mode the parameter has, we don't have a way to infer/check the mode of the high order operator itself. @shonfeder proposed to require this specification in the signature. We could have something like

pure def MyOperator: (pure (int) => bool, str) => bool
// => ok
def MyOperator: (pure (int) => bool, str) => bool
// => ok
pure def MyOperator: ((int) => bool, str) => bool
// => Error: unpure operator used by pure operator
def MyOperator: ((int) => bool, str) => bool

Alternatively, we could use a stateful/stateless syntax so this is always specified (versus omitted/present pure):

stateless def MyOperator: (stateless (int) => bool, str) => bool
// => ok
stateful def MyOperator: (stateless (int) => bool, str) => bool
// => ok
stateless def MyOperator: (stateful (int) => bool, str) => bool
// => Error: unpure operator used by pure operator
stateful def MyOperator: (stateful (int) => bool, str) => bool

WDYT? @shonfeder @konnov
I think I like the first one better. pure can be completely optional and we could tip people to include it via linting, i.e.:

💡 This operator is stateless, include the keyword pure

@bugarela
Copy link
Collaborator Author

I've created a milestone to track progress on the effect system: https://github.com/informalsystems/tnt/milestone/3

When that's finished, we should decide on how to use modes to restrict an expression's effect and add some checks.

@shonfeder shonfeder added this to the Effect System milestone May 24, 2022
@bugarela
Copy link
Collaborator Author

bugarela commented Jul 7, 2022

Upon further understanding of operator's effects, we realize almost all operators should take parameters with a Read[*] effect. Take integer addition for example:

iadd: (Read[p1], Read[p2]) => Read[p1, p2]

Even tho it represents a pure function, it can propagate reads:

x: Read['x']
1: Pure
x + 1: Read['x']

So perhaps the desired definition for the pure mode is something like: An operator that doesn't add any read effect on top of the reads of its parameters.

@konnov konnov added the effect system Quint effects checker label Jul 15, 2022
@konnov
Copy link
Contributor

konnov commented Sep 8, 2022

#187 hopefully unblocks this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effect system Quint effects checker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants