- Timestamp:
- Sep 24, 2021, 6:13:46 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 166b384
- Parents:
- 7e7a076 (diff), 9411cf0 (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. - Location:
- doc/theses/andrew_beach_MMath
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/Makefile
r7e7a076 rf93c50a 31 31 32 32 # The main rule, it does all the tex/latex processing. 33 ${BUILD}/${BASE}.dvi: ${RAWSRC} ${FIGTEX} Makefile | ${BUILD}33 ${BUILD}/${BASE}.dvi: ${RAWSRC} ${FIGTEX} termhandle.pstex resumhandle.pstex Makefile | ${BUILD} 34 34 ${LATEX} ${BASE} 35 35 ${BIBTEX} ${BUILD}/${BASE} … … 40 40 ${FIGTEX}: ${BUILD}/%.tex: %.fig | ${BUILD} 41 41 fig2dev -L eepic $< > $@ 42 43 %.pstex : %.fig | ${Build} 44 fig2dev -L pstex $< > ${BUILD}/$@ 45 fig2dev -L pstex_t -p ${BUILD}/$@ $< > ${BUILD}/$@_t 42 46 43 47 # Step through dvi & postscript to handle xfig specials. -
doc/theses/andrew_beach_MMath/existing.tex
r7e7a076 rf93c50a 49 49 asterisk (@*@) is replaced with a ampersand (@&@); 50 50 this includes cv-qualifiers (\snake{const} and \snake{volatile}) 51 %\todo{Should I go into even more detail on cv-qualifiers.}52 51 and multiple levels of reference. 53 52 -
doc/theses/andrew_beach_MMath/features.tex
r7e7a076 rf93c50a 129 129 \section{Virtuals} 130 130 \label{s:virtuals} 131 %\todo{Maybe explain what "virtual" actually means.} 131 A common feature in many programming languages is a tool to pair code 132 (behaviour) with data. 133 In \CFA this is done with the virtual system, 134 which allow type information to be abstracted away, recovered and allow 135 operations to be performed on the abstract objects. 136 132 137 Virtual types and casts are not part of \CFA's EHM nor are they required for 133 138 an EHM. … … 488 493 Since it is so general, a more specific handler can be defined, 489 494 overriding the default behaviour for the specific exception types. 490 %\todo{Examples?} 495 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@). 499 In this case the function could raise one exception and then, if it is 500 unhandled, raise the other. 501 This is not usual behaviour for either exception so changing the 502 default handler will be done locally: 503 \begin{cfa} 504 { 505 void defaultTerminationHandler(config_error &) { 506 throw (arg_error){arg_vt}; 507 } 508 throw (config_error){config_vt}; 509 } 510 \end{cfa} 491 511 492 512 \subsection{Resumption} … … 551 571 the just handled exception came from, and continues executing after it, 552 572 not after the try statement. 553 %\todo{Examples?} 573 574 For instance, a resumption used to send messages to the logger may not 575 need to be handled at all. Putting the following default handler 576 at the global scope can make handling that exception optional by default. 577 \begin{cfa} 578 void defaultResumptionHandler(log_message &) { 579 // Nothing, it is fine not to handle logging. 580 } 581 // ... No change at raise sites. ... 582 throwResume (log_message){strlit_log, "Begin event processing."} 583 \end{cfa} 554 584 555 585 \subsubsection{Resumption Marking} … … 878 908 After a coroutine stack is unwound, control returns to the @resume@ function 879 909 that most recently resumed it. @resume@ reports a 880 @CoroutineCancelled@ exception, which contains a reference sto the cancelled910 @CoroutineCancelled@ exception, which contains a reference to the cancelled 881 911 coroutine and the exception used to cancel it. 882 912 The @resume@ function also takes the \defaultResumptionHandler{} from the -
doc/theses/andrew_beach_MMath/implement.tex
r7e7a076 rf93c50a 50 50 The problem is that a type ID may appear in multiple TUs that compose a 51 51 program (see \autoref{ss:VirtualTable}), so the initial solution would seem 52 to be make it external in each translation unit. Ho vever, the type ID must52 to be make it external in each translation unit. However, the type ID must 53 53 have a declaration in (exactly) one of the TUs to create the storage. 54 54 No other declaration related to the virtual type has this property, so doing … … 167 167 \subsection{Virtual Table} 168 168 \label{ss:VirtualTable} 169 %\todo{Clarify virtual table type vs. virtual table instance.}170 169 Each virtual type has a virtual table type that stores its type ID and 171 170 virtual members. 172 Each virtual type instance is bound to a table instance that is filled with 173 the values of virtual members. 174 Both the layout of the fields and their value are decided by the rules given 171 An instance of a virtual type is bound to a virtual table instance, 172 which have the values of the virtual members. 173 Both the layout of the fields (in the virtual table type) 174 and their value (in the virtual table instance) are decided by the rules given 175 175 below. 176 176 … … 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
r7e7a076 rf93c50a 39 39 it returns control to that function. 40 40 \begin{center} 41 \input{termination} 41 %\input{termination} 42 % 43 %\medskip 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. 42 47 \end{center} 43 %\todo{What does the right half of termination.fig mean?}44 48 45 49 Resumption exception handling searches the stack for a handler and then calls … … 50 54 that preformed the raise, usually starting after the raise. 51 55 \begin{center} 52 \input{resumption} 56 %\input{resumption} 57 % 58 %\medskip 59 \input{resumhandle.pstex_t} 60 % The other one. 53 61 \end{center} 54 62 … … 214 222 unwinding the stack like in termination exception 215 223 handling.\cite{RustPanicMacro}\cite{RustPanicModule} 216 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 217 225 a catch-all by calling \code{Go}{recover()}, simplifying the interface at 218 226 the cost of flexibility.\cite{Go:2021} … … 237 245 through multiple functions before it is addressed. 238 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 239 265 \item\emph{Special Return with Global Store}: 240 266 Similar to the error codes pattern but the function itself only returns … … 246 272 247 273 This approach avoids the multiple results issue encountered with straight 248 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. 249 276 Every function that reads or writes to the global store must agree on all 250 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 // Make sure to clear the store. 283 errno = 0; 284 // Now a library function can set the error. 285 int handle = open(path_name, flags); 286 if (-1 == handle) { 287 switch (errno) { 288 case ENAMETOOLONG: 289 // path_name is a bad argument. 290 break; 291 case ENFILE: 292 // A system resource has been exausted. 293 break; 294 // And many more... 295 } 296 } 297 \end{lstlisting} 298 % cite open man page? 251 299 252 300 \item\emph{Return Union}: … … 259 307 This pattern is very popular in any functional or semi-functional language 260 308 with primitive support for tagged unions (or algebraic data types). 261 % We need listing Rust/rust to format code snippets from it. 262 % Rust's \code{rust}{Result<T, E>} 309 Return unions can also be expressed as monads (evaluation in a context) 310 and often are in languages with special syntax for monadic evaluation, 311 such as Haskell's \code{haskell}{do} blocks. 312 263 313 The main advantage is that an arbitrary object can be used to represent an 264 314 error, so it can include a lot more information than a simple error code. … … 266 316 execution, and if there aren't primitive tagged unions proper, usage can be 267 317 hard to enforce. 318 % We need listing Rust/rust to format code snippets from it. 319 % Rust's \code{rust}{Result<T, E>} 320 321 This is a simple example of examining the result of a failing function in 322 Haskell, using its \code{haskell}{Either} type. 323 Examining \code{haskell}{error} further would likely involve more matching, 324 but the type of \code{haskell}{error} is user defined so there are no 325 general cases. 326 \begin{lstlisting}[language=haskell] 327 case failingFunction argA argB of 328 Right value -> -- Use the successful computed value. 329 Left error -> -- Handle the produced error. 330 \end{lstlisting} 331 332 Return unions as monads will result in the same code, but can hide most 333 of the work to propagate errors in simple cases. The code to actually handle 334 the errors, or to interact with other monads (a common case in these 335 languages) still has to be written by hand. 336 337 If \code{haskell}{failingFunction} is implemented with two helpers that 338 use the same error type, then it can be implemented with a \code{haskell}{do} 339 block. 340 \begin{lstlisting}[language=haskell] 341 failingFunction x y = do 342 z <- helperOne x 343 helperTwo y z 344 \end{lstlisting} 268 345 269 346 \item\emph{Handler Functions}: … … 286 363 function calls, but cheaper (constant time) to call, 287 364 they are more suited to more frequent (less exceptional) situations. 365 Although, in \Cpp and other languages that do not have checked exceptions, 366 they can actually be enforced by the type system be more reliable. 367 368 This is a more local example in \Cpp, using a function to provide 369 a default value for a mapping. 370 \begin{lstlisting}[language=C++] 371 ValueT Map::key_or_default(KeyT key, ValueT(*make_default)(KeyT)) { 372 ValueT * value = find_value(key); 373 if (nullptr != value) { 374 return *value; 375 } else { 376 return make_default(key); 377 } 378 } 379 \end{lstlisting} 288 380 \end{itemize} 289 381 -
doc/theses/andrew_beach_MMath/performance.tex
r7e7a076 rf93c50a 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 %\todo{Not true in Python.} 315 The most likely explanation is that, since exceptions 316 are rarely considered to be the common case, the more optimized languages 317 make that case expensive to improve other cases. 319 The most likely explination is that, 320 the generally faster languages have made ``common cases fast" at the expense 321 of the rarer cases. Since exceptions are considered rare, they are made 322 expensive to help speed up common actions, such as entering and leaving try 323 statements. 324 Python on the other hand, while generally slower than the other languages, 325 uses exceptions more and has not scarified their performance. 318 326 In addition, languages with high-level representations have a much 319 327 easier time scanning the stack as there is less to decode. -
doc/theses/andrew_beach_MMath/uw-ethesis.bib
r7e7a076 rf93c50a 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 }
Note: See TracChangeset
for help on using the changeset viewer.