[a032992] | 1 | \chapter{Future Work} |
---|
[553f8abe] | 2 | \label{c:future} |
---|
[a032992] | 3 | |
---|
[9cd37d9] | 4 | The following discussion covers both possible interesting research |
---|
| 5 | that could follow from this work as long as simple implementation |
---|
| 6 | improvements. |
---|
| 7 | |
---|
[7eb6eb5] | 8 | \section{Language Improvements} |
---|
[9cd37d9] | 9 | |
---|
[7eb6eb5] | 10 | \CFA is a developing programming language. As such, there are partially or |
---|
[9cd37d9] | 11 | unimplemented features (including several broken components) |
---|
| 12 | that I had to workaround while building the EHM largely in |
---|
| 13 | the \CFA language (some C components). Below are a few of these issues |
---|
| 14 | and how implementing/fixing them would affect the EHM. |
---|
| 15 | In addition there are some simple improvements that had no interesting |
---|
| 16 | research attached to them but would make using the language easier. |
---|
[7eb6eb5] | 17 | \begin{itemize} |
---|
| 18 | \item |
---|
| 19 | Due to a type-system problem, the catch clause cannot bind the exception to a |
---|
| 20 | reference instead of a pointer. Since \CFA has a very general reference |
---|
| 21 | capability, programmers will want to use it. Once fixed, this capability should |
---|
[edebbf7] | 22 | result in little or no change in the exception system but simplify usage. |
---|
[7eb6eb5] | 23 | \item |
---|
| 24 | Termination handlers cannot use local control-flow transfers, \eg by @break@, |
---|
| 25 | @return@, \etc. The reason is that current code generation hoists a handler |
---|
| 26 | into a nested function for convenience (versus assemble-code generation at the |
---|
[9cd37d9] | 27 | try statement). Hence, when the handler runs, it can still access local |
---|
| 28 | variables in the lexical scope of the try statement. Still, it does mean |
---|
| 29 | that seemingly local control flow is not in fact local and crosses a function |
---|
| 30 | boundary. |
---|
| 31 | Making the termination handlers code within the surrounding |
---|
| 32 | function would remove this limitation. |
---|
| 33 | % Try blocks are much more difficult to do practically (requires our own |
---|
| 34 | % assembly) and resumption handlers have some theoretical complexity. |
---|
[29c9b23] | 35 | \item |
---|
| 36 | There is no detection of colliding unwinds. It is possible for clean-up code |
---|
| 37 | run during an unwind to trigger another unwind that escapes the clean-up code |
---|
[b51e389c] | 38 | itself; such as a termination exception caught further down the stack or a |
---|
[9cd37d9] | 39 | cancellation. There do exist ways to handle this case, but currently there is |
---|
| 40 | no detection and the first unwind will simply be forgotten, often leaving |
---|
[b51e389c] | 41 | it in a bad state. |
---|
[29c9b23] | 42 | \item |
---|
[9cd37d9] | 43 | Finally, the exception system has not had a lot of programmer testing. |
---|
| 44 | More time with encouraged usage will reveal new |
---|
| 45 | quality of life upgrades that can be made. |
---|
[7eb6eb5] | 46 | \end{itemize} |
---|
| 47 | |
---|
[a032992] | 48 | \section{Complete Virtual System} |
---|
[7eb6eb5] | 49 | The virtual system should be completed. It was not supposed to be part of this |
---|
| 50 | project, but was thrust upon it to do exception inheritance; hence, only |
---|
[edebbf7] | 51 | minimal work is done. A draft for a complete virtual system is available but |
---|
[9cd37d9] | 52 | not finalized. A future \CFA project is to complete that work and then |
---|
[7eb6eb5] | 53 | update the exception system that uses the current version. |
---|
[a032992] | 54 | |
---|
[7eb6eb5] | 55 | There are several improvements to the virtual system that would improve the |
---|
| 56 | exception traits. The most important one is an assertion to check one virtual |
---|
| 57 | type is a child of another. This check precisely captures many of the |
---|
[9cd37d9] | 58 | current ad-hoc correctness requirements. |
---|
[02b73ea] | 59 | |
---|
| 60 | The full virtual system might also include other improvement like associated |
---|
[7eb6eb5] | 61 | types to allow traits to refer to types not listed in their header. This |
---|
| 62 | feature allows exception traits to not refer to the virtual-table type |
---|
[9cd37d9] | 63 | explicitly, removing the need for the current interface macros, |
---|
| 64 | such as @EHM_IS_EXCEPTION@. |
---|
[7eb6eb5] | 65 | |
---|
| 66 | \section{Additional Raises} |
---|
| 67 | Several other kinds of exception raises were considered beyond termination |
---|
| 68 | (@throw@), resumption (@throwResume@), and reraise. |
---|
| 69 | |
---|
| 70 | The first is a non-local/concurrent raise providing asynchronous exceptions, |
---|
| 71 | \ie raising an exception on another stack. This semantics acts like signals |
---|
| 72 | allowing for out-of-band communication among coroutines and threads. This kind |
---|
| 73 | of raise is often restricted to resumption to allow the target stack to |
---|
| 74 | continue execution normally after the exception has been handled. That is, |
---|
| 75 | allowing one coroutine/thread to unwind the stack of another via termination is |
---|
| 76 | bad software engineering. |
---|
| 77 | |
---|
[edebbf7] | 78 | Non-local/concurrent raise requires more |
---|
| 79 | coordination between the concurrency system |
---|
[9cd37d9] | 80 | and the exception system. Many of the interesting design decisions center |
---|
[edebbf7] | 81 | around masking, \ie controlling which exceptions may be thrown at a stack. It |
---|
[7eb6eb5] | 82 | would likely require more of the virtual system and would also effect how |
---|
| 83 | default handlers are set. |
---|
| 84 | |
---|
| 85 | Other raises were considered to mimic bidirectional algebraic effects. |
---|
| 86 | Algebraic effects are used in some functional languages allowing one function |
---|
[a032992] | 87 | to have another function on the stack resolve an effect (which is defined with |
---|
[7eb6eb5] | 88 | a functional-like interface). This semantics can be mimicked with resumptions |
---|
| 89 | and new raises were discussed to mimic bidirectional algebraic-effects, where |
---|
| 90 | control can go back and forth between the function-effect caller and handler |
---|
| 91 | while the effect is underway. |
---|
[a032992] | 92 | % resume-top & resume-reply |
---|
[7eb6eb5] | 93 | These raises would be like the resumption raise except using different search |
---|
| 94 | patterns to find the handler. |
---|
| 95 | |
---|
[826ee62] | 96 | \section{Checked Exceptions} |
---|
[edebbf7] | 97 | Checked exceptions make exceptions part of a function's type by adding an |
---|
[826ee62] | 98 | exception signature. An exception signature must declare all checked |
---|
[9cd37d9] | 99 | exceptions that could propagate from the function, either because they were |
---|
| 100 | raised inside the function or came from a sub-function. This improves safety |
---|
[826ee62] | 101 | by making sure every checked exception is either handled or consciously |
---|
| 102 | passed on. |
---|
| 103 | |
---|
[b51e389c] | 104 | However checked exceptions were never seriously considered for this project |
---|
[9cd37d9] | 105 | because they have significant trade-offs in usability and code reuse in |
---|
[826ee62] | 106 | exchange for the increased safety. |
---|
| 107 | These trade-offs are most problematic when trying to pass exceptions through |
---|
| 108 | higher-order functions from the functions the user passed into the |
---|
| 109 | higher-order function. There are no well known solutions to this problem |
---|
[edebbf7] | 110 | that were satisfactory for \CFA (which carries some of C's flexibility |
---|
| 111 | over safety design) so additional research is needed. |
---|
[826ee62] | 112 | |
---|
[edebbf7] | 113 | Follow-up work might add some form of checked exceptions to \CFA, |
---|
| 114 | possibly using polymorphic exception signatures, |
---|
| 115 | a form of tunneling\cite{Zhang19} or |
---|
[826ee62] | 116 | checked and unchecked raises. |
---|
| 117 | |
---|
[7eb6eb5] | 118 | \section{Zero-Cost Try} |
---|
| 119 | \CFA does not have zero-cost try-statements because the compiler generates C |
---|
[df24d37] | 120 | code rather than assembler code (see \vpageref{p:zero-cost}). When the compiler |
---|
[7eb6eb5] | 121 | does create its own assembly (or LLVM byte-code), then zero-cost try-statements |
---|
| 122 | are possible. The downside of zero-cost try-statements is the LSDA complexity, |
---|
| 123 | its size (program bloat), and the high cost of raising an exception. |
---|
| 124 | |
---|
| 125 | Alternatively, some research could be done into the simpler alternative method |
---|
| 126 | with a non-zero-cost try-statement but much lower cost exception raise. For |
---|
| 127 | example, programs are starting to use exception in the normal control path, so |
---|
| 128 | more exceptions are thrown. In these cases, the cost balance switches towards |
---|
| 129 | low-cost raise. Unfortunately, while exceptions remain exceptional, the |
---|
| 130 | libunwind model will probably remain the most effective option. |
---|
| 131 | |
---|
| 132 | Zero-cost resumptions is still an open problem. First, because libunwind does |
---|
| 133 | not support a successful-exiting stack-search without doing an unwind. |
---|
| 134 | Workarounds are possible but awkward. Ideally an extension to libunwind could |
---|
[9cd37d9] | 135 | be made, but that would either require separate maintenance or gaining enough |
---|
| 136 | support to have it folded into the official library itself. |
---|
[7eb6eb5] | 137 | |
---|
| 138 | Also new techniques to skip previously searched parts of the stack need to be |
---|
| 139 | developed to handle the recursive resume problem and support advanced algebraic |
---|
| 140 | effects. |
---|
[02b73ea] | 141 | |
---|
| 142 | \section{Signal Exceptions} |
---|
[7eb6eb5] | 143 | Goodenough~\cite{Goodenough75} suggests three types of exceptions: escape, |
---|
| 144 | notify and signal. Escape are termination exceptions, notify are resumption |
---|
| 145 | exceptions, leaving signal unimplemented. |
---|
| 146 | |
---|
| 147 | A signal exception allows either behaviour, \ie after an exception is handled, |
---|
| 148 | the handler has the option of returning to the raise or after the @try@ |
---|
| 149 | statement. Currently, \CFA fixes the semantics of the handler return |
---|
| 150 | syntactically by the @catch@ or @catchResume@ clause. |
---|
| 151 | |
---|
| 152 | Signal exception should be reexamined and possibly be supported in \CFA. A very |
---|
| 153 | direct translation is to have a new raise and catch pair, and a new statement |
---|
| 154 | (or statements) would indicate if the handler returns to the raise or continues |
---|
| 155 | where it is; but there may be other options. |
---|
| 156 | |
---|
| 157 | For instance, resumption could be extended to cover this use by allowing local |
---|
| 158 | control flow out of it. This approach would require an unwind as part of the |
---|
[edebbf7] | 159 | transition as there are stack frames that have to be removed between where |
---|
| 160 | the resumption handler is installed and where it is defined. |
---|
| 161 | This approach would not require, but might benefit from, a special statement |
---|
| 162 | to leave the handler. |
---|
| 163 | Currently, mimicking this behaviour in \CFA is possible by throwing a |
---|
[9cd37d9] | 164 | termination exception inside a resumption handler. |
---|
[a032992] | 165 | |
---|
[02b73ea] | 166 | % Maybe talk about the escape; and escape CONTROL_STMT; statements or how |
---|
| 167 | % if we could choose if _Unwind_Resume proceeded to the clean-up stage this |
---|
| 168 | % would be much easier to implement. |
---|