Changeset 0111dc7 for doc/rob_thesis/conclusions.tex
- Timestamp:
- Apr 13, 2017, 8:29:38 PM (6 years ago)
- Branches:
- aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1a16e9d
- Parents:
- c87eb50
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/rob_thesis/conclusions.tex
rc87eb50 r0111dc7 2 2 \chapter{Conclusions} 3 3 %====================================================================== 4 5 Adding resource management and tuples to \CFA has been a challenging design, engineering, and implementation exercise. 6 On the surface, the work may appear as a rehash of similar mechanisms in \CC. 7 However, 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. 8 All of these new features are being used by the \CFA development-team to build the \CFA runtime system. 4 9 5 10 \section{Constructors and Destructors} … … 18 23 19 24 \section{Variadic Functions} 20 Type-safe variadic functions of a similar feel to variadic templatesare added to \CFA.25 Type-safe variadic functions, with a similar feel to variadic templates, are added to \CFA. 21 26 The new variadic functions can express complicated recursive algorithms. 22 27 Unlike variadic templates, it is possible to write @new@ as a library routine and to separately compile @ttype@ polymorphic functions. … … 29 34 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. 30 35 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 31 50 Exception handling is among the features expected to be added to \CFA in the near future. 32 51 For exception handling to properly interact with the rest of the language, it must ensure all RAII guarantees continue to be met. … … 44 63 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. 45 64 46 A caveat of this approach is that the @cleanup@ attribute only permits a name that refers to afunction 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.65 A 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@. 66 This 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. 48 67 For example, 49 68 \begin{cfacode} … … 52 71 T x; 53 72 }; 54 forall(otype T) void ^?{}(Box(T) * x); 73 forall(otype T) void ^?{}(Box(T) * x); // has implicit parameters 55 74 56 75 forall(otype T) 57 76 void 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 60 79 } 61 80 \end{cfacode} … … 148 167 void _dtor_S(struct S *); 149 168 150 struct _ _tmp_bundle_S {169 struct _tmp_bundle_S { 151 170 bool valid; 152 171 struct S value; 153 172 }; 154 173 155 void _dtor_tmpS(struct _ _tmp_bundle_S * ret) {174 void _dtor_tmpS(struct _tmp_bundle_S * ret) { 156 175 if (ret->valid) { 157 176 _dtor_S(&ret->value); … … 160 179 161 180 { 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 }; 165 184 _tmp2.value = g( 166 185 (_ctor_S( … … 189 208 struct S { T x; }; 190 209 \end{cfacode} 191 will only auto-generatethe default constructor for @S@, since the member @x@ is missing the other 3 special functions.210 only auto-generates the default constructor for @S@, since the member @x@ is missing the other 3 special functions. 192 211 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. 193 212 For example, … … 210 229 struct B { ... }; 211 230 struct A { 212 231 B x, y, z; 213 232 }; 214 233 void ?{}(A * a, B x) { 215 216 234 // y, z implicitly default constructed 235 (&a->x){ ... }; // explicitly construct x 217 236 } // constructs an entire A 218 237 void ?{}(A * a) { 219 220 221 238 (&a->y){}; // initialize y 239 a{ (B){ ... } }; // forwarding constructor call 240 // initializes entire object, including y 222 241 } 223 242 \end{cfacode} 224 243 225 244 Finally, 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.245 That 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. 227 246 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. 228 247 This approach could be added to \CFA, but it requires an idiomatic way of specifying what code is privileged. … … 239 258 \subsection{Variadic Functions} 240 259 Use of @ttype@ functions currently relies heavily on recursion. 241 \CC has opened variadic templates up so that recursion is n'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 244 Currently, \CFA does not support @ttype@-parameter generic 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. 263 Currently, \CFA does not support @ttype@-parameter generic-types, though there does not appear to be a technical reason that it cannot. 245 264 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.
Note: See TracChangeset
for help on using the changeset viewer.