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