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

Synthesis with partial functions #19

Open
1 of 6 tasks
Calvin-L opened this issue Jan 22, 2018 · 0 comments
Open
1 of 6 tasks

Synthesis with partial functions #19

Calvin-L opened this issue Jan 22, 2018 · 0 comments

Comments

@Calvin-L
Copy link
Collaborator

Calvin-L commented Jan 22, 2018

Right now all AST nodes in Cozy are total, meaning that they can never fail. A good example is map lookup (map[key]) which returns a default value if the key is missing rather than throw an exception.

Unfortunately, this means that at codegen time we need to insert additional checks (e.g. "is the key in the map? if not, return a default value"). It would be much better if the synthesizer knew that some functions were only legal under some conditions so that we would not have to emit these checks. After all, in many cases the checks will always be true.

Examples of partial functions:

  • the xs is only legal when xs is a singleton collection
  • for handles, x.val is only legal when x is not null
  • m[key] is only legal when key is in m
  • min xs is only legal when xs is not empty
  • x / y is only legal when y is nonzero

Plan:

  • As far as satisfy and eval are concerned, everything remains total
  • Need a new function fails : Exp -> Exp that produces a boolean expression describing under what circumstances the input expression fails
  • Optional: all input queries should never fail (their preconditions must be strong enough)
  • Failure on each example should be part of the fingerprint of an expression (and furthermore, failure on an input renders the output value irrelevant when comparing fingerprints)
  • core.py should ensure that not only does the new expression produce the same values, but it may only fail when the original expression fails (although the output is allowed to fail less often)
  • Codegen may then skip unnecessary checks on partial AST nodes
Calvin-L added a commit that referenced this issue Aug 23, 2018
However, true support is currently blocked on #19.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant