Index: doc/rob_thesis/cfa-format.tex
===================================================================
--- doc/rob_thesis/cfa-format.tex	(revision 74933396698c5746d8db9582869740d0dbc1a8f4)
+++ doc/rob_thesis/cfa-format.tex	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -72,4 +72,28 @@
   morecomment=[n]{/+}{+/},
   morecomment=[n][\color{blue}]{/++}{+/},
+  % Options
+  sensitive=true
+}
+
+\lstdefinelanguage{rust}{
+  % Keywords
+  morekeywords=[1]{
+    abstract, alignof, as, become, box,
+    break, const, continue, crate, do,
+    else, enum, extern, false, final,
+    fn, for, if, impl, in,
+    let, loop, macro, match, mod,
+    move, mut, offsetof, override, priv,
+    proc, pub, pure, ref, return,
+    Self, self, sizeof, static, struct,
+    super, trait, true,  type, typeof,
+    unsafe, unsized, use, virtual, where,
+    while, yield
+  },
+  % Strings
+  morestring=[b]{"},
+  % Comments
+  comment=[l]{//},
+  morecomment=[s]{/*}{*/},
   % Options
   sensitive=true
@@ -155,4 +179,12 @@
   \lstset{
     language = D,
+    style=defaultStyle,
+    #1
+  }
+}{}
+
+\lstnewenvironment{rustcode}[1][]{
+  \lstset{
+    language = rust,
     style=defaultStyle,
     #1
Index: doc/rob_thesis/conclusions.tex
===================================================================
--- doc/rob_thesis/conclusions.tex	(revision 74933396698c5746d8db9582869740d0dbc1a8f4)
+++ doc/rob_thesis/conclusions.tex	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -3,31 +3,243 @@
 %======================================================================
 
-Conclusion paragraphs.
+\section{Constructors and Destructors}
+\CFA supports the RAII idiom using constructors and destructors.
+There are many engineering challenges in introducing constructors and destructors, partially since \CFA is not an object-oriented language.
+By making use of managed types, \CFA programmers are afforded an extra layer of safety and ease of use in comparison to C programmers.
+While constructors and destructors provide a sensible default behaviour, \CFA allows experienced programmers to declare unmanaged objects to take control of object management for performance reasons.
+Constructors and destructors as named functions fit the \CFA polymorphism model perfectly, allowing polymorphic code to use managed types seamlessly.
+
+\section{Tuples}
+\CFA can express functions with multiple return values in a way that is simple, concise, and safe.
+The addition of multiple-return-value functions naturally requires a way to use multiple return values, which begets tuple types.
+Tuples provide two useful notions of assignment: multiple assignment, allowing simple, yet expressive assignment between multiple variables, and mass assignment, allowing a lossless assignment of a single value across multiple variables.
+Tuples have a flexible structure that allows the \CFA type-system to decide how to restructure tuples, making it syntactically simple to pass tuples between functions.
+Tuple types can be combined with polymorphism and tuple conversions can apply during assertion inference to produce a cohesive feel.
+
+\section{Variadic Functions}
+Type-safe variadic functions of a similar feel to variadic templates are added to \CFA.
+The new variadic functions can express complicated recursive algorithms.
+Unlike variadic templates, it is possible to write @new@ as a library routine and to separately compile @ttype@ polymorphic functions.
+Variadic functions are statically type checked and provide a user experience that is consistent with that of tuples and polymorphic functions.
 
 \section{Future Work}
-
 \subsection{Constructors and Destructors}
-% TODO: discuss move semantics; they haven't been implemented, but could be. Currently looking at alternative models.
-
-% TODO: discuss exceptions
-
-% TODO: fix return value destruction in full compiler
-
-% TODO: once deleted functions are added, unions can have deleted standard functions, like C++11 (may not need to mention this again...)
-
-% TODO: better study and fix the ways @= objects interact with the rest of the world (e.g. provide @= equivalent for assignment, or otherwise have @= objects default to using intrinsic/autogen ops?)
-
-
+Both \CC and Rust support move semantics, which expand the user's control of memory management by providing the ability to transfer ownership of large data, rather than forcing potentially expensive copy semantics.
+\CFA currently does not support move semantics, partially due to the complexity of the model.
+The design space is currently being explored with the goal of finding an alternative to move semantics that provides necessary performance benefits, while reducing the amount of repetition required to create a new type, along with the cognitive burden placed on the user.
+
+Exception handling is among the features expected to be added to \CFA in the near future.
+For exception handling to properly interact with the rest of the language, it must ensure all RAII guarantees continue to be met.
+That is, when an exception is raised, it must properly unwind the stack by calling the destructors for any objects that live between the raise and the handler.
+This can be accomplished either by augmenting the translator to properly emit code that executes the destructors, or by switching destructors to hook into the GCC @cleanup@ attribute \cite[6.32.1]{GCCExtensions}.
+
+The @cleanup@ attribute, which is attached to a variable declaration, takes a function name as an argument and schedules that routine to be executed when the variable goes out of scope.
+\begin{cfacode}
+struct S { int x; };
+void __dtor_S(struct S *);
+{
+  __attribute__((cleanup(__dtor_S))) struct S s;
+} // calls __dtor_S(&s)
+\end{cfacode}
+This mechanism is known and understood by GCC, so that the destructor is properly called in any situation where a variable goes out of scope, including function returns, branches, and built-in GCC exception handling mechanisms using libunwind.
+
+A caveat of this approach is that the @cleanup@ attribute only permits a name that refers to a function that consumes a single argument of type @T *@ for a variable of type @T@.
+This means that any destructor that consumes multiple arguments (e.g., because it is polymorphic) or any destructor that is a function pointer (e.g., because it is an assertion parameter) must be called through a local thunk.
+For example,
+\begin{cfacode}
+forall(otype T)
+struct Box {
+  T x;
+};
+forall(otype T) void ^?{}(Box(T) * x);
+
+forall(otype T)
+void f(T x) {
+  T y = x;
+  Box(T) z = { x };
+}
+\end{cfacode}
+currently generates the following
+\begin{cfacode}
+void _dtor_BoxT(  // consumes more than 1 parameter due to assertions
+  void (*_adapter_PTT)(void (*)(), void *, void *),
+  void (*_adapter_T_PTT)(void (*)(), void *, void *, void *),
+  long unsigned int _sizeof_T,
+  long unsigned int _alignof_T,
+  void *(*_assign_T_PTT)(void *, void *),
+  void (*_ctor_PT)(void *),
+  void (*_ctor_PTT)(void *, void *),
+  void (*_dtor_PT)(void *),
+  void *x
+);
+
+void f(
+  void (*_adapter_PTT)(void (*)(), void *, void *),
+  void (*_adapter_T_PTT)(void (*)(), void *, void *, void *),
+  long unsigned int _sizeof_T,
+  long unsigned int _alignof_T,
+  void *(*_assign_TT)(void *, void *),
+  void (*_ctor_T)(void *),
+  void (*_ctor_TT)(void *, void *),
+  void (*_dtor_T)(void *),
+  void *x
+){
+  void *y = __builtin_alloca(_sizeof_T);
+  // constructor call elided
+
+  // generic layout computation elided
+  long unsigned int _sizeof_BoxT = ...;
+  void *z = __builtin_alloca(_sizeof_BoxT);
+  // constructor call elided
+
+  _dtor_BoxT(  // ^?{}(&z); -- _dtor_BoxT has > 1 arguments
+    _adapter_PTT,
+    _adapter_T_PTT,
+    _sizeof_T,
+    _alignof_T,
+    _assign_TT,
+    _ctor_T,
+    _ctor_TT,
+    _dtor_T,
+    z
+  );
+  _dtor_T(y);  // ^?{}(&y); -- _dtor_T is a function pointer
+}
+\end{cfacode}
+Further to this point, every distinct array type will require a thunk for its destructor, where array destructor code is currently inlined, since array destructors hard code the length of the array.
+
+For function call temporaries, new scopes have to be added for destructor ordering to remain consistent.
+In particular, the translator currently destroys argument and return value temporary objects as soon as the statement they were created for ends.
+In order for this behaviour to be maintained, new scopes have to be added around every statement that contains a function call.
+Since a nested expression can raise an exception, care must be taken when destroying temporary objects.
+One way to achieve this is to split statements at every function call, to provide the correct scoping to destroy objects as necessary.
+For example,
+\begin{cfacode}
+struct S { ... };
+void ?{}(S *, S);
+void ^?{}(S *);
+
+S f();
+S g(S);
+
+g(f());
+\end{cfacode}
+would generate
+\begin{cfacode}
+struct S { ... };
+void _ctor_S(struct S *, struct S);
+void _dtor_S(struct S *);
+
+{
+  __attribute__((cleanup(_dtor_S))) struct S _tmp1 = f();
+  __attribute__((cleanup(_dtor_S))) struct S _tmp2 =
+    (_ctor_S(&_tmp2, _tmp1), _tmp2);
+  __attribute__((cleanup(_dtor_S))) struct S _tmp3 = g(_tmp2);
+} // destroy _tmp3, _tmp2, _tmp1
+\end{cfacode}
+Note that destructors must be registered after the temporary is fully initialized, since it is possible for initialization expressions to raise exceptions, and a destructor should never be called on an uninitialized object.
+This requires a slightly strange looking initializer for constructor calls, where a comma expression is used to produce the value of the object being initialized, after the constructor call, conceptually bitwise copying the initialized data into itself.
+Since this copy is wholly unnecessary, it is easily optimized away.
+
+A second approach is to attach an accompanying boolean to every temporary that records whether the object contains valid data, and thus whether the value should be destructed.
+\begin{cfacode}
+struct S { ... };
+void _ctor_S(struct S *, struct S);
+void _dtor_S(struct S *);
+
+struct __tmp_bundle_S {
+  bool valid;
+  struct S value;
+};
+
+void _dtor_tmpS(struct __tmp_bundle_S * ret) {
+  if (ret->valid) {
+    _dtor_S(&ret->value);
+  }
+}
+
+{
+  __attribute__((cleanup(_dtor_tmpS))) struct __tmp_bundle_S _tmp1 = { 0 };
+  __attribute__((cleanup(_dtor_tmpS))) struct __tmp_bundle_S _tmp2 = { 0 };
+  __attribute__((cleanup(_dtor_tmpS))) struct __tmp_bundle_S _tmp3 = { 0 };
+  _tmp2.value = g(
+    (_ctor_S(
+      &_tmp2.value,
+      (_tmp1.value = f(), _tmp1.valid = 1, _tmp1.value)
+    ), _tmp2.valid = 1, _tmp2.value)
+  ), _tmp3.valid = 1, _tmp3.value;
+} // destroy _tmp3, _tmp2, _tmp1
+\end{cfacode}
+In particular, the boolean is set immediately after argument construction and immediately after return value copy.
+The boolean is checked as a part of the @cleanup@ routine, forwarding to the object's destructor if the object is valid.
+One such type and @cleanup@ routine needs to be generated for every type used in a function parameter or return value.
+
+The former approach generates much simpler code, however splitting expressions requires care to ensure that expression evaluation order does not change.
+Expression ordering has to be performed by a full compiler, so it is possible that the latter approach would be more suited to the \CFA prototype, whereas the former approach is clearly the better option in a full compiler.
+More investigation is needed to determine whether the translator's current design can easily handle proper expression ordering.
+
+As discussed in Section \ref{s:implicit_copy_construction}, return values are destructed with a different @this@ pointer than they are constructed with.
+This problem can be easily fixed once a full \CFA compiler is built, since it would have full control over the call/return mechanism.
+In particular, since the callee is aware of where it needs to place the return value, it can construct the return value directly, rather than bitwise copy the internal data.
+
+Currently, the special functions are always auto-generated, except for generic types where the type parameter does not have assertions for the corresponding operation.
+For example,
+\begin{cfacode}
+forall(dtype T | sized(T) | { void ?{}(T *); })
+struct S { T x; };
+\end{cfacode}
+will only auto-generate the default constructor for @S@, since the member @x@ is missing the other 3 special functions.
+Once deleted functions have been added, function generation can make use of this information to disable generation of special functions when a member has a deleted function.
+For example,
+\begin{cfacode}
+struct A {};
+void ?{}(A *) = delete;
+struct S { A x; };  // does not generate void ?{}(S *);
+\end{cfacode}
+
+Unmanaged objects and their interactions with the managed \CFA environment are an open problem that deserves greater attention.
+In particular, the interactions between unmanaged objects and copy semantics are subtle and can easily lead to errors.
+It is possible that the compiler should mark some of these situations as errors by default, and possibly conditionally emit warnings for some situations.
+Another possibility is to construct, destruct, and assign unmanaged objects using the intrinsic and auto-generated functions.
+A more thorough examination of the design space for this problem is required.
+
+Currently, the \CFA translator does not support any warnings.
+Ideally, the translator should support optional warnings in the case where it can detect that an object has been constructed twice.
+For example, forwarding constructor calls are guaranteed to initialize the entire object, so redundant constructor calls can cause problems such as memory leaks, while looking innocuous to a novice user.
+\begin{cfacode}
+struct B { ... };
+struct A {
+	B x, y, z;
+};
+void ?{}(A * a, B x) {
+	// y, z implicitly default constructed
+	(&a->x){ ... }; // explicitly construct x
+} // constructs an entire A
+void ?{}(A * a) {
+	(&a->y){}; // initialize y
+	a{ (B){ ... } }; // forwarding constructor call
+	                 // initializes entire object, including y
+}
+\end{cfacode}
+
+Finally, while constructors provide a mechanism for establishing invariants, there is currently no mechanism for maintaining invariants without resorting to opaque types.
+That is, structure fields can be accessed and modified by any block of code without restriction, so while it's possible to ensure that an object is initially set to a valid state, it isn't possible to ensure that it remains in a consistent state throughout its lifetime.
+A popular technique for ensuring consistency in object-oriented programming languages is to provide access modifiers such as @private@, which provides compile-time checks that only privileged code accesses private data.
+This approach could be added to \CFA, but it requires an idiomatic way of specifying what code is privileged.
+One possibility is to tie access control into an eventual module system.
 
 \subsection{Tuples}
-
-% TODO: named return values are not currently implemented in CFA - tie in with named tuples?
-
-% TODO: tuples are allowed in expressions, exact meaning is defined by operator overloading (e.g. can add tuples). An important caveat to note is that it is currently impossible to allow adding two triples but prevent adding a pair with a quadruple (single flattening/structuring conversions are implicit, only total number of components matters). May be able to solve this with more nuanced conversion rules
+Named result values are planned, but not yet implemented.
+This feature ties nicely into named tuples, as seen in D and Swift.
+
+Currently, tuple flattening and structuring conversions are 0-cost.
+This makes tuples conceptually very simple to work with, but easily causes unnecessary ambiguity in situations where the type system should be able to differentiate between alternatives.
+Adding an appropriate cost function to tuple conversions will allow tuples to interact with the rest of the programming language more cohesively.
 
 \subsection{Variadic Functions}
-% TODO: look into 'nicer' expansion syntax
-
-% TODO: consider more sophisticated argument matching algorithms, e.g. forall(ttype Params) void f(Params, Params); f(1,2); f(1,2,3,4); => f([1], [2]); f([1,2], [3,4]); => okay if Params can be bound to a type that is consistent throughout the expression's type
-
-
+Use of @ttype@ functions currently relies heavily on recursion.
+\CC has opened variadic templates up so that recursion isn't strictly necessary in some cases, and it would be interesting to see if any such cases can be applied to \CFA.
+
+\CC supports variadic templated data types, making it possible to express arbitrary length tuples, arbitrary parameter function objects, and more with generic types.
+Currently, \CFA does not support @ttype@-parameter generic types, though there does not appear to be a technical reason that it cannot.
+Notably, opening up support for this makes it possible to implement the exit form of scope guard (see section \ref{s:ResMgmt}), making it possible to call arbitrary functions at scope exit in idiomatic \CFA.
Index: doc/rob_thesis/ctordtor.tex
===================================================================
--- doc/rob_thesis/ctordtor.tex	(revision 74933396698c5746d8db9582869740d0dbc1a8f4)
+++ doc/rob_thesis/ctordtor.tex	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -3,551 +3,6 @@
 %======================================================================
 
-% TODO: as an experiment, implement Andrei Alexandrescu's ScopeGuard http://www.drdobbs.com/cpp/generic-change-the-way-you-write-excepti/184403758?pgno=2
+% TODO now: as an experiment, implement Andrei Alexandrescu's ScopeGuard http://www.drdobbs.com/cpp/generic-change-the-way-you-write-excepti/184403758?pgno=2
 % doesn't seem possible to do this without allowing ttype on generic structs?
-
-% If a Cforall constructor is in scope, C style initialization is
-% disabled by default.
-% * initialization rule: if any constructor is in scope for type T, try
-%   to find a matching constructor for the call. If there are no
-%   constructors in scope for type T, then attempt to fall back on
-%   C-style initialization.
-% + if this rule was not in place, it would be easy to accidentally
-%   use C-style initialization in certain cases, which could lead to
-%   subtle errors [2]
-% - this means we need special syntax if we want to allow users to force
-%   a C-style initialization (to give users more control)
-% - two different declarations in the same scope can be implicitly
-%   initialized differently. That is, there may be two objects of type
-%   T that are initialized differently because there is a constructor
-%   definition between them. This is not technically specific to
-%   constructors.
-
-% C-style initializers can be accessed with @= syntax
-% + provides a way to get around the requirement of using a constructor
-%   (for advanced programmers only)
-% - can break invariants in the type => unsafe
-% * provides a way of asserting that a variable is an instance of a
-%   C struct (i.e. a POD struct), and so will not be implicitly
-%   destructed (this can be useful at times, maybe mitigates the need
-%   for move semantics?) [3]
-% + can modernize a code base one step at a time
-
-% Cforall constructors can be used in expressions to initialize any
-% piece of memory.
-% + malloc() { ... } calls the appropriate constructor on the newly
-%   allocated space; the argument is moved into the constructor call
-%   without taking its address [4]
-% - with the above form, there is still no way to ensure that
-%   dynamically allocated objects are constructed. To resolve this,
-%   we might want a stronger "new" function which always calls the
-%   constructor, although how we accomplish that is currently still
-%   unresolved (compiler magic vs. better variadic functions?)
-% + This can be used as a placement syntax [5]
-% - can call the constructor on an object more than once, which could
-%   cause resource leaks and reinitialize const fields (can try to
-%   detect and prevent this in some cases)
-%   * compiler always tries to implicitly insert a ctor/dtor pair for
-%     non-@= objects.
-%     * For POD objects, this will resolve to an autogenerated or
-%       intrinsic function.
-%     * Intrinsic functions are not automatically called. Autogenerated
-%       are, because they may call a non-autogenerated function.
-%     * destructors are automatically inserted at appropriate branches
-%       (e.g. return, break, continue, goto) and at the end of the block
-%       in which they are declared.
-%   * For @= objects, the compiler never tries to interfere and insert
-%     constructor and destructor calls for that object. Copy constructor
-%     calls do not count, because the object is not the target of the copy
-%     constructor.
-
-% A constructor is declared with the name ?{}
-% + combines the look of C initializers with the precedent of ?() being
-%   the name for the function call operator
-% + it is possible to easily search for all constructors in a project
-%   and immediately know that a function is a constructor by seeing the
-%   name "?{}"
-
-% A destructor is declared with the name ^?{}
-% + name mirrors a constructor's name, with an extra symbol to
-%   distinguish it
-% - the symbol '~' cannot be used due to parsing conflicts with the
-%   unary '~' (bitwise negation) operator - this conflict exists because
-%   we want to allow users to write ^x{}; to destruct x, rather than
-%   ^?{}(&x);
-
-% The first argument of a constructor must be a pointer. The constructed
-% type is the base type of the pointer. E.g. void ?{}(T *) is a default
-% constructor for a T.
-% + can name the argument whatever you like, so not constrained by
-%   language keyword "this" or "self", etc.
-% - have to explicitly qualify all object members to initialize them
-%   (e.g. this->x = 0, rather than just x = 0)
-
-% Destructors can take arguments other than just the destructed pointer
-% * open research problem: not sure how useful this is
-
-% Pointer constructors
-% + can construct separately compiled objects (opaque types) [6]
-% + orthogonal design, follows directly from the definition of the first
-%   argument of a constructor
-% - may require copy constructor or move constructor (or equivalent)
-%   for correct implementation, which may not be obvious to everyone
-% + required feature for the prelude to specify as much behavior as possible
-%   (similar to pointer assignment operators in this respect)
-
-% Designations can only be used for C-style initialization
-% * designation for constructors is equivalent to designation for any
-%   general function call. Since a function prototype can be redeclared
-%   many times, with arguments named differently each time (or not at
-%   all!), this is considered to be an undesirable feature. We could
-%   construct some set of rules to allow this behaviour, but it is
-%   probably more trouble than it's worth, and no matter what we choose,
-%   it is not likely to be obvious to most people.
-
-% Constructing an anonymous member [7]
-% + same as with calling any other function on an anonymous member
-%   (implicit conversion by the compiler)
-% - may be some cases where this is ambiguous => clarify with a cast
-%   (try to design APIs to avoid sharing function signatures between
-%   composed types to avoid this)
-
-% Default Constructors and Destructors are called implicitly
-% + cannot forget to construct or destruct an object
-% - requires special syntax to specify that an object is not to be
-%   constructed (@=)
-% * an object will not be implicitly constructed OR destructed if
-%   explicitly initialized like a C object (@= syntax)
-% * an object will be destructed if there are no constructors in scope
-%   (even though it is initialized like a C object) [8]
-
-% An object which changes from POD type to non POD type will not change
-% the semantics of a type containing it by composition
-% * That is, constructors will not be regenerated at the point where
-%   an object changes from POD type to non POD type, because this could
-%   cause a cascade of constructors being regenerated for many other
-%   types. Further, there is precedence for this behaviour in other
-%   facets of Cforall's design, such as how nested functions interact.
-% * This behaviour can be simplified in a language without declaration
-%   before use, because a type can be classified as POD or non POD
-%   (rather than potentially changing between the two at some point) at
-%   at the global scope (which is likely the most common case)
-% * [9]
-
-% Changes to polymorphic type classes
-% * dtype and ftype remain the same
-% * forall(otype T) is currently essentially the same as
-%   forall(dtype T | { @size(T); void ?=?(T *, T); }).
-%   The big addition is that you can declare an object of type T, rather
-%   than just a pointer to an object of type T since you know the size,
-%   and you can assign into a T.
-%   * this definition is changed to add default constructor and
-%     destructor declarations, to remain consistent with what type meant
-%     before the introduction of constructors and destructors.
-%     * that is, forall(type T) is now essentially the same as
-%       forall(dtype T | { @size(T); void ?=?(T *, T);
-%                          void ?{}(T *); void ^?{}(T *); })
-%     + this is required to make generic types work correctly in
-%       polymorphic functions
-%     ? since declaring a constructor invalidates the autogenerated
-%       routines, it is possible for a type to have constructors, but
-%       not default constructors. That is, it might be the case that
-%       you want to write a polymorphic function for a type which has
-%       a size, but non-default constructors? Some options:
-%       * declaring a constructor as a part of the assertions list for
-%         a type declaration invalidates the default, so
-%         forall(otype T | { void ?{}(T *, int); })
-%         really means
-%         forall(dtype T | { @size(T); void ?=?(T *, T);
-%                            void ?{}(T *, int); void ^?{}(T *); })
-%       * force users to fully declare the assertions list like the
-%         above in this case (this seems very undesirable)
-%       * add another type class with the current desugaring of type
-%         (just size and assignment)
-%       * provide some way of subtracting from an existing assertions
-%         list (this might be useful to have in general)
-
-% Implementation issues:
-% Changes to prelude/autogen or built in defaults?
-% * pointer ctors/dtors [prelude]
-%   * other pointer type routines are declared in the prelude, and this
-%     doesn't seem like it should be any different
-% * basic type ctors/dtors [prelude]
-%   * other basic type routines are declared in the prelude, and this
-%     doesn't seem like it should be any different
-% ? aggregate types [undecided, but leaning towards autogenerate]
-%   * prelude
-%     * routines specific to aggregate types cannot be predeclared in
-%       the prelude because we don't know the name of every
-%       aggregate type in the entire program
-%   * autogenerate
-%     + default assignment operator is already autogenerated for
-%       aggregate types
-%       * this seems to lead us in the direction of autogenerating,
-%         because we may have a struct which contains other objects
-%         that require construction [10]. If we choose not to
-%         autogenerate in this case, then objects which are part of
-%         other objects by composition will not be constructed unless
-%         a constructor for the outer type is explicitly defined
-%       * in this case, we would always autogenerate the appropriate
-%         constructor(s) for an aggregate type, but just like with
-%         basic types, pointer types, and enum types, the constructor
-%         call can be elided when when it is not necessary.
-%     + constructors will have to be explicitly autogenerated
-%       in the case where they are required for a polymorphic function,
-%       when no user defined constructor is in scope, which may make it
-%       easiest to always autogenerate all appropriate constructors
-%     - n+2 constructors would have to be generated for a POD type
-%       * one constructor for each number of valid arguments [0, n],
-%         plus the copy constructor
-%         * this is taking a simplified approach: in C, it is possible
-%           to omit the enclosing braces in a declaration, which would
-%           lead to a combinatorial explosion of generated constructors.
-%           In the interest of keeping things tractable, Cforall may be
-%           incompatible with C in this case. [11]
-%       * for non-POD types, only autogenerate the default and copy
-%         constructors
-%       * alternative: generate only the default constructor and
-%         special case initialization for any other constructor when
-%         only the autogenerated one exists
-%         - this is not very sensible, as by the previous point, these
-%           constructors may be needed for polymorphic functions
-%           anyway.
-%     - must somehow distinguish in resolver between autogenerated and
-%       user defined constructors (autogenerated should never be chosen
-%       when a user defined option exists [check first parameter], even
-%       if full signature differs) (this may also have applications
-%       to other autogenerated routines?)
-%     - this scheme does not naturally support designation (i.e. general
-%       functions calls do not support designation), thus these cases
-%       will have to be treated specially in either case
-%   * defaults
-%     * i.e. hardcode a new set of rules for some "appropriate" default
-%       behaviour for
-%     + when resolving an initialization expression, explicitly check to
-%       see if any constructors are in scope. If yes, attempt to resolve
-%       to a constructor, and produce an error message if a match is not
-%       found. If there are no constructors in scope, resolve to
-%       initializing each field individually (C-style)
-%     + does not attempt to autogenerate constructors for POD types,
-%       which can be seen as a space optimization for the program
-%       binary
-%     - as stated previously, a polymorphic routine may require these
-%       autogenerated constructors, so this doesn't seem like a big win,
-%       because this leads to more complicated logic and tracking of
-%       which constructors have already been generated
-%     - even though a constructor is not explicitly declared or used
-%       polymorphically, we might still need one for all uses of a
-%       struct (e.g. in the case of composition).
-%   * the biggest tradeoff in autogenerating vs. defaulting appears to
-%     be in where and how the special code to check if constructors are
-%     present is handled. It appears that there are more reasons to
-%     autogenerate than not.
-
-% --- examples
-% [1] As an example of using constructors polymorphically, consider a
-% slight modification on the foldl example I put on the mailing list a
-% few months ago:
-
-% context iterable(type collection, type element, type iterator) {
-%   void ?{}(iterator *, collection); // used to be makeIterator, but can
-%                             // idiomatically use constructor
-%   int hasNext(iterator);
-%   iterator ++?(iterator *);
-%   lvalue element *?(iterator);
-% };
-
-
-% forall(type collection, type element, type result, type iterator
-%   | iterable(collection, element, iterator))
-% result foldl(collection c, result acc,
-%     result (*reduce)(result, element)) {
-%   iterator it = { c };
-%   while (hasNext(it)) {
-%     acc = reduce(acc, *it);
-%     ++it;
-%   }
-%   return acc;
-% }
-
-% Now foldl makes use of the knowledge that the iterator type has a
-% single argument constructor which takes the collection to iterate
-% over. This pattern allows polymorphic code to look more natural
-% (constructors are generally preferred to named initializer/creation
-% routines, e.g. "makeIterator")
-
-% [2] An example of some potentially dangerous code that we don't want
-% to let easily slip through the cracks - if this is really what you
-% want, then use @= syntax for the second declaration to quiet the
-% compiler.
-
-% struct A { int x, y, z; }
-% ?{}(A *, int);
-% ?{}(A *, int, int, int);
-
-% A a1 = { 1 };         // uses ?{}(A *, int);
-% A a2 = { 2, 3 };      // C-style initialization -> no invariants!
-% A a3 = { 4, 5, 6 };   // uses ?{}(A *, int, int, int);
-
-% [3] Since @= syntax creates a C object (essentially a POD, as far as
-% the compiler is concerned), the object will not be destructed
-% implicitly when it leaves scope, nor will it be copy constructed when
-% it is returned. In this case, a memcpy should be equivalent to a move.
-
-% // Box.h
-% struct Box;
-% void ?{}(Box **, int};
-% void ^?{}(Box **);
-% Box * make_fortytwo();
-
-% // Box.cfa
-% Box * make_fortytwo() {
-%   Box *b @= {};
-%   (&b){ 42 }; // construct explicitly
-%   return b; // no destruction, essentially a move?
-% }
-
-% [4] Cforall's typesafe malloc can be composed with constructor
-% expressions. It is possible for a user to define their own functions
-% similar to malloc and achieve the same effects (e.g. Aaron's example
-% of an arena allocator)
-
-% // CFA malloc
-% forall(type T)
-% T * malloc() { return (T *)malloc(sizeof(T)); }
-
-% struct A { int x, y, z; };
-% void ?{}(A *, int);
-
-% int foo(){
-%   ...
-%   // desugars to:
-%   // A * a = ?{}(malloc(), 123);
-%   A * a = malloc() { 123 };
-%   ...
-% }
-
-% [5] Aaron's example of combining function calls with constructor
-% syntax to perform an operation similar to C++'s std::vector::emplace
-% (i.e. to construct a new element in place, without the need to
-% copy)
-
-% forall(type T)
-% struct vector {
-%   T * elem;
-%   int len;
-%   ...
-% };
-
-% ...
-% forall(type T)
-% T * vector_new(vector(T) * v) {
-%   // reallocate if needed
-%   return &v->elem[len++];
-% }
-
-% int main() {
-%   vector(int) * v = ...
-%   vector_new(v){ 42 };  // add element to the end of vector
-% }
-
-% [6] Pointer Constructors. It could be useful to use the existing
-% constructor syntax even more uniformly for ADTs. With this, ADTs can
-% be initialized in the same manor as any other object in a polymorphic
-% function.
-
-% // vector.h
-% forall(type T) struct vector;
-% forall(type T) void ?{}(vector(T) **);
-% // adds an element to the end
-% forall(type T) vector(T) * ?+?(vector(T) *, T);
-
-% // vector.cfa
-% // don't want to expose the implementation to the user and/or don't
-% // want to recompile the entire program if the struct definition
-% // changes
-
-% forall(type T) struct vector {
-%   T * elem;
-%   int len;
-%   int capacity;
-% };
-
-% forall(type T) void resize(vector(T) ** v) { ... }
-
-% forall(type T) void ?{}(vector(T) ** v) {
-%   vector(T) * vect = *v = malloc();
-%   vect->capacity = 10;
-%   vect->len = 0;
-%   vect->elem = malloc(vect->capacity);
-% }
-
-% forall(type T) vector(T) * ?+?(vector(T) *v, T elem) {
-%   if (v->len == v->capacity) resize(&v);
-%   v->elem[v->len++] = elem;
-% }
-
-% // main.cfa
-% #include "adt.h"
-% forall(type T | { T ?+?(T, int); }
-% T sumRange(int lower, int upper) {
-%   T x;    // default construct
-%   for (int i = lower; i <= upper; i++) {
-%     x = x + i;
-%   }
-%   return x;
-% }
-
-% int main() {
-%   vector(int) * numbers = sumRange(1, 10);
-%   // numbers is now a vector containing [1..10]
-
-%   int sum = sumRange(1, 10);
-%   // sum is now an int containing the value 55
-% }
-
-% [7] The current proposal is to use the plan 9 model of inheritance.
-% Under this model, all of the members of an unnamed struct instance
-% become members of the containing struct. In addition, an object
-% can be passed as an argument to a function expecting one of its
-% base structs.
-
-% struct Point {
-%   double x;
-%   double y;
-% };
-
-% struct ColoredPoint {
-%   Point;        // anonymous member (no identifier)
-%                 // => a ColoredPoint has an x and y of type double
-%   int color;
-% };
-
-% ColoredPoint cp = ...;
-% cp.x = 10.3;    // x from Point is accessed directly
-% cp.color = 0x33aaff; // color is accessed normally
-% foo(cp);        // cp can be used directly as a Point
-
-% void ?{}(Point *p, double x, double y) {
-%   p->x = x;
-%   p->y = y;
-% }
-
-% void ?{}(ColoredPoint *cp, double x, double y, int color) {
-%   (&cp){ x, y };  // unambiguous, no ?{}(ColoredPoint*,double,double)
-%   cp->color = color;
-% }
-
-% struct Size {
-%   double width;
-%   double height;
-% };
-
-% void ?{}(Size *s, double w, double h) {
-%   p->width = w;
-%   p->height = h;
-% }
-
-% struct Foo {
-%   Point;
-%   Size;
-% }
-
-% ?{}(Foo &f, double x, double y, double w, double h) {
-%   // (&F,x,y) is ambiguous => is it ?{}(Point*,double,double) or
-%   // ?{}(Size*,double,double)? Solve with a cast:
-%   ((Point*)&F){ x, y };
-%   ((Size*)&F){ w, h };
-% }
-
-% [8] Destructors will be called on objects that were not constructed.
-
-% struct A { ... };
-% ^?{}(A *);
-% {
-%   A x;
-%   A y @= {};
-% } // x is destructed, even though it wasn't constructed
-%   // y is not destructed, because it is explicitly a C object
-
-
-% [9] A type's constructor is generated at declaration time using
-% current information about an object's members. This is analogous to
-% the treatment of other operators. For example, an object's assignment
-% operator will not change to call the override of a member's assignment
-% operator unless the object's assignment is also explicitly overridden.
-% This problem can potentially be treated differently in Do, since each
-% compilation unit is passed over at least twice (once to gather
-% symbol information, once to generate code - this is necessary to
-% achieve the "No declarations" goal)
-
-% struct A { ... };
-% struct B { A x; };
-% ...
-% void ?{}(A *);  // from this point on, A objects will be constructed
-% B b1;           // b1 and b1.x are both NOT constructed, because B
-%                 // objects are not constructed
-% void ?{}(B *);  // from this point on, B objects will be constructed
-% B b2;           // b2 and b2.x are both constructed
-
-% struct C { A x; };
-% // implicit definition of ?{}(C*), because C is not a POD type since
-% // it contains a non-POD type by composition
-% C c;            // c and c.x are both constructed
-
-% [10] Requiring construction by composition
-
-% struct A {
-%   ...
-% };
-
-% // declared ctor disables default c-style initialization of
-% // A objects; A is no longer a POD type
-% void ?{}(A *);
-
-% struct B {
-%   A x;
-% };
-
-% // B objects can not be C-style initialized, because A objects
-% // must be constructed => B objects are transitively not POD types
-% B b; // b.x must be constructed, but B is not constructible
-%      // => must autogenerate ?{}(B *) after struct B definition,
-%      // which calls ?{}(&b.x)
-
-% [11] Explosion in the number of generated constructors, due to strange
-% C semantics.
-
-% struct A { int x, y; };
-% struct B { A u, v, w; };
-
-% A a = { 0, 0 };
-
-% // in C, you are allowed to do this
-% B b1 = { 1, 2, 3, 4, 5, 6 };
-% B b2 = { 1, 2, 3 };
-% B b3 = { a, a, a };
-% B b4 = { a, 5, 4, a };
-% B b5 = { 1, 2, a, 3 };
-
-% // we want to disallow b1, b2, b4, and b5 in Cforall.
-% // In particular, we will autogenerate these constructors:
-% void ?{}(A *);             // default/0 parameters
-% void ?{}(A *, int);        // 1 parameter
-% void ?{}(A *, int, int);   // 2 parameters
-% void ?{}(A *, const A *);  // copy constructor
-
-% void ?{}(B *);             // default/0 parameters
-% void ?{}(B *, A);          // 1 parameter
-% void ?{}(B *, A, A);       // 2 parameters
-% void ?{}(B *, A, A, A);    // 3 parameters
-% void ?{}(B *, const B *);  // copy constructor
-
-% // we will not generate constructors for every valid combination
-% // of members in C. For example, we will not generate
-% void ?{}(B *, int, int, int, int, int, int);   // b1 would need this
-% void ?{}(B *, int, int, int);                  // b2 would need this
-% void ?{}(B *, A, int, int, A);                 // b4 would need this
-% void ?{}(B *, int, int, A, int);               // b5 would need this
-% // and so on
 
 Since \CFA is a true systems language, it does not provide a garbage collector.
@@ -557,5 +12,5 @@
 
 This chapter details the design of constructors and destructors in \CFA, along with their current implementation in the translator.
-Generated code samples have been edited to provide comments for clarity and to save on space.
+Generated code samples have been edited for clarity and brevity.
 
 \section{Design Criteria}
@@ -579,5 +34,6 @@
 Use of uninitialized variables yields undefined behaviour, which is a common source of errors in C programs.
 
-Declaration initialization is insufficient, because it permits uninitialized variables to exist and because it does not allow for the insertion of arbitrary code before a variable is live.
+Initialization of a declaration is strictly optional, permitting uninitialized variables to exist.
+Furthermore, declaration initialization is limited to expressions, so there is no way to insert arbitrary code before a variable is live, without delaying the declaration.
 Many C compilers give good warnings for uninitialized variables most of the time, but they cannot in all cases.
 \begin{cfacode}
@@ -592,5 +48,5 @@
 Other languages are able to give errors in the case of uninitialized variable use, but due to backwards compatibility concerns, this is not the case in \CFA.
 
-In C, constructors and destructors are often mimicked by providing routines that create and teardown objects, where the teardown function is typically only necessary if the type modifies the execution environment.
+In C, constructors and destructors are often mimicked by providing routines that create and tear down objects, where the tear down function is typically only necessary if the type modifies the execution environment.
 \begin{cfacode}
 struct array_int {
@@ -618,5 +74,5 @@
 Furthermore, even with this idiom it is easy to make mistakes, such as forgetting to destroy an object or destroying it multiple times.
 
-A constructor provides a way of ensuring that the necessary aspects of object initialization is performed, from setting up invariants to providing compile-time checks for appropriate initialization parameters.
+A constructor provides a way of ensuring that the necessary aspects of object initialization is performed, from setting up invariants to providing compile- and run-time checks for appropriate initialization parameters.
 This goal is achieved through a guarantee that a constructor is called implicitly after every object is allocated from a type with associated constructors, as part of an object's definition.
 Since a constructor is called on every object of a managed type, it is impossible to forget to initialize such objects, as long as all constructors perform some sensible form of initialization.
@@ -658,5 +114,5 @@
 In other words, a default constructor is a constructor that takes a single argument: the @this@ parameter.
 
-In \CFA, a destructor is a function much like a constructor, except that its name is \lstinline!^?{}!.
+In \CFA, a destructor is a function much like a constructor, except that its name is \lstinline!^?{}! and it take only one argument.
 A destructor for the @Array@ type can be defined as such.
 \begin{cfacode}
@@ -701,5 +157,5 @@
 
 It is possible to define a constructor that takes any combination of parameters to provide additional initialization options.
-For example, a reasonable extension to the array type would be a constructor that allocates the array to a given initial capacity and initializes the array to a given @fill@ value.
+For example, a reasonable extension to the array type would be a constructor that allocates the array to a given initial capacity and initializes the elements of the array to a given @fill@ value.
 \begin{cfacode}
 void ?{}(Array * arr, int capacity, int fill) {
@@ -812,6 +268,39 @@
 One of these three syntactic forms should appeal to either C or \CC programmers using \CFA.
 
+\subsection{Constructor Expressions}
+In \CFA, it is possible to use a constructor as an expression.
+Like other operators, the function name @?{}@ matches its operator syntax.
+For example, @(&x){}@ calls the default constructor on the variable @x@, and produces @&x@ as a result.
+A key example for this capability is the use of constructor expressions to initialize the result of a call to standard C routine @malloc@.
+\begin{cfacode}
+struct X { ... };
+void ?{}(X *, double);
+X * x = malloc(sizeof(X)){ 1.5 };
+\end{cfacode}
+In this example, @malloc@ dynamically allocates storage and initializes it using a constructor, all before assigning it into the variable @x@.
+If this extension is not present, constructing dynamically allocated objects is much more cumbersome, requiring separate initialization of the pointer and initialization of the pointed-to memory.
+\begin{cfacode}
+X * x = malloc(sizeof(X));
+x{ 1.5 };
+\end{cfacode}
+Not only is this verbose, but it is also more error prone, since this form allows maintenance code to easily sneak in between the initialization of @x@ and the initialization of the memory that @x@ points to.
+This feature is implemented via a transformation producing the value of the first argument of the constructor, since constructors do not themselves have a return value.
+Since this transformation results in two instances of the subexpression, care is taken to allocate a temporary variable to hold the result of the subexpression in the case where the subexpression may contain side effects.
+The previous example generates the following code.
+\begin{cfacode}
+struct X *_tmp_ctor;
+struct X *x = ?{}(  // construct result of malloc
+  _tmp_ctor=malloc(sizeof(struct X)), // store result of malloc
+  1.5
+), _tmp_ctor; // produce constructed result of malloc
+\end{cfacode}
+It should be noted that this technique is not exclusive to @malloc@, and allows a user to write a custom allocator that can be idiomatically used in much the same way as a constructed @malloc@ call.
+
+It is also possible to use operator syntax with destructors.
+Unlike constructors, operator syntax with destructors is a statement and thus does not produce a value, since the destructed object is invalidated by the use of a destructor.
+For example, \lstinline!^(&x){}! calls the destructor on the variable @x@.
+
 \subsection{Function Generation}
-In \CFA, every type is defined to have the core set of four functions described previously.
+In \CFA, every type is defined to have the core set of four special functions described previously.
 Having these functions exist for every type greatly simplifies the semantics of the language, since most operations can simply be defined directly in terms of function calls.
 In addition to simplifying the definition of the language, it also simplifies the analysis that the translator must perform.
@@ -826,5 +315,5 @@
 
 The generated functions for enumerations are the simplest.
-Since enumerations in C are essentially just another integral type, the generated functions behave in the same way that the builtin functions for the basic types work.
+Since enumerations in C are essentially just another integral type, the generated functions behave in the same way that the built-in functions for the basic types work.
 For example, given the enumeration
 \begin{cfacode}
@@ -839,5 +328,5 @@
 }
 void ?{}(enum Colour *_dst, enum Colour _src){
-  (*_dst)=_src;  // bitwise copy
+  *_dst=_src;  // bitwise copy
 }
 void ^?{}(enum Colour *_dst){
@@ -845,5 +334,5 @@
 }
 enum Colour ?=?(enum Colour *_dst, enum Colour _src){
-  return (*_dst)=_src; // bitwise copy
+  return *_dst=_src; // bitwise copy
 }
 \end{cfacode}
@@ -903,5 +392,5 @@
 For copy constructor and assignment operations, a bitwise @memcpy@ is applied.
 In standard C, a union can also be initialized using a value of the same type as its first member, and so a corresponding field constructor is generated to perform a bitwise @memcpy@ of the object.
-An alterantive to this design is to always construct and destruct the first member of a union, to match with the C semantics of initializing the first member of the union.
+An alternative to this design is to always construct and destruct the first member of a union, to match with the C semantics of initializing the first member of the union.
 This approach ultimately feels subtle and unsafe.
 Another option is to, like \CC, disallow unions from containing members that are themselves managed types.
@@ -1000,5 +489,5 @@
 Instead, @a2->x@ is initialized to @0@ as if it were a C object, because of the explicit initializer.
 
-In addition to freedom, \ateq provides a simple path to migrating legacy C code to Cforall, in that objects can be moved from C-style initialization to \CFA gradually and individually.
+In addition to freedom, \ateq provides a simple path to migrating legacy C code to \CFA, in that objects can be moved from C-style initialization to \CFA gradually and individually.
 It is worth noting that the use of unmanaged objects can be tricky to get right, since there is no guarantee that the proper invariants are established on an unmanaged object.
 It is recommended that most objects be managed by sensible constructors and destructors, except where absolutely necessary.
@@ -1026,5 +515,5 @@
 When defining a constructor or destructor for a struct @S@, any members that are not explicitly constructed or destructed are implicitly constructed or destructed automatically.
 If an explicit call is present, then that call is taken in preference to any implicitly generated call.
-A consequence of this rule is that it is possible, unlike \CC, to precisely control the order of construction and destruction of subobjects on a per-constructor basis, whereas in \CC subobject initialization and destruction is always performed based on the declaration order.
+A consequence of this rule is that it is possible, unlike \CC, to precisely control the order of construction and destruction of sub-objects on a per-constructor basis, whereas in \CC sub-object initialization and destruction is always performed based on the declaration order.
 \begin{cfacode}
 struct A {
@@ -1045,7 +534,7 @@
 }
 \end{cfacode}
-Finally, it is illegal for a subobject to be explicitly constructed for the first time after it is used for the first time.
+Finally, it is illegal for a sub-object to be explicitly constructed for the first time after it is used for the first time.
 If the translator cannot be reasonably sure that an object is constructed prior to its first use, but is constructed afterward, an error is emitted.
-More specifically, the translator searches the body of a constructor to ensure that every subobject is initialized.
+More specifically, the translator searches the body of a constructor to ensure that every sub-object is initialized.
 \begin{cfacode}
 void ?{}(A * a, double x) {
@@ -1054,5 +543,5 @@
 }
 \end{cfacode}
-However, if the translator sees a subobject used within the body of a constructor, but does not see a constructor call that uses the subobject as the target of a constructor, then the translator assumes the object is to be implicitly constructed (copy constructed in a copy constructor and default constructed in any other constructor).
+However, if the translator sees a sub-object used within the body of a constructor, but does not see a constructor call that uses the sub-object as the target of a constructor, then the translator assumes the object is to be implicitly constructed (copy constructed in a copy constructor and default constructed in any other constructor).
 \begin{cfacode}
 void ?{}(A * a) {
@@ -1070,5 +559,5 @@
 } // z, y, w implicitly destructed, in this order
 \end{cfacode}
-If at any point, the @this@ parameter is passed directly as the target of another constructor, then it is assumed that constructor handles the initialization of all of the object's members and no implicit constructor calls are added. % TODO: this is basically always wrong. if anything, I should check that such a constructor does not initialize any members, otherwise it'll always initialize the member twice (once locally, once by the called constructor). This might be okay in some situations, but it deserves a warning at the very least.
+If at any point, the @this@ parameter is passed directly as the target of another constructor, then it is assumed that constructor handles the initialization of all of the object's members and no implicit constructor calls are added.
 To override this rule, \ateq can be used to force the translator to trust the programmer's discretion.
 This form of \ateq is not yet implemented.
@@ -1102,5 +591,5 @@
 };
 \end{cfacode}
-In C, nesting initializers means that the programmer intends to initialize subobjects with the nested initializers.
+In C, nesting initializers means that the programmer intends to initialize sub-objects with the nested initializers.
 The reason for this omission is to both simplify the mental model for using constructors, and to make initialization simpler for the expression resolver.
 If this were allowed, it would be necessary for the expression resolver to decide whether each argument to the constructor call could initialize to some argument in one of the available constructors, making the problem highly recursive and potentially much more expensive.
@@ -1125,5 +614,4 @@
 }
 \end{cfacode}
-% TODO: in CFA if the array dimension is empty, no object constructors are added -- need to fix this.
 The body of @A@ has been omitted, since only the constructor interfaces are important.
 
@@ -1153,5 +641,5 @@
     if (i == 2) return; // destruct x, y
   } // destruct y
-}
+} // destruct x
 \end{cfacode}
 
@@ -1169,10 +657,10 @@
 Since a destructor call is automatically inserted at the end of the block, nothing special needs to happen to destruct @x@ in the case where control reaches the end of the loop.
 In the case where @i@ is @2@, the continue statement runs the loop update expression and attempts to begin the next iteration of the loop.
-Since continue is a C statement, which does not understand destructors, a destructor call is added just before the continue statement to ensure that @x@ is destructed.
+Since continue is a C statement, which does not understand destructors, it is transformed into a @goto@ statement that branches to the end of the loop, just before the block's destructors, to ensure that @x@ is destructed.
 When @i@ is @3@, the break statement moves control to just past the end of the loop.
-Like the previous case, a destructor call for @x@ is inserted just before the break statement.
-
-\CFA also supports labelled break and continue statements, which allow more precise manipulation of control flow.
-Labelled break and continue allow the programmer to specify which control structure to target by using a label attached to a control structure.
+Unlike the previous case, the destructor for @x@ cannot be reused, so a destructor call for @x@ is inserted just before the break statement.
+
+\CFA also supports labeled break and continue statements, which allow more precise manipulation of control flow.
+Labeled break and continue allow the programmer to specify which control structure to target by using a label attached to a control structure.
 \begin{cfacode}[emph={L1,L2}, emphstyle=\color{red}]
 L1: for (int i = 0; i < 10; i++) {
@@ -1189,7 +677,6 @@
 \end{cfacode}
 The statement @continue L1@ begins the next iteration of the outer for-loop.
-Since the semantics of continue require the loop update expression to execute, control branches to the \emph{end} of the outer for loop, meaning that the block destructor for @x@ can be reused, and it is only necessary to generate the destructor for @y@.
-% TODO: "why not do this all the time? fix or justify"
-Break, on the other hand, requires jumping out of the loop, so the destructors for both @x@ and @y@ are generated and inserted before the @break L1@ statement.
+Since the semantics of continue require the loop update expression to execute, control branches to the end of the outer for loop, meaning that the block destructor for @x@ can be reused, and it is only necessary to generate the destructor for @y@.
+Break, on the other hand, requires jumping out of both loops, so the destructors for both @x@ and @y@ are generated and inserted before the @break L1@ statement.
 
 Finally, an example which demonstrates goto.
@@ -1238,5 +725,5 @@
 }
 \end{cfacode}
-Labelled break and continue are implemented in \CFA in terms of goto statements, so the more constrained forms are precisely goverened by these rules.
+All break and continue statements are implemented in \CFA in terms of goto statements, so the more constrained forms are precisely governed by these rules.
 
 The next example demonstrates the error case.
@@ -1255,7 +742,8 @@
 
 \subsection{Implicit Copy Construction}
+\label{s:implicit_copy_construction}
 When a function is called, the arguments supplied to the call are subject to implicit copy construction (and destruction of the generated temporary), and the return value is subject to destruction.
 When a value is returned from a function, the copy constructor is called to pass the value back to the call site.
-Exempt from these rules are intrinsic and builtin functions.
+Exempt from these rules are intrinsic and built-in functions.
 It should be noted that unmanaged objects are subject to copy constructor calls when passed as arguments to a function or when returned from a function, since they are not the \emph{target} of the copy constructor call.
 That is, since the parameter is not marked as an unmanaged object using \ateq, it will be copy constructed if it is returned by value or passed as an argument to another function, so to guarantee consistent behaviour, unmanaged objects must be copy constructed when passed as arguments.
@@ -1318,9 +806,9 @@
 It should be noted that reference types will allow specifying that a value does not need to be copied, however reference types do not provide a means of preventing implicit copy construction from uses of the reference, so the problem is still present when passing or returning the reference by value.
 
-A known issue with this implementation is that the return value of a function is not guaranteed to have the same address for its entire lifetime.
-Specifically, since @_retval_f@ is allocated and constructed in @f@ then returned by value, the internal data is bitwise copied into the caller's stack frame.
+A known issue with this implementation is that the argument and return value temporaries are not guaranteed to have the same address for their entire lifetimes.
+In the previous example, since @_retval_f@ is allocated and constructed in @f@, then returned by value, the internal data is bitwise copied into the caller's stack frame.
 This approach works out most of the time, because typically destructors need to only access the fields of the object and recursively destroy.
 It is currently the case that constructors and destructors that use the @this@ pointer as a unique identifier to store data externally do not work correctly for return value objects.
-Thus, it is not safe to rely on an object's @this@ pointer to remain constant throughout execution of the program.
+Thus, it is currently not safe to rely on an object's @this@ pointer to remain constant throughout execution of the program.
 \begin{cfacode}
 A * external_data[32];
@@ -1350,5 +838,5 @@
 \end{cfacode}
 In the above example, a global array of pointers is used to keep track of all of the allocated @A@ objects.
-Due to copying on return, the current object being destructed does not exist in the array if an @A@ object is ever returned by value from a function.
+Due to copying on return, the current object being destructed does not exist in the array if an @A@ object is ever returned by value from a function, such as in @makeA@.
 
 This problem could be solved in the translator by changing the function signatures so that the return value is moved into the parameter list.
@@ -1399,5 +887,5 @@
 \end{cfacode}
 An alternative is to instead make the attribute \emph{identifiable}, which states that objects of this type use the @this@ parameter as an identity.
-This strikes more closely to the visibile problem, in that only types marked as identifiable would need to have the return value moved into the parameter list, and every other type could remain the same.
+This strikes more closely to the visible problem, in that only types marked as identifiable would need to have the return value moved into the parameter list, and every other type could remain the same.
 Furthermore, no restrictions would need to be placed on whether objects can be constructed.
 \begin{cfacode}
@@ -1409,7 +897,7 @@
 \end{cfacode}
 
-Ultimately, this is the type of transformation that a real compiler would make when generating assembly code.
-Since a compiler has full control over its calling conventions, it can seamlessly allow passing the return parameter without outwardly changing the signature of a routine.
-As such, it has been decided that this issue is not currently a priority.
+Ultimately, both of these are patchwork solutions.
+Since a real compiler has full control over its calling conventions, it can seamlessly allow passing the return parameter without outwardly changing the signature of a routine.
+As such, it has been decided that this issue is not currently a priority and will be fixed when a full \CFA compiler is implemented.
 
 \section{Implementation}
@@ -1534,8 +1022,8 @@
 It is, however, guaranteed that any global objects in the standard library are initialized prior to the initialization of any object in the user program.
 
-This feature is implemented in the \CFA translator by grouping every global constructor call into a function with the GCC attribute \emph{constructor}, which performs most of the heavy lifting. % TODO: CITE: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
+This feature is implemented in the \CFA translator by grouping every global constructor call into a function with the GCC attribute \emph{constructor}, which performs most of the heavy lifting \cite[6.31.1]{GCCExtensions}.
 A similar function is generated with the \emph{destructor} attribute, which handles all global destructor calls.
 At the time of writing, initialization routines in the library are specified with priority \emph{101}, which is the highest priority level that GCC allows, whereas initialization routines in the user's code are implicitly given the default priority level, which ensures they have a lower priority than any code with a specified priority level.
-This mechanism allows arbitrarily complicated initialization to occur before any user code runs, making it possible for library designers to initialize their modules without requiring the user to call specific startup or teardown routines.
+This mechanism allows arbitrarily complicated initialization to occur before any user code runs, making it possible for library designers to initialize their modules without requiring the user to call specific startup or tear-down routines.
 
 For example, given the following global declarations.
@@ -1565,5 +1053,5 @@
 %   https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html#C_002b_002b-Attributes
 % suggestion: implement this in CFA by picking objects with a specified priority and pulling them into their own init functions (could even group them by priority level -> map<int, list<ObjectDecl*>>) and pull init_priority forward into constructor and destructor attributes with the same priority level
-GCC provides an attribute @init_priority@, which specifies allows specifying the relative priority for initialization of global objects on a per-object basis in \CC.
+GCC provides an attribute @init_priority@, which allows specifying the relative priority for initialization of global objects on a per-object basis in \CC.
 A similar attribute can be implemented in \CFA by pulling marked objects into global constructor/destructor-attribute functions with the specified priority.
 For example,
@@ -1587,5 +1075,5 @@
 \subsection{Static Local Variables}
 In standard C, it is possible to mark variables that are local to a function with the @static@ storage class.
-Unlike normal local variables, a @static@ local variable is defined to live for the entire duration of the program, so that each call to the function has access to the same variable with the same address and value as it had in the previous call to the function. % TODO: mention dynamic loading caveat??
+Unlike normal local variables, a @static@ local variable is defined to live for the entire duration of the program, so that each call to the function has access to the same variable with the same address and value as it had in the previous call to the function.
 Much like global variables, in C @static@ variables can only be initialized to a \emph{compile-time constant value} so that a compiler is able to create storage for the variable and initialize it at compile-time.
 
@@ -1599,5 +1087,5 @@
 Construction of @static@ local objects is implemented via an accompanying @static bool@ variable, which records whether the variable has already been constructed.
 A conditional branch checks the value of the companion @bool@, and if the variable has not yet been constructed then the object is constructed.
-The object's destructor is scheduled to be run when the program terminates using @atexit@, and the companion @bool@'s value is set so that subsequent invocations of the function do not reconstruct the object.
+The object's destructor is scheduled to be run when the program terminates using @atexit@ \footnote{When using the dynamic linker, it is possible to dynamically load and unload a shared library. Since glibc 2.2.3 \cite{atexit}, functions registered with @atexit@ within the shared library are called when unloading the shared library. As such, static local objects can be destructed using this mechanism even in shared libraries on Linux systems.}, and the companion @bool@'s value is set so that subsequent invocations of the function do not reconstruct the object.
 Since the parameter to @atexit@ is a parameter-less function, some additional tweaking is required.
 First, the @static@ variable must be hoisted up to global scope and uniquely renamed to prevent name clashes with other global objects.
@@ -1605,5 +1093,4 @@
 Finally, the newly generated function is registered with @atexit@, instead of registering the destructor directly.
 Since @atexit@ calls functions in the reverse order in which they are registered, @static@ local variables are guaranteed to be destructed in the reverse order that they are constructed, which may differ between multiple executions of the same program.
-
 Extending the previous example
 \begin{cfacode}
@@ -1656,33 +1143,26 @@
 \end{cfacode}
 
-% TODO: move this section forward?? maybe just after constructor syntax? would need to remove _tmp_cp_ret0, since copy constructors are not discussed yet, but this might not be a big issue.
-\subsection{Constructor Expressions}
-In \CFA, it is possible to use a constructor as an expression.
-Like other operators, the function name @?{}@ matches its operator syntax.
-For example, @(&x){}@ calls the default constructor on the variable @x@, and produces @&x@ as a result.
-A key example for this capability is the use of constructor expressions to initialize the result of a call to standard C routine @malloc@.
-\begin{cfacode}
-struct X { ... };
-void ?{}(X *, double);
-X * x = malloc(sizeof(X)){ 1.5 };
-\end{cfacode}
-In this example, @malloc@ dynamically allocates storage and initializes it using a constructor, all before assigning it into the variable @x@.
-If this extension is not present, constructing dynamically allocated objects is much more cumbersome, requiring separate initialization of the pointer and initialization of the pointed-to memory.
-\begin{cfacode}
-X * x = malloc(sizeof(X));
-x{ 1.5 };
-\end{cfacode}
-Not only is this verbose, but it is also more error prone, since this form allows maintenance code to easily sneak in between the initialization of @x@ and the initialization of the memory that @x@ points to.
-This feature is implemented via a transformation produceing the value of the first argument of the constructor, since constructors do not themslves have a return value.
-Since this transformation results in two instances of the subexpression, care is taken to allocate a temporary variable to hold the result of the subexpression in the case where the subexpression may contain side effects.
-The previous example generates the following code.
-\begin{cfacode}
-struct X *_tmp_ctor;
-struct X *x = ?{}((_tmp_ctor=((_tmp_cp_ret0=
-  malloc(sizeof(struct X))), _tmp_cp_ret0))), 1.5), _tmp_ctor);
-\end{cfacode}
-It should be noted that this technique is not exclusive to @malloc@, and allows a user to write a custom allocator that can be idiomatically used in much the same way as a constructed @malloc@ call.
-
-It is also possible to use operator syntax with destructors.
-Unlike constructors, operator syntax with destructors is a statement and thus does not produce a value, since the destructed object is invalidated by the use of a destructor.
-For example, \lstinline!^(&x){}! calls the destructor on the variable @x@.
+\subsection{Polymorphism}
+As mentioned in section \ref{sub:polymorphism}, \CFA currently has 3 type-classes that are used to designate polymorphic data types: @otype@, @dtype@, and @ftype@.
+In previous versions of \CFA, @otype@ was syntactic sugar for @dtype@ with known size/alignment information and an assignment function.
+That is,
+\begin{cfacode}
+forall(otype T)
+void f(T);
+\end{cfacode}
+was equivalent to
+\begin{cfacode}
+forall(dtype T | sized(T) | { T ?=?(T *, T); })
+void f(T);
+\end{cfacode}
+This allows easily specifying constraints that are common to all complete object types very simply.
+
+Now that \CFA has constructors and destructors, more of a complete object's behaviour can be specified by than was previously possible.
+As such, @otype@ has been augmented to include assertions for a default constructor, copy constructor, and destructor.
+That is, the previous example is now equivalent to
+\begin{cfacode}
+forall(dtype T | sized(T) | { T ?=?(T *, T); void ?{}(T *); void ?{}(T *, T); void ^?{}(T *); })
+void f(T);
+\end{cfacode}
+This allows @f@'s body to create and destroy objects of type @T@, and pass objects of type @T@ as arguments to other functions, following the normal \CFA rules.
+A point of note here is that objects can be missing default constructors (and eventually other functions through deleted functions), so it is important for \CFA programmers to think carefully about the operations needed by their function, as to not over-constrain the acceptable parameter types.
Index: doc/rob_thesis/examples/conclusions/dtor.c
===================================================================
--- doc/rob_thesis/examples/conclusions/dtor.c	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
+++ doc/rob_thesis/examples/conclusions/dtor.c	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -0,0 +1,11 @@
+forall(otype T)
+struct Box {
+  T x;
+};
+forall(otype T) void ^?{}(Box(T) * x);
+
+forall(otype T)
+void f(T x) {
+  T y = x;
+  Box(T) z = { x };
+}
Index: doc/rob_thesis/examples/conclusions/except.c
===================================================================
--- doc/rob_thesis/examples/conclusions/except.c	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
+++ doc/rob_thesis/examples/conclusions/except.c	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -0,0 +1,20 @@
+#include <stdio.h>
+typedef struct S {
+  int x;
+} S;
+
+void _dtor_S(S * s);
+//  {
+//   printf("called destructor!\n");
+// }
+
+void _ctor_S(struct S *s);
+//  {
+//   s->x = 123;
+// }
+
+int main() {
+  struct S _tmp3;
+  __attribute__((cleanup(_dtor_S))) struct S _tmp2 = (_ctor_S(&_tmp2), _tmp2);
+  printf("%d\n", _tmp2.x);
+}
Index: doc/rob_thesis/examples/conclusions/except.cc
===================================================================
--- doc/rob_thesis/examples/conclusions/except.cc	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
+++ doc/rob_thesis/examples/conclusions/except.cc	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -0,0 +1,31 @@
+#include <iostream>
+using namespace std;
+
+struct S {
+  int x;
+};
+
+void _dtor_S(S * s) {
+  cout << "called destructor!" << endl;
+}
+
+S f() {
+  throw 3;
+  return (S) { 0 };
+}
+
+void _ctor_S(struct S *s, struct S) {
+  s->x = 123;
+}
+
+int main() {
+  try {
+//    __attribute__((cleanup(_dtor_S))) S s = f();
+  struct S _tmp1;
+  struct S _tmp2 = (_ctor_S(&_tmp2, _tmp1), _tmp2);
+  cout << _tmp2.x << endl;
+
+  } catch(...) {
+
+  }
+}
Index: doc/rob_thesis/intro.tex
===================================================================
--- doc/rob_thesis/intro.tex	(revision 74933396698c5746d8db9582869740d0dbc1a8f4)
+++ doc/rob_thesis/intro.tex	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -5,5 +5,5 @@
 \section{\CFA Background}
 \label{s:background}
