Changeset 471ff17 for doc/theses/andrew_beach_MMath
- Timestamp:
- Jun 10, 2021, 4:20:25 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 4aba055
- Parents:
- 382edbe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/intro.tex
r382edbe r471ff17 1 1 \chapter{Introduction} 2 2 3 % T alk about Cforall and exceptions generally.3 % The highest level overview of Cforall and EHMs. Get this done right away. 4 4 This thesis goes over the design and implementation of the exception handling 5 5 mechanism (EHM) of 6 6 \CFA (pernounced sea-for-all and may be written Cforall or CFA). 7 8 % Now take a step back and explain what exceptions are generally. 7 9 Exception handling provides dynamic inter-function control flow. 8 10 There are two forms of exception handling covered in this thesis: 9 11 termination, which acts as a multi-level return, 10 12 and resumption, which is a dynamic function call. 13 Termination handling is much more common, 14 to the extent that it is often seen 11 15 This seperation is uncommon because termination exception handling is so 12 16 much more common that it is often assumed. 17 % WHY: Mention other forms of continuation and \cite{CommonLisp} here? 18 A language's EHM is the combination of language syntax and run-time 19 components that are used to construct, raise and handle exceptions, 20 including all control flow. 13 21 14 22 Termination exception handling allows control to return to any previous … … 30 38 most of the cost only when the error actually occurs. 31 39 32 % Overview of exceptions in Cforall. 40 \section{Thesis Overview} 33 41 This work describes the design and implementation of the \CFA EHM. 34 42 The \CFA EHM implements all of the common exception features (or an … … 52 60 53 61 % A note that yes, that was a very fast overview. 54 All the design and implementation of all of \CFA's EHM's features are62 The design and implementation of all of \CFA's EHM's features are 55 63 described in detail throughout this thesis, whether they are a common feature 56 64 or one unique to \CFA. 57 65 58 66 % The current state of the project and what it contributes. 59 All of these features have been added to the \CFA implemenation, along with67 All of these features have been implemented in \CFA, along with 60 68 a suite of test cases as part of this project. 61 69 The implementation techniques are generally applicable in other programming … … 82 90 \end{enumerate} 83 91 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.} 93 The next section covers the existing state of exceptions. 94 The existing state of \CFA is also covered in \autoref{c:existing}. 95 The new features are introduced in \autoref{c:features}, 96 which explains their usage and design. 88 97 That is followed by the implementation of those features in 89 98 \autoref{c:implement}. 90 % Future Work \autoref{c:future} 99 The performance results are examined in \autoref{c:performance}. 100 Possibilities to extend this project are discussed in \autoref{c:future}. 101 102 \section{Background} 103 \label{s:background} 104 105 Exception handling is not a new concept, 106 with papers on the subject dating back 70s. 107 108 Their were popularised by \Cpp, 109 which added them in its first major wave of non-object-orientated features 110 in 1990. 111 % https://en.cppreference.com/w/cpp/language/history 112 113 Java was the next popular language to use exceptions. It is also the most 114 popular language with checked exceptions. 115 Checked exceptions are part of the function interface they are raised from. 116 This includes functions they propogate through, until a handler for that 117 type of exception is found. 118 This makes exception information explicit, which can improve clarity and 119 safety, but can slow down programming. 120 Some of these, such as dealing with high-order methods or an overly specified 121 throws clause, are technical. However some of the issues are much more 122 human, in that writing/updating all the exception signatures can be enough 123 of a burden people will hack the system to avoid them. 124 Including the ``catch-and-ignore" pattern where a catch block is used without 125 anything to repair or recover from the exception. 126 127 %\subsection 128 Resumption exceptions have been much less popular. 129 Although resumption has a history as old as termination's, very few 130 programming languages have implement them. 131 % http://bitsavers.informatik.uni-stuttgart.de/pdf/xerox/parc/techReports/ 132 % CSL-79-3_Mesa_Language_Manual_Version_5.0.pdf 133 Mesa is one programming languages that did and experiance with that 134 languages is quoted as being one of the reasons resumptions were not 135 included in the \Cpp standard. 136 % https://en.wikipedia.org/wiki/Exception_handling 137 \todo{A comment about why we did include them when they are so unpopular 138 might be approprate.} 139 140 %\subsection 141 Functional languages, tend to use solutions like the return union, but some 142 exception-like constructs still appear. 143 144 For instance Haskell's built in error mechanism can make the result of any 145 expression, including function calls. Any expression that examines an 146 error value will in-turn produce an error. This continues until the main 147 function produces an error or until it is handled by one of the catch 148 functions. 149 150 %\subsection 151 More recently exceptions seem to be vanishing from newer programming 152 languages. 153 Rust and Go reduce this feature to panics. 154 Panicing is somewhere between a termination exception and a program abort. 155 Notably in Rust a panic can trigger either, a panic may unwind the stack or 156 simply kill the process. 157 % https://doc.rust-lang.org/std/panic/fn.catch_unwind.html 158 Go's panic is much more similar to a termination exception but there is 159 only a catch-all function with \code{Go}{recover()}. 160 So exceptions still are appearing, just in reduced forms. 161 162 %\subsection 163 Exception handling's most common use cases are in error handling. 164 Here are some other ways to handle errors and comparisons with exceptions. 165 \begin{itemize} 166 \item\emph{Error Codes}: 167 This pattern uses an enumeration (or just a set of fixed values) to indicate 168 that an error has occured and which error it was. 169 170 There are some issues if a function wants to return an error code and another 171 value. The main issue is that it can be easy to forget checking the error 172 code, which can lead to an error being quitely and implicitly ignored. 173 Some new languages have tools that raise warnings if the return value is 174 discarded to avoid this. 175 It also puts more code on the main execution path. 176 \item\emph{Special Return with Global Store}: 177 A function that encounters an error returns some value indicating that it 178 encountered a value but store which error occured in a fixed global location. 179 180 Perhaps the C standard @errno@ is the most famous example of this, 181 where some standard library functions will return some non-value (often a 182 NULL pointer) and set @errno@. 183 184 This avoids the multiple results issue encountered with straight error codes 185 but otherwise many of the same advantages and disadvantages. 186 It does however introduce one other major disadvantage: 187 Everything that uses that global location must agree on all possible errors. 188 \item\emph{Return Union}: 189 Replaces error codes with a tagged union. 190 Success is one tag and the errors are another. 191 It is also possible to make each possible error its own tag and carry its own 192 additional information, but the two branch format is easy to make generic 193 so that one type can be used everywhere in error handling code. 194 195 This pattern is very popular in functional or semi-functional language, 196 anything 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>} 199 200 The main disadvantage is again it puts code on the main execution path. 201 This is also the first technique that allows for more information about an 202 error, other than one of a fix-set of ids, to be sent. 203 They can be missed but some languages can force that they are checked. 204 It is also implicitly forced in any languages with checked union access. 205 \item\emph{Handler Functions}: 206 On error the function that produced the error calls another function to 207 handle it. 208 The handler function can be provided locally (passed in as an argument, 209 either directly as as a field of a structure/object) or globally (a global 210 variable). 211 212 C++ uses this as its fallback system if exception handling fails. 213 \snake{std::terminate_handler} and for a time \snake{std::unexpected_handler} 214 215 Handler functions work a lot like resumption exceptions. 216 The difference is they are more expencive to set up but cheaper to use, and 217 so are more suited to more fequent errors. 218 The exception being global handlers if they are rarely change as the time 219 in both cases strinks towards zero. 220 \end{itemize} 221 222 %\subsection 223 Because of their cost exceptions are rarely used for hot paths of execution. 224 There is an element of self-fulfilling prophocy here as implementation 225 techniques have been designed to make exceptions cheap to set-up at the cost 226 of making them expencive to use. 227 Still, use of exceptions for other tasks is more common in higher-level 228 scripting languages. 229 An iconic example is Python's StopIteration exception which is thrown by 230 an iterator to indicate that it is exausted. Combined with Python's heavy 231 use of the iterator based for-loop. 232 % https://docs.python.org/3/library/exceptions.html#StopIteration
Note: See TracChangeset
for help on using the changeset viewer.