Ignore:
Timestamp:
Sep 10, 2021, 10:43:15 AM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
63b3279
Parents:
d0b9247
Message:

Andrew MMath: Used (most of) Gregor's feedback to update the thesis. There are still a few \todo items as well as a general request for examples.

File:
1 edited

Legend:

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

    rd0b9247 r9cdfa5fb  
    2525All types of exception handling link a raise with a handler.
    2626Both operations are usually language primitives, although raises can be
    27 treated as a primitive function that takes an exception argument.
    28 Handlers are more complex as they are added to and removed from the stack
    29 during execution, must specify what they can handle and give the code to
     27treated as a function that takes an exception argument.
     28Handlers are more complex, as they are added to and removed from the stack
     29during execution, must specify what they can handle and must give the code to
    3030handle the exception.
    3131
     
    4141\input{termination}
    4242\end{center}
     43%\todo{What does the right half of termination.fig mean?}
    4344
    4445Resumption exception handling searches the stack for a handler and then calls
     
    4647The handler is run on top of the existing stack, often as a new function or
    4748closure capturing the context in which the handler was defined.
    48 After the handler has finished running it returns control to the function
     49After the handler has finished running, it returns control to the function
    4950that preformed the raise, usually starting after the raise.
    5051\begin{center}
     
    5354
    5455Although a powerful feature, exception handling tends to be complex to set up
    55 and expensive to use
     56and expensive to use,
    5657so it is often limited to unusual or ``exceptional" cases.
    57 The classic example is error handling, exceptions can be used to
     58The classic example is error handling; exceptions can be used to
    5859remove error handling logic from the main execution path, and pay
    5960most of the cost only when the error actually occurs.
     
    6364The \CFA EHM implements all of the common exception features (or an
    6465equivalent) found in most other EHMs and adds some features of its own.
    65 The design of all the features had to be adapted to \CFA's feature set as
     66The design of all the features had to be adapted to \CFA's feature set, as
    6667some of the underlying tools used to implement and express exception handling
    6768in other languages are absent in \CFA.
    68 Still the resulting syntax resembles that of other languages:
     69Still, the resulting syntax resembles that of other languages:
    6970\begin{cfa}
    7071try {
     
    8889covering both changes to the compiler and the run-time.
    8990In addition, a suite of test cases and performance benchmarks were created
    90 along side the implementation.
     91alongside the implementation.
    9192The implementation techniques are generally applicable in other programming
    9293languages and much of the design is as well.
     
    100101\item Implementing stack unwinding and the \CFA EHM, including updating
    101102the \CFA compiler and the run-time environment.
    102 \item Designed and implemented a prototype virtual system.
     103\item Designing and implementing a prototype virtual system.
    103104% I think the virtual system and per-call site default handlers are the only
    104105% "new" features, everything else is a matter of implementation.
    105106\item Creating tests to check the behaviour of the EHM.
    106 \item Creating benchmarks to check the performances of the EHM,
     107\item Creating benchmarks to check the performance of the EHM,
    107108as compared to other languages.
    108109\end{enumerate}
     
    110111The rest of this thesis is organized as follows.
    111112The current state of exceptions is covered in \autoref{s:background}.
    112 The existing state of \CFA is also covered in \autoref{c:existing}.
     113The existing state of \CFA is covered in \autoref{c:existing}.
    113114New EHM features are introduced in \autoref{c:features},
    114115covering their usage and design.
     
    137138inheriting from
    138139\code{C++}{std::exception}.
    139 Although there is a special catch-all syntax (@catch(...)@) there are no
     140Although there is a special catch-all syntax (@catch(...)@), there are no
    140141operations that can be performed on the caught value, not even type inspection.
    141 Instead the base exception-type \code{C++}{std::exception} defines common
     142Instead, the base exception-type \code{C++}{std::exception} defines common
    142143functionality (such as
    143144the ability to describe the reason the exception was raised) and all
     
    148149
    149150Java was the next popular language to use exceptions.\cite{Java8}
    150 Its exception system largely reflects that of \Cpp, except that requires
     151Its exception system largely reflects that of \Cpp, except that it requires
    151152you throw a child type of \code{Java}{java.lang.Throwable}
    152153and it uses checked exceptions.
    153154Checked exceptions are part of a function's interface,
    154155the exception signature of the function.
    155 Every function that could be raised from a function, either directly or
     156Every exception that could be raised from a function, either directly or
    156157because it is not handled from a called function, is given.
    157158Using this information, it is possible to statically verify if any given
    158 exception is handled and guarantee that no exception will go unhandled.
     159exception is handled, and guarantee that no exception will go unhandled.
    159160Making exception information explicit improves clarity and safety,
    160161but can slow down or restrict programming.
     
    169170recovery or repair. In theory that could be good enough to properly handle
    170171the exception, but more often is used to ignore an exception that the       
    171 programmer does not feel is worth the effort of handling it, for instance if
     172programmer does not feel is worth the effort of handling, for instance if
    172173they do not believe it will ever be raised.
    173 If they are incorrect the exception will be silenced, while in a similar
     174If they are incorrect, the exception will be silenced, while in a similar
    174175situation with unchecked exceptions the exception would at least activate   
    175 the language's unhandled exception code (usually program abort with an 
     176the language's unhandled exception code (usually, a program abort with an
    176177error message).
    177178
    178179%\subsection
    179180Resumption exceptions are less popular,
    180 although resumption is as old as termination; hence, few
     181although resumption is as old as termination; that is, few
    181182programming languages have implemented them.
    182183% http://bitsavers.informatik.uni-stuttgart.de/pdf/xerox/parc/techReports/
     
    186187included in the \Cpp standard.
    187188% https://en.wikipedia.org/wiki/Exception_handling
    188 Since then resumptions have been ignored in main-stream programming languages.
     189Since then, resumptions have been ignored in main-stream programming languages.
    189190However, resumption is being revisited in the context of decades of other
    190191developments in programming languages.
    191192While rejecting resumption may have been the right decision in the past,
    192193the situation has changed since then.
    193 Some developments, such as the function programming equivalent to resumptions,
     194Some developments, such as the functional programming equivalent to resumptions,
    194195algebraic effects\cite{Zhang19}, are enjoying success.
    195 A complete reexamination of resumptions is beyond this thesis,
    196 but there reemergence is enough to try them in \CFA.
     196A complete reexamination of resumption is beyond this thesis,
     197but their reemergence is enough reason to try them in \CFA.
    197198% Especially considering how much easier they are to implement than
    198199% termination exceptions and how much Peter likes them.
     
    208209
    209210%\subsection
    210 More recently exceptions seem to be vanishing from newer programming
     211More recently exceptions, seem to be vanishing from newer programming
    211212languages, replaced by ``panic".
    212213In Rust, a panic is just a program level abort that may be implemented by
     
    218219
    219220%\subsection
    220 While exception handling's most common use cases are in error handling,
     221As exception handling's most common use cases are in error handling,
    221222here are some other ways to handle errors with comparisons with exceptions.
    222223\begin{itemize}
     
    233234is discarded to avoid this problem.
    234235Checking error codes also bloats the main execution path,
    235 especially if the error is not handled immediately hand has to be passed
     236especially if the error is not handled immediately and has to be passed
    236237through multiple functions before it is addressed.
    237238
    238239\item\emph{Special Return with Global Store}:
    239240Similar to the error codes pattern but the function itself only returns
    240 that there was an error
    241 and store the reason for the error in a fixed global location.
    242 For example many routines in the C standard library will only return some
     241that there was an error,
     242and stores the reason for the error in a fixed global location.
     243For example, many routines in the C standard library will only return some
    243244error value (such as -1 or a null pointer) and the error code is written into
    244245the standard variable @errno@.
     
    253254Success is one tag and the errors are another.
    254255It is also possible to make each possible error its own tag and carry its own
    255 additional information, but the two branch format is easy to make generic
     256additional information, but the two-branch format is easy to make generic
    256257so that one type can be used everywhere in error handling code.
    257258
     
    261262% Rust's \code{rust}{Result<T, E>}
    262263The main advantage is that an arbitrary object can be used to represent an
    263 error so it can include a lot more information than a simple error code.
     264error, so it can include a lot more information than a simple error code.
    264265The disadvantages include that the it does have to be checked along the main
    265 execution and if there aren't primitive tagged unions proper usage can be
     266execution, and if there aren't primitive tagged unions proper, usage can be
    266267hard to enforce.
    267268
     
    274275variable).
    275276C++ uses this approach as its fallback system if exception handling fails,
    276 such as \snake{std::terminate_handler} and, for a time,
    277 \snake{std::unexpected_handler}.
     277such as \snake{std::terminate} and, for a time,
     278\snake{std::unexpected}.\footnote{\snake{std::unexpected} was part of the
     279Dynamic Exception Specification, which has been removed from the standard
     280as of C++20.\cite{CppExceptSpec}}
    278281
    279282Handler functions work a lot like resumption exceptions,
     
    291294happily making them expensive to use in exchange.
    292295This difference is less important in higher-level scripting languages,
    293 where using exception for other tasks is more common.
     296where using exceptions for other tasks is more common.
    294297An iconic example is Python's
    295 \code{Python}{StopIteration}\cite{PythonExceptions} exception that
     298\code{Python}{StopIteration}\cite{PythonExceptions} exception, that
    296299is thrown by an iterator to indicate that it is exhausted.
    297 When paired with Python's iterator-based for-loop this will be thrown every
     300When paired with Python's iterator-based for-loop, this will be thrown every
    298301time the end of the loop is reached.\cite{PythonForLoop}
Note: See TracChangeset for help on using the changeset viewer.