Ignore:
Timestamp:
Apr 13, 2017, 8:29:38 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
1a16e9d
Parents:
c87eb50
Message:

penultimate thesis draft

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/rob_thesis/conclusions.tex

    rc87eb50 r0111dc7  
    22\chapter{Conclusions}
    33%======================================================================
     4
     5Adding resource management and tuples to \CFA has been a challenging design, engineering, and implementation exercise.
     6On the surface, the work may appear as a rehash of similar mechanisms in \CC.
     7However, every added feature is different than its \CC counterpart, often with extended functionality, better integration with C and its programmers, and always supports separate compilation.
     8All of these new features are being used by the \CFA development-team to build the \CFA runtime system.
    49
    510\section{Constructors and Destructors}
     
    1823
    1924\section{Variadic Functions}
    20 Type-safe variadic functions of a similar feel to variadic templates are added to \CFA.
     25Type-safe variadic functions, with a similar feel to variadic templates, are added to \CFA.
    2126The new variadic functions can express complicated recursive algorithms.
    2227Unlike variadic templates, it is possible to write @new@ as a library routine and to separately compile @ttype@ polymorphic functions.
     
    2934The 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.
    3035
     36% One technique being evaluated is whether named return-values can be used to eliminate unnecessary temporaries \cite{Buhr94a}.
     37% For example,
     38% \begin{cfacode}
     39% struct A { ... };
     40% [A x] f(A x);
     41% [A y] g(A y);
     42% [A z] h(A z);
     43
     44% struct A a1, a2;
     45% a2 = h(g(f(a1)));
     46% \end{cfacode}
     47% Here, since both @f@'s argument and return value have the same name and type, the compiler can infer that @f@ returns its argument.
     48% With this knowledge, the compiler can reuse the storage for the argument to @f@ as the argument to @g@.  % TODO: cite Till thesis?
     49
    3150Exception handling is among the features expected to be added to \CFA in the near future.
    3251For exception handling to properly interact with the rest of the language, it must ensure all RAII guarantees continue to be met.
     
    4463This 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.
    4564
    46 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@.
    47 This means that any destructor that consumes multiple arguments (\eg, because it is polymorphic) or any destructor that is a function pointer (\eg, because it is an assertion parameter) must be called through a local thunk.
     65A caveat of this approach is that the @cleanup@ attribute only permits a function that consumes a single argument of type @T *@ for a variable of type @T@.
     66This restriction means that any destructor that consumes multiple arguments (\eg, because it is polymorphic) or any destructor that is a function pointer (\eg, because it is an assertion parameter) must be called through a local thunk.
    4867For example,
    4968\begin{cfacode}
     
    5271  T x;
    5372};
    54 forall(otype T) void ^?{}(Box(T) * x);
     73forall(otype T) void ^?{}(Box(T) * x); // has implicit parameters
    5574
    5675forall(otype T)
    5776void f(T x) {
    58   T y = x;
    59   Box(T) z = { x };
     77  T y = x;  // destructor is a function-pointer parameter
     78  Box(T) z = { x }; // destructor has multiple parameters
    6079}
    6180\end{cfacode}
     
    148167void _dtor_S(struct S *);
    149168
    150 struct __tmp_bundle_S {
     169struct _tmp_bundle_S {
    151170  bool valid;
    152171  struct S value;
    153172};
    154173
    155 void _dtor_tmpS(struct __tmp_bundle_S * ret) {
     174void _dtor_tmpS(struct _tmp_bundle_S * ret) {
    156175  if (ret->valid) {
    157176    _dtor_S(&ret->value);
     
    160179
    161180{
    162   __attribute__((cleanup(_dtor_tmpS))) struct __tmp_bundle_S _tmp1 = { 0 };
    163   __attribute__((cleanup(_dtor_tmpS))) struct __tmp_bundle_S _tmp2 = { 0 };
    164   __attribute__((cleanup(_dtor_tmpS))) struct __tmp_bundle_S _tmp3 = { 0 };
     181  __attribute__((cleanup(_dtor_tmpS))) struct _tmp_bundle_S _tmp1 = { 0 };
     182  __attribute__((cleanup(_dtor_tmpS))) struct _tmp_bundle_S _tmp2 = { 0 };
     183  __attribute__((cleanup(_dtor_tmpS))) struct _tmp_bundle_S _tmp3 = { 0 };
    165184  _tmp2.value = g(
    166185    (_ctor_S(
     
    189208struct S { T x; };
    190209\end{cfacode}
    191 will only auto-generate the default constructor for @S@, since the member @x@ is missing the other 3 special functions.
     210only auto-generates the default constructor for @S@, since the member @x@ is missing the other 3 special functions.
    192211Once 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.
    193212For example,
     
    210229struct B { ... };
    211230struct A {
    212         B x, y, z;
     231  B x, y, z;
    213232};
    214233void ?{}(A * a, B x) {
    215         // y, z implicitly default constructed
    216         (&a->x){ ... }; // explicitly construct x
     234  // y, z implicitly default constructed
     235  (&a->x){ ... }; // explicitly construct x
    217236} // constructs an entire A
    218237void ?{}(A * a) {
    219         (&a->y){}; // initialize y
    220         a{ (B){ ... } }; // forwarding constructor call
    221                          // initializes entire object, including y
     238  (&a->y){}; // initialize y
     239  a{ (B){ ... } }; // forwarding constructor call
     240                   // initializes entire object, including y
    222241}
    223242\end{cfacode}
    224243
    225244Finally, while constructors provide a mechanism for establishing invariants, there is currently no mechanism for maintaining invariants without resorting to opaque types.
    226 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.
     245That is, structure fields can be accessed and modified by any block of code without restriction, so while it is possible to ensure that an object is initially set to a valid state, it is not possible to ensure that it remains in a consistent state throughout its lifetime.
    227246A 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.
    228247This approach could be added to \CFA, but it requires an idiomatic way of specifying what code is privileged.
     
    239258\subsection{Variadic Functions}
    240259Use of @ttype@ functions currently relies heavily on recursion.
    241 \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.
    242 
    243 \CC supports variadic templated data types, making it possible to express arbitrary length tuples, arbitrary parameter function objects, and more with generic types.
    244 Currently, \CFA does not support @ttype@-parameter generic types, though there does not appear to be a technical reason that it cannot.
     260\CC has opened variadic templates up so that recursion is not strictly necessary in some cases, and it would be interesting to see if any such cases can be applied to \CFA.
     261
     262\CC supports variadic templated data-types, making it possible to express arbitrary length tuples, arbitrary parameter function objects, and more with generic types.
     263Currently, \CFA does not support @ttype@-parameter generic-types, though there does not appear to be a technical reason that it cannot.
    245264Notably, 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.
Note: See TracChangeset for help on using the changeset viewer.