source: doc/theses/andrew_beach_MMath/future.tex @ 9cd37d9

Last change on this file since 9cd37d9 was 9cd37d9, checked in by Andrew Beach <ajbeach@…>, 22 months ago

Andrew MMath: Folded in Peter's feedback on the Future Work chapter.

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