relax
relax copied to clipboard
[Discuss][Types] Adding annotations for purity, dataflow, etc into function signatures
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:
- 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.
- 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?