Changeset 5ebb1368
 Timestamp:
 Dec 12, 2018, 9:16:23 AM (5 years ago)
 Branches:
 ADT, aaronthesis, armeh, astexperimental, cleanupdtors, deferred_resn, enum, forallpointerdecay, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, no_list, persistentindexer, pthreademulation, qualifiedEnum
 Children:
 85acec94, ac1ae2c6
 Parents:
 200fcb3 (diff), 29207bf (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/aaron_moss_PhD/phd/typeenvironment.tex
r200fcb3 r5ebb1368 24 24 $add(T_i, v_{i,j})$ & & Add variable to class \\ 25 25 $bind(T_i, b_i)$ & & Set or update class bound \\ 26 $remove(T, T_i)$ & & Remove class from environment \\27 26 $unify(T, T_i, T_j)$ & $\rightarrow \top  \bot$ & Combine two type classes \\ 27 $split(T, T_i)$ & $\rightarrow T'$ & Revert the last $unify$ operation on $T_i$ \\ 28 28 $combine(T, T')$ & $\rightarrow \top  \bot$ & Merge two environments \\ 29 29 $save(T)$ & $\rightarrow H$ & Get handle for current state \\ … … 40 40 The $add(T_i, v_{i,j})$ operation adds a new type variable $v_{i,j}$ to class $T_i$; again, $v_{i,j}$ cannot exist elsewhere in $T$. 41 41 $bind(T_i, b_i)$ mutates the bound for a type class, setting or updating the current bound. 42 The final basic mutation operation is $remove(T, T_i)$, which removes a class $T_i$ and all its type variables from an environment $T$.43 42 44 43 The $unify$ operation is the fundamental nontrivial operation a type environment data structure must support. … … 50 49 For instance, unifying !R*! with !S*! for type variables !R! and !S! will result in a call to $unify(T, find($!R!$), find($!S!$))$, while unifying !R*! with !int*! will result in a call to $unifyBound$ on !int! and the bound type of the class containing !R!. 51 50 As such, a call to $unify(T, T_i, T_j)$ may touch every type class in $T$, not just $T_i$ and $T_j$, collapsing the entirety of $T$ into a single type class in extreme cases. 51 For more information on \CFA{} unification, see \cite{Bilson03}. 52 The inverse of $unify$ is $split(T, T_i)$, which produces a new environment $T'$ which is the same as $T$ except that $T_i$ has been replaced by two classes corresponding to the arguments to the previous call to $unify$ on $T_i$. 53 If there has been no call to $unify$ on $T_i$ (\ie{} $T_i$ is a singleelement class) $T_i$ is absent in $T'$. 52 54 53 55 Given the nature of the expression resolution problem as backtracking search, caching and concurrency are both useful tools to decrease runtime. … … 57 59 The invalid state of $T$ on failure is not important, given that a combination failure will result in the resolution algorithm backtracking to a different environment. 58 60 $combine$ proceeds by calls to $insert$, $add$, and $unify$ as needed, and can be roughly thought of as calling $unify$ on every pair of classes in $T$ that have variables $v'_{i,j}$ and $v'_{i,k}$ in the same class $T'_i$ in $T'$. 59 Like for$unify$, $combine$ can always find a mutuallyconsistent partition of type variables into classes (in the extreme case, all type variables from $T$ and $T'$ in a single type class), but may fail due to inconsistent bounds on merged type classes.61 Like $unify$, $combine$ can always find a mutuallyconsistent partition of type variables into classes (in the extreme case, all type variables from $T$ and $T'$ in a single type class), but may fail due to inconsistent bounds on merged type classes. 60 62 61 63 Finally, the backtracking access patterns of the compiler can be exploited to reduce memory usage or runtime through use of an appropriately designed data structure. … … 103 105 \subsection{UnionFind with Classes} \label{envunionfindclassesapproach} 104 106 105 Another type environment operation not supported directly by the unionfind data structure is $report$, which lists the type variables in a given class, and similarly $ remove$, which removes a class and all its type variables from the environment.107 Another type environment operation not supported directly by the unionfind data structure is $report$, which lists the type variables in a given class, and similarly $split$, which reverts a $unify$ operation. 106 108 Since the unionfind data structure stores only links from children to parents and not viceversa, there is no way to reconstruct a class from one of its elements without a linear search over the entire data structure, with $find$ called on each element to check its membership in the class. 107 The situation is even worse for the $ remove$ operation, where a na\"{\i}ve removal of every element belonging to a specific class would likely remove some parents before their children, requiring either extra bookkeeping or passes through the data structure to remove the leaf elements of the class first.109 The situation is even worse for the $split$ operation, which would require extra information to maintain the order that each child was added to its parent node. 108 110 Unfortunately, the literature\cite{Tarjan84,Galil91,Patwary10} on unionfind does not present a way to keep references to children without breaking the asymptotic time bounds of the algorithm; I have discovered a method to do so which, despite its simplicity, seems to be novel. 109 111 … … 112 114 The core idea of this ``unionfind with classes'' data structure and algorithm is to keep the members of each class stored in a circularlylinked list. 113 115 Aho, Hopcroft, and Ullman also include a circularlylinked list in their 1974 textbook~\cite{Aho74}. 114 However, the algorithm presented by Aho~\etal{} has an entirely flat class hierarchy, where all elements were direct children of the representative, giving constanttime $find$ at the cost of lineartime $union$ operations.116 However, the algorithm presented by Aho~\etal{} has an entirely flat class hierarchy, where all elements are direct children of the representative, giving constanttime $find$ at the cost of lineartime $union$ operations. 115 117 In my version, the list data structure does not affect the layout of the unionfind tree, maintaining the same asymptotic bounds as unionfind. 116 118 In more detail, each element is given a !next! pointer to another element in the same class; this !next! pointer initially points to the element itself. … … 143 145 \TODO{port figure from slideshow} 144 146 145 In Baker's persistent array, an array reference contains either a pointer to the array or a pointer to an \emph{edit node}; these edit nodes contain an array index, the value in that index, and another array indexpointing either to the array or a different edit node.147 In Baker's persistent array, an array reference contains either a pointer to the array or a pointer to an \emph{edit node}; these edit nodes contain an array index, the value in that index, and another array reference pointing either to the array or a different edit node. 146 148 In this manner, a tree of edits is formed, rooted at the actual array. 147 149 Read from the actual array at the root can be performed in constant time, as with a nonpersistent array. 148 The persistent array can be mutated by directly modifying the underlying array, then replacing its array reference with an edit node containing the mutated index, the previous value at that index, and a reference to the mutated array.149 Th is mutation algorithmis in some sense a special case of the key operation on persistent arrays, $reroot$.150 The persistent array can be mutated in constant time by directly modifying the underlying array, then replacing its array reference with an edit node containing the mutated index, the previous value at that index, and a reference to the mutated array. If the current array reference is not the root, mutation consists simply of constructing a new edit node encoding the change and referring to the current array reference. 151 The mutation algorithm at the root is in some sense a special case of the key operation on persistent arrays, $reroot$. 150 152 151 153 A rerooting operation takes any array reference and makes it the root node of the array. … … 182 184 In this section I present asymptotic analyses of the various approaches to a type environment data structure discussed in the previous section. 183 185 186 \begin{table} 187 \caption[Type environment operation bounds]{Worstcase analysis of type environment operations. $n$ is the number of type classes, $m$ the maximum size of a type class, and $p$ the edit distance between two environments or a single environment and the empty environment; $u(n)$ captures the recursive cost of class unification.} 188 \label{envboundstable} 189 \centering 190 \begin{tabular}{rllll} 191 \hline 192 & \textbf{Na\"{\i}ve} & \textbf{Incremental} & \textbf{UnionFind} & \textbf{UF with Classes} \\ 193 \hline 194 $find$ & $O(n)$ & $O(p)$ & $O(\alpha(m))$ & $O(\log m)$ \\ 195 $report$ & $O(m)$ & $O(m)$ & $O(n \log m)$ & $O(m)$ \\ 196 $bound$ & $O(1)$ & $O(1)$ & $O(1)$ & $O(1)$ \\ 197 $insert$ & $O(1)$ & $O(1)$ & $O(1)$ & $O(1)$ \\ 198 $add$ & $O(1)$ & $O(1)$ & $O(1)$ & $O(1)$ \\ 199 $bind$ & $O(1)$ & $O(1)$ & $O(1)$ & $O(1)$ \\ 200 $unify$ & $O(m + u(n))$ & $O(m + u(n))$ & $O(\log m + u(n))$ & $O(\log m + u(n))$ \\ 201 $split$ &  &  &  & $O(\log m)$ \\ 202 $combine$ & $O(nm \cdot u(n))$ & $O(pm \cdot u(n))$ & $O(n \log m \cdot u(n))$ & $O(p \log m \cdot u(n))$ \\ 203 $save$ & $O(nm)$ & $O(1)$ & $O(nm)$ & $O(1)$ \\ 204 $backtrack$ & $O(nm)$ & $O(pm)$ & $O(nm)$ & $O(p)$ \\ 205 \hline 206 \end{tabular} 207 \end{table} 208 184 209 % Future work: design multithreaded version of C&F persistent map  core idea is some sort of threadboundary edit node
Note: See TracChangeset
for help on using the changeset viewer.