-\CFA is a modern non-object-oriented extension to the C programming language.
+\CFA \footnote{Pronounced ``C-for-all'', and written \CFA or Cforall.} is a modern non-object-oriented extension to the C programming language.
 As it is an extension of C, there is already a wealth of existing C code and principles that govern the design of the language.
 Among the goals set out in the original design of \CFA, four points stand out \cite{Bilson03}.
@@ -29,5 +29,5 @@
 A a1 = { 1, .y:7, 6 };
 A a2[4] = { [2]:a0, [0]:a1, { .z:3 } };
-// equvialent to
+// equivalent to
 // A a0 = { 0, 8, 0, 1 };
 // A a1 = { 1, 0, 7, 6 };
@@ -36,7 +36,7 @@
 Designations allow specifying the field to initialize by name, rather than by position.
 Any field not explicitly initialized is initialized as if it had static storage duration \cite[p.~141]{C11}.
-A designator specifies the current object for initialization, and as such any undesignated subobjects pick up where the last initialization left off.
-For example, in the initialization of @a1@, the initializer of @y@ is @7@, and the unnamed initializer @6@ initializes the next subobject, @z@.
-Later initializers override earlier initializers, so a subobject for which there is more than one initializer is only initailized by its last initializer.
+A designator specifies the current object for initialization, and as such any undesignated sub-objects pick up where the last initialization left off.
+For example, in the initialization of @a1@, the initializer of @y@ is @7@, and the unnamed initializer @6@ initializes the next sub-object, @z@.
+Later initializers override earlier initializers, so a sub-object for which there is more than one initializer is only initialized by its last initializer.
 These semantics can be seen in the initialization of @a0@, where @x@ is designated twice, and thus initialized to @8@.
 Note that in \CFA, designations use a colon separator, rather than an equals sign as in C, because this syntax is one of the few places that conflicts with the new language features.
