Ignore:
Timestamp:
May 1, 2017, 1:39:55 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
2055098
Parents:
b3d70eba
Message:

final revisions to thesis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/rob_thesis/tuples.tex

    rb3d70eba r12d3187  
    161161\end{cfacode}
    162162
     163\begin{sloppypar}
    163164In addition to variables of tuple type, it is also possible to have pointers to tuples, and arrays of tuples.
    164 Tuple types can be composed of any types, except for array types, since arrays do not carry their size around, which makes tuple assignment difficult when a tuple contains an array.
     165Tuple types can be composed of any types, except for array types, since array assignment is disallowed, which makes tuple assignment difficult when a tuple contains an array.
    165166\begin{cfacode}
    166167[double, int] di;
     
    169170\end{cfacode}
    170171This examples declares a variable of type @[double, int]@, a variable of type pointer to @[double, int]@, and an array of ten @[double, int]@.
     172\end{sloppypar}
    171173
    172174\subsection{Tuple Indexing}
     
    212214The flexible structure of tuples permits a simple and expressive function-call syntax to work seamlessly with both single- and multiple-return-value functions, and with any number of arguments of arbitrarily complex structure.
    213215
    214 In \KWC \cite{Buhr94a,Till89}, a precursor to \CFA, there were 4 tuple coercions: opening, closing, flattening, and structuring.
     216In \KWC \cite{Buhr94a,Till89}, there were 4 tuple coercions: opening, closing, flattening, and structuring.
    215217Opening coerces a tuple value into a tuple of values, while closing converts a tuple of values into a single tuple value.
    216218Flattening coerces a nested tuple into a flat tuple, \ie it takes a tuple with tuple components and expands it into a tuple with only non-tuple components.
     
    218220
    219221In \CFA, the design has been simplified to require only the two conversions previously described, which trigger only in function call and return situations.
     222This simplification is a primary contribution of this thesis to the design of tuples in \CFA.
    220223Specifically, the expression resolution algorithm examines all of the possible alternatives for an expression to determine the best match.
    221224In resolving a function call expression, each combination of function value and list of argument alternatives is examined.
     
    254257Let $L_i$ for $i$ in $[0, n)$ represent each component of the flattened left side, $R_i$ represent each component of the flattened right side of a multiple assignment, and $R$ represent the right side of a mass assignment.
    255258
    256 For a multiple assignment to be valid, both tuples must have the same number of elements when flattened. Multiple assignment assigns $R_i$ to $L_i$ for each $i$.
     259For a multiple assignment to be valid, both tuples must have the same number of elements when flattened.
     260For example, the following is invalid because the number of components on the left does not match the number of components on the right.
     261\begin{cfacode}
     262[int, int] x, y, z;
     263[x, y] = z;   // multiple assignment, invalid 4 != 2
     264\end{cfacode}
     265Multiple assignment assigns $R_i$ to $L_i$ for each $i$.
    257266That is, @?=?(&$L_i$, $R_i$)@ must be a well-typed expression.
    258267In the previous example, @[x, y] = z@, @z@ is flattened into @z.0, z.1@, and the assignments @x = z.0@ and @y = z.1@ happen.
     
    265274
    266275Both kinds of tuple assignment have parallel semantics, such that each value on the left side and right side is evaluated \emph{before} any assignments occur.
    267 As a result, it is possible to swap the values in two variables without explicitly creating any temporary variables or calling a function,
     276As a result, it is possible to swap the values in two variables without explicitly creating any temporary variables or calling a function.
    268277\begin{cfacode}
    269278int x = 10, y = 20;
     
    296305\subsection{Tuple Construction}
    297306Tuple construction and destruction follow the same rules and semantics as tuple assignment, except that in the case where there is no right side, the default constructor or destructor is called on each component of the tuple.
     307As constructors and destructors did not exist in previous versions of \CFA or in \KWC, this is a primary contribution of this thesis to the design of tuples.
    298308\begin{cfacode}
    299309struct S;
     
    433443\section{Casting}
    434444In C, the cast operator is used to explicitly convert between types.
    435 In \CFA, the cast operator has a secondary use, which is type ascription, since it force the expression resolution algorithm to choose the lowest cost conversion to the target type.
     445In \CFA, the cast operator has a secondary use, which is type ascription, since it forces the expression resolution algorithm to choose the lowest cost conversion to the target type.
    436446That is, a cast can be used to select the type of an expression when it is ambiguous, as in the call to an overloaded function.
    437447\begin{cfacode}
     
    487497\section{Polymorphism}
    488498Due to the implicit flattening and structuring conversions involved in argument passing, @otype@ and @dtype@ parameters are restricted to matching only with non-tuple types.
     499The integration of polymorphism, type assertions, and monomorphic specialization of tuple-assertions are a primary contribution of this thesis to the design of tuples.
    489500\begin{cfacode}
    490501forall(otype T, dtype U)
     
    524535It is also important to note that these calls could be disambiguated if the function return types were different, as they likely would be for a reasonable implementation of @?+?@, since the return type is used in overload resolution.
    525536Still, these semantics are a deficiency of the current argument matching algorithm, and depending on the function, differing return values may not always be appropriate.
    526 These issues could be rectified by applying an appropriate cost to the structuring and flattening conversions, which are currently 0-cost conversions.
     537These issues could be rectified by applying an appropriate conversion cost to the structuring and flattening conversions, which are currently 0-cost conversions in the expression resolver.
    527538Care would be needed in this case to ensure that exact matches do not incur such a cost.
    528539\begin{cfacode}
     
    559570\section{Implementation}
    560571Tuples are implemented in the \CFA translator via a transformation into generic types.
     572Generic types are an independent contribution developed at the same time.
     573The transformation into generic types and the generation of tuple-specific code are primary contributions of this thesis to tuples.
     574
    561575The first time an $N$-tuple is seen for each $N$ in a scope, a generic type with $N$ type parameters is generated.
    562576For example,
Note: See TracChangeset for help on using the changeset viewer.