cadence
cadence copied to clipboard
Purity Enforcement
Closes https://github.com/onflow/cadence/issues/1806
Implements the enforcement for the purity analysis implemented in https://github.com/onflow/cadence/pull/1818
Currently, impure operations (those operations banned in pure
contexts), are:
- Calling an impure function (including any functions that modify account state or storage or log values)
- Emitting an event
- Writing to any resources
- Writing to any references
- Indexed assignment or writes to any variables not statically knowable to have been defined in the current function's scope
This is very restrictive; however given that the purpose of pure
functions is to allow some operations to be performed in function pre and post-conditions, it is unlikely that support for a more complex analysis is worth the complexity it would require. As it stands, this allows calls to pure functions on composites, creation of composites with pure
initializers, and any operations that don't perform an assignment.
- [ ] Targeted PR against
master
branch - [X] Linked to Github issue with discussion and accepted design OR link to spec that describes this work
- [X] Code follows the standards mentioned here
- [X] Updated relevant documentation
- [X] Re-reviewed
Files changed
in the Github PR explorer - [X] Added appropriate labels