@@ -116,5 +116,5 @@
 Both solutions are syntactically unnatural.
 
-In \CFA, it is possible to directly declare a function returning mutliple values.
+In \CFA, it is possible to directly declare a function returning multiple values.
 This extension provides important semantic information to the caller, since return values are only for output.
 \begin{cfacode}
@@ -308,5 +308,5 @@
 S * s = malloc();       // malloc(sizeof(S))
 \end{cfacode}
-The built-in trait @sized@ ensures that size and alignment information for @T@ is available to @malloc@ through @sizeof@ and @_Alignof@ expressions respectively.
+The built-in trait @sized@ ensures that size and alignment information for @T@ is available in the body of @malloc@ through @sizeof@ and @_Alignof@ expressions respectively.
 In calls to @malloc@, the type @T@ is bound based on call-site information, allowing \CFA code to allocate memory without the potential for errors introduced by manually specifying the size of the allocated block.
 
@@ -371,5 +371,5 @@
 Note, these invariants are internal to the type's correct behaviour.
 
-Types also have external invarients with state of the execution environment, including the heap, the open file-table, the state of global variables, etc.
+Types also have external invariants with the state of the execution environment, including the heap, the open-file table, the state of global variables, etc.
 Since resources are finite and shared (concurrency), it is important to ensure that objects clean up properly when they are finished, restoring the execution environment to a stable state so that new objects can reuse resources.
 
@@ -382,11 +382,11 @@
 The program stack grows and shrinks automatically with each function call, as needed for local variables.
 However, whenever a program needs a variable to outlive the block it is created in, the storage must be allocated dynamically with @malloc@ and later released with @free@.
-This pattern is extended to more complex objects, such as files and sockets, which also outlive the block where they are created, but at their core is resource management.
+This pattern is extended to more complex objects, such as files and sockets, which can also outlive the block where they are created, and thus require their own resource management.
 Once allocated storage escapes\footnote{In garbage collected languages, such as Java, escape analysis \cite{Choi:1999:EAJ:320385.320386} is used to determine when dynamically allocated objects are strictly contained within a function, which allows the optimizer to allocate them on the stack.} a block, the responsibility for deallocating the storage is not specified in a function's type, that is, that the return value is owned by the caller.
 This implicit convention is provided only through documentation about the expectations of functions.
 
 In other languages, a hybrid situation exists where resources escape the allocation block, but ownership is precisely controlled by the language.
-This pattern requires a strict interface and protocol for a data structure, where the protocol consists of a pre-initialization and a post-termination call, and all intervening access is done via interface routines.
-This kind of encapsulation is popular in object-oriented programming languages, and like the stack, it contains a significant portion of resource management cases.
+This pattern requires a strict interface and protocol for a data structure, consisting of a pre-initialization and a post-termination call, and all intervening access is done via interface routines.
+This kind of encapsulation is popular in object-oriented programming languages, and like the stack, it takes care of a significant portion of resource management cases.
 
 For example, \CC directly supports this pattern through class types and an idiom known as RAII \footnote{Resource Acquisition is Initialization} by means of constructors and destructors.
