Changes in / [716b62c:056cbdb]
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/features.tex
r716b62c r056cbdb 84 84 \paragraph{Hierarchy} 85 85 A common way to organize exceptions is in a hierarchical structure. 86 This pattern comes from object-orient ated languages where the86 This pattern comes from object-oriented languages where the 87 87 exception hierarchy is a natural extension of the object hierarchy. 88 88 … … 131 131 A common feature in many programming languages is a tool to pair code 132 132 (behaviour) with data. 133 In \CFA this is done with the virtual system,133 In \CFA, this is done with the virtual system, 134 134 which allow type information to be abstracted away, recovered and allow 135 135 operations to be performed on the abstract objects. … … 495 495 496 496 For example, consider an error reading a configuration file. 497 This is most likely a problem with the configuration file @config_error@,498 but the function could have been passed the wrong file name @arg_error@.497 This is most likely a problem with the configuration file (@config_error@), 498 but the function could have been passed the wrong file name (@arg_error@). 499 499 In this case the function could raise one exception and then, if it is 500 500 unhandled, raise the other. … … 574 574 For instance, a resumption used to send messages to the logger may not 575 575 need to be handled at all. Putting the following default handler 576 at the global scope can make handling th eexception optional by default.576 at the global scope can make handling that exception optional by default. 577 577 \begin{cfa} 578 578 void defaultResumptionHandler(log_message &) { … … 908 908 After a coroutine stack is unwound, control returns to the @resume@ function 909 909 that most recently resumed it. @resume@ reports a 910 @CoroutineCancelled@ exception, which contains a reference sto the cancelled910 @CoroutineCancelled@ exception, which contains a reference to the cancelled 911 911 coroutine and the exception used to cancel it. 912 912 The @resume@ function also takes the \defaultResumptionHandler{} from the -
doc/theses/andrew_beach_MMath/implement.tex
r716b62c r056cbdb 414 414 of a function's state with @setjmp@ and restoring that snapshot with 415 415 @longjmp@. This approach bypasses the need to know stack details by simply 416 reset ing to a snapshot of an arbitrary but existing function frame on the416 resetting to a snapshot of an arbitrary but existing function frame on the 417 417 stack. It is up to the programmer to ensure the snapshot is valid when it is 418 418 reset and that all required cleanup from the unwound stacks is performed. 419 This approach is fragile and requires extra work in the surrounding code. 419 Because it does not automate or check any of this cleanup, 420 it can be easy to make mistakes and always must be handled manually. 420 421 421 422 With respect to the extra work in the surrounding code, … … 435 436 library that provides tools for stack walking, handler execution, and 436 437 unwinding. What follows is an overview of all the relevant features of 437 libunwind needed for this work, and how \CFA uses them to implement exception 438 handling. 438 libunwind needed for this work. 439 Following that is the description of the \CFA code that uses libunwind 440 to implement termination. 439 441 440 442 \subsection{libunwind Usage} -
doc/theses/andrew_beach_MMath/intro.tex
r716b62c r056cbdb 39 39 it returns control to that function. 40 40 \begin{center} 41 \input{termination}42 43 \medskip41 %\input{termination} 42 % 43 %\medskip 44 44 \input{termhandle.pstex_t} 45 % I hate these diagrams, but I can't access xfig to fix them and they are 46 % better than the alternative. 45 47 \end{center} 46 \todo*{Can I make the new diagrams fit the old style?}47 48 48 49 Resumption exception handling searches the stack for a handler and then calls … … 53 54 that preformed the raise, usually starting after the raise. 54 55 \begin{center} 55 \input{resumption}56 57 \medskip56 %\input{resumption} 57 % 58 %\medskip 58 59 \input{resumhandle.pstex_t} 60 % The other one. 59 61 \end{center} 60 62 … … 136 138 message as a payload\cite{Ada12}. 137 139 138 The modern flag -ship for termination exceptionsis \Cpp,140 The modern flagship for termination exceptions -- if one exists -- is \Cpp, 139 141 which added them in its first major wave of non-object-orientated features 140 142 in 1990.\cite{CppHistory} … … 193 195 included in the \Cpp standard. 194 196 % https://en.wikipedia.org/wiki/Exception_handling 195 Since then, resumptions have been ignored in main -stream programming languages.197 Since then, resumptions have been ignored in mainstream programming languages. 196 198 However, resumption is being revisited in the context of decades of other 197 199 developments in programming languages. … … 215 217 216 218 %\subsection 217 More recently exceptions,seem to be vanishing from newer programming219 More recently, exceptions seem to be vanishing from newer programming 218 220 languages, replaced by ``panic". 219 221 In Rust, a panic is just a program level abort that may be implemented by 220 222 unwinding the stack like in termination exception 221 223 handling.\cite{RustPanicMacro}\cite{RustPanicModule} 222 Go's panic th rough is very similar to a termination, except it only supports224 Go's panic though is very similar to a termination, except it only supports 223 225 a catch-all by calling \code{Go}{recover()}, simplifying the interface at 224 226 the cost of flexibility.\cite{Go:2021} … … 243 245 through multiple functions before it is addressed. 244 246 247 Here is an example of the pattern in Bash, where commands can only ``return" 248 numbers and most output is done through streams of text. 249 \begin{lstlisting}[language=bash,escapechar={}] 250 # Immediately after running a command: 251 case $? in 252 0) 253 # Success 254 ;; 255 1) 256 # Error Code 1 257 ;; 258 2|3) 259 # Error Code 2 or Error Code 3 260 ;; 261 # Add more cases as needed. 262 asac 263 \end{lstlisting} 264 245 265 \item\emph{Special Return with Global Store}: 246 266 Similar to the error codes pattern but the function itself only returns … … 252 272 253 273 This approach avoids the multiple results issue encountered with straight 254 error codes but otherwise has the same disadvantages and more. 274 error codes as only a single error value has to be returned, 275 but otherwise has the same disadvantages and more. 255 276 Every function that reads or writes to the global store must agree on all 256 277 possible errors and managing it becomes more complex with concurrency. 278 279 This example shows some of what has to be done to robustly handle a C 280 standard library function that reports errors this way. 281 \begin{lstlisting}[language=C] 282 // Now a library function can set the error. 283 int handle = open(path_name, flags); 284 if (-1 == handle) { 285 switch (errno) { 286 case ENAMETOOLONG: 287 // path_name is a bad argument. 288 break; 289 case ENFILE: 290 // A system resource has been exausted. 291 break; 292 // And many more... 293 } 294 } 295 \end{lstlisting} 296 % cite open man page? 257 297 258 298 \item\emph{Return Union}: … … 265 305 This pattern is very popular in any functional or semi-functional language 266 306 with primitive support for tagged unions (or algebraic data types). 267 % We need listing Rust/rust to format code snippets from it. 268 % Rust's \code{rust}{Result<T, E>} 307 Return unions can also be expressed as monads (evaluation in a context) 308 and often are in languages with special syntax for monadic evaluation, 309 such as Haskell's \code{haskell}{do} blocks. 310 269 311 The main advantage is that an arbitrary object can be used to represent an 270 312 error, so it can include a lot more information than a simple error code. … … 272 314 execution, and if there aren't primitive tagged unions proper, usage can be 273 315 hard to enforce. 316 % We need listing Rust/rust to format code snippets from it. 317 % Rust's \code{rust}{Result<T, E>} 318 319 This is a simple example of examining the result of a failing function in 320 Haskell, using its \code{haskell}{Either} type. 321 Examining \code{haskell}{error} further would likely involve more matching, 322 but the type of \code{haskell}{error} is user defined so there are no 323 general cases. 324 \begin{lstlisting}[language=haskell] 325 case failingFunction argA argB of 326 Right value -> -- Use the successful computed value. 327 Left error -> -- Handle the produced error. 328 \end{lstlisting} 329 330 Return unions as monads will result in the same code, but can hide most 331 of the work to propagate errors in simple cases. The code to actually handle 332 the errors, or to interact with other monads (a common case in these 333 languages) still has to be written by hand. 334 335 If \code{haskell}{failingFunction} is implemented with two helpers that 336 use the same error type, then it can be implemented with a \code{haskell}{do} 337 block. 338 \begin{lstlisting}[language=haskell,literate={}] 339 failingFunction x y = do 340 z <- helperOne x 341 helperTwo y z 342 \end{lstlisting} 274 343 275 344 \item\emph{Handler Functions}: … … 292 361 function calls, but cheaper (constant time) to call, 293 362 they are more suited to more frequent (less exceptional) situations. 363 Although, in \Cpp and other languages that do not have checked exceptions, 364 they can actually be enforced by the type system be more reliable. 365 366 This is a more local example in \Cpp, using a function to provide 367 a default value for a mapping. 368 \begin{lstlisting}[language=C++] 369 ValueT Map::key_or_default(KeyT key, ValueT(*make_default)(KeyT)) { 370 ValueT * value = find_value(key); 371 if (nullptr != value) { 372 return *value; 373 } else { 374 return make_default(key); 375 } 376 } 377 \end{lstlisting} 294 378 \end{itemize} 295 379 … … 297 381 Because of their cost, exceptions are rarely used for hot paths of execution. 298 382 Hence, there is an element of self-fulfilling prophecy as implementation 299 techniques have been focused on making them cheap to set -up,383 techniques have been focused on making them cheap to set up, 300 384 happily making them expensive to use in exchange. 301 385 This difference is less important in higher-level scripting languages, -
doc/theses/andrew_beach_MMath/performance.tex
r716b62c r056cbdb 37 37 resumption exceptions. Even the older programming languages with resumption 38 38 seem to be notable only for having resumption. 39 On the other hand, the functional equivalents to resumption are too new. 40 There does not seem to be any standard implementations in well-known 41 languages; so far, they seem confined to extensions and research languages. 42 % There was some maybe interesting comparison to an OCaml extension 43 % but I'm not sure how to get that working if it is interesting. 39 44 Instead, resumption is compared to its simulation in other programming 40 45 languages: fixup functions that are explicitly passed into a function. … … 312 317 \CFA, \Cpp and Java. 313 318 % To be exact, the Match All and Match None cases. 314 The most likely expl ination is that,319 The most likely explanation is that 315 320 the generally faster languages have made ``common cases fast" at the expense 316 321 of the rarer cases. Since exceptions are considered rare, they are made 317 322 expensive to help speed up common actions, such as entering and leaving try 318 323 statements. 319 Python on the other hand, while generally slower than the other languages,320 uses exceptions more and has not s carified their performance.324 Python, on the other hand, while generally slower than the other languages, 325 uses exceptions more and has not sacrificed their performance. 321 326 In addition, languages with high-level representations have a much 322 327 easier time scanning the stack as there is less to decode. -
doc/theses/andrew_beach_MMath/uw-ethesis-frontpgs.tex
r716b62c r056cbdb 156 156 \begin{center}\textbf{Acknowledgements}\end{center} 157 157 158 I would like to thank all the people who made this thesis possible. 159 (I'm waiting until who is involved is finalized.) 158 As is tradition and his due, I would like to begin by thanking my 159 supervisor Peter Buhr. From accepting me in a first place, 160 to helping me run performance tests, I would not be here without him. 161 Also if there was an ``artist" field here he would be listed there as well, 162 he helped me a lot with the diagrams. 163 164 I would like to thank the readers 165 Gregor Richards and Yizhou Zhang 166 for their feedback and approval. 167 The presentation of the thesis has definitely been improved with their 168 feedback. 169 170 I also thank the entire Cforall Team who built the rest of the 171 \CFA compiler. From the existing features I used in my work, to the 172 internal tooling that makes further development easier and the optimizations 173 that make running tests pass by quickly. 174 This includes: Aaron Moss, Rob Schluntz, Thierry Delisle, Michael Brooks, 175 Mubeen Zulfieqar \& Fangren Yu. 176 177 And thank-you Henry Xue, the co-op student who 178 converted my macro implementation of exception declarations into 179 the compiler features presented in this thesis. 180 181 Finally I thank my family, who are still relieved I learned how to read. 160 182 161 183 \cleardoublepage -
doc/theses/andrew_beach_MMath/uw-ethesis.bib
r716b62c r056cbdb 50 50 author={The Rust Team}, 51 51 key={Rust Panic Macro}, 52 howpublished={\href{https://doc.rust-lang.org/std/ panic/index.html}{https://\-doc.rust-lang.org/\-std/\-panic/\-index.html}},52 howpublished={\href{https://doc.rust-lang.org/std/macro.panic.html}{https://\-doc.rust-lang.org/\-std/\-macro.panic.html}}, 53 53 addendum={Accessed 2021-08-31}, 54 54 } -
libcfa/src/fstream.hfa
r716b62c r056cbdb 80 80 void release( ofstream & ); 81 81 82 void lock( ofstream & ); 83 void unlock( ofstream & ); 84 82 85 struct osacquire { 83 86 ofstream & os;
Note: See TracChangeset
for help on using the changeset viewer.