Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

[Discuss][Types] Adding annotations for purity, dataflow, etc into function signatures #224

Open
slyubomirsky opened this issue Aug 17, 2022 · 0 comments

Comments

@slyubomirsky
Copy link
Collaborator

slyubomirsky commented Aug 17, 2022

Currently, there is no way to indicate which packed funcs are safe to call inside a dataflow block, since any of them can potentially have side effects. It would be useful to have a system of annotations to indicate properties about functions that might be relevant to the compiler. For example, we could have a "dataflow" property that indicates that the function is pure and does not have control flow and "pure" to indicate simply a pure function.

Here are some ways we could achieve this:

  1. Add annotations to the type signature. These properties could be checked during type checking. We might indicate them as a decorator, like so:
@R.function
@R.dataflow
def f(...):
     # error during type checking if there is a recursive call, an if-else expression, or a call to a function or packed func that is not marked as dataflow
     ...

(for calls to call_packed, we could take an annotation argument). The type checker could potentially infer dataflow or purity properties as well.

  1. Include "dataflow" or "pure" as an attribute at call sites. This would be easier in terms of type checking but might be harder to automatically enforce and would require attributes to be indicated in many places.

Any other thoughts on how we might add a mechanism for indicating what is safe to call inside a dataflow block?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant