Changeset b5ec090 for doc/theses/andrew_beach_MMath/intro.tex
- Timestamp:
- Sep 13, 2021, 1:42:07 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 445f984
- Parents:
- 56e5b24 (diff), 63b3279 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/intro.tex
r56e5b24 rb5ec090 25 25 All types of exception handling link a raise with a handler. 26 26 Both operations are usually language primitives, although raises can be 27 treated as a primitivefunction that takes an exception argument.28 Handlers are more complex as they are added to and removed from the stack29 during execution, must specify what they can handle and give the code to27 treated as a 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 must give the code to 30 30 handle the exception. 31 31 … … 41 41 \input{termination} 42 42 \end{center} 43 %\todo{What does the right half of termination.fig mean?} 43 44 44 45 Resumption exception handling searches the stack for a handler and then calls … … 46 47 The handler is run on top of the existing stack, often as a new function or 47 48 closure capturing the context in which the handler was defined. 48 After the handler has finished running it returns control to the function49 After the handler has finished running, it returns control to the function 49 50 that preformed the raise, usually starting after the raise. 50 51 \begin{center} … … 53 54 54 55 Although a powerful feature, exception handling tends to be complex to set up 55 and expensive to use 56 and expensive to use, 56 57 so it is often limited to unusual or ``exceptional" cases. 57 The classic example is error handling ,exceptions can be used to58 The classic example is error handling; exceptions can be used to 58 59 remove error handling logic from the main execution path, and pay 59 60 most of the cost only when the error actually occurs. … … 63 64 The \CFA EHM implements all of the common exception features (or an 64 65 equivalent) 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 as66 The design of all the features had to be adapted to \CFA's feature set, as 66 67 some of the underlying tools used to implement and express exception handling 67 68 in other languages are absent in \CFA. 68 Still the resulting syntax resembles that of other languages:69 Still, the resulting syntax resembles that of other languages: 69 70 \begin{cfa} 70 71 try { … … 88 89 covering both changes to the compiler and the run-time. 89 90 In addition, a suite of test cases and performance benchmarks were created 90 along 91 alongside the implementation. 91 92 The implementation techniques are generally applicable in other programming 92 93 languages and much of the design is as well. … … 100 101 \item Implementing stack unwinding and the \CFA EHM, including updating 101 102 the \CFA compiler and the run-time environment. 102 \item Design ed and implementeda prototype virtual system.103 \item Designing and implementing a prototype virtual system. 103 104 % I think the virtual system and per-call site default handlers are the only 104 105 % "new" features, everything else is a matter of implementation. 105 106 \item Creating tests to check the behaviour of the EHM. 106 \item Creating benchmarks to check the performance sof the EHM,107 \item Creating benchmarks to check the performance of the EHM, 107 108 as compared to other languages. 108 109 \end{enumerate} … … 110 111 The rest of this thesis is organized as follows. 111 112 The current state of exceptions is covered in \autoref{s:background}. 112 The existing state of \CFA is alsocovered in \autoref{c:existing}.113 The existing state of \CFA is covered in \autoref{c:existing}. 113 114 New EHM features are introduced in \autoref{c:features}, 114 115 covering their usage and design. … … 137 138 inheriting from 138 139 \code{C++}{std::exception}. 139 Although there is a special catch-all syntax (@catch(...)@) there are no140 Although there is a special catch-all syntax (@catch(...)@), there are no 140 141 operations that can be performed on the caught value, not even type inspection. 141 Instead the base exception-type \code{C++}{std::exception} defines common142 Instead, the base exception-type \code{C++}{std::exception} defines common 142 143 functionality (such as 143 144 the ability to describe the reason the exception was raised) and all … … 148 149 149 150 Java was the next popular language to use exceptions.\cite{Java8} 150 Its exception system largely reflects that of \Cpp, except that requires151 Its exception system largely reflects that of \Cpp, except that it requires 151 152 you throw a child type of \code{Java}{java.lang.Throwable} 152 153 and it uses checked exceptions. 153 154 Checked exceptions are part of a function's interface, 154 155 the exception signature of the function. 155 Every function that could be raised from a function, either directly or156 Every exception that could be raised from a function, either directly or 156 157 because it is not handled from a called function, is given. 157 158 Using this information, it is possible to statically verify if any given 158 exception is handled and guarantee that no exception will go unhandled.159 exception is handled, and guarantee that no exception will go unhandled. 159 160 Making exception information explicit improves clarity and safety, 160 161 but can slow down or restrict programming. … … 169 170 recovery or repair. In theory that could be good enough to properly handle 170 171 the 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 if172 programmer does not feel is worth the effort of handling, for instance if 172 173 they do not believe it will ever be raised. 173 If they are incorrect the exception will be silenced, while in a similar174 If they are incorrect, the exception will be silenced, while in a similar 174 175 situation with unchecked exceptions the exception would at least activate 175 the language's unhandled exception code (usually program abort with an176 the language's unhandled exception code (usually, a program abort with an 176 177 error message). 177 178 178 179 %\subsection 179 180 Resumption exceptions are less popular, 180 although resumption is as old as termination; hence, few181 although resumption is as old as termination; that is, few 181 182 programming languages have implemented them. 182 183 % http://bitsavers.informatik.uni-stuttgart.de/pdf/xerox/parc/techReports/ … … 186 187 included in the \Cpp standard. 187 188 % https://en.wikipedia.org/wiki/Exception_handling 188 Since then resumptions have been ignored in main-stream programming languages.189 Since then, resumptions have been ignored in main-stream programming languages. 189 190 However, resumption is being revisited in the context of decades of other 190 191 developments in programming languages. 191 192 While rejecting resumption may have been the right decision in the past, 192 193 the situation has changed since then. 193 Some developments, such as the function programming equivalent to resumptions,194 Some developments, such as the functional programming equivalent to resumptions, 194 195 algebraic effects\cite{Zhang19}, are enjoying success. 195 A complete reexamination of resumption sis beyond this thesis,196 but the re reemergence is enoughto try them in \CFA.196 A complete reexamination of resumption is beyond this thesis, 197 but their reemergence is enough reason to try them in \CFA. 197 198 % Especially considering how much easier they are to implement than 198 199 % termination exceptions and how much Peter likes them. … … 208 209 209 210 %\subsection 210 More recently exceptions seem to be vanishing from newer programming211 More recently exceptions, seem to be vanishing from newer programming 211 212 languages, replaced by ``panic". 212 213 In Rust, a panic is just a program level abort that may be implemented by … … 218 219 219 220 %\subsection 220 Whileexception handling's most common use cases are in error handling,221 As exception handling's most common use cases are in error handling, 221 222 here are some other ways to handle errors with comparisons with exceptions. 222 223 \begin{itemize} … … 233 234 is discarded to avoid this problem. 234 235 Checking error codes also bloats the main execution path, 235 especially if the error is not handled immediately hand has to be passed236 especially if the error is not handled immediately and has to be passed 236 237 through multiple functions before it is addressed. 237 238 238 239 \item\emph{Special Return with Global Store}: 239 240 Similar 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 some241 that there was an error, 242 and stores the reason for the error in a fixed global location. 243 For example, many routines in the C standard library will only return some 243 244 error value (such as -1 or a null pointer) and the error code is written into 244 245 the standard variable @errno@. … … 253 254 Success is one tag and the errors are another. 254 255 It is also possible to make each possible error its own tag and carry its own 255 additional information, but the two 256 additional information, but the two-branch format is easy to make generic 256 257 so that one type can be used everywhere in error handling code. 257 258 … … 261 262 % Rust's \code{rust}{Result<T, E>} 262 263 The 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.264 error, so it can include a lot more information than a simple error code. 264 265 The disadvantages include that the it does have to be checked along the main 265 execution and if there aren't primitive tagged unions properusage can be266 execution, and if there aren't primitive tagged unions proper, usage can be 266 267 hard to enforce. 267 268 … … 274 275 variable). 275 276 C++ 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}. 277 such as \snake{std::terminate} and, for a time, 278 \snake{std::unexpected}.\footnote{\snake{std::unexpected} was part of the 279 Dynamic Exception Specification, which has been removed from the standard 280 as of C++20.\cite{CppExceptSpec}} 278 281 279 282 Handler functions work a lot like resumption exceptions, … … 291 294 happily making them expensive to use in exchange. 292 295 This difference is less important in higher-level scripting languages, 293 where using exception for other tasks is more common.296 where using exceptions for other tasks is more common. 294 297 An iconic example is Python's 295 \code{Python}{StopIteration}\cite{PythonExceptions} exception that298 \code{Python}{StopIteration}\cite{PythonExceptions} exception, that 296 299 is thrown by an iterator to indicate that it is exhausted. 297 When paired with Python's iterator-based for-loop this will be thrown every300 When paired with Python's iterator-based for-loop, this will be thrown every 298 301 time the end of the loop is reached.\cite{PythonForLoop}
Note: See TracChangeset
for help on using the changeset viewer.