@@ -397,7 +397,7 @@
 RAII ensures that if all resources are acquired in a constructor and released in a destructor, there are no resource leaks, even in exceptional circumstances.
 A type with at least one non-trivial constructor or destructor is henceforth referred to as a \emph{managed type}.
-In the context of \CFA, a non-trivial constructor is either a user defined constructor or an auto generated constructor that calls a non-trivial constructor.
-
-For the remaining resource ownership cases, programmer must follow a brittle, explicit protocol for freeing resources or an implicit porotocol implemented via the programming language.
+In the context of \CFA, a non-trivial constructor is either a user defined constructor or an auto-generated constructor that calls a non-trivial constructor.
+
+For the remaining resource ownership cases, programmer must follow a brittle, explicit protocol for freeing resources or an implicit protocol implemented via the programming language.
 
 In garbage collected languages, such as Java, resources are largely managed by the garbage collector.
@@ -406,5 +406,5 @@
 In particular, Java supports \emph{finalizers}, which are similar to destructors.
 Sadly, finalizers are only guaranteed to be called before an object is reclaimed by the garbage collector \cite[p.~373]{Java8}, which may not happen if memory use is not contentious.
-Due to operating-system resource-limits, this is unacceptable for many long running programs. % TODO: citation?
+Due to operating-system resource-limits, this is unacceptable for many long running programs.
 Instead, the paradigm in Java requires programmers to manually keep track of all resources \emph{except} memory, leading many novices and experts alike to forget to close files, etc.
 Complicating the picture, uncaught exceptions can cause control flow to change dramatically, leaking a resource that appears on first glance to be released.
