Changeset 471ff17

Jun 10, 2021, 4:20:25 PM (2 years ago)
Andrew Beach <ajbeach@…>
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum

Andrew MMath: Addressed most of the changes in intro and worked on the new background section. (2/3 for this review.)

1 edited


  • doc/theses/andrew_beach_MMath/intro.tex

    r382edbe r471ff17  
    3 % Talk about Cforall and exceptions generally.
     3% The highest level overview of Cforall and EHMs. Get this done right away.
    44This thesis goes over the design and implementation of the exception handling
    55mechanism (EHM) of
    66\CFA (pernounced sea-for-all and may be written Cforall or CFA).
     8% Now take a step back and explain what exceptions are generally.
    79Exception handling provides dynamic inter-function control flow.
    810There are two forms of exception handling covered in this thesis:
    911termination, which acts as a multi-level return,
    1012and resumption, which is a dynamic function call.
     13Termination handling is much more common,
     14to the extent that it is often seen
    1115This seperation is uncommon because termination exception handling is so
    1216much more common that it is often assumed.
     17% WHY: Mention other forms of continuation and \cite{CommonLisp} here?
     18A language's EHM is the combination of language syntax and run-time
     19components that are used to construct, raise and handle exceptions,
     20including all control flow.
    1422Termination exception handling allows control to return to any previous
    3038most of the cost only when the error actually occurs.
    32 % Overview of exceptions in Cforall.
     40\section{Thesis Overview}
    3341This work describes the design and implementation of the \CFA EHM.
    3442The \CFA EHM implements all of the common exception features (or an
    5361% A note that yes, that was a very fast overview.
    54 All the design and implementation of all of \CFA's EHM's features are
     62The design and implementation of all of \CFA's EHM's features are
    5563described in detail throughout this thesis, whether they are a common feature
    5664or one unique to \CFA.
    5866% The current state of the project and what it contributes.
    59 All of these features have been added to the \CFA implemenation, along with
     67All of these features have been implemented in \CFA, along with
    6068a suite of test cases as part of this project.
    6169The implementation techniques are generally applicable in other programming
    84 \todo{I can't figure out a good lead-in to the overview.}
    85 Covering the existing \CFA features in \autoref{c:existing}.
    86 Then the new features are introduce in \autoref{c:features}, explaining their
    87 usage and design.
     92\todo{I can't figure out a good lead-in to the roadmap.}
     93The next section covers the existing state of exceptions.
     94The existing state of \CFA is also covered in \autoref{c:existing}.
     95The new features are introduced in \autoref{c:features},
     96which explains their usage and design.
    8897That is followed by the implementation of those features in
    90 % Future Work \autoref{c:future}
     99The performance results are examined in \autoref{c:performance}.
     100Possibilities to extend this project are discussed in \autoref{c:future}.
     105Exception handling is not a new concept,
     106with papers on the subject dating back 70s.
     108Their were popularised by \Cpp,
     109which added them in its first major wave of non-object-orientated features
     110in 1990.
     113Java was the next popular language to use exceptions. It is also the most
     114popular language with checked exceptions.
     115Checked exceptions are part of the function interface they are raised from.
     116This includes functions they propogate through, until a handler for that
     117type of exception is found.
     118This makes exception information explicit, which can improve clarity and
     119safety, but can slow down programming.
     120Some of these, such as dealing with high-order methods or an overly specified
     121throws clause, are technical. However some of the issues are much more
     122human, in that writing/updating all the exception signatures can be enough
     123of a burden people will hack the system to avoid them.
     124Including the ``catch-and-ignore" pattern where a catch block is used without
     125anything to repair or recover from the exception.
     128Resumption exceptions have been much less popular.
     129Although resumption has a history as old as termination's, very few
     130programming languages have implement them.
     132%   CSL-79-3_Mesa_Language_Manual_Version_5.0.pdf
     133Mesa is one programming languages that did and experiance with that
     134languages is quoted as being one of the reasons resumptions were not
     135included in the \Cpp standard.
     137\todo{A comment about why we did include them when they are so unpopular
     138might be approprate.}
     141Functional languages, tend to use solutions like the return union, but some
     142exception-like constructs still appear.
     144For instance Haskell's built in error mechanism can make the result of any
     145expression, including function calls. Any expression that examines an
     146error value will in-turn produce an error. This continues until the main
     147function produces an error or until it is handled by one of the catch
     151More recently exceptions seem to be vanishing from newer programming
     153Rust and Go reduce this feature to panics.
     154Panicing is somewhere between a termination exception and a program abort.
     155Notably in Rust a panic can trigger either, a panic may unwind the stack or
     156simply kill the process.
     158Go's panic is much more similar to a termination exception but there is
     159only a catch-all function with \code{Go}{recover()}.
     160So exceptions still are appearing, just in reduced forms.
     163Exception handling's most common use cases are in error handling.
     164Here are some other ways to handle errors and comparisons with exceptions.
     166\item\emph{Error Codes}:
     167This pattern uses an enumeration (or just a set of fixed values) to indicate
     168that an error has occured and which error it was.
     170There are some issues if a function wants to return an error code and another
     171value. The main issue is that it can be easy to forget checking the error
     172code, which can lead to an error being quitely and implicitly ignored.
     173Some new languages have tools that raise warnings if the return value is
     174discarded to avoid this.
     175It also puts more code on the main execution path.
     176\item\emph{Special Return with Global Store}:
     177A function that encounters an error returns some value indicating that it
     178encountered a value but store which error occured in a fixed global location.
     180Perhaps the C standard @errno@ is the most famous example of this,
     181where some standard library functions will return some non-value (often a
     182NULL pointer) and set @errno@.
     184This avoids the multiple results issue encountered with straight error codes
     185but otherwise many of the same advantages and disadvantages.
     186It does however introduce one other major disadvantage:
     187Everything that uses that global location must agree on all possible errors.
     188\item\emph{Return Union}:
     189Replaces error codes with a tagged union.
     190Success is one tag and the errors are another.
     191It is also possible to make each possible error its own tag and carry its own
     192additional information, but the two branch format is easy to make generic
     193so that one type can be used everywhere in error handling code.
     195This pattern is very popular in functional or semi-functional language,
     196anything with primitive support for tagged unions (or algebraic data types).
     197% We need listing Rust/rust to format code snipits from it.
     198% Rust's \code{rust}{Result<T, E>}
     200The main disadvantage is again it puts code on the main execution path.
     201This is also the first technique that allows for more information about an
     202error, other than one of a fix-set of ids, to be sent.
     203They can be missed but some languages can force that they are checked.
     204It is also implicitly forced in any languages with checked union access.
     205\item\emph{Handler Functions}:
     206On error the function that produced the error calls another function to
     207handle it.
     208The handler function can be provided locally (passed in as an argument,
     209either directly as as a field of a structure/object) or globally (a global
     212C++ uses this as its fallback system if exception handling fails.
     213\snake{std::terminate_handler} and for a time \snake{std::unexpected_handler}
     215Handler functions work a lot like resumption exceptions.
     216The difference is they are more expencive to set up but cheaper to use, and
     217so are more suited to more fequent errors.
     218The exception being global handlers if they are rarely change as the time
     219in both cases strinks towards zero.
     223Because of their cost exceptions are rarely used for hot paths of execution.
     224There is an element of self-fulfilling prophocy here as implementation
     225techniques have been designed to make exceptions cheap to set-up at the cost
     226of making them expencive to use.
     227Still, use of exceptions for other tasks is more common in higher-level
     228scripting languages.
     229An iconic example is Python's StopIteration exception which is thrown by
     230an iterator to indicate that it is exausted. Combined with Python's heavy
     231use of the iterator based for-loop.
Note: See TracChangeset for help on using the changeset viewer.