Ignore:
Timestamp:
Mar 4, 2021, 7:40:25 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
77d601f
Parents:
342af53 (diff), a5040fe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/future.tex

    r342af53 r8e4aa05  
    11\chapter{Future Work}
    22
     3\section{Language Improvements}
     4\CFA is a developing programming language. As such, there are partially or
     5unimplemented features of the language (including several broken components)
     6that I had to workaround while building an exception handling system largely in
     7the \CFA language (some C components).  The following are a few of these
     8issues, and once implemented/fixed, how this would affect the exception system.
     9\begin{itemize}
     10\item
     11The implementation of termination is not portable because it includes
     12hand-crafted assembly statements. These sections must be ported by hand to
     13support more hardware architectures, such as the ARM processor.
     14\item
     15Due to a type-system problem, the catch clause cannot bind the exception to a
     16reference instead of a pointer. Since \CFA has a very general reference
     17capability, programmers will want to use it. Once fixed, this capability should
     18result in little or no change in the exception system.
     19\item
     20Termination handlers cannot use local control-flow transfers, \eg by @break@,
     21@return@, \etc. The reason is that current code generation hoists a handler
     22into a nested function for convenience (versus assemble-code generation at the
     23@try@ statement). Hence, when the handler runs, its code is not in the lexical
     24scope of the @try@ statement, where the local control-flow transfers are
     25meaningful.
     26\item
     27There is no detection of colliding unwinds. It is possible for clean-up code
     28run during an unwind to trigger another unwind that escapes the clean-up code
     29itself; such as a termination exception caught further down the stack or a
     30cancellation. There do exist ways to handle this but currently they are not
     31even detected and the first unwind will simply be forgotten, often leaving
     32it in a bad state.
     33\item
     34Also the exception system did not have a lot of time to be tried and tested.
     35So just letting people use the exception system more will reveal new
     36quality of life upgrades that can be made with time.
     37\end{itemize}
     38
    339\section{Complete Virtual System}
    4 The virtual system should be completed. It was never supposed to be part of
    5 this project and so minimal work was done on it. A draft of what the complete
    6 system might look like was created but it was never finalized or implemented.
    7 A future project in \CFA would be to complete that work and to update the
    8 parts of the exception system that use the current version.
     40The virtual system should be completed. It was not supposed to be part of this
     41project, but was thrust upon it to do exception inheritance; hence, only
     42minimal work was done. A draft for a complete virtual system is available but
     43it is not finalized.  A future \CFA project is to complete that work and then
     44update the exception system that uses the current version.
    945
    10 For instance a full virtual system would probably allow for several
    11 improvements to the exception traits. Although they do currently work they
    12 could be made easier to use by making the virtual table type implitate in the
    13 trait (which would remove the need for those wrapper marcos) or allowing
    14 for assertions that give the layout of a virtual table for safety.
     46There are several improvements to the virtual system that would improve the
     47exception traits. The most important one is an assertion to check one virtual
     48type is a child of another. This check precisely captures many of the
     49correctness requirements.
    1550
    16 \section{Additional Throws}
    17 Several other kinds of throws, beyond the termination throw (\codeCFA{throw}),
    18 the resumption throw (\codeCFA{throwResume}) and the re-throws, were considered.
    19 None were as useful as the core throws but they would likely be worth
    20 revising.
     51The full virtual system might also include other improvement like associated
     52types to allow traits to refer to types not listed in their header. This
     53feature allows exception traits to not refer to the virtual-table type
     54explicitly, removing the need for the current interface macros.
    2155
    22 The first ones are throws for asynchronous exceptions, throwing exceptions
    23 from one stack to another. These act like signals allowing for communication
    24 between the stacks. This is usually used with resumption as it allows the
    25 target stack to continue execution normally after the exception has been
    26 handled.
     56\section{Additional Raises}
     57Several other kinds of exception raises were considered beyond termination
     58(@throw@), resumption (@throwResume@), and reraise.
    2759
    28 This would much more coordination between the concurrency system and the
    29 exception system to handle. Most of the interesting design decisions around
    30 applying asynchronous exceptions appear to be around masking (controlling
    31 which exceptions may be thrown at a stack). It would likely require more of
    32 the virtual system and would also effect how default handlers are set.
     60The first is a non-local/concurrent raise providing asynchronous exceptions,
     61\ie raising an exception on another stack. This semantics acts like signals
     62allowing for out-of-band communication among coroutines and threads. This kind
     63of raise is often restricted to resumption to allow the target stack to
     64continue execution normally after the exception has been handled. That is,
     65allowing one coroutine/thread to unwind the stack of another via termination is
     66bad software engineering.
    3367
    34 The other throws were designed to mimic bidirectional algebraic effects.
    35 Algebraic effects are used in some functional languages and allow a function
     68Non-local/concurrent requires more coordination between the concurrency system
     69and the exception system. Many of the interesting design decisions centre
     70around masking (controlling which exceptions may be thrown at a stack). It
     71would likely require more of the virtual system and would also effect how
     72default handlers are set.
     73
     74Other raises were considered to mimic bidirectional algebraic effects.
     75Algebraic effects are used in some functional languages allowing one function
    3676to have another function on the stack resolve an effect (which is defined with
    37 a function-like interface).
    38 These can be mimiced with resumptions and the the new throws were designed
    39 to try and mimic bidirectional algebraic effects, where control can go back
    40 and forth between the function effect caller and handler while the effect
    41 is underway.
     77a functional-like interface).  This semantics can be mimicked with resumptions
     78and new raises were discussed to mimic bidirectional algebraic-effects, where
     79control can go back and forth between the function-effect caller and handler
     80while the effect is underway.
    4281% resume-top & resume-reply
     82These raises would be like the resumption raise except using different search
     83patterns to find the handler.
    4384
    44 These throws would likely be just like the resumption throw except they would
    45 use different search patterns to find the handler to reply to.
     85\section{Zero-Cost Try}
     86\CFA does not have zero-cost try-statements because the compiler generates C
     87code rather than assembler code \see{\VPageref{p:zero-cost}}. When the compiler
     88does create its own assembly (or LLVM byte-code), then zero-cost try-statements
     89are possible. The downside of zero-cost try-statements is the LSDA complexity,
     90its size (program bloat), and the high cost of raising an exception.
    4691
    47 \section{Zero-Cost Exceptions}
    48 \CFA does not have zero-cost exceptions because it does not generate assembly
    49 but instead generates C code. See the implementation section. When the
    50 compiler does start to create its own assembly (or LLVM byte code) then
    51 zero-cost exceptions could be implemented.
     92Alternatively, some research could be done into the simpler alternative method
     93with a non-zero-cost try-statement but much lower cost exception raise. For
     94example, programs are starting to use exception in the normal control path, so
     95more exceptions are thrown. In these cases, the cost balance switches towards
     96low-cost raise. Unfortunately, while exceptions remain exceptional, the
     97libunwind model will probably remain the most effective option.
    5298
    53 Now in zero-cost exceptions the only part that is zero-cost are the try
    54 blocks. Some research could be done into the alternative methods for systems
    55 that expect a lot more exceptions to be thrown, allowing some overhead in
    56 entering and leaving try blocks to make throws faster. But while exceptions
    57 remain exceptional the libunwind model will probably remain the most effective
    58 option.
     99Zero-cost resumptions is still an open problem. First, because libunwind does
     100not support a successful-exiting stack-search without doing an unwind.
     101Workarounds are possible but awkward. Ideally an extension to libunwind could
     102be made, but that would either require separate maintenance or gain enough
     103support to have it folded into the standard.
    59104
    60 Zero-cost resumptions have more problems to solve. First because libunwind
    61 does not support a successful exiting stack search without doing an unwind.
    62 There are several ways to hack that functionality in. Ideally an extension to
    63 libunwind could be made, but that would either require seperate maintenance
    64 or gain enough support to have it folded into the standard.
     105Also new techniques to skip previously searched parts of the stack need to be
     106developed to handle the recursive resume problem and support advanced algebraic
     107effects.
    65108
    66 Also new techniques to skip previously searched parts of the stack will have
    67 to be developed.
     109\section{Signal Exceptions}
     110Goodenough~\cite{Goodenough75} suggests three types of exceptions: escape,
     111notify and signal.  Escape are termination exceptions, notify are resumption
     112exceptions, leaving signal unimplemented.
    68113
    69 \section{Support for More Platforms}
    70 Termination is not portable because it is implemented with inline assembly.
    71 Those sections will have to be rewritten to support different architectures
     114A signal exception allows either behaviour, \ie after an exception is handled,
     115the handler has the option of returning to the raise or after the @try@
     116statement. Currently, \CFA fixes the semantics of the handler return
     117syntactically by the @catch@ or @catchResume@ clause.
    72118
    73 \section{Quality-of-Life Improvements}
    74 Finally come various improvements to the usability of \CFA. Most of these
    75 would just require time. Time that would not lead to interesting research so
    76 it has been left aside for now. A few examples are included here but there
    77 are more:
     119Signal exception should be reexamined and possibly be supported in \CFA. A very
     120direct translation is to have a new raise and catch pair, and a new statement
     121(or statements) would indicate if the handler returns to the raise or continues
     122where it is; but there may be other options.
    78123
    79 \begin{itemize}
    80 \item Allowing exception handler to bind the exception to a reference instead
    81 of a pointer. This should actually result in no change in behaviour so there
    82 is no reason not to allow it. It is however a small improvement; giving a bit
    83 of flexibility to the user in what style they want to use.
    84 \item Enabling local control flow (by \codeCFA{break}, \codeCFA{return} and
    85 similar statements) out of a termination handler. The current set-up makes
    86 this very difficult but the catch function that runs the handler after it has
    87 been matched could be inlined into the function's body, which would make this
    88 much easier. (To do the same for try blocks would probably wait for zero-cost
    89 exceptions, which would allow the try block to be inlined as well.)
    90 \item Enabling local control flow out of a resumption handler. This would be
    91 a weighty operation, causing a stack unwind like a termination, so there might
    92 be a different statement or a statement modifier to make sure the user does
    93 this purposefully.
     124For instance, resumption could be extended to cover this use by allowing local
     125control flow out of it. This approach would require an unwind as part of the
     126transition as there are stack frames that have to be removed.  This approach
     127means there is no notify raise, but because \CFA does not have exception
     128signatures, a termination can be thrown from within any resumption handler so
     129there is already a way to do mimic this in existing \CFA.
    94130
    95 However this would require the more complex system as they cannot be inlined
    96 into the original function as they can be run at a different place on the
    97 stack. So instead the unwinding will have to carry with it information on
    98 which one of these points to continue at and possibly also the return value
    99 for the function if a \codeCFA{return} statement was used.
    100 \end{itemize}
     131% Maybe talk about the escape; and escape CONTROL_STMT; statements or how
     132% if we could choose if _Unwind_Resume proceeded to the clean-up stage this
     133% would be much easier to implement.
Note: See TracChangeset for help on using the changeset viewer.