@@ -452,7 +452,55 @@
 Depending on when the exception is raised, both @out@ and @log@ are null, @log@ is null, or both are non-null, therefore, the cleanup for these variables at the end is appropriately guarded and conditionally executed to prevent null-pointer exceptions.
 
-% TODO: discuss Rust?
-% Like \CC, Rust \cite{Rust} provides RAII through constructors and destructors.
-% Smart pointers are deeply integrated in the Rust type-system.
+While Rust \cite{Rust} does not enforce the use of a garbage collector, it does provide a manual memory management environment, with a strict ownership model that automatically frees allocated memory and prevents common memory management errors.
+In particular, a variable has ownership over its associated value, which is freed automatically when the owner goes out of scope.
+Furthermore, values are \emph{moved} by default on assignment, rather than copied, which invalidates the previous variable binding.
+\begin{rustcode}
+struct S {
+  x: i32
+}
+let s = S { x: 123 };
+let z = s;           // move, invalidate s
+println!("{}", s.x); // error, s has been moved
+\end{rustcode}
+Types can be made copyable by implementing the @Copy@ trait.
+
+Rust allows multiple unowned views into an object through references, also known as borrows, provided that a reference does not outlive its referent.
+A mutable reference is allowed only if it is the only reference to its referent, preventing data race errors and iterator invalidation errors.
+\begin{rustcode}
+let mut x = 10;
+{
+  let y = &x;
+  let z = &x;
+  println!("{} {}", y, z); // prints 10 10
+}
+{
+  let y = &mut x;
+  // let z1 = &x;     // not allowed, have mutable reference
+  // let z2 = &mut x; // not allowed, have mutable reference
+  *y = 5;
+  println!("{}", y); // prints 5
+}
+println!("{}", x); // prints 5
+\end{rustcode}
+Since references are not owned, they do not release resources when they go out of scope.
+There is no runtime cost imposed on these restrictions, since they are enforced at compile-time.
+
+Rust provides RAII through the @Drop@ trait, allowing arbitrary code to execute when the object goes out of scope, allowing Rust programs to automatically clean up auxiliary resources much like a \CC program.
+\begin{rustcode}
+struct S {
+  name: &'static str
+}
+
+impl Drop for S {  // RAII for S
+  fn drop(&mut self) {
+    println!("dropped {}", self.name);
+  }
+}
+
+{
+  let x = S { name: "x" };
+  let y = S { name: "y" };
+} // prints "dropped y" "dropped x"
+\end{rustcode}
 
 % D has constructors and destructors that are worth a mention (under classes) https://dlang.org/spec/spec.html
