cadence icon indicating copy to clipboard operation
cadence copied to clipboard

Expose on statement handler in runtime config

Open devbugging opened this issue 1 year ago • 17 comments

Issue to be solved

Providing custom statement handlers to the runtime is currently not possible.

Suggested Solution

Exposing the statement handler to config could be beneficial for passing any kind of custom statement handlers, which one such use case would be the execution debugger I'm working on, but also I feel the coverage reporter is another use case. Currently, the coverage report was added to the config https://github.com/onflow/cadence/blob/cc5644b671468ee11075b1a81cd1d7797a895b2a/runtime/config.go#L37 and then the runtime environment depends on that type and has control to decide what to do with it https://github.com/onflow/cadence/blob/ce732a847ddf31e9f07ea3d5414ea5d0707e7450/runtime/environment.go#L609 I think the inversion of control could be done and have config define a statement handlers slice, which would be defined by an interface having OnStatement, then the newOnStatementHandler could just make sure the handlers are wrapped inside of the returning interpreter.OnStatementFunc. This would also make the runtime config more configurable and contain less exposed members, as if adding different members for each use case where we need to have an action on execution of a statement.

devbugging avatar Apr 07 '23 10:04 devbugging