Changeset 779a4a3 for doc/papers/general


Ignore:
Timestamp:
May 3, 2018, 4:33:19 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
f3152ab
Parents:
f465f0e (diff), c9d5c4f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into fix-reference-overloading

Location:
doc/papers/general
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/Makefile

    rf465f0e r779a4a3  
    6969        mkdir -p ${Build}
    7070
    71 ${BASE}.out.ps:
    72         ln -fs build/Paper.out.ps .
     71${BASE}.out.ps: ${Build}
     72        ln -fs ${Build}/Paper.out.ps .
    7373
    7474WileyNJD-AMA.bst:
    7575        ln -fs ../AMA/AMA-stix/ama/WileyNJD-AMA.bst .
    7676
    77 ${GRAPHS} : timing.gp timing.dat
     77${GRAPHS} : ${Build} timing.gp timing.dat
    7878        gnuplot -e Build="'${Build}/'" evaluation/timing.gp
    7979
    80 %.tex : %.fig
     80%.tex : %.fig ${Build}
    8181        fig2dev -L eepic $< > ${Build}/$@
    8282
    83 %.ps : %.fig
     83%.ps : %.fig ${Build}
    8484        fig2dev -L ps $< > ${Build}/$@
    8585
    86 %.pstex : %.fig
     86%.pstex : %.fig ${Build}
    8787        fig2dev -L pstex $< > ${Build}/$@
    8888        fig2dev -L pstex_t -p ${Build}/$@ $< > ${Build}/$@_t
  • doc/papers/general/Paper.tex

    rf465f0e r779a4a3  
    228228Nevertheless, C, first standardized over thirty years ago, lacks many features that make programming in more modern languages safer and more productive.
    229229
    230 \CFA (pronounced ``C-for-all'', and written \CFA or Cforall) is an evolutionary extension of the C programming language that aims to add modern language features to C, while maintaining both source and runtime compatibility with C and a familiar programming model for programmers.
     230\CFA (pronounced ``C-for-all'', and written \CFA or Cforall) is an evolutionary extension of the C programming language that adds modern language-features to C, while maintaining both source and runtime compatibility with C and a familiar programming model for programmers.
    231231The four key design goals for \CFA~\cite{Bilson03} are:
    232232(1) The behaviour of standard C code must remain the same when translated by a \CFA compiler as when translated by a C compiler;
     
    237237\CC is used similarly, but has the disadvantages of multiple legacy design-choices that cannot be updated and active divergence of the language model from C, requiring significant effort and training to incrementally add \CC to a C-based project.
    238238
     239All languages features discussed in this paper are working, except some advanced exception-handling features.
     240Not discussed in this paper are the integrated concurrency-constructs and user-level threading-library~\cite{Delisle18}.
    239241\CFA is an \emph{open-source} project implemented as an source-to-source translator from \CFA to the gcc-dialect of C~\cite{GCCExtensions}, allowing it to leverage the portability and code optimizations provided by gcc, meeting goals (1)--(3).
    240242Ultimately, a compiler is necessary for advanced features and optimal performance.
    241 All features discussed in this paper are working, unless otherwise stated as under construction.
     243% @plg2[9]% cd cfa-cc/src; cloc ArgTweak CodeGen CodeTools Common Concurrency ControlStruct Designators GenPoly InitTweak MakeLibCfa.cc MakeLibCfa.h Parser ResolvExpr SymTab SynTree Tuples driver prelude main.cc
     244% -------------------------------------------------------------------------------
     245% Language                     files          blank        comment           code
     246% -------------------------------------------------------------------------------
     247% C++                            108           5420           5232          34961
     248% C/C++ Header                    86           2379           2450           8464
     249% Teamcenter def                   2            115             65           1387
     250% make                             5            168             87           1052
     251% C                               20            109            403            488
     252% awk                              1             12             26            121
     253% sed                              1              0              0              6
     254% -------------------------------------------------------------------------------
     255% SUM:                           223           8203           8263          46479
     256% -------------------------------------------------------------------------------
     257The \CFA translator is 200+ files and 46,000+ lines of code written in C/\CC.
     258Starting with a translator versus a compiler makes it easier and faster to generate and debug C object-code rather than intermediate, assembler or machine code.
     259The translator design is based on the \emph{visitor pattern}, allowing multiple passes over the abstract code-tree, which works well for incrementally adding new feature through additional visitor passes.
     260At the heart of the translator is the type resolver, which handles the polymorphic routine/type overload-resolution.
     261% @plg2[8]% cd cfa-cc/src; cloc libcfa
     262% -------------------------------------------------------------------------------
     263% Language                     files          blank        comment           code
     264% -------------------------------------------------------------------------------
     265% C                               35           1256           1240           9116
     266% C/C++ Header                    54            358           1106           1198
     267% make                             2            201            325           1167
     268% C++                              3             18             17            124
     269% Assembly                         3             56             97            111
     270% Bourne Shell                     2              2              0             25
     271% awk                              1              4              0             22
     272% -------------------------------------------------------------------------------
     273% SUM:                           100           1895           2785          11763
     274% -------------------------------------------------------------------------------
     275The \CFA runtime system is 100+ files and 11,000+ lines of code, written in \CFA.
     276Currently, the \CFA runtime is the largest \emph{user} of \CFA providing a vehicle to test the language features and implementation.
     277% @plg2[6]% cd cfa-cc/src; cloc tests examples benchmark
     278% -------------------------------------------------------------------------------
     279% Language                     files          blank        comment           code
     280% -------------------------------------------------------------------------------
     281% C                              237          12260           2869          23286
     282% make                             8            464            245           2838
     283% C/C++ Header                    22            225            175            785
     284% Python                           5            131             93            420
     285% C++                             10             48              5            201
     286% Lua                              2             31              4            126
     287% Java                             4              5              0             80
     288% Go                               2             11              9             40
     289% -------------------------------------------------------------------------------
     290% SUM:                           290          13175           3400          27776
     291% -------------------------------------------------------------------------------
     292The \CFA tests are 290+ files and 27,000+ lines of code.
     293The tests illustrate syntactic and semantic features in \CFA, plus a growing number of runtime benchmarks.
     294The tests check for correctness and are used for daily regression testing of commits (3800+).
    242295
    243296Finally, it is impossible to describe a programming language without usages before definitions.
     
    260313There are only two hard things in Computer Science: cache invalidation and \emph{naming things} -- Phil Karlton
    261314\end{quote}
     315\vspace{-10pt}
    262316C already has a limited form of ad-hoc polymorphism in the form of its basic arithmetic operators, which apply to a variety of different types using identical syntax.
    263317\CFA extends the built-in operator overloading by allowing users to define overloads for any function, not just operators, and even any variable;
     
    354408
    355409\CFA has replacement libraries condensing hundreds of existing C functions into tens of \CFA overloaded functions, all without rewriting the actual computations (see Section~\ref{sec:libraries}).
    356 For example, it is possible to write a type-safe \CFA wrapper @malloc@ based on the C @malloc@:
     410For example, it is possible to write a type-safe \CFA wrapper @malloc@ based on the C @malloc@, where the return type supplies the type/size of the allocation, which is impossible in most type systems.
    357411\begin{cfa}
    358412forall( dtype T | sized(T) ) T * malloc( void ) { return (T *)malloc( sizeof(T) ); }
    359 int * ip = malloc();                                            $\C{// select type and size from left-hand side}$
    360 double * dp = malloc();
    361 struct S {...} * sp = malloc();
    362 \end{cfa}
    363 where the return type supplies the type/size of the allocation, which is impossible in most type systems.
     413// select type and size from left-hand side
     414int * ip = malloc();  double * dp = malloc();  struct S {...} * sp = malloc();
     415\end{cfa}
    364416
    365417Call-site inferencing and nested functions provide a localized form of inheritance.
     
    373425}
    374426\end{cfa}
    375 Within the block, the nested version of @?<?@ performs @?>?@ and this local version overrides the built-in @?<?@ so it is passed to @qsort@.
     427The local version of @?<?@ performs @?>?@ overriding the built-in @?<?@ so it is passed to @qsort@.
    376428Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types.
    377429
     
    382434        inline {                                                                        $\C{// nested distribution block, add forall/inline to declarations}$
    383435                void push( stack(`T`) & s, `T` value ) ...      $\C{// generic operations}$
    384                 T pop( stack(`T`) & s ) ...
    385436        }
    386437}
     
    388439
    389440
     441\vspace*{-2pt}
    390442\subsection{Traits}
    391443
    392444\CFA provides \newterm{traits} to name a group of type assertions, where the trait name allows specifying the same set of assertions in multiple locations, preventing repetition mistakes at each function declaration:
     445
    393446\begin{cquote}
    394447\lstDeleteShortInline@%
     
    462515
    463516
     517\vspace*{-2pt}
    464518\section{Generic Types}
    465519
     
    474528
    475529\CC, Java, and other languages use \newterm{generic types} to produce type-safe abstract data-types.
    476 \CFA also implements generic types that integrate efficiently and naturally with the existing polymorphic functions, while retaining backwards compatibility with C and providing separate compilation.
     530\CFA generic types integrate efficiently and naturally with the existing polymorphic functions, while retaining backwards compatibility with C and providing separate compilation.
    477531However, for known concrete parameters, the generic-type definition can be inlined, like \CC templates.
    478532
     
    480534\begin{cquote}
    481535\lstDeleteShortInline@%
    482 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
     536\begin{tabular}{@{}l|@{\hspace{2\parindentlnth}}l@{}}
    483537\begin{cfa}
    484538forall( otype R, otype S ) struct pair {
     
    13731427resume( $\emph{alternate-stack}$ )
    13741428\end{cfa}
    1375 These overloads of @resume@ raise the specified exception or the currently propagating exception (reresume) at another \CFA coroutine or task\footnote{\CFA coroutine and concurrency features are discussed in a separately submitted paper.}~\cite{Delisle18}.
     1429These overloads of @resume@ raise the specified exception or the currently propagating exception (reresume) at another \CFA coroutine or task~\cite{Delisle18}.
    13761430Nonlocal raise is restricted to resumption to provide the exception handler the greatest flexibility because processing the exception does not unwind its stack, allowing it to continue after the handler returns.
    13771431
     
    20402094
    20412095
     2096\begin{comment}
    20422097\subsection{Integral Suffixes}
    20432098
     
    20732128\lstMakeShortInline@%
    20742129\end{cquote}
     2130\end{comment}
    20752131
    20762132
     
    26442700Figure~\ref{fig:eval} and Table~\ref{tab:eval} show the results of running the benchmark in Figure~\ref{fig:BenchmarkTest} and its C, \CC, and \CCV equivalents.
    26452701The graph plots the median of 5 consecutive runs of each program, with an initial warm-up run omitted.
    2646 All code is compiled at \texttt{-O2} by gcc or g++ 6.3.0, with all \CC code compiled as \CCfourteen.
     2702All code is compiled at \texttt{-O2} by gcc or g++ 6.4.0, with all \CC code compiled as \CCfourteen.
    26472703The benchmarks are run on an Ubuntu 16.04 workstation with 16 GB of RAM and a 6-core AMD FX-6300 CPU with 3.5 GHz maximum clock frequency.
    26482704
     
    26622718                                                                        & \CT{C}        & \CT{\CFA}     & \CT{\CC}      & \CT{\CCV}             \\ \hline
    26632719maximum memory usage (MB)                       & 10,001        & 2,502         & 2,503         & 11,253                \\
    2664 source code size (lines)                        & 196           & 186           & 125           & 290                   \\
     2720source code size (lines)                        & 201           & 191           & 125           & 294                   \\
    26652721redundant type annotations (lines)      & 27            & 0                     & 2                     & 16                    \\
    26662722binary size (KB)                                        & 14            & 257           & 14            & 37                    \\
     
    27652821data-parallel features have not yet been added to \CFA, but are easily incorporated within its design, while concurrency primitives similar to those in $\mu$\CC have already been added~\cite{Delisle18}.
    27662822Finally, CCured~\cite{Necula02} and Ironclad \CC~\cite{DeLozier13} attempt to provide a more memory-safe C by annotating pointer types with garbage collection information; type-checked polymorphism in \CFA covers several of C's memory-safety issues, but more aggressive approaches such as annotating all pointer types with their nullability or requiring runtime garbage collection are contradictory to \CFA's backwards compatibility goals.
    2767 
    2768 
    2769 \begin{comment}
    2770 \subsection{Control Structures / Declarations / Literals}
    2771 
    2772 Java has default fall through like C/\CC.
    2773 Pascal/Ada/Go/Rust do not have default fall through.
    2774 \Csharp does not have fall through but still requires a break.
    2775 Python uses dictionary mapping. \\
    2776 \CFA choose is like Rust match.
    2777 
    2778 Java has labelled break/continue. \\
    2779 Languages with and without exception handling.
    2780 
    2781 Alternative C declarations. \\
    2782 Different references \\
    2783 Constructors/destructors
    2784 
    2785 0/1 Literals \\
    2786 user defined: D, Objective-C
    2787 \end{comment}
    27882823
    27892824
     
    28752910}
    28762911_Bool stack_empty( const stack * s ) {
    2877          return s->head == NULL;
     2912        return s->head == NULL;
    28782913}
    28792914void push_stack( stack * s, void * v ) {
    2880         node * n = malloc(sizeof(node)); /***/
     2915        node * n = malloc( sizeof(node) ); /***/
    28812916        *n = (node){ v, s->head }; /***/
    28822917        s->head = n;
     
    29082943        };
    29092944        struct stack { node(T) * head; };
    2910         void ?{}( stack(T) & s ) { (s.head){ 0 }; }
    2911         void ?{}( stack(T) & s, stack(T) t ) {
     2945        void ?{}( stack(T) & s, stack(T) t ) { // copy
    29122946                node(T) ** cr = &s.head;
    29132947                for ( node(T) * nx = t.head; nx; nx = nx->next ) {
     
    29232957                        nx = cr->next;
    29242958                        ^(*cr){};
    2925                         free(cr);
     2959                        free( cr );
    29262960                }
    29272961                head = 0;
    29282962        }
     2963
    29292964\end{cfa}
    29302965&
    29312966\begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
     2967        void ?{}( stack(T) & s ) { (s.head){ 0 }; }
    29322968        void ^?{}( stack(T) & s) { clear( s ); }
    29332969        stack(T) ?=?( stack(T) & s, stack(T) t ) {
     
    29542990        }
    29552991}
    2956 
    29572992\end{cfa}
    29582993\end{tabular}
     
    30033038                return *this;
    30043039        }
    3005         bool empty() const { return head == nullptr; }
     3040        bool empty() const {
     3041                return head == nullptr;
     3042        }
    30063043        void push( const T & value ) {
    30073044                head = new node{ value, head };  /***/
     
    30153052        }
    30163053};
    3017 
    3018 
    30193054
    30203055\end{cfa}
     
    30663101                return *this;
    30673102        }
    3068         bool empty() const { return head == nullptr; }
     3103        bool empty() const {
     3104                return head == nullptr;
     3105        }
    30693106        void push( const object & value ) {
    30703107                head = new node{ value, head }; /***/
     
    30793116};
    30803117
    3081 
    3082 
    30833118\end{cfa}
    30843119\end{tabular}
  • doc/papers/general/evaluation/c-stack.c

    rf465f0e r779a4a3  
    2727}
    2828
    29 stack new_stack() { return (stack){ NULL }; /***/ }
     29stack new_stack() {
     30        return (stack){ NULL }; /***/
     31}
    3032
    3133stack * assign_stack( stack * s, const stack * t,
     
    3739}
    3840
    39 _Bool stack_empty( const stack * s ) { return s->head == NULL; }
     41_Bool stack_empty( const stack * s ) {
     42        return s->head == NULL;
     43}
    4044
    4145void push_stack( stack * s, void * v ) {
  • doc/papers/general/evaluation/c-stack.h

    rf465f0e r779a4a3  
    66} stack;
    77
     8void copy_stack(stack * dst, const stack * src, void * (* copy)(const void *));
     9void clear_stack(stack * s, void (*free_el)(void *));
    810stack new_stack();
    9 void copy_stack(stack * dst, const stack * src, void * (* copy)(const void *));
    1011stack * assign_stack( stack * dst, const stack * src,
    1112        void * (* copy_el)(const void *), void (* free_el)(void *));
    12 void clear_stack(stack * s, void (*free_el)(void *));
    1313
    1414_Bool stack_empty( const stack * s );
  • doc/papers/general/evaluation/cfa-stack.c

    rf465f0e r779a4a3  
    88        };
    99
    10         void ?{}( stack(T) & s ) { (s.head){ 0 }; }
    11 
    12         void ?{}( stack(T) & s, stack(T) t ) {
     10        void ?{}( stack(T) & s, stack(T) t ) {          // copy
    1311                node(T) ** cr = &s.head;
    1412                for ( node(T) * nx = t.head; nx; nx = nx->next ) {
     
    2018        }
    2119
    22         void ^?{}( stack(T) & s) { clear( s ); }
    23 
    24     void clear( stack(T) & s ) with( s ) {
     20        void clear( stack(T) & s ) with( s ) {
    2521                for ( node(T) * nx = head; nx; ) {
    2622                        node(T) * cr = nx;
    2723                        nx = cr->next;
    2824                        ^(*cr){};
    29                         free(cr);
     25                        free( cr );
    3026                }
    3127                head = 0;
    3228        }
     29
     30        void ?{}( stack(T) & s ) { (s.head){ 0 }; }
     31        void ^?{}( stack(T) & s) { clear( s ); }
    3332
    3433        stack(T) ?=?( stack(T) & s, stack(T) t ) {
     
    3938        }
    4039
    41         _Bool empty( const stack(T) & s ) { return s.head == 0; }
     40        _Bool empty( const stack(T) & s ) {
     41                return s.head == 0;
     42        }
    4243
    4344        void push( stack(T) & s, T value ) with( s ) {
  • doc/papers/general/evaluation/cfa-stack.h

    rf465f0e r779a4a3  
    77        };
    88
     9        void ?{}( stack(T) & s, stack(T) t );
     10        void clear( stack(T) & s );
    911        void ?{}( stack(T) & s );
    10         void ?{}( stack(T) & s, stack(T) t );
    1112        void ^?{}( stack(T) & s);
    12         void clear( stack(T) & s );
    1313
    1414        stack(T) ?=?( stack(T) & s, stack(T) t );
  • doc/papers/general/evaluation/cpp-stack.hpp

    rf465f0e r779a4a3  
    1010        node * head;
    1111
    12         stack() : head( nullptr ) {}
    13         stack( const stack<T> & o ) { copy( o ); }
     12        void copy( const stack<T> & o ) {
     13                node ** cr = &head;
     14                for ( node * nx = o.head; nx; nx = nx->next ) {
     15                        *cr = new node{ nx->value }; /***/
     16                        cr = &(*cr)->next;
     17                }
     18                *cr = nullptr;
     19        }
    1420
    1521        void clear() {
     
    2228        }
    2329
    24         void copy( const stack<T> & o ) {
    25                 node ** cr = &head;
    26                 for ( node * nx = o.head; nx; nx = nx->next ) {
    27                         *cr = new node{ nx->value }; /***/
    28                         cr = &(*cr)->next;
    29                 }
    30                 *cr = nullptr;
    31         }
    32 
     30        stack() : head( nullptr ) {}
     31        stack( const stack<T> & o ) { copy( o ); }
    3332        ~stack() { clear(); }
    3433
    35         stack & operator= ( const stack<T> & o ) {
     34        stack & operator=( const stack<T> & o ) {
    3635                if ( this == &o ) return *this;
    3736                clear();
     
    4039        }
    4140
    42         bool empty() const { return head == nullptr; }
     41        bool empty() const {
     42                return head == nullptr;
     43        }
    4344
    44         void push( const T & value ) { head = new node{ value, head };  /***/ }
     45        void push( const T & value ) {
     46                head = new node{ value, head };  /***/
     47        }
    4548
    4649        T pop() {
  • doc/papers/general/evaluation/cpp-vstack.cpp

    rf465f0e r779a4a3  
    33
    44stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {}
     5
     6void stack::copy( const stack & o ) {
     7        node ** cr = &head;
     8        for ( node * nx = o.head; nx; nx = nx->next ) {
     9                *cr = new node{ *nx->value }; /***/
     10                cr = &(*cr)->next;
     11        }
     12        *cr = nullptr;
     13}
    514
    615void stack::clear() {
     
    1120        }
    1221        head = nullptr;
    13 }
    14 
    15 void stack::copy( const stack & o ) {
    16         node ** cr = &head;
    17         for ( node * nx = o.head; nx; nx = nx->next ) {
    18                 *cr = new node{ *nx->value }; /***/
    19                 cr = &(*cr)->next;
    20         }
    21         *cr = nullptr;
    2222}
    2323
     
    3333}
    3434
    35 bool stack::empty() const { return head == nullptr; }
     35bool stack::empty() const {
     36        return head == nullptr;
     37}
    3638
    37 void stack::push( const object & value ) { head = new node{ value, head }; /***/ }
     39void stack::push( const object & value ) {
     40        head = new node{ value, head }; /***/
     41}
    3842
    3943ptr<object> stack::pop() {
  • doc/papers/general/evaluation/cpp-vstack.hpp

    rf465f0e r779a4a3  
    1010        node * head;
    1111
     12        void copy( const stack & o );
    1213        void clear();
    13         void copy( const stack & o );
    1414
    1515        stack();
  • doc/papers/general/evaluation/timing.dat

    rf465f0e r779a4a3  
    11"400 million repetitions"       "C"     "\\CFA{}"       "\\CC{}"        "\\CC{obj}"
    2 "push\nint"     3002    2459    1542    3269
    3 "copy\nint"     2985    2057    1539    3083
    4 "clear\nint"    1374    827     756     1469
    5 "pop\nint"      1416    1221    760     5098
    6 "push\npair"    4214    2752    950     6873
    7 "copy\npair"    6127    2105    987     7293
    8 "clear\npair"   2881    885     751     3460
    9 "pop\npair"     3046    5434    822     24962
     2"push\nint"     2911    2034    1504    3246
     3"copy\nint"     2953    1622    1526    3075
     4"clear\nint"    1397    754     753     1452
     5"pop\nint"      1446    1203    760     5016
     6"push\npair"    3673    2297    955     6971
     7"copy\npair"    6027    1183    998     7204
     8"clear\npair"   2840    773     748     3511
     9"pop\npair"     3025    5414    813     23867
     10
  • doc/papers/general/evaluation/timing.gp

    rf465f0e r779a4a3  
    2424set yrange [0:10]
    2525
    26 set label "25.0" at 7.125,10.5
     26set label "23.9" at 7.125,10.5
    2727
    2828# set datafile separator ","
Note: See TracChangeset for help on using the changeset viewer.