@@ -462,14 +510,14 @@
 The programming language, D, also manages resources with constructors and destructors \cite{D}.
 In D, @struct@s are stack allocated and managed via scoping like in \CC, whereas @class@es are managed automatically by the garbage collector.
-Like Java, using the garbage collector means that destructors may never be called, requiring the use of finally statements to ensure dynamically allocated resources that are not managed by the garbage collector, such as open files, are cleaned up.
+Like Java, using the garbage collector means that destructors are called indeterminately, requiring the use of finally statements to ensure dynamically allocated resources that are not managed by the garbage collector, such as open files, are cleaned up.
 Since D supports RAII, it is possible to use the same techniques as in \CC to ensure that resources are released in a timely manner.
-Finally, D provides a scope guard statement, which allows an arbitrary statement to be executed at normal scope exit with \emph{success}, at exceptional scope exit with \emph{failure}, or at normal and exceptional scope exit with \emph{exit}. % TODO: cite? https://dlang.org/spec/statement.html#ScopeGuardStatement
+Finally, D provides a scope guard statement, which allows an arbitrary statement to be executed at normal scope exit with \emph{success}, at exceptional scope exit with \emph{failure}, or at normal and exceptional scope exit with \emph{exit}. % https://dlang.org/spec/statement.html#ScopeGuardStatement
 It has been shown that the \emph{exit} form of the scope guard statement can be implemented in a library in \CC \cite{ExceptSafe}.
 
-To provide managed types in \CFA, new kinds of constructors and destructors are added to C and discussed in Chapter 2.
+To provide managed types in \CFA, new kinds of constructors and destructors are added to \CFA and discussed in Chapter 2.
 
 \section{Tuples}
 \label{s:Tuples}
-In mathematics, tuples are finite-length sequences which, unlike sets, allow duplicate elements.
+In mathematics, tuples are finite-length sequences which, unlike sets, are ordered and allow duplicate elements.
 In programming languages, tuples provide fixed-sized heterogeneous lists of elements.
 Many programming languages have tuple constructs, such as SETL, \KWC, ML, and Scala.
@@ -523,5 +571,5 @@
 Like \CC, D provides tuples through a library variadic template struct.
 In D, it is possible to name the fields of a tuple type, which creates a distinct type.
-% TODO: cite http://dlang.org/phobos/std_typecons.html
+% http://dlang.org/phobos/std_typecons.html
 \begin{dcode}
 Tuple!(float, "x", float, "y") point2D;
@@ -572,5 +620,5 @@
 
 
-\Csharp also has tuples, but has similarly strange limitations, allowing tuples of size up to 7 components. % TODO: cite https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx
+\Csharp also has tuples, but has similarly strange limitations, allowing tuples of size up to 7 components. % https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx
 The officially supported workaround for this shortcoming is to nest tuples in the 8th component.
 \Csharp allows accessing a component of a tuple by using the field @Item$N$@ for components 1 through 7, and @Rest@ for the nested tuple.
@@ -585,6 +633,5 @@
 In Swift, @Void@ is an alias for the empty tuple, and there are no single element tuples.
 
-% TODO: this statement feels like it's too strong
-Tuples as powerful as the above languages are added to C and discussed in Chapter 3.
+Tuples comparable to those described above are added to \CFA and discussed in Chapter 3.
 
 \section{Variadic Functions}
@@ -600,5 +647,5 @@
 printf("%d %g %c %s", 10, 3.5, 'X', "a string");
 \end{cfacode}
-Through the use of a format string, @printf@ allows C programmers to print any of the standard C data types.
+Through the use of a format string, C programmers can communicate argument type information to @printf@, allowing C programmers to print any of the standard C data types.
 Still, @printf@ is extremely limited, since the format codes are specified by the C standard, meaning users cannot define their own format codes to extend @printf@ for new data types or new formatting rules.
 
@@ -692,3 +739,3 @@
 The combination of these two issues greatly restricts the usefulness of variadic functions in Java.
 
