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