Effects to Control Code Generation
Certain operations require specific capabilities of the code generated by a
compiler. An example is a feature
callTrace that would deliver a
list of all the calls that led to the current position.
Wrapping code that creates a call trace into an effect would mean that the
fact that a call trace is created becomes clear from the effects required by a
feature (and listed in its signature). The code to obtain a call trace would
then be something like
Such an effect could then be implemented by different effect handlers, the default one should provide a full call trace, while there could be dummy handlers that suppress call traces or some that restrict call traces, e.g., to restrict information flow or enable optimizations.
There could be several application areas to influence code generation. Examples include:
- call traces for debugging, exceptions, etc.
- callback hooks on every call, for tracing, breakpoints, etc.
- callback hooks on a field write, for debugging
- callback hooks in loops and (recursive) calls to allow, e.g.,
- async abort, i.e., throwing an exception from another thread
- abort after a timeout
- single-step debugging
- enabling generation of specific code, e.g.,
- code to run in specialized hardware (FPGA, GPU, etc.)
- switching CPU mode, e.g., ARM thumb code
- enabling or disabling optimization levels
- control numeric accuracy
- enable region-based memory management
- Allocations will be released when effect is left, assignments will perform checks to make sure no dangling references are created.