-Type-safe variadic functions are added to C and discussed in Chapter 4.
+Type-safe variadic functions are added to \CFA and discussed in Chapter 4.
Index: doc/rob_thesis/thesis.bib
===================================================================
--- doc/rob_thesis/thesis.bib	(revision 74933396698c5746d8db9582869740d0dbc1a8f4)
+++ doc/rob_thesis/thesis.bib	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -24,4 +24,5 @@
   year = 2011,
   url = {http://www.oracle.com/technetwork/articles/java/trywithresources-401775.html},
+  note = {\url{http://www.oracle.com/technetwork/articles/java/trywithresources-401775.html}},
   urldate = {2017-04-03}
 }
@@ -33,4 +34,5 @@
   year = 2000,
   url = {http://www.drdobbs.com/cpp/generic-change-the-way-you-write-excepti/184403758},
+  note = {\url{http://www.drdobbs.com/cpp/generic-change-the-way-you-write-excepti/184403758}},
   urldate = {2017-04-03}
 }
@@ -53,4 +55,13 @@
   pages = {1--6},
   numpages = {6},
-  url = {http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0144r0.pdf},
+  note = {\url{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0144r0.pdf}},
 }
+
+@manual{atexit,
+  keywords  = {The Linux Programmer's Manual atexit},
+  contributer = {rschlunt@uwaterloo.ca},
+  title = {The Linux Programmer's Manual},
+  organization= {The GNU Project},
+  year  = 2017,
+  note  = {\url{http://man7.org/linux/man-pages/man3/atexit.3.html}},
+}
Index: doc/rob_thesis/thesis.tex
===================================================================
--- doc/rob_thesis/thesis.tex	(revision 74933396698c5746d8db9582869740d0dbc1a8f4)
+++ doc/rob_thesis/thesis.tex	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -67,4 +67,8 @@
 }{xcolor}
 \documentclass[letterpaper,12pt,titlepage,oneside,final]{book}
+
+% For PDF, suitable for double-sided printing, change the PrintVersion variable below
+% to "true" and use this \documentclass line instead of the one above:
+% \documentclass[letterpaper,12pt,titlepage,openright,twoside,final]{book}
 
 \usepackage[T1]{fontenc}                                % allow Latin1 (extended ASCII) characters
@@ -92,8 +96,4 @@
 
 \interfootnotelinepenalty=10000
-
-% For PDF, suitable for double-sided printing, change the PrintVersion variable below
-% to "true" and use this \documentclass line instead of the one above:
-%\documentclass[letterpaper,12pt,titlepage,openright,twoside,final]{book}
 
 % Some LaTeX commands I define for my own nomenclature.
Index: doc/rob_thesis/tuples.tex
===================================================================
--- doc/rob_thesis/tuples.tex	(revision 74933396698c5746d8db9582869740d0dbc1a8f4)
+++ doc/rob_thesis/tuples.tex	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -2,8 +2,4 @@
 \chapter{Tuples}
 %======================================================================
-
-\section{Introduction}
-% TODO: no passing input parameters by assignment, instead will have reference types => this is not a very C-like model and greatly complicates syntax for likely little gain (and would cause confusion with already supported return-by-reference)
-% TODO: benefits (conclusion) by Till: reduced number of variables and statements; no specified order of execution for multiple assignment (more optimzation freedom); can store parameter lists in variable; MRV routines (natural code); more convenient assignment statements; simple and efficient access of record fields; named return values more legible and efficient in use of storage
 
 \section{Multiple-Return-Value Functions}
@@ -12,10 +8,6 @@
 This restriction results in code which emulates functions with multiple return values by \emph{aggregation} or by \emph{aliasing}.
 In the former situation, the function designer creates a record type that combines all of the return values into a single type.
-For example, consider a function returning the most frequently occuring letter in a string, and its frequency.
-% TODO: consider simplifying the example!
-%   Two things I like about this example:
-%   * it uses different types to illustrate why an array is insufficient (this is not necessary, but is nice)
-%   * it's complicated enough to show the uninitialized pitfall that exists in the aliasing example.
-%   Still, it may be a touch too complicated. Is there a simpler example with these two properties?
+For example, consider a function returning the most frequently occurring letter in a string, and its frequency.
+This example is complex enough to illustrate that an array is insufficient, since arrays are homogeneous, and demonstrates a potential pitfall that exists with aliasing.
 \begin{cfacode}
 struct mf_ret {
@@ -87,5 +79,5 @@
 The expression resolution phase of the \CFA translator ensures that the correct form is used depending on the values being returned and the return type of the current function.
 A multiple-returning function with return type @T@ can return any expression that is implicitly convertible to @T@.
-Using the running example, the @most_frequent@ function can be written in using multiple return values as such,
+Using the running example, the @most_frequent@ function can be written using multiple return values as such,
 \begin{cfacode}
 [int, char] most_frequent(const char * str) {
@@ -282,5 +274,5 @@
 These semantics allow cascading tuple assignment to work out naturally in any context where a tuple is permitted.
 These semantics are a change from the original tuple design in \KWC \cite{Till89}, wherein tuple assignment was a statement that allows cascading assignments as a special case.
-The \KWC semantics fix what was seen as a problem with assignment, wherein it can be used in many different locations, such as in function-call argument position. % TODO: remove??
+Restricting tuple assignment to statements was an attempt to to fix what was seen as a problem with assignment, wherein it can be used in many different locations, such as in function-call argument position.
 While permitting assignment as an expression does introduce the potential for subtle complexities, it is impossible to remove assignment expressions from \CFA without affecting backwards compatibility.
 Furthermore, there are situations where permitting assignment as an expression improves readability by keeping code succinct and reducing repetition, and complicating the definition of tuple assignment puts a greater cognitive burden on the user.
@@ -313,5 +305,5 @@
 [S, S] z = x.0;        // uses (4), (4), copy constructor
 \end{cfacode}
-In this example, @x@ is initialized by the multiple constructor calls @?{}(&x.0, 3)@ and @?{}(&x.1, 6.28)@, while @y@ is initilaized by two default constructor calls @?{}(&y.0)@ and @?{}(&y.1)@.
+In this example, @x@ is initialized by the multiple constructor calls @?{}(&x.0, 3)@ and @?{}(&x.1, 6.28)@, while @y@ is initialized by two default constructor calls @?{}(&y.0)@ and @?{}(&y.1)@.
 @z@ is initialized by mass copy constructor calls @?{}(&z.0, x.0)@ and @?{}(&z.1, x.0)@.
 Finally, @x@, @y@, and @z@ are destructed, i.e. the calls @^?{}(&x.0)@, @^?{}(&x.1)@, @^?{}(&y.0)@, @^?{}(&y.1)@, @^?{}(&z.0)@, and @^?{}(&z.1)@.
@@ -392,12 +384,12 @@
 z.y;  // ???
 \end{cfacode}
-One possiblity is for @s.1@ to select the second member of @s@.
+One possibility is for @s.1@ to select the second member of @s@.
 Under this interpretation, it becomes possible to not only access members of a struct by name, but also by position.
 Likewise, it seems natural to open this mechanism to enumerations as well, wherein the left side would be a type, rather than an expression.
-One benefit of this interpretation is familiar, since it is extremely reminiscent of tuple-index expressions.
+One benefit of this interpretation is familiarity, since it is extremely reminiscent of tuple-index expressions.
 On the other hand, it could be argued that this interpretation is brittle in that changing the order of members or adding new members to a structure becomes a brittle operation.
 This problem is less of a concern with tuples, since modifying a tuple affects only the code that directly uses the tuple, whereas modifying a structure has far reaching consequences for every instance of the structure.
 
-As for @z.y@, a one interpretation is to extend the meaning of member tuple expressions.
+As for @z.y@, one interpretation is to extend the meaning of member tuple expressions.
 That is, currently the tuple must occur as the member, i.e. to the right of the dot.
 Allowing tuples to the left of the dot could distribute the member across the elements of the tuple, in much the same way that member tuple expressions distribute the aggregate across the member tuple.
@@ -430,8 +422,8 @@
 p1.0 + p1.1 + p2.0 + p2.1;  // equivalent
 \end{cfacode}
-In this simpler interpretation, a named tuple type carries with it a list of possibly empty identifiers.
+In this simpler interpretation, a tuple type carries with it a list of possibly empty identifiers.
 This approach fits naturally with the named return-value feature, and would likely go a long way towards implementing it.
 
-Ultimately, the first two extensions introduce complexity into the model, with relatively little peceived benefit, and so were dropped from consideration.
+Ultimately, the first two extensions introduce complexity into the model, with relatively little perceived benefit, and so were dropped from consideration.
 Named tuples are a potentially useful addition to the language, provided they can be parsed with a reasonable syntax.
 
@@ -439,5 +431,5 @@
 \section{Casting}
 In C, the cast operator is used to explicitly convert between types.
-In \CFA, the cast operator has a secondary use, which is type ascription.
+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.
 That 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.
 \begin{cfacode}
@@ -515,6 +507,6 @@
 \end{cfacode}
 Note that due to the implicit tuple conversions, this function is not restricted to the addition of two triples.
+A call to this plus operator type checks as long as a total of 6 non-tuple arguments are passed after flattening, and all of the arguments have a common type that can bind to @T@, with a pairwise @?+?@ over @T@.
 For example, these expressions also succeed and produce the same value.
-A call to this plus operator type checks as long as a total of 6 non-tuple arguments are passed after flattening, and all of the arguments have a common type that can bind to @T@, with a pairwise @?+?@ over @T@.
 \begin{cfacode}
 ([x.0, x.1]) + ([x.2, 10, 20, 30]);  // x + ([10, 20, 30])
@@ -522,5 +514,5 @@
 \end{cfacode}
 This presents a potential problem if structure is important, as these three expressions look like they should have different meanings.
-Furthermore, these calls can be made ambiguous by adding seemingly different functions.
+Furthermore, these calls can be made ambiguous by introducing seemingly different functions.
 \begin{cfacode}
 forall(otype T | { T ?+?(T, T); })
@@ -630,10 +622,10 @@
 g(h());
 \end{cfacode}
-Interally, this is converted to psuedo-\CFA
+Internally, this is converted to pseudo-\CFA
 \begin{cfacode}
 void g(int, double);
 [int, double] h();
-lazy [int, double] unq<0> = h();
-g(unq<0>.0, unq<0>.1);
+lazy [int, double] unq0 = h(); // deferred execution
+g(unq0.0, unq0.1);             // execute h() once
 \end{cfacode}
 That is, the function @h@ is evaluated lazily and its result is stored for subsequent accesses.
@@ -654,6 +646,6 @@
 Every subsequent evaluation of the unique expression then results in an access to the stored result of the actual expression.
 
-Currently, the \CFA translator has a very broad, imprecise definition of impurity (side-effects), where any function call is assumed to be impure.
-This notion could be made more precise for certain intrinsic, autogenerated, and builtin functions, and could analyze function bodies, when they are available, to recursively detect impurity, to eliminate some unique expressions.
+Currently, the \CFA translator has a very broad, imprecise definition of impurity (side-effects), where every function call is assumed to be impure.
+This notion could be made more precise for certain intrinsic, auto-generated, and built-in functions, and could analyze function bodies, when they are available, to recursively detect impurity, to eliminate some unique expressions.
 It is possible that lazy evaluation could be exposed to the user through a lazy keyword with little additional effort.
 
Index: doc/rob_thesis/variadic.tex
===================================================================
--- doc/rob_thesis/variadic.tex	(revision 74933396698c5746d8db9582869740d0dbc1a8f4)
+++ doc/rob_thesis/variadic.tex	(revision f3be34244c109eb245f654bf5077bbafc2fcb0ac)
@@ -3,10 +3,10 @@
 %======================================================================
 
-\section{Design Criteria} % TOOD: better section name???
+\section{Design Criteria} % TODO: better section name???
 C provides variadic functions through the manipulation of @va_list@ objects.
 A variadic function is one which contains at least one parameter, followed by @...@ as the last token in the parameter list.
 In particular, some form of \emph{argument descriptor} is needed to inform the function of the number of arguments and their types.
 Two common argument descriptors are format strings or counter parameters.
-It is important to note that both of these mechanisms are inherently redundant, because they require the user to specify information that the compiler knows explicitly.
+It is important to note that both of these mechanisms are inherently redundant, because they require the user to explicitly specify information that the compiler already knows.
 This required repetition is error prone, because it is easy for the user to add or remove arguments without updating the argument descriptor.
 In addition, C requires the programmer to hard code all of the possible expected types.
@@ -63,6 +63,6 @@
 Likewise, when inferring assertion @g@, an exact match is found.
 
-This approach is strict with respect to argument structure by nature, which makes it syntactically awkward to use in ways that the existing tuple design is not.
-For example, consider a @new@ function that allocates memory using @malloc@ and constructs the result, using arbitrary arguments.
+This approach is strict with respect to argument structure, by nature, which makes it syntactically awkward to use in ways that the existing tuple design is not.
+For example, consider a @new@ function that allocates memory using @malloc@, and constructs the result using arbitrary arguments.
 \begin{cfacode}
 struct Array;
@@ -110,5 +110,5 @@
 In order to call (1), @10@ is matched with @x@, and the argument resolution moves on to the argument pack @rest@, which consumes the remainder of the argument list and @Params@ is bound to @[20, 30]@.
 In order to finish the resolution of @sum@, an assertion parameter that matches @int sum(int, int)@ is required.
-Like in the previous iteration, (0) is not a valid candiate, so (1) is examined with @Params@ bound to @[int]@, requiring the assertion @int sum(int)@.
+Like in the previous iteration, (0) is not a valid candidate, so (1) is examined with @Params@ bound to @[int]@, requiring the assertion @int sum(int)@.
 Next, (0) fails, and to satisfy (1) @Params@ is bound to @[]@, requiring an assertion @int sum()@.
 Finally, (0) matches and (1) fails, which terminates the recursion.
@@ -173,10 +173,10 @@
 A notable limitation of this approach is that it heavily relies on recursive assertions.
 The \CFA translator imposes a limitation on the depth of the recursion for assertion satisfaction.
-Currently, the limit is set to 4, which means that the first iteration of the @sum@ function is limited to at most 5 arguments, while the second iteration can support up to 6 arguments.
+Currently, the limit is set to 4, which means that the first version of the @sum@ function is limited to at most 5 arguments, while the second version can support up to 6 arguments.
 The limit is set low due to inefficiencies in the current implementation of the \CFA expression resolver.
 There is ongoing work to improve the performance of the resolver, and with noticeable gains, the limit can be relaxed to allow longer argument lists to @ttype@ functions.
 
 C variadic syntax and @ttype@ polymorphism probably should not be mixed, since it is not clear where to draw the line to decide which arguments belong where.
-Furthermore, it might be desirable to disallow polymorphic functions to use C variadic syntax to encourage a Cforall style.
+Furthermore, it might be desirable to disallow polymorphic functions to use C variadic syntax to encourage a \CFA style.
 Aside from calling C variadic functions, it is not obvious that there is anything that can be done with C variadics that could not also be done with @ttype@ parameters.
 
