Changeset f93c50a for doc


Ignore:
Timestamp:
Sep 24, 2021, 6:13:46 PM (3 years ago)
Author:
caparsons <caparson@…>
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.
Message:

fixed merge

Location:
doc/theses/andrew_beach_MMath
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/Makefile

    r7e7a076 rf93c50a  
    3131
    3232# 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}
    3434        ${LATEX} ${BASE}
    3535        ${BIBTEX} ${BUILD}/${BASE}
     
    4040${FIGTEX}: ${BUILD}/%.tex: %.fig | ${BUILD}
    4141        fig2dev -L eepic $< > $@
     42
     43%.pstex : %.fig | ${Build}
     44        fig2dev -L pstex $< > ${BUILD}/$@
     45        fig2dev -L pstex_t -p ${BUILD}/$@ $< > ${BUILD}/$@_t
    4246
    4347# Step through dvi & postscript to handle xfig specials.
  • doc/theses/andrew_beach_MMath/existing.tex

    r7e7a076 rf93c50a  
    4949asterisk (@*@) is replaced with a ampersand (@&@);
    5050this includes cv-qualifiers (\snake{const} and \snake{volatile})
    51 %\todo{Should I go into even more detail on cv-qualifiers.}
    5251and multiple levels of reference.
    5352
  • doc/theses/andrew_beach_MMath/features.tex

    r7e7a076 rf93c50a  
    129129\section{Virtuals}
    130130\label{s:virtuals}
    131 %\todo{Maybe explain what "virtual" actually means.}
     131A common feature in many programming languages is a tool to pair code
     132(behaviour) with data.
     133In \CFA this is done with the virtual system,
     134which allow type information to be abstracted away, recovered and allow
     135operations to be performed on the abstract objects.
     136
    132137Virtual types and casts are not part of \CFA's EHM nor are they required for
    133138an EHM.
     
    488493Since it is so general, a more specific handler can be defined,
    489494overriding the default behaviour for the specific exception types.
    490 %\todo{Examples?}
     495
     496For example, consider an error reading a configuration file.
     497This is most likely a problem with the configuration file (@config_error@),
     498but the function could have been passed the wrong file name (@arg_error@).
     499In this case the function could raise one exception and then, if it is
     500unhandled, raise the other.
     501This is not usual behaviour for either exception so changing the
     502default 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}
    491511
    492512\subsection{Resumption}
     
    551571the just handled exception came from, and continues executing after it,
    552572not after the try statement.
    553 %\todo{Examples?}
     573
     574For instance, a resumption used to send messages to the logger may not
     575need to be handled at all. Putting the following default handler
     576at the global scope can make handling that exception optional by default.
     577\begin{cfa}
     578void defaultResumptionHandler(log_message &) {
     579    // Nothing, it is fine not to handle logging.
     580}
     581// ... No change at raise sites. ...
     582throwResume (log_message){strlit_log, "Begin event processing."}
     583\end{cfa}
    554584
    555585\subsubsection{Resumption Marking}
     
    878908After a coroutine stack is unwound, control returns to the @resume@ function
    879909that most recently resumed it. @resume@ reports a
    880 @CoroutineCancelled@ exception, which contains a references to the cancelled
     910@CoroutineCancelled@ exception, which contains a reference to the cancelled
    881911coroutine and the exception used to cancel it.
    882912The @resume@ function also takes the \defaultResumptionHandler{} from the
  • doc/theses/andrew_beach_MMath/implement.tex

    r7e7a076 rf93c50a  
    5050The problem is that a type ID may appear in multiple TUs that compose a
    5151program (see \autoref{ss:VirtualTable}), so the initial solution would seem
    52 to be make it external in each translation unit. Hovever, the type ID must
     52to be make it external in each translation unit. However, the type ID must
    5353have a declaration in (exactly) one of the TUs to create the storage.
    5454No other declaration related to the virtual type has this property, so doing
     
    167167\subsection{Virtual Table}
    168168\label{ss:VirtualTable}
    169 %\todo{Clarify virtual table type vs. virtual table instance.}
    170169Each virtual type has a virtual table type that stores its type ID and
    171170virtual 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
     171An instance of a virtual type is bound to a virtual table instance,
     172which have the values of the virtual members.
     173Both the layout of the fields (in the virtual table type)
     174and their value (in the virtual table instance) are decided by the rules given
    175175below.
    176176
     
    414414of a function's state with @setjmp@ and restoring that snapshot with
    415415@longjmp@. This approach bypasses the need to know stack details by simply
    416 reseting to a snapshot of an arbitrary but existing function frame on the
     416resetting to a snapshot of an arbitrary but existing function frame on the
    417417stack. It is up to the programmer to ensure the snapshot is valid when it is
    418418reset and that all required cleanup from the unwound stacks is performed.
    419 This approach is fragile and requires extra work in the surrounding code.
     419Because it does not automate or check any of this cleanup,
     420it can be easy to make mistakes and always must be handled manually.
    420421
    421422With respect to the extra work in the surrounding code,
     
    435436library that provides tools for stack walking, handler execution, and
    436437unwinding. 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.
     438libunwind needed for this work.
     439Following that is the description of the \CFA code that uses libunwind
     440to implement termination.
    439441
    440442\subsection{libunwind Usage}
  • doc/theses/andrew_beach_MMath/intro.tex

    r7e7a076 rf93c50a  
    3939it returns control to that function.
    4040\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.
    4247\end{center}
    43 %\todo{What does the right half of termination.fig mean?}
    4448
    4549Resumption exception handling searches the stack for a handler and then calls
     
    5054that preformed the raise, usually starting after the raise.
    5155\begin{center}
    52 \input{resumption}
     56%\input{resumption}
     57%
     58%\medskip
     59\input{resumhandle.pstex_t}
     60% The other one.
    5361\end{center}
    5462
     
    214222unwinding the stack like in termination exception
    215223handling.\cite{RustPanicMacro}\cite{RustPanicModule}
    216 Go's panic through is very similar to a termination, except it only supports
     224Go's panic though is very similar to a termination, except it only supports
    217225a catch-all by calling \code{Go}{recover()}, simplifying the interface at
    218226the cost of flexibility.\cite{Go:2021}
     
    237245through multiple functions before it is addressed.
    238246
     247Here is an example of the pattern in Bash, where commands can only  ``return"
     248numbers and most output is done through streams of text.
     249\begin{lstlisting}[language=bash,escapechar={}]
     250# Immediately after running a command:
     251case $? in
     2520)
     253        # Success
     254        ;;
     2551)
     256        # Error Code 1
     257        ;;
     2582|3)
     259        # Error Code 2 or Error Code 3
     260        ;;
     261# Add more cases as needed.
     262asac
     263\end{lstlisting}
     264
    239265\item\emph{Special Return with Global Store}:
    240266Similar to the error codes pattern but the function itself only returns
     
    246272
    247273This approach avoids the multiple results issue encountered with straight
    248 error codes but otherwise has the same disadvantages and more.
     274error codes as only a single error value has to be returned,
     275but otherwise has the same disadvantages and more.
    249276Every function that reads or writes to the global store must agree on all
    250277possible errors and managing it becomes more complex with concurrency.
     278
     279This example shows some of what has to be done to robustly handle a C
     280standard library function that reports errors this way.
     281\begin{lstlisting}[language=C]
     282// Make sure to clear the store.
     283errno = 0;
     284// Now a library function can set the error.
     285int handle = open(path_name, flags);
     286if (-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?
    251299
    252300\item\emph{Return Union}:
     
    259307This pattern is very popular in any functional or semi-functional language
    260308with 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>}
     309Return unions can also be expressed as monads (evaluation in a context)
     310and often are in languages with special syntax for monadic evaluation,
     311such as Haskell's \code{haskell}{do} blocks.
     312
    263313The main advantage is that an arbitrary object can be used to represent an
    264314error, so it can include a lot more information than a simple error code.
     
    266316execution, and if there aren't primitive tagged unions proper, usage can be
    267317hard to enforce.
     318% We need listing Rust/rust to format code snippets from it.
     319% Rust's \code{rust}{Result<T, E>}
     320
     321This is a simple example of examining the result of a failing function in
     322Haskell, using its \code{haskell}{Either} type.
     323Examining \code{haskell}{error} further would likely involve more matching,
     324but the type of \code{haskell}{error} is user defined so there are no
     325general cases.
     326\begin{lstlisting}[language=haskell]
     327case failingFunction argA argB of
     328    Right value -> -- Use the successful computed value.
     329    Left error -> -- Handle the produced error.
     330\end{lstlisting}
     331
     332Return unions as monads will result in the same code, but can hide most
     333of the work to propagate errors in simple cases. The code to actually handle
     334the errors, or to interact with other monads (a common case in these
     335languages) still has to be written by hand.
     336
     337If \code{haskell}{failingFunction} is implemented with two helpers that
     338use the same error type, then it can be implemented with a \code{haskell}{do}
     339block.
     340\begin{lstlisting}[language=haskell]
     341failingFunction x y = do
     342        z <- helperOne x
     343        helperTwo y z
     344\end{lstlisting}
    268345
    269346\item\emph{Handler Functions}:
     
    286363function calls, but cheaper (constant time) to call,
    287364they are more suited to more frequent (less exceptional) situations.
     365Although, in \Cpp and other languages that do not have checked exceptions,
     366they can actually be enforced by the type system be more reliable.
     367
     368This is a more local example in \Cpp, using a function to provide
     369a default value for a mapping.
     370\begin{lstlisting}[language=C++]
     371ValueT 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}
    288380\end{itemize}
    289381
  • doc/theses/andrew_beach_MMath/performance.tex

    r7e7a076 rf93c50a  
    3737resumption exceptions. Even the older programming languages with resumption
    3838seem to be notable only for having resumption.
     39On the other hand, the functional equivalents to resumption are too new.
     40There does not seem to be any standard implementations in well-known
     41languages, 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.
    3944Instead, resumption is compared to its simulation in other programming
    4045languages: fixup functions that are explicitly passed into a function.
     
    312317\CFA, \Cpp and Java.
    313318% 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.
     319The most likely explination is that,
     320the generally faster languages have made ``common cases fast" at the expense
     321of the rarer cases. Since exceptions are considered rare, they are made
     322expensive to help speed up common actions, such as entering and leaving try
     323statements.
     324Python on the other hand, while generally slower than the other languages,
     325uses exceptions more and has not scarified their performance.
    318326In addition, languages with high-level representations have a much
    319327easier time scanning the stack as there is less to decode.
  • doc/theses/andrew_beach_MMath/uw-ethesis.bib

    r7e7a076 rf93c50a  
    5050    author={The Rust Team},
    5151    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}},
    5353    addendum={Accessed 2021-08-31},
    5454}
Note: See TracChangeset for help on using the changeset viewer.