Changeset 5d9c4bb


Ignore:
Timestamp:
Mar 22, 2023, 11:34:45 AM (20 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
1d245ea, d63aeba
Parents:
1f771fc
Message:

proofread Mike's list chapter

Location:
doc/theses/mike_brooks_MMath
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/mike_brooks_MMath/list.tex

    r1f771fc r5d9c4bb  
    1313
    1414
    15 
    1615\section{Design Issues}
    1716\label{toc:lst:issue}
     
    2019
    2120All design-issue discussions assume the following invariants.
    22 They are stated here to clarify that none of the discussed design issues refers to one of these.
     21\PAB{They are stated here to clarify that none of the discussed design issues refers to one of these.}
    2322Alternatives to the assumptions are discussed under Future Work (Section~\ref{toc:lst:futwork}).
    2423\begin{itemize}
     
    3029          The system has freedom over how to represent these links.
    3130          The library is not providing applied wrapper operations that consume a user's hand-implemented list primitives.
    32     \item These issues are compared at a requirement/functional level.
     31    \item \PAB{These issues are compared at a requirement/functional level.}
    3332\end{itemize}
    3433
    3534Two preexisting linked-list libraries are used throughout, to show examples of the concepts being defined,
    3635and further libraries are introduced as needed.
    37 A general comparison of libraries' abilities is given under Related Work (Section~\ref{toc:lst:relwork}).
    3836\begin{description}
    3937    \item[LQ] Linux Queue library\cite{lst:linuxq} of @<sys/queue.h>@.
    4038    \item[STL] C++ Standard Template Library's @std::list@\cite{lst:stl}
    4139\end{description}
     40A general comparison of libraries' abilities is given under Related Work (Section~\ref{toc:lst:relwork}).
    4241
    4342The fictional type @req@ (request) is the user's payload in examples.
     
    5857
    5958The wrapped style admits the further distinction between wrapping a reference and wrapping a value.
    60 This distinction is pervasive in all STL collections; @list<req*>@ wraps a reference; @list<req>@ wraps a value.
    61 (For this discussion, @list<req&>@ is similar to @list<req*>@.)
     59This distinction is pervasive in all STL collections; @list<req *>@ wraps a reference; @list<req>@ wraps a value.
     60(For this discussion, @list<req &>@ is similar to @list<req *>@.)
    6261This difference is one of user style, not framework capability.
    63 
     62Figure~\ref{fig:lst-issues-attach} compares the three styles.
     63
     64\begin{comment}
    6465\begin{figure}
    6566    \begin{tabularx}{\textwidth}{Y|Y|Y}\lstinputlisting[language=C  , firstline=20, lastline=39]{lst-issues-intrusive.run.c}
     
    7778        (a) & (b) & (c)
    7879    \end{tabularx}
    79     \caption{
     80\caption{
    8081        Three styles of link attachment: (a)~intrusive, (b)~wrapped reference, and (c)~wrapped value.
    8182        The diagrams show the memory layouts that result after the code runs, eliding the head object \lstinline{reqs};
     
    8788        (TODO: cite? found in  /usr/include/c++/7/bits/stl\_list.h )
    8889    }
     90     \label{fig:lst-issues-attach}
     91\end{figure}
     92\end{comment}
     93
     94\begin{figure}
     95\centering
     96\newsavebox{\myboxA}                                    % used with subfigure
     97\newsavebox{\myboxB}
     98\newsavebox{\myboxC}
     99
     100\begin{lrbox}{\myboxA}
     101\begin{tabular}{@{}l@{}}
     102\lstinputlisting[language=C, firstline=20, lastline=39]{lst-issues-intrusive.run.c} \\
     103\ \\
     104\includegraphics[page=1]{lst-issues-attach.pdf}
     105\end{tabular}
     106\end{lrbox}
     107
     108\begin{lrbox}{\myboxB}
     109\begin{tabular}{@{}l@{}}
     110\lstinputlisting[language=C++, firstline=20, lastline=39]{lst-issues-wrapped-byref.run.cpp} \\
     111\ \\
     112\includegraphics[page=2]{lst-issues-attach.pdf}
     113\end{tabular}
     114\end{lrbox}
     115
     116\begin{lrbox}{\myboxC}
     117\begin{tabular}{@{}l@{}}
     118\lstinputlisting[language=C++, firstline=20, lastline=39]{lst-issues-wrapped-emplaced.run.cpp} \\
     119\ \\
     120\includegraphics[page=3]{lst-issues-attach.pdf}
     121\end{tabular}
     122\end{lrbox}
     123
     124\subfloat[Intrusive]{\label{f:Intrusive}\usebox\myboxA}
     125\hspace{10pt}
     126\vrule
     127\hspace{10pt}
     128\subfloat[Wrapped reference]{\label{f:WrappedRef}\usebox\myboxB}
     129\hspace{10pt}
     130\vrule
     131\hspace{10pt}
     132\subfloat[Wrapped value]{\label{f:WrappedValue}\usebox\myboxC}
     133
     134\caption{
     135        Three styles of link attachment: \protect\subref*{f:Intrusive}~intrusive, \protect\subref*{f:WrappedRef}~wrapped
     136        reference, and \protect\subref*{f:WrappedValue}~wrapped value.
     137        The diagrams show the memory layouts that result after the code runs, eliding the head object \lstinline{reqs};
     138        head objects are discussed in Section~\ref{toc:lst:issue:ident}.
     139        In \protect\subref*{f:Intrusive}, the field \lstinline{req.x} names a list direction;
     140        these are discussed in Section~\ref{toc:lst:issue:derection}.
     141        In \protect\subref*{f:WrappedRef} and \protect\subref*{f:WrappedValue}, the type \lstinline{node} represents a
     142        system-internal type, which is \lstinline{std::_List_node} in the GNU implementation.
     143        (TODO: cite? found in  /usr/include/c++/7/bits/stl\_list.h )
     144    }
    89145    \label{fig:lst-issues-attach}
    90146\end{figure}
    91 
    92 
    93 Figure~\ref{fig:lst-issues-attach} compares the three styles.
    94147
    95148The advantage of intrusive attachment is the control that it gives the user over memory layout.
     
    97150Both wrapped attachment styles imply system-induced heap allocations.
    98151Such an allocation has a lifetime that matches the item's membership in the list.
    99 In (a) and (b), one @req@ object can enter and leave a list many times.
    100 In (b), doing do implies a dynamic allocation for each time joining; in (a), it does not.
     152In \subref*{f:Intrusive} and \subref*{f:WrappedRef}, one @req@ object can enter and leave a list many times.
     153In \subref*{f:WrappedRef}, it implies a dynamic allocation/deallocation for each enter/leave; in \subref*{f:Intrusive}, it does not.
    101154
    102155A further aspect of layout control is allowing the user to specify the location of the link fields within the @req@ object.
     
    110163Another subtle advantage of intrusive arrangement is that
    111164a reference to a user-level item (@req@) is sufficient to navigate or manage the item's membership.
    112 In LQ, (a), a @req@ pointer is the right argument type for operations @LIST_NEXT@ or @LIST_REMOVE@;
     165In LQ, \subref*{f:Intrusive}, a @req@ pointer is the right argument type for operations @LIST_NEXT@ or @LIST_REMOVE@;
    113166there is no distinguishing a @req@ from ``a @req@ in a list.''
    114 The same is not true of STL, (b) or (c).
     167The same is not true of STL, \subref*{f:WrappedRef} or \subref*{f:WrappedValue}.
    115168There, the analogous operations work on a parameter of type @list<T>::iterator@;
    116169they are @iterator::operator++()@, @iterator::operator*()@, and @list::erase(iterator)@.
    117 There is no mapping from @req&@ to @list<req>::iterator@, except for linear search.
     170There is no mapping from @req &@ to @list<req>::iterator@, except for linear search.
    118171
    119172The advantage of wrapped attachment is the abstraction of a data item from its list membership(s).
    120173In the wrapped style, the @req@ type can come from a library that serves many independent uses,
    121174which generally have no need for listing.
    122 Then, a novel use can still put @req@ in a (further) list, without requiring any upstream change in the @re@ library.
     175Then, a novel use can still put @req@ in a (further) list, without requiring any upstream change in the @req@ library.
    123176In intrusive attachment, the ability to be listed must be planned during the definition of @req@.
    124 Similarly, style (b) allows for one @req@ to occur at several positions in one list.
    125 Styles (a) and (c) do not support this ability.
     177Similarly, style \subref*{f:WrappedRef} allows for one @req@ to occur at several positions in one list.
     178Styles \subref*{f:Intrusive} and \subref*{f:WrappedValue} do not support this ability.
     179\PAB{But style \subref*{f:WrappedValue} can sort of mimic this effect by have multiple copies of \lstinline{req} in the list, modulo changes to the copies are not seen by the original.}
    126180
    127181\begin{figure}
     
    135189        the LQ C macros do not expand to valid C++ when instantiated with template parameters---there is no \lstinline{struct El}.
    136190        When using a custom-patched version of LQ to work around this issue,
    137         the programs of Figure~\ref{fig:lst-issues-attach}~(b) and (c) work with this shim in place of real STL.
     191        the programs of Figure~\ref{f:WrappedRef} and \protect\subref*{f:WrappedValue} work with this shim in place of real STL.
    138192        Their executions lead to the same memory layouts.
    139193    }
     
    147201
    148202So intrusion is a lower-level listing primitive.
    149 And so, the system design choice is not between forcing users to use intrusion and forcing them to use wrapping.
     203And so, the system design choice is not between forcing users to use intrusion or wrapping.
    150204The choice is whether or not to provide access to an allocation-free layer of functionality.
    151205A wrapped-primitive library like STL forces users to incur the costs of wrapping, whether or not they access its benefits.
     
    153207
    154208
    155 
    156 
    157209\subsection{Directionality: Single vs.\ Multi-Static vs.\ Dynamic}
    158210\label{toc:lst:issue:derection}
    159211
     212\PAB{I'm not sure about the term \newterm{Directionality}. Directionality to me, means going forward or backwards through a list.
     213Would \newterm{dimensionality} work? Think of each list containing the node as a different dimension in which the node sits.}
     214
    160215Directionality deals with the question:
    161216In how many different lists can an item be stored, at a given time?
    162217
    163 
    164 Consider STL in the wrapped-value arrangement of Figure~\ref{fig:lst-issues-attach}~(c).
     218Consider STL in the wrapped-value arrangement of Figure~\ref{f:WrappedValue}.
    165219The STL API completely hides its @node@ type from a user; the user cannot configure this choice or impose a custom one.
    166220STL's @node@ type offers the sole set of links shown in the diagram.
    167 Therefore, every @req@ in existence was allocated either to belong to an occurrence of the diagrammed arrangement,
     221Therefore, every @req@ in existence is allocated either to belong to an occurrence of the diagrammed arrangement,
    168222or to be apart from all occurrences of it.
    169223In the first case, the @req@ belongs to exactly one list (of the style in question).
     
    171225
    172226\begin{figure}
    173     \label{fig:lst-issues-multi-static}
    174227    \parbox[t]{3.5in} {
    175228        \lstinputlisting[language=C++, firstline=20, lastline=60]{lst-issues-multi-static.run.c}
     
    187240        The zoomed-in diagram portion shows the field-level state that results from running the LQ code.
    188241    }
     242    \label{fig:lst-issues-multi-static}
    189243\end{figure}
    190244
     
    205259The corresponding flexibility of wrapped attachment means
    206260the STL wrapped-reference arrangement supports an item being a member of arbitrarily many lists.
    207 This support also applies to the hybrid in which an item's allocation is within a wrapped-value list,
     261This support also applies to the wrapped-value list because the @req@ is copied,
    208262but wrapped-reference lists provide further link directions.
     263\PAB{Explain how}
    209264STL with wrapped references supports dynamic link directions.
    210 
    211 When allowing multiple static directions,frameworks differ in their ergonomics for
    212 the typical case, when the user needs only one direction, vs.\ the atypical case, when the user needs several.
    213 
     265\PAB{Expand}
     266
     267When allowing multiple static directions, frameworks differ in their ergonomics for
     268the typical case: when the user needs only one direction, vs.\ the atypical case, when the user needs several.
    214269LQ's ergonomics are well-suited to the uncommon case of multiple list directions.
    215270Its intrusion declaration and insertion operation both use a mandatory explicit parameter naming the direction.
    216271This decision works well in Figure~\ref{fig:lst-issues-multi-static}, where the names @by_pri@ and @by_rqr@ work well,
    217 but it clutters Figure~\ref{fig:lst-issues-attach}~(a), where a contrived name must be invented and used.
    218 The example uses @x@; @reqs@ would be a more readily ignored choice.
     272but it clutters Figure~\ref{f:Intrusive}, where a contrived name must be invented and used.
     273The example uses @x@; @reqs@ would be a more readily ignored choice. \PAB{wording?}
    219274
    220275\uCpp offers an intrusive list that makes the opposite choice.  TODO: elaborate on inheritance for first direction and acrobatics for subsequent directions.
    221276
    222277
    223 
    224 
    225278\subsection{User integration: Preprocessed vs.\ Type-System Mediated}
    226279
    227280% example of poor error message due to LQ's preprocessed integration
    228 % programs/lst-issues-multi-static.run.c:46:1: error: expected identifier or ‘(’ before ‘do’
     281% programs/lst-issues-multi-static.run.c:46:1: error: expected identifier or '(' before 'do'
    229282%    46 | LIST_INSERT_HEAD(&reqs_rtr_42, &r42b, by_rqr);
    230283%       | ^~~~~~~~~~~~~~~~
     
    239292an item found in a list (type @req@, of variables like @r1@), and
    240293a list (type @reql@ or @list<req>@, of variables like @reqs@ or @reqs_rqr_42@).
    241 The latter type is a head, and these examples are of are headed lists.
     294\see{Figure~\ref{fig:lst-issues-attach} and Figure~\ref{fig:lst-issues-multi-static}}
     295The latter type is a head, and these examples are of headed lists.
    242296
    243297A bespoke ``pointer to next @req@'' implementation often omits the latter type.
     
    246300In headed thinking, there are length-zero lists (heads with no elements), and an element can be listed or not listed.
    247301In ad-hoc thinking, there are no length-zero lists and every element belongs to a list of length at least one.
     302\PAB{Create a figure for this.}
    248303
    249304By omitting the head, elements can enter into an adjacency relationship,
     
    283338identifies a list using an explicit head.
    284339
    285 
    286 \begin{figure}
    287     \label{fig:lst-features-intro}
    288     \lstinputlisting[language=CFA, firstline=20, lastline=32]{lst-features-intro.run.cfa}
    289     \caption[Multiple link directions in \CFA list library]{
    290         Demonstration of the running \lstinline{req} example, done using the \CFA list library\protect\footnotemark.
    291         This example does the same job that Figure~\ref{fig:lst-issues-attach} shows three ways.
    292     }
    293 \end{figure}
    294 \footnotetext{
     340The \CFA list library's version of the running @req@ example is in Figure~\ref{fig:lst-features-intro}.
     341Its link attachment is intrusive and the resulting memory layout is pure-stack, just as for the LQ version of Figure~\ref{f:Intrusive}.
     342The framework-provided type @dlink(...)@ provides the links.
     343The user inserts the links into the @req@ structure by using \CFA inline-inheritance (TODO: reference introduction).
     344Inline inheritance means the type of the field is @dlink(req)@, the field is unnamed, a reference to a @req@ is implicitly convertible to @dlink@.\footnote{
    295345    The \CFA list examples elide the \lstinline{P9_EMBEDDED} annotations that (TODO: xref P9E future work) proposes to obviate.
    296346    Thus, these examples illustrate a to-be state, free of what is to be historic clutter.
    297347    The elided portions are immaterial to the discussion and the examples work with the annotations provided.
    298     The \CFA test suite (TODO:cite?) includes equivalent demonstrations, with the annotations included.
    299 }.
    300 
    301 My \CFA list library's version of the running @req@ example is in Figure~\ref{fig:lst-features-intro}.
    302 Its link attachment is intrusive and the resulting memory layout is pure-stack, just as for the LQ version of Figure~\ref{fig:lst-issues-attach}-(a).
    303 The framework-provided type @dlink(-)@ provides the links.
    304 The user puts links into the @req@ structure by inline-inheriting (TODO: reference introduction) this type.
    305 Which means: the type of the field is @dlink(req)@; the field is unnamed; a reference to a @req@ is implicitly convertible to @dlink@.
    306 As these links have a nontrivial, user-specified location within the @req@ structure, this conversion also encapsulates the implied pointer arithmetic safely.
    307 
    308 \begin{figure}
    309     \label{fig:lst-features-multidir}
    310     \lstinputlisting[language=CFA, firstline=20, lastline=25]{lst-features-multidir.run.cfa}
     348    The \CFA test suite (TODO:cite?) includes equivalent demonstrations, with the annotations included.}
     349These links have a nontrivial, user-specified location within the @req@ structure;
     350this convention encapsulates the implied pointer arithmetic safely.
     351
     352\begin{figure}
     353    \lstinputlisting[language=CFA, firstline=20, lastline=32]{lst-features-intro.run.cfa}
     354    \caption[Multiple link directions in \CFA list library]{
     355        Demonstration of the running \lstinline{req} example, done using the \CFA list library.
     356        This example does the same job that Figure~\ref{fig:lst-issues-attach} shows three ways.
     357    }
     358    \label{fig:lst-features-intro}
     359\end{figure}
     360
     361\begin{figure}
     362\centering
     363\begin{tabular}{@{}ll@{}}
     364\begin{tabular}{@{}l@{}}
     365    \lstinputlisting[language=CFA, firstline=20, lastline=25]{lst-features-multidir.run.cfa} \\
    311366    \lstinputlisting[language=CFA, firstline=40, lastline=67]{lst-features-multidir.run.cfa}
    312     \caption{
     367    \end{tabular}
     368        &
     369        \lstinputlisting[language=C++, firstline=20, lastline=60]{lst-issues-multi-static.run.c}
     370        \end{tabular}
     371
     372\caption{
    313373        Demonstration of multiple static link directions done in the \CFA list library.
    314374        This example does the same job as Figure~\ref{fig:lst-issues-multi-static}.
    315375    }
    316 \end{figure}
    317 
    318 The \CFA library supports multi-static link directionality.  Figure~\ref{fig:lst-features-multidir} illustrates how.
     376    \label{fig:lst-features-multidir}
     377\end{figure}
     378
     379Figure~\ref{fig:lst-features-multidir} shows how the \CFA library supports multi-static link directionality.
    319380The declaration of @req@ now has two inline-inheriting @dlink@ occurrences.
    320 The first of these lines gives a type named @req.by_pri@; @req@ inherits from it; it inherits from @dlink@.
    321 The second line gives a similar @req.by_rqr@.
     381The first of these lines gives a type named @req.by_pri@, @req@ inherits from it, and it inherits from @dlink@.
     382The second line @req.by_rqr@ is similar to @req.by_pri@.
    322383Thus, there is a diamond, non-virtual, inheritance from @req@ to @dlink@, with @by_pri@ and @by_rqr@ being the mid-level types.
    323384Disambiguation occurs in the declarations of the list-head objects.
    324385The type of the variable @reqs_pri_global@ is @dlist(req, req.by_pri)@,
    325386meaning operations called on @reqs_pri_global@ are implicitly disambiguated.
    326 In the example, the calls @insert_first(reqs_pri_global, ...)@ imply, ``here, we're working by priority.''
     387In the example, the calls @insert_first(reqs_pri_global, ...)@ imply, ``here, we are working by priority.''
    327388
    328389The \CFA library also supports the common case, of single directionality, more naturally than LQ. 
    329390Figure~\ref{fig:lst-features-intro} shows a single-direction list done with no contrived name for the link direction,
    330 where Figure~\ref{fig:lst-issues-attach}-(a) adds the unnecessary name, @x@.
     391where Figure~\ref{f:Intrusive} adds the unnecessary name, @x@.
    331392In \CFA, a user doing a single direction (Figure~\ref{fig:lst-features-intro})
    332 sets up a simple inheritance with @dlink@, and declares a list head to have the simpler type @dlist(-)@.
     393sets up a simple inheritance with @dlink@, and declares a list head to have the simpler type @dlist(...)@.
    333394While a user doing multiple link directions (Figure~\ref{fig:lst-features-multidir})
    334 sets up a diamond inheritance with @dlink@, and declares a list head to have the more-informed type @dlist(-, DIR)@.
     395sets up a diamond inheritance with @dlink@, and declares a list head to have the more-informed type @dlist(..., DIR)@.
    335396
    336397The \CFA library offers a type-system mediated integration with user code.
     
    348409
    349410
    350 
    351 
    352 
    353411\subsection{Iteration}
    354412
  • doc/theses/mike_brooks_MMath/uw-ethesis.tex

    r1f771fc r5d9c4bb  
    6060% For hyperlinked PDF, suitable for viewing on a computer, use this:
    6161\documentclass[letterpaper,12pt,titlepage,oneside,final]{book}
     62\usepackage{times}
    6263\usepackage[T1]{fontenc}        % Latin-1 => 256-bit characters, => | not dash, <> not Spanish question marks
    6364
     
    8788\usepackage{comment} % Removes large sections of the document.
    8889\usepackage{tabularx}
    89 \usepackage{subfigure}
     90\usepackage[labelformat=simple,aboveskip=0pt,farskip=0pt,font=normalsize]{subfig}
     91\renewcommand\thesubfigure{(\alph{subfigure})}
    9092
    9193\usepackage{algorithm}
    9294\usepackage{algpseudocode}
    93 
    94 \usepackage{pbox}
    9595
    9696% Hyperlinks make it very easy to navigate an electronic document.
     
    117117    citecolor=blue,        % color of links to bibliography
    118118    filecolor=magenta,      % color of file links
    119     urlcolor=blue           % color of external links
     119    urlcolor=blue,           % color of external links
     120    breaklinks=true
    120121}
    121122\ifthenelse{\boolean{PrintVersion}}{   % for improved print quality, change some hyperref options
     
    180181\CFAStyle                                               % CFA code-style
    181182\lstset{language=CFA}                                   % default language
    182 \lstset{basicstyle=\linespread{0.9}\tt}                 % CFA typewriter font
     183\lstset{basicstyle=\linespread{0.9}\sf}                 % CFA typewriter font
    183184\lstset{inputpath={programs}}
    184185\newcommand{\PAB}[1]{{\color{red}PAB: #1}}
    185186
    186 
    187 \newcommand{\uCpp}{$\mu${C}{\kern-.1em\hbox{\large\texttt{+\kern-.25em+}}}}
     187\newcommand{\uCpp}{$\mu$\CC}
    188188
    189189%======================================================================
Note: See TracChangeset for help on using the changeset viewer.