- Timestamp:
- Mar 29, 2017, 10:35:58 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 6a86a0a, 9d944b2, b2daebd4
- Parents:
- 3ed64ff
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/generic_types.tex
r3ed64ff r95448f1e 1 % take of review (for line numbers) and anonymous (for anonymization) on submission 2 \documentclass[format=acmlarge, anonymous, review]{acmart} 1 % take off review (for line numbers) and anonymous (for anonymization) on submission 2 % \documentclass[format=acmlarge, anonymous, review]{acmart} 3 \documentclass[format=acmlarge, review]{acmart} 3 4 4 5 \usepackage{listings} % For code listings … … 150 151 \begin{lstlisting} 151 152 forall(otype T) 152 T identity(T x) { 153 return x; 154 } 153 T identity(T x) { return x; } 155 154 156 155 int forty_two = identity(42); // T is bound to int, forty_two == 42 … … 163 162 \begin{lstlisting} 164 163 forall(otype T | { T twice(T); }) 165 T four_times(T x) { 166 return twice( twice(x) ); 167 } 164 T four_times(T x) { return twice( twice(x) ); } 168 165 169 166 double twice(double d) { return d * 2.0; } // (1) … … 257 254 typedef list *list_iterator; 258 255 259 lvalue int *?( list_iterator it ) { 260 return it->value; 261 } 256 lvalue int *?( list_iterator it ) { return it->value; } 262 257 \end{lstlisting} 263 258 … … 410 405 return ret; 411 406 } 407 412 408 sum(3, 10, 20, 30); // must keep initial counter argument in sync 413 409 \end{lstlisting} … … 679 675 void print(int x) { printf("%d", x); } 680 676 void print(S s) { print("{ ", s.x, ",", s.y, " }"); } 677 681 678 print("s = ", (S){ 1, 2 }, "\n"); 682 679 \end{lstlisting} … … 693 690 return ((T*)malloc( sizeof(T) )){ p }; // construct into result of malloc 694 691 } 692 695 693 Pair(int, char) * x = new(42, '!'); 696 694 \end{lstlisting} … … 794 792 In conclusion, the authors' design for generic types and tuples imposes minimal runtime overhead while still supporting a full range of C features, including separately-compiled modules. There is ongoing work on a wide range of \CFA{} feature extensions, including reference types, exceptions, and concurrent programming primitives. In addition to this work, there are some interesting future directions the polymorphism design could take. Notably, \CC{} template functions trade compile time and code bloat for optimal runtime of individual instantiations of polymorphic functions. \CFA{} polymorphic functions, by contrast, use an approach that is essentially dynamic virtual dispatch. The runtime overhead of this approach is low, but not as low as \CC{} template functions, and it may be beneficial to provide a mechanism for particularly performance-sensitive code to close this gap. Further research is needed, but two promising approaches are to allow an annotation on polymorphic function call sites that tells the translator to create a template-specialization of the function (provided the code is visible in the current translation unit) or placing an annotation on polymorphic function definitions that instantiates a version of the polymorphic function specialized to some set of types. These approaches are not mutually exclusive, and would allow these performance optimizations to be applied only where most useful to increase performance, without suffering the code bloat or loss of generality of a template expansion approach where it is unnecessary. 795 793 794 \begin{acks} 795 This work is supported in part by a corporate partnership with \grantsponsor{Huawei}{Huawei Ltd.}{http://www.huawei.com}\ and the first author's \grantsponsor{NSERC-PGS}{NSERC PGS D}{http://www.nserc-crsng.gc.ca/Students-Etudiants/PG-CS/BellandPostgrad-BelletSuperieures_eng.asp} scholarship. 796 \end{acks} 797 796 798 \bibliographystyle{ACM-Reference-Format} 797 799 \bibliography{generic_types}
Note: See TracChangeset
for help on using the changeset viewer.