Changes in / [660665f:5a46e09]


Ignore:
Files:
1 added
25 deleted
84 edited

Legend:

Unmodified
Added
Removed
  • INSTALL

    r660665f r5a46e09  
    1 cfa-cc: Cforall to C Trans-compiler
     1cfa-cc: The Cforall->C Compiler System
    22======================================
    33
    44Cforall is built using GNU Make and the GNU Autoconf system.  It also requires
    5 g++ version >= 6, bison and flex.  On systems where GNU Make is the default
     5g++ version >= 4.6, bison and flex.  On systems where GNU Make is the default
    66make, the system is built by entering the commands:
    77
    8 For developers using the root git:
     8For devs using the root git:
    99
    10   $ ./autogen.sh
    11   $ ./configure [ --prefix=/some/directory ]
    12   $ make -j 8 install
     10  ./autogen.sh
     11        ./configure
     12        make
     13        make install
    1314
    14 For users using the distributed tarball / github:
     15For users using the distributed tarball:
    1516
    16   $ ./configure
    17   $ make -j 8 install
     17        ./configure
     18        make
     19        make install
    1820
    19 where 8 is the number of CPUs on your computer.
     21Options for 'configure'
     22-----------------------
     23The script 'configure' accepts many command line arguments.  Run './configure
     24--help' to see a list of all of them.  This document attempts to summarize the
     25most useful arguments.
    2026
    21 
    22 Options for configure
    23 ======================================
    24 The script 'configure' accepts many command-line arguments.  Run
    25 
    26   $ ./configure --help
    27 
    28 to list them.  The most common argument is:
    29 
    30   --prefix=/some/directory controls the path prefix common to all installed
    31     cfa-cc components.  Components are installed in directories bin and lib.
    32     If unspecified, prefix defaults to /usr/local.  To use (a subdirectory of)
    33     your home directory, ${HOME}/some/dir, but do not put quotes around the
    34     directory path; Cforall may appear to build, but the installed version may
    35     not work properly.
    36 
    37 
    38 Build Test
    39 ======================================
    40 
    41   $ cd ./test
    42   $ make -j 8 all-tests
    43 
    44 The tests take about 2-5 minutes and can be stopped at any time.
     27--prefix=/some/directory controls the path prefix common to all installed
     28  cfa-cc components.  Some components are installed in /some/directory/bin,
     29  others in /some/directory/lib.  If unspecified, this defaults to /usr/local.
     30  To use (a subdirectory of) your home directory, ${HOME}/some/dir works, but
     31  it is important not to put quotes around the directory path; Cforall may
     32  appear to build, but the installed version may not work properly.
  • Jenkins/Distribute

    r660665f r5a46e09  
    22
    33import groovy.transform.Field
     4
     5// For skipping stages
     6import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
    47
    58//===========================================================================================================
     
    710//===========================================================================================================
    811
    9 // Globals
    10 BuildDir  = null
    11 SrcDir    = null
    12 Settings  = null
    13 Version   = ''
     12node('master') {
     13        // Globals
     14        BuildDir  = pwd tmp: true
     15        SrcDir    = pwd tmp: false
     16        Settings  = null
     17        Version   = ''
    1418
    15 // Local variables
    16 def err = null
    17 def log_needed = false
     19        // Local variables
     20        def err = null
     21        def log_needed = false
    1822
    19 currentBuild.result = "SUCCESS"
    20 
    21 final commit, build
    22 node {
     23        currentBuild.result = "SUCCESS"
    2324
    2425        //Wrap build to add timestamp to command line
    2526        wrap([$class: 'TimestamperBuildWrapper']) {
     27
     28                final commit, build
    2629                (commit, build) = prepare_build()
    27         }
    28 }
    2930
    30 node('x64') {
    31         //Wrap build to add timestamp to command line
    32         wrap([$class: 'TimestamperBuildWrapper']) {
     31                node('x64') {
     32                        BuildDir  = pwd tmp: true
     33                        SrcDir    = pwd tmp: false
     34
     35                        Tools.Clean()
     36
     37                        Tools.Checkout( commit )
     38
     39                        Version = GetVersion( build )
     40
     41                        Configure()
     42
     43                        Package()
     44
     45                        Test()
     46
     47                        Archive()
     48                }
     49
     50                // Update the build directories when exiting the node
    3351                BuildDir  = pwd tmp: true
    3452                SrcDir    = pwd tmp: false
     53        }
    3554
    36                 Tools.Clean()
    37 
    38                 Tools.Checkout( commit )
    39 
    40                 Version = GetVersion( build )
    41 
    42                 Configure()
    43 
    44                 Package()
    45 
    46                 Test()
    47 
    48                 Archive()
    49         }
    5055}
    5156
  • Jenkins/FullBuild

    r660665f r5a46e09  
    55//===========================================================================================================
    66
    7 node {
     7node ('master') {
    88        def err = null
    99
     
    1818
    1919                                parallel (
    20                                         gcc_08_x86_new: { trigger_build( 'gcc-8',   'x86' ) },
    21                                         gcc_07_x86_new: { trigger_build( 'gcc-7',   'x86' ) },
    22                                         gcc_06_x86_new: { trigger_build( 'gcc-6',   'x86' ) },
    23                                         gcc_10_x64_new: { trigger_build( 'gcc-10',  'x64' ) },
    24                                         gcc_09_x64_new: { trigger_build( 'gcc-9',   'x64' ) },
    25                                         gcc_08_x64_new: { trigger_build( 'gcc-8',   'x64' ) },
    26                                         gcc_07_x64_new: { trigger_build( 'gcc-7',   'x64' ) },
    27                                         gcc_06_x64_new: { trigger_build( 'gcc-6',   'x64' ) },
    28                                         clang_x64_new:  { trigger_build( 'clang',   'x64' ) },
     20                                        gcc_8_x86_new: { trigger_build( 'gcc-8',   'x86' ) },
     21                                        gcc_7_x86_new: { trigger_build( 'gcc-7',   'x86' ) },
     22                                        gcc_6_x86_new: { trigger_build( 'gcc-6',   'x86' ) },
     23                                        gcc_9_x64_new: { trigger_build( 'gcc-9',   'x64' ) },
     24                                        gcc_8_x64_new: { trigger_build( 'gcc-8',   'x64' ) },
     25                                        gcc_7_x64_new: { trigger_build( 'gcc-7',   'x64' ) },
     26                                        gcc_6_x64_new: { trigger_build( 'gcc-6',   'x64' ) },
     27                                        gcc_5_x64_new: { trigger_build( 'gcc-5',   'x64' ) },
     28                                        clang_x64_new: { trigger_build( 'clang',   'x64' ) },
    2929                                )
    3030                        }
     
    106106
    107107        if(result.result != 'SUCCESS') {
    108                 sh("wget -q -O - https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/${result.number}/consoleText")
     108                sh("wget -q -O - http://localhost:8084/jenkins/job/Cforall/job/master/${result.number}/consoleText")
    109109                error(result.result)
    110110        }
     
    144144//Email notification on a full build failure
    145145def promote_email(boolean success) {
    146         node {
    147                 echo('notifying users')
     146        echo('notifying users')
    148147
    149                 def result = success ? "PROMOTE - SUCCESS" : "PROMOTE - FAILURE"
     148        def result = success ? "PROMOTE - SUCCESS" : "PROMOTE - FAILURE"
    150149
    151                 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
    152                 //Configurations for email format
    153                 def email_subject = "[cforall git][${result}]"
    154                 def email_body = """<p>This is an automated email from the Jenkins build machine. It was
    155         generated following the result of the C\u2200 nightly build.</p>
     150        //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
     151        //Configurations for email format
     152        def email_subject = "[cforall git][${result}]"
     153        def email_body = """<p>This is an automated email from the Jenkins build machine. It was
     154generated following the result of the C\u2200 nightly build.</p>
    156155
    157         <p>Check console output at ${env.BUILD_URL} to view the results.</p>
     156<p>Check console output at ${env.BUILD_URL} to view the results.</p>
    158157
    159         <p>- Status --------------------------------------------------------------</p>
     158<p>- Status --------------------------------------------------------------</p>
    160159
    161         <p>${result}</p>
     160<p>${result}</p>
    162161
    163         <p>- Performance ---------------------------------------------------------</p>
     162<p>- Performance ---------------------------------------------------------</p>
    164163
    165         <img src="https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/plot/Compilation/getPlot?index=0" >
    166         <img src="https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/plot/Compilation/getPlot?index=1" >
     164<img src="https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/plot/Compilation/getPlot?index=0" >
     165<img src="https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/plot/Compilation/getPlot?index=1" >
    167166
    168         <p>- Logs ----------------------------------------------------------------</p>
    169         """
     167<p>- Logs ----------------------------------------------------------------</p>
     168"""
    170169
    171                 def email_to = "cforall@lists.uwaterloo.ca"
     170        def email_to = "cforall@lists.uwaterloo.ca"
    172171
    173                 //send email notification
    174                 emailext body: email_body, subject: email_subject, to: email_to, attachLog: !success
    175         }
     172        //send email notification
     173        emailext body: email_body, subject: email_subject, to: email_to, attachLog: !success
    176174}
  • Jenkins/tools.groovy

    r660665f r5a46e09  
    6161}
    6262
    63 def ConstructGitLogMessage(String oldRef, String newRef) {
     63PrevGitOldRef = ''
     64PrevGitNewRef = ''
     65def GitLogMessage(String oldRef = '', String newRef = '') {
     66        if (!oldRef) { if(!PrevGitOldRef) { return "\nERROR retrieveing current git information!\n"  } else { oldRef = PrevGitOldRef } }
     67        if (!newRef) { if(!PrevGitNewRef) { return "\nERROR retrieveing previous git information!\n" } else { newRef = PrevGitNewRef } }
     68
    6469        def revText = sh(returnStdout: true, script: "git rev-list ${oldRef}..${newRef}").trim()
    6570        def revList = SplitLines( revText )
     
    8287        gitDiff = gitDiff.replace('[m', '</span>')
    8388
     89        PrevGitOldRef = oldRef
     90        PrevGitNewRef = newRef
     91
    8492        return """
    85 <p>- Changes -------------------------------------------------------------</p>
    86 
    8793<pre>
    8894The branch ${env.BRANCH_NAME} has been updated.
    8995${gitUpdate}
    9096</pre>
     97
     98<p>Check console output at ${env.BUILD_URL} to view the results.</p>
     99
     100<p>- Status --------------------------------------------------------------</p>
     101
     102<p>BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}</p>
    91103
    92104<p>- Log -----------------------------------------------------------------</p>
     
    104116}
    105117
    106 EmailMessage = ''
    107 def GitLogMessage(String oldRef = '', String newRef = '') {
    108         if(!EmailMessage) {
    109                 if (!oldRef) { return "\nERROR retrieveing current git information!\n"  }
    110                 if (!newRef) { return "\nERROR retrieveing previous git information!\n" }
    111 
    112                 echo "Constructing new git message"
    113 
    114                 EmailMessage = ConstructGitLogMessage(oldRef, newRef)
    115         }
    116         else {
    117                 echo "Reusing previously constructed message"
    118         }
    119         return EmailMessage;
    120 }
    121 
    122118return this;
  • Jenkinsfile

    r660665f r5a46e09  
    77//===========================================================================================================
    88
    9 // Globals
    10 BuildDir  = null
    11 SrcDir    = null
    12 Settings  = null
    13 Tools     = null
    14 
    15 // Local variables
    16 def err = null
    17 def log_needed = false
    18 
    19 currentBuild.result = "SUCCESS"
    20 
    21 try {
    22         node {
     9node('master') {
     10        // Globals
     11        BuildDir  = pwd tmp: true
     12        SrcDir    = pwd tmp: false
     13        Settings  = null
     14        Tools     = null
     15
     16        // Local variables
     17        def err = null
     18        def log_needed = false
     19
     20        currentBuild.result = "SUCCESS"
     21
     22        try {
    2323                //Wrap build to add timestamp to command line
    2424                wrap([$class: 'TimestamperBuildWrapper']) {
     25
    2526                        Settings = prepare_build()
    26                 }
    27         }
    28 
    29         node(Settings.Architecture.node) {
    30                 //Wrap build to add timestamp to command line
    31                 wrap([$class: 'TimestamperBuildWrapper']) {
     27
     28                        node(Settings.Architecture.node) {
     29                                BuildDir  = pwd tmp: true
     30                                SrcDir    = pwd tmp: false
     31                                currentBuild.description = "${currentBuild.description} on ${env.NODE_NAME}"
     32
     33                                Tools.Clean()
     34
     35                                Tools.Checkout()
     36
     37                                build()
     38
     39                                test()
     40
     41                                benchmark()
     42
     43                                build_doc()
     44
     45                                publish()
     46                        }
     47
     48                        // Update the build directories when exiting the node
    3249                        BuildDir  = pwd tmp: true
    3350                        SrcDir    = pwd tmp: false
    34                         currentBuild.description = "${currentBuild.description} on ${env.NODE_NAME}"
    35 
    36                         Tools.Clean()
    37 
    38                         Tools.Checkout()
    39 
    40                         build()
    41 
    42                         test()
    43 
    44                         benchmark()
    45 
    46                         build_doc()
    47 
    48                         publish()
    49                 }
    50         }
    51 }
    52 
    53 //If an exception is caught we need to change the status and remember to
    54 //attach the build log to the email
    55 catch (Exception caughtError) {
    56         // Store the result of the build log
    57         currentBuild.result = "FAILURE"
    58 
    59         // An error has occured, the build log is relevent
    60         log_needed = true
    61 
    62         // rethrow error later
    63         err = caughtError
    64 
    65         // print the error so it shows in the log
    66         echo err.toString()
    67 }
    68 
    69 finally {
    70         //Send email with final results if this is not a full build
    71         email(log_needed)
    72 
    73         echo 'Build Completed'
    74 
    75         /* Must re-throw exception to propagate error */
    76         if (err) {
    77                 throw err
     51                }
     52        }
     53
     54        //If an exception is caught we need to change the status and remember to
     55        //attach the build log to the email
     56        catch (Exception caughtError) {
     57                // Store the result of the build log
     58                currentBuild.result = "FAILURE"
     59
     60                // An error has occured, the build log is relevent
     61                log_needed = true
     62
     63                // rethrow error later
     64                err = caughtError
     65
     66                // print the error so it shows in the log
     67                echo err.toString()
     68        }
     69
     70        finally {
     71                //Send email with final results if this is not a full build
     72                email(log_needed)
     73
     74                echo 'Build Completed'
     75
     76                /* Must re-throw exception to propagate error */
     77                if (err) {
     78                        throw err
     79                }
    7880        }
    7981}
     
    226228//Standard build email notification
    227229def email(boolean log) {
    228         node {
    229                 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
    230                 //Configurations for email format
    231                 echo 'Notifying users of result'
    232 
    233                 def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
    234                 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}] - branch ${env.BRANCH_NAME}"
    235                 def email_body = """<p>This is an automated email from the Jenkins build machine. It was
     230        //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
     231        //Configurations for email format
     232        echo 'Notifying users of result'
     233
     234        def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
     235        def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}] - branch ${env.BRANCH_NAME}"
     236        def email_body = """<p>This is an automated email from the Jenkins build machine. It was
    236237generated because of a git hooks/post-receive script following
    237238a ref change which was pushed to the C\u2200 repository.</p>
    238 
    239 <p>- Status --------------------------------------------------------------</p>
    240 
    241 <p>BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}</p>
    242 <p>Check console output at ${env.BUILD_URL} to view the results.</p>
    243239""" + Tools.GitLogMessage()
    244240
    245                 def email_to = !Settings.IsSandbox ? "cforall@lists.uwaterloo.ca" : "tdelisle@uwaterloo.ca"
    246 
    247                 if( Settings && !Settings.Silent ) {
    248                         //send email notification
    249                         emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
    250                 } else {
    251                         echo "Would send email to: ${email_to}"
    252                         echo "With title: ${email_subject}"
    253                         echo "Content: \n${email_body}"
    254                 }
     241        def email_to = !Settings.IsSandbox ? "cforall@lists.uwaterloo.ca" : "tdelisle@uwaterloo.ca"
     242
     243        if( Settings && !Settings.Silent ) {
     244                //send email notification
     245                emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
     246        } else {
     247                echo "Would send email to: ${email_to}"
     248                echo "With title: ${email_subject}"
     249                echo "Content: \n${email_body}"
    255250        }
    256251}
     
    305300        BuildSettings(java.util.Collections$UnmodifiableMap param, String branch) {
    306301                switch( param.Compiler ) {
    307                         case 'gcc-11':
    308                                 this.Compiler = new CC_Desc('gcc-11', 'g++-11', 'gcc-11', '-flto=auto')
    309                         break
    310                         case 'gcc-10':
    311                                 this.Compiler = new CC_Desc('gcc-10', 'g++-10', 'gcc-10', '-flto=auto')
    312                         break
    313302                        case 'gcc-9':
    314303                                this.Compiler = new CC_Desc('gcc-9', 'g++-9', 'gcc-9', '-flto=auto')
     
    330319                        break
    331320                        case 'clang':
    332                                 this.Compiler = new CC_Desc('clang', 'clang++-10', 'gcc-10', '-flto=thin -flto-jobs=0')
     321                                this.Compiler = new CC_Desc('clang', 'clang++-10', 'gcc-9', '-flto=thin -flto-jobs=0')
    333322                        break
    334323                        default :
     
    401390                                        description: 'Which compiler to use',                                   \
    402391                                        name: 'Compiler',                                                                       \
    403                                         choices: 'gcc-11\ngcc-10\ngcc-9\ngcc-8\ngcc-7\ngcc-6\ngcc-5\ngcc-4.9\nclang',   \
     392                                        choices: 'gcc-9\ngcc-8\ngcc-7\ngcc-6\ngcc-5\ngcc-4.9\nclang',   \
    404393                                        defaultValue: 'gcc-8',                                                          \
    405394                                ],                                                                                              \
  • README

    r660665f r5a46e09  
    1 cfa-cc: Cforall to C Trans-compiler
     1cfa-cc: The Cforall->C Compiler System
    22======================================
    33
     
    66responsibility for the consequences of any malfunction of the software,
    77including the malfunction of any programs compiled using the software.
    8 
    98
    109What is Cforall?
     
    2625into a modern programming language.
    2726
    28 
    2927What is cfa-cc?
    3028---------------
    31 cfa-cc is a collection of programs centred around a translator (trans-compiler)
    32 that takes Cforall code as input and outputs augmented C code that implements
    33 new features.  The translator is complemented by a compiler driver in the style
    34 of "gcc", which handles preprocessing (including cfa-cc after cpp), compiling,
    35 assembling, and linking.
     29cfa-cc is a collection of programs centred around a translator that takes
     30Cforall code as input and outputs corresponding C code.  This is complemented
     31by a compiler driver in the style of "gcc", which handles preprocessing,
     32compiling, assembling, and linking and invokes the translator at appropriate
     33moments.
    3634
    37 cfa-cc is currently written in C++, but will be eventually rewritten in Cforall.
     35What is required in order to use cfa-cc?
     36----------------------------------------
     37Building cfa-cc requires GNU Make and gcc/g++ 4.  cfa-cc is written in C++.
    3838
     39The compiler driver uses an installed version of gcc to handle all aspects of
     40the compilation process except for the Cforall->C translation.  Currently, only
     41gcc 4.x is supported.
    3942
    40 How to download and build cfa-cc?
    41 ----------------------------------------
    42 Download cfa-cc using
    43 
    44   $ git clone https://github.com/cforall/cforall.git
    45 
    46 Read the ./INSTALL file for build instructions.
    47 
    48 
    49 How to use cfa-cc?
     43How is cfa-cc used?
    5044-------------------
    51 The compiler driver "cfa" accepts all of the arguments for gcc, and is used in
     45The compiler driver "cfa" accepts all of the arguments of gcc, and is used in
    5246the same way.  For example:
    5347
    54   cfa -c test.c
    55   cfa test.o
     48        cfa -c test.c
     49        cfa test.o
    5650
    57 Cforall source files may end with '.c' or '.cfa' in order to be compiled by the
    58 compiler driver.  In addition, the flag "-CFA" causes cfa to invoke the C
    59 preprocessor and Cforall translator and write the translator output to standard
    60 output.
     51Cforall source files must end with '.c' in order to be compiled by the compiler
     52driver.  In addition, the flag "-CFA" causes cfa to invoke the preprocessor and
     53translator and send the translator output to standard output.
    6154
     55It is possible to invoke the translator directly.  The translator is installed
     56by default as /usr/local/lib/cfa-cpp.  A typical invocation is:
    6257
    63 How to use C code with cfa-cc?
     58        /usr/local/lib/cfa-cpp -cp infile outfile
     59
     60If outfile is omitted, output goes to standard output; if infile is also
     61omitted, input comes from standard input.  Options to the translator other than
     62"-cp" will not produce valid C code and are only useful for debugging the
     63translator.
     64
     65How can C code be used with cfa-cc?
    6466-----------------------------------
    65 cfa-cc should be able to compile and link most ANSI C programs with associated
    66 C standard libraries.
     67cfa-cc should be able to compile most ANSI C programs.  It is also possible to
     68link against C libraries in most cases.  Since Cforall supports overloading,
     69however, names used in Cforall code are mangled in the output C code.  This
     70caused linker failures when the names refer to functions and objects in code
     71compiled with a standard C compiler.  For this reason, it is necessary to
     72enclose the declarations of these functions and objects in extern "C" {}
     73blocks.  For example:
    6774
    68 Like C++, Cforall supports overloading, resulting in duplicate names that are
    69 disambiguated using name mangling in the translated C code.  To prevent
    70 mangling of C names, it is necessary to wrap C declarations in an extern "C"
    71 block, as for C++.  For example:
    72 
    73   extern "C" {
    74   #include <curses.h>
    75   #include <getopt.h>
    76   }
     75        extern "C" {
     76        #include <stdio.h>
     77        #include <stdlib.h>
     78        }
    7779
    7880The extern "C" turns off name mangling for functions and objects declared
    79 within the block. All C standard headers are pre-wrapped, so most wrapping is
    80 unnecessary.
    81 
     81within the block.  As a result, it is not possible to overload their names.
    8282
    8383What's wrong with cfa-cc?
    8484-------------------------
    8585
    86 The authors consider cfa-cc to be in a semi-stable state.  It is possible for
    87 reasonable Cforall programs to fail compilation.  A list of bugs and fixes is
    88 available here: https://cforall.uwaterloo.ca/trac.  We encourage users to
    89 report their experiences to cforall@plg.uwaterloo.ca, but we can make no
    90 promises regarding support.
     86The authors consider this software to be in an unstable state.  It is quite
     87likely that there are many reasonable programs that will fail to compile.  We
     88encourage users to report their experiences to cforall@plg.uwaterloo.ca, but we
     89make no promises regarding support.
    9190
    92 Also, the Cforall features web-page https://cforall.uwaterloo.ca/features lists
    93 small syntactic and semantic differences with standard C.
     91We have fixed most of the problems that we are aware of.  There are some
     92exceptions:
    9493
     94- initializers are poorly implemented; in particular, file-scope initializers
     95  may result in the generation of invalid C code
     96
     97- the ISO C99 designated initialization syntax '[n] = m' or '.n = m' is not
     98  supported; use a colon in place of the equal sign
     99
     100- some legitimate programs will produce warnings from the C compiler; these are
     101  harmless (in particular, the creation of libcfa.a in the build process should
     102  cause four warnings from gcc)
     103
     104- abstract types introduced using the keyword 'type' are not implemented
     105  (although 'type' can be used to introduce type parameters)
     106
     107- the implicit coercion of structure types to the type of their first member is
     108  not implemented
    95109
    96110Who is responsible for cfa-cc?
    97111------------------------------
    98 Cforall was designed and implemented by Andrew Beach, Richard Bilson, Michael
    99 Brooks, Peter A. Buhr, Thierry Delisle Glen Ditchfield, Rodolfo G. Esteves,
    100 Aaron Moss, Colby Parsons, Rob Schluntz, Fangren Yu, Mubeen Zulfiqar, and others.
     112cfa-cc was written by Peter Buhr, Richard Bilson, and Rodolfo Esteves.
     113Questions and comments can be sent to cforall@plg.uwaterloo.ca.
    101114
    102 Check the Cforall web site https://cforall.uwaterloo.ca for news and updates.
     115The Cforall project maintains a web page:
     116
     117        https://cforall.uwaterloo.ca
  • benchmark/io/io_uring.h

    r660665f r5a46e09  
    11extern "C" {
     2        #ifndef _GNU_SOURCE         /* See feature_test_macros(7) */
     3        #define _GNU_SOURCE         /* See feature_test_macros(7) */
     4        #endif
    25        #include <errno.h>
    36        #include <stdio.h>
  • doc/bibliography/pl.bib

    r660665f r5a46e09  
    16731673    address     = {Waterloo Ontario, Canada},
    16741674    month       = sep,
    1675     year        = 2020,
     1675    year        = 2018,
    16761676    note        = {\href{https://plg.uwaterloo.ca/~usystem/pub/uSystem/uC++.pdf}{https://\-plg.uwaterloo.ca/\-$\sim$usystem/\-pub/\-uSystem/uC++.pdf}},
    16771677}
     
    45524552    author      = {Martin Karsten},
    45534553    title       = {{libfibre:~User-Level Threading Runtime}},
    4554     howpublished= {\href{https://git.uwaterloo.ca/mkarsten/libfibre}{https://\-git.uwaterloo.ca/\-mkarsten/\-libfibre}},
     4554    howpublished= {\href{https://git.uwaterloo.ca/mkarsten/libfibre}
     4555                  {https://\-git.uwaterloo.ca/\-mkarsten/\-libfibre}},
    45554556    note        = {[Online; accessed 2020-04-15]},
    45564557}
  • doc/theses/andrew_beach_MMath/cfalab.sty

    r660665f r5a46e09  
    143143}
    144144
    145 % These somehow control how much of a page can be a floating element before
    146 % the float is forced onto its own page.   
    147 \renewcommand{\topfraction}{0.8}
    148 \renewcommand{\bottomfraction}{0.8}
    149 \renewcommand{\floatpagefraction}{0.8}
    150 % Sort of the reverse, I think it is the minimum amount of text that can
    151 % be on a page before its all removed. (0 for always fix what you can.)
    152 \renewcommand{\textfraction}{0.0}
    153 
    154145% common.tex Compatablity ===================================================
    155146% Below this line is for compatability with the old common.tex file.
  • doc/theses/andrew_beach_MMath/existing.tex

    r660665f r5a46e09  
    1 \chapter{\CFA{} Existing Features}
     1\chapter{\CFA Existing Features}
    22\label{c:existing}
    33
     
    99existing C code-base allowing programmers to learn \CFA on an as-needed basis.
    1010
    11 Only those \CFA features pertaining to this thesis are discussed.
    12 Also, only new features of \CFA will be discussed, a familiarity with
    13 C or C-like languages is assumed.
     11Only those \CFA features pertaining to this thesis are discussed.  Many of the
     12\CFA syntactic and semantic features used in the thesis should be fairly
     13obvious to the reader.
    1414
    1515\section{Overloading and \lstinline{extern}}
     
    2929// name mangling on by default
    3030int i; // _X1ii_1
    31 extern "C" {  // disables name mangling
     31@extern "C"@ {  // disables name mangling
    3232        int j; // j
    33         extern "Cforall" {  // enables name mangling
     33        @extern "Cforall"@ {  // enables name mangling
    3434                int k; // _X1ki_1
    3535        }
     
    4747Reference-types are written the same way as a pointer-type but each
    4848asterisk (@*@) is replaced with a ampersand (@&@);
    49 this includes cv-qualifiers and multiple levels of reference.
    50 
    51 Generally, references act like pointers with an implicate dereferencing
    52 operation added to each use of the variable.
    53 These automatic dereferences may be disabled with the address-of operator
    54 (@&@).
    55 
    56 % Check to see if these are generating errors.
     49this includes cv-qualifiers and multiple levels of reference, \eg:
     50
    5751\begin{minipage}{0,5\textwidth}
    5852With references:
     
    6256int && rri = ri;
    6357rri = 3;
    64 &ri = &j;
     58&ri = &j; // reference assignment
    6559ri = 5;
    6660\end{cfa}
     
    7367int ** ppi = &pi;
    7468**ppi = 3;
    75 pi = &j;
     69pi = &j; // pointer assignment
    7670*pi = 5;
    7771\end{cfa}
    7872\end{minipage}
    7973
    80 References are intended to be used when you would use pointers but would
     74References are intended for cases where you would want to use pointers but would
    8175be dereferencing them (almost) every usage.
    82 Mutable references may be assigned to by converting them to a pointer
    83 with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above
     76In most cases a reference can just be thought of as a pointer that
     77automatically puts a dereference in front of each of its uses (per-level of
     78reference).
     79The address-of operator (@&@) acts as an escape and removes one of the
     80automatic dereference operations.
     81Mutable references may be assigned by converting them to a pointer
     82with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above.
    8483
    8584\section{Operators}
    8685
    87 \CFA implements operator overloading by providing special names.
    88 Operator uses are translated into function calls using these names.
    89 These names are created by taking the operator symbols and joining them with
    90 @?@s to show where the arguments go.
    91 For example,
     86In general, operator names in \CFA are constructed by bracketing an operator
     87token with @?@, which indicates the position of the arguments. For example,
    9288infixed multiplication is @?*?@ while prefix dereference is @*?@.
    9389This syntax make it easy to tell the difference between prefix operations
    9490(such as @++?@) and post-fix operations (@?++@).
    9591
    96 \begin{cfa}
    97 point ?+?(point a, point b) { return point{a.x + b.x, a.y + b.y}; }
    98 bool ?==?(point a, point b) { return a.x == b.x && a.y == b.y; }
    99 {
    100         assert(point{1, 2} + point{3, 4} == point{4, 6});
    101 }
    102 \end{cfa}
    103 Note that these special names are not limited to just being used for these
    104 operator functions, and may be used name other declarations.
    105 Some ``near misses", that will not match an operator form but looks like
    106 it may have been supposed to, will generate wantings but otherwise they are
    107 left alone.
    108 
    109 %\subsection{Constructors and Destructors}
     92An operator name may describe any function signature (it is just a name) but
     93only certain signatures may be called in operator form.
     94\begin{cfa}
     95int ?+?( int i, int j, int k ) { return i + j + k; }
     96{
     97        sout | ?+?( 3, 4, 5 ); // no infix form
     98}
     99\end{cfa}
     100Some ``near-misses" for unary/binary operator prototypes generate warnings.
    110101
    111102Both constructors and destructors are operators, which means they are
    112103functions with special operator names rather than type names in \Cpp. The
    113 special operator names may be used to call the functions explicitly.
    114 % Placement new means that this is actually equivant to C++.
    115 
    116 The special name for a constructor is @?{}@, which comes from the
    117 initialization syntax in C, \eg @Example e = { ... }@.
    118 \CFA will generate a constructor call each time a variable is declared,
    119 passing the initialization arguments to the constructort.
    120 \begin{cfa}
    121 struct Example { ... };
    122 void ?{}(Example & this) { ... }
    123 {
    124         Example a;
    125         Example b = {};
    126 }
    127 void ?{}(Example & this, char first, int num) { ... }
    128 {
    129         Example c = {'a', 2};
    130 }
    131 \end{cfa}
    132 Both @a@ and @b@ will be initalized with the first constructor,
    133 while @c@ will be initalized with the second.
    134 Currently, there is no general way to skip initialation.
     104special operator names may be used to call the functions explicitly (not
     105allowed in \Cpp for constructors).
     106
     107The special name for a constructor is @?{}@, where the name @{}@ comes from the
     108initialization syntax in C, \eg @Structure s = {...}@.
     109% That initialization syntax is also the operator form.
     110\CFA generates a constructor call each time a variable is declared,
     111passing the initialization arguments to the constructor.
     112\begin{cfa}
     113struct Structure { ... };
     114void ?{}(Structure & this) { ... }
     115{
     116        Structure a;
     117        Structure b = {};
     118}
     119void ?{}(Structure & this, char first, int num) { ... }
     120{
     121        Structure c = {'a', 2};
     122}
     123\end{cfa}
     124Both @a@ and @b@ are initialized with the first constructor,
     125while @c@ is initialized with the second.
     126Currently, there is no general way to skip initialization.
    135127
    136128% I don't like the \^{} symbol but $^\wedge$ isn't better.
    137 Similarly destructors use the special name @^?{}@ (the @^@ has no special
    138 meaning).
    139 These are a normally called implicitly called on a variable when it goes out
    140 of scope. They can be called explicitly as well.
    141 \begin{cfa}
    142 void ^?{}(Example & this) { ... }
    143 {
    144         Example d;
     129Similarly, destructors use the special name @^?{}@ (the @^@ has no special
     130meaning).  Normally, they are implicitly called on a variable when it goes out
     131of scope but they can be called explicitly as well.
     132\begin{cfa}
     133void ^?{}(Structure & this) { ... }
     134{
     135        Structure d;
    145136} // <- implicit destructor call
    146137\end{cfa}
    147138
    148 Whenever a type is defined, \CFA will create a default zero-argument
     139Whenever a type is defined, \CFA creates a default zero-argument
    149140constructor, a copy constructor, a series of argument-per-field constructors
    150141and a destructor. All user constructors are defined after this.
     
    207198void do_once(double y) { ... }
    208199int quadruple(int x) {
    209         void do_once(int & y) { y = y * 2; }
    210         do_twice(x);
     200        void do_once(int y) { y = y * 2; } // replace global do_once
     201        do_twice(x); // use local do_once
     202        do_twice(x + 1.5); // use global do_once
    211203        return x;
    212204}
    213205\end{cfa}
    214206Specifically, the complier deduces that @do_twice@'s T is an integer from the
    215 argument @x@. It then looks for the most specific definition matching the
     207argument @x@. It then looks for the most \emph{specific} definition matching the
    216208assertion, which is the nested integral @do_once@ defined within the
    217209function. The matched assertion function is then passed as a function pointer
    218 to @do_twice@ and called within it.
    219 The global definition of @do_once@ is ignored, however if quadruple took a
    220 @double@ argument then the global definition would be used instead as it
    221 would be a better match.
    222 % Aaron's thesis might be a good reference here.
     210to @do_twice@ and called within it.  The global definition of @do_once@ is used
     211for the second call because the float-point argument is a better match.
    223212
    224213To avoid typing long lists of assertions, constraints can be collect into
     
    290279Each coroutine has a @main@ function, which takes a reference to a coroutine
    291280object and returns @void@.
    292 %[numbers=left] Why numbers on this one?
    293 \begin{cfa}
     281\begin{cfa}[numbers=left]
    294282void main(CountUp & this) {
    295283        for (unsigned int next = 0 ; true ; ++next) {
  • doc/theses/andrew_beach_MMath/features.tex

    r660665f r5a46e09  
    22\label{c:features}
    33
    4 This chapter covers the design and user interface of the \CFA EHM
     4This chapter covers the design and user interface of the \CFA
     5EHM, % or exception system.
    56and begins with a general overview of EHMs. It is not a strict
    67definition of all EHMs nor an exhaustive list of all possible features.
    7 However it does cover the most common structure and features found in them.
    8 
    9 \section{Overview of EHMs}
     8However it does cover the most common structures and features found in them.
     9
    1010% We should cover what is an exception handling mechanism and what is an
    1111% exception before this. Probably in the introduction. Some of this could
    1212% move there.
    13 \subsection{Raise / Handle}
     13\section{Raise / Handle}
    1414An exception operation has two main parts: raise and handle.
    15 These terms are sometimes known as throw and catch but this work uses
     15These terms are sometimes also known as throw and catch but this work uses
    1616throw/catch as a particular kind of raise/handle.
    1717These are the two parts that the user writes and may
     
    2424
    2525Some well known examples include the @throw@ statements of \Cpp and Java and
    26 the \code{Python}{raise} statement from Python. In real systems a raise may
    27 preform some other work (such as memory management) but for the
     26the \code{Python}{raise} statement from Python. A raise may
     27perform some other work (such as memory management) but for the
    2828purposes of this overview that can be ignored.
    2929
     
    3333
    3434A handler has three common features: the previously mentioned user code, a
    35 region of code they guard and an exception label/condition that matches
     35region of code they guard, and an exception label/condition that matches
    3636certain exceptions.
    3737Only raises inside the guarded region and raising exceptions that match the
    3838label can be handled by a given handler.
    39 If multiple handlers could can handle an exception,
    40 EHMs will define a rule to pick one, such as ``best match" or ``first found".
     39Different EHMs have different rules to pick a handler,
     40if multiple handlers could be used, such as ``best match" or ``first found".
    4141
    4242The @try@ statements of \Cpp, Java and Python are common examples. All three
     
    4444region.
    4545
    46 \subsection{Propagation}
     46\section{Propagation}
    4747After an exception is raised comes what is usually the biggest step for the
    4848EHM: finding and setting up the handler. The propagation from raise to
    4949handler can be broken up into three different tasks: searching for a handler,
    50 matching against the handler and installing the handler.
     50matching against the handler, and installing the handler.
    5151
    5252\paragraph{Searching}
     
    5555thrown as it looks for handlers that have the raise site in their guarded
    5656region.
    57 The search includes handlers in the current function, as well as any in
    58 callers on the stack that have the function call in their guarded region.
     57This search includes handlers in the current function, as well as any in callers
     58on the stack that have the function call in their guarded region.
    5959
    6060\paragraph{Matching}
    6161Each handler found has to be matched with the raised exception. The exception
    62 label defines a condition that is used with exception and decides if
     62label defines a condition that is used with the exception to decide if
    6363there is a match or not.
    6464
    6565In languages where the first match is used, this step is intertwined with
    66 searching; a match check is preformed immediately after the search finds
     66searching: a match check is performed immediately after the search finds
    6767a possible handler.
    6868
    69 \paragraph{Installing}
     69\section{Installing}
    7070After a handler is chosen it must be made ready to run.
    7171The implementation can vary widely to fit with the rest of the
     
    7474case when stack unwinding is involved.
    7575
    76 If a matching handler is not guaranteed to be found, the EHM needs a
     76If a matching handler is not guarantied to be found, the EHM needs a
    7777different course of action for the case where no handler matches.
    7878This situation only occurs with unchecked exceptions as checked exceptions
    7979(such as in Java) can make the guarantee.
    80 This unhandled action is usually very general, such as aborting the program.
     80This unhandled action can abort the program or install a very general handler.
    8181
    8282\paragraph{Hierarchy}
    8383A common way to organize exceptions is in a hierarchical structure.
    84 This pattern comes from object-orientated languages where the
     84This organization is often used in object-orientated languages where the
    8585exception hierarchy is a natural extension of the object hierarchy.
    8686
     
    9090\end{center}
    9191
    92 A handler labeled with any given exception can handle exceptions of that
     92A handler labelled with any given exception can handle exceptions of that
    9393type or any child type of that exception. The root of the exception hierarchy
    9494(here \code{C}{exception}) acts as a catch-all, leaf types catch single types
     
    104104% Could I cite the rational for the Python IO exception rework?
    105105
    106 \subsection{Completion}
    107 After the handler has finished, the entire exception operation has to complete
     106\paragraph{Completion}
     107After the handler has finished the entire exception operation has to complete
    108108and continue executing somewhere else. This step is usually simple,
    109109both logically and in its implementation, as the installation of the handler
     
    111111
    112112The EHM can return control to many different places,
    113 the most common are after the handler definition (termination)
    114 and after the raise (resumption).
    115 
    116 \subsection{Communication}
     113the most common are after the handler definition (termination) and after the raise (resumption).
     114
     115\paragraph{Communication}
    117116For effective exception handling, additional information is often passed
    118117from the raise to the handler and back again.
    119118So far only communication of the exceptions' identity has been covered.
    120 A common communication method is putting fields into the exception instance
    121 and giving the handler access to them.
    122 Passing the exception by reference instead of by value can allow data to be
    123 passed in both directions.
     119A common communication method is putting fields into the exception instance and giving the
     120handler access to them. References in the exception instance can push data back to the raise.
    124121
    125122\section{Virtuals}
    126123Virtual types and casts are not part of \CFA's EHM nor are they required for
    127124any EHM.
    128 However, it is one of the best ways to support an exception hierarchy
    129 is via a virtual hierarchy and dispatch system.
     125However, one of the best ways to support an exception hierarchy is via a virtual system
     126among exceptions and used for exception matching.
    130127
    131128Ideally, the virtual system would have been part of \CFA before the work
    132129on exception handling began, but unfortunately it was not.
    133 Hence, only the features and framework needed for the EHM were
     130Therefore, only the features and framework needed for the EHM were
    134131designed and implemented. Other features were considered to ensure that
    135 the structure could accommodate other desirable features in the future
    136 but they were not implemented.
    137 The rest of this section will only discuss the implemented subset of the
    138 virtual system design.
     132the structure could accommodate other desirable features in the future but they were not
     133implemented.
     134The rest of this section discusses the implemented subset of the
     135virtual-system design.
    139136
    140137The virtual system supports multiple ``trees" of types. Each tree is
     
    146143% A type's ancestors are its parent and its parent's ancestors.
    147144% The root type has no ancestors.
    148 % A type's descendants are its children and its children's descendants.
     145% A type's decedents are its children and its children's decedents.
    149146
    150147Every virtual type also has a list of virtual members. Children inherit
     
    153150of object-orientated programming, and can be of any type.
    154151
     152\PAB{I do not understand these sentences. Can you add an example? $\Rightarrow$
    155153\CFA still supports virtual methods as a special case of virtual members.
    156154Function pointers that take a pointer to the virtual type are modified
    157155with each level of inheritance so that refers to the new type.
    158156This means an object can always be passed to a function in its virtual table
    159 as if it were a method.
    160 \todo{Clarify (with an example) virtual methods.}
     157as if it were a method.}
    161158
    162159Each virtual type has a unique id.
     
    164161into a virtual table type. Each virtual type has a pointer to a virtual table
    165162as a hidden field.
    166 \todo{Might need a diagram for virtual structure.}
     163
     164\PAB{God forbid, maybe you need a UML diagram to relate these entities.}
    167165
    168166Up until this point the virtual system is similar to ones found in
     
    175173types can begin to satisfy a trait, stop satisfying a trait or satisfy the same
    176174trait in a different way at any lexical location in the program.
    177 In this sense, they are ``open" as they can change at any time.
    178 This capability means it is impossible to pick a single set of functions
    179 that represent the type's implementation across the program.
     175In this sense, they are ``open" as they can change at any time. This capability means it
     176is impossible to pick a single set of functions that represent the type's
     177implementation across the program.
    180178
    181179\CFA side-steps this issue by not having a single virtual table for each
    182180type. A user can define virtual tables that are filled in at their
    183 declaration and given a name. Anywhere that name is visible, even if it is
     181declaration and given a name. Anywhere that name is visible, even if
    184182defined locally inside a function (although that means it does not have a
    185183static lifetime), it can be used.
     
    188186through the object.
    189187
     188\PAB{The above explanation is very good!}
     189
    190190While much of the virtual infrastructure is created, it is currently only used
    191191internally for exception handling. The only user-level feature is the virtual
    192 cast, which is the same as the \Cpp \code{C++}{dynamic_cast}.
     192cast
    193193\label{p:VirtualCast}
    194194\begin{cfa}
    195195(virtual TYPE)EXPRESSION
    196196\end{cfa}
     197which is the same as the \Cpp \code{C++}{dynamic_cast}.
    197198Note, the syntax and semantics matches a C-cast, rather than the function-like
    198199\Cpp syntax for special casts. Both the type of @EXPRESSION@ and @TYPE@ must be
     
    217218The trait is defined over two types, the exception type and the virtual table
    218219type. Each exception type should have a single virtual table type.
    219 There are no actual assertions in this trait because the trait system
    220 cannot express them yet (adding such assertions would be part of
     220There are no actual assertions in this trait because currently the trait system
     221cannot express them (adding such assertions would be part of
    221222completing the virtual system). The imaginary assertions would probably come
    222223from a trait defined by the virtual system, and state that the exception type
    223 is a virtual type, is a descendant of @exception_t@ (the base exception type)
     224is a virtual type, is a descendent of @exception_t@ (the base exception type)
    224225and note its virtual table type.
    225226
     
    240241};
    241242\end{cfa}
    242 Both traits ensure a pair of types are an exception type, its virtual table
    243 type
     243Both traits ensure a pair of types are an exception type and its virtual table,
    244244and defines one of the two default handlers. The default handlers are used
    245245as fallbacks and are discussed in detail in \vref{s:ExceptionHandling}.
     
    269269\section{Exception Handling}
    270270\label{s:ExceptionHandling}
    271 As stated,
    272 \CFA provides two kinds of exception handling: termination and resumption.
     271As stated, \CFA provides two kinds of exception handling: termination and resumption.
    273272These twin operations are the core of \CFA's exception handling mechanism.
    274 This section will cover the general patterns shared by the two operations and
    275 then go on to cover the details each individual operation.
     273This section covers the general patterns shared by the two operations and
     274then go on to cover the details of each individual operation.
    276275
    277276Both operations follow the same set of steps.
    278 Both start with the user preforming a raise on an exception.
     277Both start with the user performing a raise on an exception.
    279278Then the exception propagates up the stack.
    280279If a handler is found the exception is caught and the handler is run.
    281 After that control continues at a raise-dependent location.
    282 If the search fails a default handler is run and, if it returns, then control
    283 continues after the raise.
     280After that control returns to a point specific to the kind of exception.
     281If the search fails a default handler is run, and if it returns, control
     282continues after the raise. Note, the default handler may further change control flow rather than return.
    284283
    285284This general description covers what the two kinds have in common.
    286 Differences include how propagation is preformed, where exception continues
     285Differences include how propagation is performed, where exception continues
    287286after an exception is caught and handled and which default handler is run.
    288287
    289288\subsection{Termination}
    290289\label{s:Termination}
     290
    291291Termination handling is the familiar kind and used in most programming
    292292languages with exception handling.
     
    313313
    314314The throw copies the provided exception into managed memory to ensure
    315 the exception is not destroyed if the stack is unwound.
     315the exception is not destroyed when the stack is unwound.
    316316It is the user's responsibility to ensure the original exception is cleaned
    317317up whether the stack is unwound or not. Allocating it on the stack is
    318318usually sufficient.
    319319
    320 % How to say propagation starts, its first sub-step is the search.
    321 Then propagation starts with the search. \CFA uses a ``first match" rule so
    322 matching is preformed with the copied exception as the search continues.
    323 It starts from the throwing function and proceeds towards base of the stack,
     320Then propagation starts the search. \CFA uses a ``first match" rule so
     321matching is performed with the copied exception as the search continues.
     322It starts from the throwing function and proceeds towards the base of the stack,
    324323from callee to caller.
    325324At each stack frame, a check is made for resumption handlers defined by the
     
    335334\end{cfa}
    336335When viewed on its own, a try statement simply executes the statements
    337 in \snake{GUARDED_BLOCK} and when those are finished,
    338 the try statement finishes.
     336in \snake{GUARDED_BLOCK} and when those are finished, the try statement finishes.
    339337
    340338However, while the guarded statements are being executed, including any
    341 invoked functions, all the handlers in these statements are included in the
    342 search path.
    343 Hence, if a termination exception is raised these handlers may be matched
    344 against the exception and may handle it.
     339invoked functions, all the handlers in these statements are included on the search
     340path. Hence, if a termination exception is raised, the search includes the added handlers associated with the guarded block and those further up the
     341stack from the guarded block.
    345342
    346343Exception matching checks the handler in each catch clause in the order
    347344they appear, top to bottom. If the representation of the raised exception type
    348345is the same or a descendant of @EXCEPTION_TYPE@$_i$ then @NAME@$_i$
    349 (if provided) is
    350 bound to a pointer to the exception and the statements in @HANDLER_BLOCK@$_i$
    351 are executed. If control reaches the end of the handler, the exception is
     346(if provided) is bound to a pointer to the exception and the statements in
     347@HANDLER_BLOCK@$_i$ are executed.
     348If control reaches the end of the handler, the exception is
    352349freed and control continues after the try statement.
    353350
    354 If no termination handler is found during the search then the default handler
    355 (\defaultTerminationHandler) visible at the raise statement is run.
    356 Through \CFA's trait system the best match at the raise statement will be used.
    357 This function is run and is passed the copied exception.
    358 If the default handler is run control continues after the raise statement.
     351If no termination handler is found during the search, the default handler
     352(\defaultTerminationHandler) visible at the raise statement is called.
     353Through \CFA's trait system, the best match at the raise sight is used.
     354This function is run and is passed the copied exception. If the default
     355handler returns, control continues after the throw statement.
    359356
    360357There is a global @defaultTerminationHandler@ that is polymorphic over all
    361 termination exception types.
    362 Since it is so general a more specific handler can be
     358termination exception types. Since it is so general, a more specific handler can be
    363359defined and is used for those types, effectively overriding the handler
    364360for a particular exception type.
     
    374370matched a closure is taken from up the stack and executed,
    375371after which the raising function continues executing.
    376 The common uses for resumption exceptions include
    377 potentially repairable errors, where execution can continue in the same
    378 function once the error is corrected, and
    379 ignorable events, such as logging where nothing needs to happen and control
    380 should always continue from the same place.
     372These are most often used when a potentially repairable error occurs, some handler is found on the stack to fix it, and
     373the raising function can continue with the correction.
     374Another common usage is dynamic event analysis, \eg logging, without disrupting control flow.
     375Note, if an event is raised and there is no interest, control continues normally.
     376
     377\PAB{We also have \lstinline{report} instead of \lstinline{throwResume}, \lstinline{recover} instead of \lstinline{catch}, and \lstinline{fixup} instead of \lstinline{catchResume}.
     378You may or may not want to mention it. You can still stick with \lstinline{catch} and \lstinline{throw/catchResume} in the thesis.}
    381379
    382380A resumption raise is started with the @throwResume@ statement:
     
    384382throwResume EXPRESSION;
    385383\end{cfa}
    386 \todo{Decide on a final set of keywords and use them everywhere.}
    387384It works much the same way as the termination throw.
    388385The expression must return a reference to a resumption exception,
     
    390387@is_resumption_exception@ at the call site.
    391388The assertions from this trait are available to
    392 the exception system while handling the exception.
    393 
    394 At run-time, no exception copy is made.
    395 Resumption does not unwind the stack nor otherwise remove values from the
    396 current scope, so there is no need to manage memory to keep things in scope.
    397 
    398 The EHM then begins propagation. The search starts from the raise in the
    399 resuming function and proceeds towards the base of the stack,
    400 from callee to caller.
     389the exception system, while handling the exception.
     390
     391Resumption does not need to copy the raised exception, as the stack is not unwound.
     392The exception and
     393any values on the stack remain in scope, while the resumption is handled.
     394
     395The EHM then begins propogation. The search starts from the raise in the
     396resuming function and proceeds towards the base of the stack, from callee to caller.
    401397At each stack frame, a check is made for resumption handlers defined by the
    402398@catchResume@ clauses of a @try@ statement.
     
    416412kind of raise.
    417413When a try statement is executed, it simply executes the statements in the
    418 @GUARDED_BLOCK@ and then finishes.
     414@GUARDED_BLOCK@ and then returns.
    419415
    420416However, while the guarded statements are being executed, including any
    421 invoked functions, all the handlers in these statements are included in the
    422 search path.
    423 Hence, if a resumption exception is raised these handlers may be matched
    424 against the exception and may handle it.
     417invoked functions, all the handlers in these statements are included on the search
     418path. Hence, if a resumption exception is raised the search includes the added handlers associated with the guarded block and those further up the
     419stack from the guarded block.
    425420
    426421Exception matching checks the handler in each catch clause in the order
     
    432427the raise statement that raised the handled exception.
    433428
    434 Like termination, if no resumption handler is found during the search,
    435 the default handler (\defaultResumptionHandler) visible at the raise
    436 statement is called. It will use the best match at the raise sight according
    437 to \CFA's overloading rules. The default handler is
    438 passed the exception given to the raise. When the default handler finishes
     429Like termination, if no resumption handler is found during the search, the default handler
     430(\defaultResumptionHandler) visible at the raise statement is called.
     431It uses the best match at the
     432raise sight according to \CFA's overloading rules. The default handler is
     433passed the exception given to the throw. When the default handler finishes
    439434execution continues after the raise statement.
    440435
    441 There is a global \defaultResumptionHandler{} is polymorphic over all
    442 resumption exceptions and preforms a termination throw on the exception.
    443 The \defaultTerminationHandler{} can be overridden by providing a new
    444 function that is a better match.
     436There is a global \defaultResumptionHandler{} that is polymorphic over all
     437resumption exception types and preforms a termination throw on the exception.
     438The \defaultTerminationHandler{} can be
     439customized by introducing a new or better match as well.
    445440
    446441\subsubsection{Resumption Marking}
    447442\label{s:ResumptionMarking}
     443
    448444A key difference between resumption and termination is that resumption does
    449445not unwind the stack. A side effect that is that when a handler is matched
    450 and run it's try block (the guarded statements) and every try statement
    451 searched before it are still on the stack. There presence can lead to
    452 the recursive resumption problem.
     446and run, its try block (the guarded statements) and every try statement
     447searched before it are still on the stack. Their existence can lead to the recursive
     448resumption problem.
    453449
    454450The recursive resumption problem is any situation where a resumption handler
     
    463459\end{cfa}
    464460When this code is executed, the guarded @throwResume@ starts a
    465 search and matches the handler in the @catchResume@ clause. This
    466 call is placed on the stack above the try-block. The second raise then
    467 searches the same try block and puts another instance of the
    468 same handler on the stack leading to infinite recursion.
     461search and matchs the handler in the @catchResume@ clause. This
     462call is placed on the top of stack above the try-block. The second throw
     463searchs the same try block and puts call another instance of the
     464same handler on the stack leading to an infinite recursion.
    469465
    470466While this situation is trivial and easy to avoid, much more complex cycles
    471467can form with multiple handlers and different exception types.
    472468
    473 To prevent all of these cases, a each try statement is ``marked" from the
    474 time the exception search reaches it to either when the exception is being
    475 handled completes the matching handler or when the search reaches the base
    476 of the stack.
    477 While a try statement is marked, its handlers are never matched, effectively
    478 skipping over it to the next try statement.
     469To prevent all of these cases, the exception search marks the try statements it visits.
     470A try statement is marked when a match check is preformed with it and an
     471exception. The statement is unmarked when the handling of that exception
     472is completed or the search completes without finding a handler.
     473While a try statement is marked, its handlers are never matched, effectify
     474skipping over them to the next try statement.
    479475
    480476\begin{center}
     
    482478\end{center}
    483479
    484 There are other sets of marking rules that could be used,
    485 for instance, marking just the handlers that caught the exception,
    486 would also prevent recursive resumption.
    487 However, these rules mirror what happens with termination.
    488 
    489 The try statements that are marked are the ones that would be removed from
    490 the stack if this was a termination exception, that is those on the stack
    491 between the handler and the raise statement.
    492 This symmetry applies to the default handler as well, as both kinds of
    493 default handlers are run at the raise statement, rather than (physically
    494 or logically) at the bottom of the stack.
    495 % In early development having the default handler happen after
    496 % unmarking was just more useful. We assume that will continue.
     480These rules mirror what happens with termination.
     481When a termination throw happens in a handler, the search does not look at
     482any handlers from the original throw to the original catch because that
     483part of the stack is unwound.
     484A resumption raise in the same situation wants to search the entire stack,
     485but with marking, the search does match exceptions for try statements at equivalent sections
     486that would have been unwound by termination.
     487
     488The symmetry between resumption termination is why this pattern is picked.
     489Other patterns, such as marking just the handlers that caught the exception, also work but
     490lack the symmetry, meaning there are more rules to remember.
    497491
    498492\section{Conditional Catch}
     493
    499494Both termination and resumption handler clauses can be given an additional
    500495condition to further control which exceptions they handle:
     
    509504did not match.
    510505
    511 The condition matching allows finer matching by checking
     506The condition matching allows finer matching to check
    512507more kinds of information than just the exception type.
    513508\begin{cfa}
     
    524519// Can't handle a failure relating to f2 here.
    525520\end{cfa}
    526 In this example the file that experienced the IO error is used to decide
     521In this example, the file that experianced the IO error is used to decide
    527522which handler should be run, if any at all.
    528523
     
    553548
    554549\subsection{Comparison with Reraising}
     550
    555551A more popular way to allow handlers to match in more detail is to reraise
    556552the exception after it has been caught, if it could not be handled here.
    557 On the surface these two features seem interchangeable.
    558 
    559 If @throw;@ (no argument) starts a termination reraise,
    560 which is the same as a raise but reuses the last caught exception,
    561 then these two statements have the same behaviour:
     553On the surface these two features seem interchangable.
     554
     555If @throw@ is used to start a termination reraise then these two statements
     556have the same behaviour:
    562557\begin{cfa}
    563558try {
     
    579574}
    580575\end{cfa}
    581 That is, they will have the same behaviour in isolation.
    582 Two things can expose differences between these cases.
    583 
    584 One is the existence of multiple handlers on a single try statement.
    585 A reraise skips all later handlers on this try statement but a conditional
    586 catch does not.
    587 Hence, if an earlier handler contains a reraise later handlers are
    588 implicitly skipped, with a conditional catch they are not.
    589 Still, they are equivalently powerful,
    590 both can be used two mimic the behaviour of the other,
    591 as reraise can pack arbitrary code in the handler and conditional catches
    592 can put arbitrary code in the predicate.
    593 % I was struggling with a long explanation about some simple solutions,
    594 % like repeating a condition on later handlers, and the general solution of
    595 % merging everything together. I don't think it is useful though unless its
    596 % for a proof.
    597 % https://en.cppreference.com/w/cpp/language/throw
    598 
    599 The question then becomes ``Which is a better default?"
    600 We believe that not skipping possibly useful handlers is a better default.
    601 If a handler can handle an exception it should and if the handler can not
    602 handle the exception then it is probably safer to have that explicitly
    603 described in the handler itself instead of implicitly described by its
    604 ordering with other handlers.
    605 % Or you could just alter the semantics of the throw statement. The handler
    606 % index is in the exception so you could use it to know where to start
    607 % searching from in the current try statement.
    608 % No place for the `goto else;` metaphor.
    609 
    610 The other issue is all of the discussion above assumes that the only
    611 way to tell apart two raises is the exception being raised and the remaining
    612 search path.
    613 This is not true generally, the current state of the stack can matter in
    614 a number of cases, even only for a stack trace after an program abort.
    615 But \CFA has a much more significant need of the rest of the stack, the
    616 default handlers for both termination and resumption.
    617 
    618 % For resumption it turns out it is possible continue a raise after the
    619 % exception has been caught, as if it hadn't been caught in the first place.
    620 This becomes a problem combined with the stack unwinding used in termination
    621 exception handling.
    622 The stack is unwound before the handler is installed, and hence before any
    623 reraises can run. So if a reraise happens the previous stack is gone,
    624 the place on the stack where the default handler was supposed to run is gone,
    625 if the default handler was a local function it may have been unwound too.
    626 There is no reasonable way to restore that information, so the reraise has
    627 to be considered as a new raise.
    628 This is the strongest advantage conditional catches have over reraising,
    629 they happen before stack unwinding and avoid this problem.
    630 
    631 % The one possible disadvantage of conditional catch is that it runs user
    632 % code during the exception search. While this is a new place that user code
    633 % can be run destructors and finally clauses are already run during the stack
    634 % unwinding.
    635 %
    636 % https://www.cplusplus.com/reference/exception/current_exception/
    637 %   `exception_ptr current_exception() noexcept;`
    638 % https://www.python.org/dev/peps/pep-0343/
     576However, if there are further handlers after this handler only the first is
     577check. For multiple handlers on a single try block that could handle the
     578same exception, the equivalent translations to conditional catch becomes more complex, resulting is multiple nested try blocks for all possible reraises.
     579So while catch-with-reraise is logically equivilant to conditional catch, there is a lexical explosion for the former.
     580
     581\PAB{I think the following discussion makes an incorrect assumption.
     582A conditional catch CAN happen with the stack unwound.
     583Roy talked about this issue in Section 2.3.3 here: \newline
     584\url{http://plg.uwaterloo.ca/theses/KrischerThesis.pdf}}
     585
     586Specifically for termination handling, a
     587conditional catch happens before the stack is unwound, but a reraise happens
     588afterwards. Normally this might only cause you to loose some debug
     589information you could get from a stack trace (and that can be side stepped
     590entirely by collecting information during the unwind). But for \CFA there is
     591another issue, if the exception is not handled the default handler should be
     592run at the site of the original raise.
     593
     594There are two problems with this: the site of the original raise does not
     595exist anymore and the default handler might not exist anymore. The site is
     596always removed as part of the unwinding, often with the entirety of the
     597function it was in. The default handler could be a stack allocated nested
     598function removed during the unwind.
     599
     600This means actually trying to pretend the catch didn't happening, continuing
     601the original raise instead of starting a new one, is infeasible.
     602That is the expected behaviour for most languages and we can't replicate
     603that behaviour.
    639604
    640605\section{Finally Clauses}
    641606\label{s:FinallyClauses}
     607
    642608Finally clauses are used to preform unconditional clean-up when leaving a
    643609scope and are placed at the end of a try statement after any handler clauses:
     
    652618The @FINALLY_BLOCK@ is executed when the try statement is removed from the
    653619stack, including when the @GUARDED_BLOCK@ finishes, any termination handler
    654 finishes or during an unwind.
     620finishes, or during an unwind.
    655621The only time the block is not executed is if the program is exited before
    656622the stack is unwound.
     
    668634
    669635Not all languages with unwinding have finally clauses. Notably \Cpp does
    670 without it as descructors, and the RAII design pattern, serve a similar role.
    671 Although destructors and finally clauses can be used in the same cases,
    672 they have their own strengths, similar to top-level function and lambda
    673 functions with closures.
    674 Destructors take more work for their first use, but if there is clean-up code
    675 that needs to be run every time a type is used they soon become much easier
    676 to set-up.
    677 On the other hand finally clauses capture the local context, so is easy to
    678 use when the clean-up is not dependent on the type of a variable or requires
    679 information from multiple variables.
    680 % To Peter: I think these are the main points you were going for.
     636without it as destructors with RAII serve a similar role. Although destructors and
     637finally clauses have overlapping usage cases, they have their own
     638specializations, like top-level functions and lambda functions with closures.
     639Destructors take more work if a number of unrelated, local variables without destructors or dynamically allocated variables must be passed for de-intialization.
     640Maintaining this destructor during local-block modification is a source of errors.
     641A finally clause places local de-intialization inline with direct access to all local variables.
    681642
    682643\section{Cancellation}
     
    691652raise, this exception is not used in matching only to pass information about
    692653the cause of the cancellation.
    693 (This also means matching cannot fail so there is no default handler.)
     654(This restriction also means matching cannot fail so there is no default handler.)
    694655
    695656After @cancel_stack@ is called the exception is copied into the EHM's memory
    696 and the current stack is unwound.
    697 The behaviour after that depends on the kind of stack being cancelled.
     657and the current stack is
     658unwound.
     659The result of a cancellation depends on the kind of stack that is being unwound.
    698660
    699661\paragraph{Main Stack}
     
    702664After the main stack is unwound there is a program-level abort.
    703665
    704 There are two reasons for these semantics.
    705 The first is that it had to do this abort.
     666There are two reasons for this semantics. The first is that it obviously had to do the abort
    706667in a sequential program as there is nothing else to notify and the simplicity
    707668of keeping the same behaviour in sequential and concurrent programs is good.
    708 Also, even in concurrent programs there may not currently be any other stacks
    709 and even if other stacks do exist, main has no way to know where they are.
     669\PAB{I do not understand this sentence. $\Rightarrow$ Also, even in concurrent programs, there is no stack that an innate connection
     670to, so it would have be explicitly managed.}
    710671
    711672\paragraph{Thread Stack}
     
    719680and an implicit join (from a destructor call). The explicit join takes the
    720681default handler (@defaultResumptionHandler@) from its calling context while
    721 the implicit join provides its own; which does a program abort if the
     682the implicit join provides its own, which does a program abort if the
    722683@ThreadCancelled@ exception cannot be handled.
    723684
    724 The communication and synchronization are done here because threads only have
    725 two structural points (not dependent on user-code) where
    726 communication/synchronization happens: start and join.
     685\PAB{Communication can occur during the lifetime of a thread using shared variable and \lstinline{waitfor} statements.
     686Are you sure you mean communication here? Maybe you mean synchronization (rendezvous) point. $\Rightarrow$ Communication is done at join because a thread only has two points of
     687communication with other threads: start and join.}
    727688Since a thread must be running to perform a cancellation (and cannot be
    728689cancelled from another stack), the cancellation must be after start and
    729 before the join, so join is used.
     690before the join, so join is use.
    730691
    731692% TODO: Find somewhere to discuss unwind collisions.
     
    734695a destructor and prevents cascading the error across multiple threads if
    735696the user is not equipped to deal with it.
    736 It is always possible to add an explicit join if that is the desired behaviour.
    737 
    738 With explicit join and a default handler that triggers a cancellation, it is
    739 possible to cascade an error across any number of threads, cleaning up each
    740 in turn, until the error is handled or the main thread is reached.
     697Also you can always add an explicit join if that is the desired behaviour.
    741698
    742699\paragraph{Coroutine Stack}
     
    744701satisfies the @is_coroutine@ trait.
    745702After a coroutine stack is unwound, control returns to the @resume@ function
    746 that most recently resumed it. @resume@ reports a
    747 @CoroutineCancelled@ exception, which contains a references to the cancelled
     703that most recently resumed it. The resume reports a
     704@CoroutineCancelled@ exception, which contains references to the cancelled
    748705coroutine and the exception used to cancel it.
    749706The @resume@ function also takes the \defaultResumptionHandler{} from the
    750 caller's context and passes it to the internal report.
     707caller's context and passes it to the internal cancellation.
    751708
    752709A coroutine knows of two other coroutines, its starter and its last resumer.
     
    754711(in terms of coroutine state) called resume on this coroutine, so the message
    755712is passed to the latter.
    756 
    757 With a default handler that triggers a cancellation, it is possible to
    758 cascade an error across any number of coroutines, cleaning up each in turn,
    759 until the error is handled or a thread stack is reached.
  • doc/theses/andrew_beach_MMath/future.tex

    r660665f r5a46e09  
    33
    44\section{Language Improvements}
    5 \todo{Future/Language Improvements seems to have gotten mixed up. It is
    6 presented as ``waiting on language improvements" but really its more
    7 non-research based impovements.}
    85\CFA is a developing programming language. As such, there are partially or
    96unimplemented features of the language (including several broken components)
    107that I had to workaround while building an exception handling system largely in
    118the \CFA language (some C components).  The following are a few of these
    12 issues, and once implemented/fixed, how they would affect the exception system.
     9issues, and once implemented/fixed, how this would affect the exception system.
    1310\begin{itemize}
    1411\item
    1512The implementation of termination is not portable because it includes
    16 hand-crafted assembly statements.
    17 The existing compilers cannot translate that for other platforms and those
    18 sections must be ported by hand to
     13hand-crafted assembly statements. These sections must be ported by hand to
    1914support more hardware architectures, such as the ARM processor.
    2015\item
     
    2217reference instead of a pointer. Since \CFA has a very general reference
    2318capability, programmers will want to use it. Once fixed, this capability should
    24 result in little or no change in the exception system but simplify usage.
     19result in little or no change in the exception system.
    2520\item
    2621Termination handlers cannot use local control-flow transfers, \eg by @break@,
     
    4641The virtual system should be completed. It was not supposed to be part of this
    4742project, but was thrust upon it to do exception inheritance; hence, only
    48 minimal work is done. A draft for a complete virtual system is available but
     43minimal work was done. A draft for a complete virtual system is available but
    4944it is not finalized.  A future \CFA project is to complete that work and then
    5045update the exception system that uses the current version.
     
    7267bad software engineering.
    7368
    74 Non-local/concurrent raise requires more
    75 coordination between the concurrency system
     69Non-local/concurrent requires more coordination between the concurrency system
    7670and the exception system. Many of the interesting design decisions centre
    77 around masking, \ie controlling which exceptions may be thrown at a stack. It
     71around masking (controlling which exceptions may be thrown at a stack). It
    7872would likely require more of the virtual system and would also effect how
    7973default handlers are set.
     
    9185
    9286\section{Checked Exceptions}
    93 Checked exceptions make exceptions part of a function's type by adding an
     87Checked exceptions make exceptions part of a function's type by adding the
    9488exception signature. An exception signature must declare all checked
    95 exceptions that could propagate from the function (either because they were
     89exceptions that could propogate from the function (either because they were
    9690raised inside the function or came from a sub-function). This improves safety
    9791by making sure every checked exception is either handled or consciously
     
    9993
    10094However checked exceptions were never seriously considered for this project
    101 because they have significant trade-offs in usablity and code reuse in
     95for two reasons. The first is due to time constraints, even copying an
     96existing checked exception system would be pushing the remaining time and
     97trying to address the second problem would take even longer. The second
     98problem is that checked exceptions have some real usability trade-offs in
    10299exchange for the increased safety.
     100
    103101These trade-offs are most problematic when trying to pass exceptions through
    104102higher-order functions from the functions the user passed into the
    105103higher-order function. There are no well known solutions to this problem
    106 that were satisfactory for \CFA (which carries some of C's flexibility
    107 over safety design) so additional research is needed.
     104that were statifactory for \CFA (which carries some of C's flexability
     105over safety design) so one would have to be researched and developed.
    108106
    109 Follow-up work might add some form of checked exceptions to \CFA,
    110 possibly using polymorphic exception signatures,
    111 a form of tunneling\cite{Zhang19} or
     107Follow-up work might add checked exceptions to \CFA, possibly using
     108polymorphic exception signatures, a form of tunneling\cite{Zhang19} or
    112109checked and unchecked raises.
    113110
     
    153150For instance, resumption could be extended to cover this use by allowing local
    154151control flow out of it. This approach would require an unwind as part of the
    155 transition as there are stack frames that have to be removed between where
    156 the resumption handler is installed and where it is defined.
    157 This approach would not require, but might benefit from, a special statement
    158 to leave the handler.
    159 Currently, mimicking this behaviour in \CFA is possible by throwing a
    160 termination inside a resumption handler.
     152transition as there are stack frames that have to be removed.  This approach
     153means there is no notify raise, but because \CFA does not have exception
     154signatures, a termination can be thrown from within any resumption handler so
     155there is already a way to do mimic this in existing \CFA.
    161156
    162157% Maybe talk about the escape; and escape CONTROL_STMT; statements or how
  • doc/theses/andrew_beach_MMath/implement.tex

    r660665f r5a46e09  
    22\label{c:implement}
    33
    4 % Local Helpers:
    5 \newcommand\transformline[1][becomes...]{
    6   \hrulefill#1\hrulefill
    7   \medskip
    8 }
    9 
    10 The implementation work for this thesis covers the two components: virtual
     4The implementation work for this thesis covers two components: the virtual
    115system and exceptions. Each component is discussed in detail.
    126
     
    2721\todo{Talk about constructors for virtual types (after they are working).}
    2822
    29 The virtual table pointer binds an instance of a virtual type
    30 to a virtual table.
    31 The pointer is also the table's id and how the system accesses the
     23This is what binds an instance of a virtual type to a virtual table. This
     24pointer can be used as an identity check. It can also be used to access the
    3225virtual table and the virtual members there.
    3326
    3427\subsection{Type Id}
    3528Every virtual type has a unique id.
    36 Type ids can be compared for equality,
    37 which checks if the types reperented are the same,
     29Type ids can be compared for equality (the types reperented are the same)
    3830or used to access the type's type information.
    3931The type information currently is only the parent's type id or, if the
    40 type has no parent, the null pointer.
     32type has no parent, zero.
    4133
    4234The id's are implemented as pointers to the type's type information instance.
    43 Dereferencing the pointer gets the type information.
    44 The ancestors of a virtual type are found by traversing type ids through
    45 the type information.
    46 The information pushes the issue of creating a unique value (for
     35Derefencing the pointer gets the type information.
     36By going back-and-forth between the type id and
     37the type info one can find every ancestor of a virtual type.
     38It also pushes the issue of creating a unique value (for
    4739the type id) to the problem of creating a unique instance (for type
    48 information), which the linker can solve.
    49 
    50 The advanced linker support is used here to avoid having to create
    51 a new declaration to attach this data to.
    52 With C/\CFA's header/implementation file divide for something to appear
    53 exactly once it must come from a declaration that appears in exactly one
    54 implementation file; the declarations in header files may exist only once
    55 they can be included in many different translation units.
    56 Therefore, structure's declaration will not work.
    57 Neither will attaching the type information to the virtual table -- although
    58 a vtable declarations are in implemention files they are not unique, see
    59 \autoref{ss:VirtualTable}.
    60 Instead the same type information is generated multiple times and then
    61 the new attribute \snake{cfa_linkone} is used to removed duplicates.
    62 
    63 Type information is constructed as follows:
    64 \begin{enumerate}
    65 \item
    66 Use the type's name to generate a name for the type information structure.
    67 This is saved so it may be reused.
    68 \item
    69 Generate a new structure definition to store the type
     40information) which the linker can solve.
     41
     42Advanced linker support is required because there is no place that appears
     43only once to attach the type information to. There should be one structure
     44definition but it is included in multiple translation units. Each virtual
     45table definition should be unique but there are an arbitrary number of thoses.
     46So the special section prefix \texttt{.gnu.linkonce} is used.
     47With a unique suffix (making the entire section name unique) the linker will
     48remove multiple definition making sure only one version exists after linking.
     49Then it is just a matter of making sure there is a unique name for each type.
     50
     51This is done in three phases.
     52The first phase is to generate a new structure definition to store the type
    7053information. The layout is the same in each case, just the parent's type id,
    71 but the types used change from instance to instance.
    72 The generated name is used for both this structure and, if relivant, the
    73 parent pointer.
     54but the types are changed.
     55The structure's name is change, it is based off the virtual type's name, and
     56the type of the parent's type id.
    7457If the virtual type is polymorphic then the type information structure is
    7558polymorphic as well, with the same polymorphic arguments.
    76 \item
    77 A seperate name for instances is generated from the type's name.
    78 \item
    79 The definition is generated and initialised.
    80 The parent id is set to the null pointer or to the address of the parent's
    81 type information instance. Name resolution handles the rest.
    82 \item
    83 \CFA's name mangler does its regular name mangling encoding the type of
    84 the declaration into the instance name. This gives a completely unique name
    85 including different instances of the same polymorphic type.
    86 \end{enumerate}
    87 \todo{The list is making me realise, some of this isn't ordered.}
    88 
    89 Writing that code manually, with helper macros for the early name mangling,
    90 would look like this:
    91 \begin{cfa}
    92 struct INFO_TYPE(TYPE) {
    93         INFO_TYPE(PARENT) const * parent;
     59
     60The second phase is to generate an instance of the type information with a
     61almost unique name, generated by mangling the virtual type name.
     62
     63The third phase is implicit with \CFA's overloading scheme. \CFA mangles
     64names with type information so that all of the symbols exported to the linker
     65are unique even if in \CFA code they are the same. Having two declarations
     66with the same name and same type is forbidden because it is impossible for
     67overload resolution to pick between them. This is why a unique type is
     68generated for each virtual type.
     69Polymorphic information is included in this mangling so polymorphic
     70types will have seperate instances for each set of polymorphic arguments.
     71
     72\begin{cfa}
     73struct TYPE_ID_TYPE {
     74        PARENT_ID_TYPE const * parent;
    9475};
    9576
    9677__attribute__((cfa_linkonce))
    97 INFO_TYPE(TYPE) const INFO_NAME(TYPE) = {
    98         &INFO_NAME(PARENT),
     78TYPE_ID_TYPE const TYPE_ID_NAME = {
     79        &PARENT_ID_NAME,
    9980};
    10081\end{cfa}
    10182
    102 \subsubsection{\lstinline{cfa\_linkonce} Attribute}
    103 % I just realised: This is an extension of the inline keyword.
    104 % An extension of C's at least, it is very similar to C++'s.
     83\subsubsection{cfa\_linkonce Attribute}
    10584Another feature added to \CFA is a new attribute: \texttt{cfa\_linkonce}.
    106 This attribute is attached to an object or function definition
    107 (any global declaration with a name and a type)
    108 allowing it to be defined multiple times.
    109 All matching definitions mush have the link-once attribute
    110 and their implementations should be identical as well.
    111 
    112 A single definition with the attribute can be included in a header
    113 file as if it was a forward declaration, except no definition is required.
    114 
    115 This technique is used for type-id instances. A link-once definition is
    116 generated each time the structure is seen. This will result in multiple
    117 copies but the link-once attribute ensures all but one are removed for a
    118 unique instance.
    119 
    120 Internally, @cfa_linkonce@ is replaced with
     85This attribute can be put on an object or function definition
     86(any global declaration with a name and a type).
     87This allows you to define that object or function multiple times.
     88All definitions should have the link-once attribute on them and all should
     89be identical.
     90
     91The simplist way to use it is to put a definition in a header where the
     92forward declaration would usually go.
     93This is how it is used for type-id instances. There was is no unique location
     94associated with a type except for the type definition which is in a header.
     95This allows the unique type-id object to be generated there.
     96
     97Internally @cfa_linkonce@ removes all @section@ attributes
     98from the declaration (as well as itself) and replaces them with
    12199@section(".gnu.linkonce.NAME")@ where \texttt{NAME} is replaced by the
    122100mangled name of the object.
    123 Any other @section@ attributes are removed from the declaration.
    124101The prefix \texttt{.gnu.linkonce} in section names is recognized by the
    125 linker. If two of these sections appear with the same name, including
    126 everything that comes after the special prefix, then only one is used
    127 and the other is discarded.
     102linker. If two of these sections with the same name, including everything
     103that comes after the special prefix, then only one will be used and the other
     104will be discarded.
    128105
    129106\subsection{Virtual Table}
    130 \label{ss:VirtualTable}
    131107Each virtual type has a virtual table type that stores its type id and
    132108virtual members.
     
    137113
    138114The layout always comes in three parts.
    139 \todo{Add labels to the virtual table layout figure.}
    140115The first section is just the type id at the head of the table. It is always
    141 there to ensure that it can be found even when the accessing code does not
    142 know which virtual type it has.
     116there to ensure that
    143117The second section are all the virtual members of the parent, in the same
    144118order as they appear in the parent's virtual table. Note that the type may
     
    159133prefix that has the same layout and types as its parent virtual table.
    160134This, combined with the fixed offset to the virtual table pointer, means that
    161 for any virtual type, it is always safe to access its virtual table and,
    162 from there, it is safe to check the type id to identify the exact type of the
     135for any virtual type it doesn't matter if we have it or any of its
     136descendants, it is still always safe to access the virtual table through
     137the virtual table pointer.
     138From there it is safe to check the type id to identify the exact type of the
    163139underlying object, access any of the virtual members and pass the object to
    164140any of the method-like virtual members.
    165141
    166 When a virtual table is declared, the user decides where to declare it and its
     142When a virtual table is declared the user decides where to declare it and its
    167143name. The initialization of the virtual table is entirely automatic based on
    168144the context of the declaration.
    169145
    170 The type id is always fixed; with each virtual table type having
     146The type id is always fixed, each virtual table type will always have one
    171147exactly one possible type id.
    172 The virtual members are usually filled in by type resolution.
    173 The best match for a given name and type at the declaration site is used.
    174 There are two exceptions to that rule: the @size@ field, the type's size,
    175 is set using a @sizeof@ expression and the @align@ field, the
    176 type's alignment, is set using an @alignof@ expression.
     148The virtual members are usually filled in by resolution. The best match for
     149a given name and type at the declaration site is filled in.
     150There are two exceptions to that rule: the @size@ field is the type's size
     151and is set to the result of a @sizeof@ expression, the @align@ field is the
     152type's alignment and similarly uses an @alignof@ expression.
    177153
    178154\subsubsection{Concurrency Integration}
    179155Coroutines and threads need instances of @CoroutineCancelled@ and
    180156@ThreadCancelled@ respectively to use all of their functionality. When a new
    181 data type is declared with @coroutine@ or @thread@, a forward declaration for
     157data type is declared with @coroutine@ or @thread@ the forward declaration for
    182158the instance is created as well. The definition of the virtual table is created
    183159at the definition of the main function.
    184 
    185 This is showned through code re-writing in
    186 \autoref{f:ConcurrencyTypeTransformation} and
    187 \autoref{f:ConcurrencyMainTransformation}.
    188 In both cases the original declaration is not modified,
    189 only new ones are added.
    190160
    191161\begin{figure}
     
    195165};
    196166\end{cfa}
    197 
    198 \transformline[appends...]
    199167
    200168\begin{cfa}
     
    207175extern CoroutineCancelled_vtable & _default_vtable;
    208176\end{cfa}
    209 \caption{Concurrency Type Transformation}
    210 \label{f:ConcurrencyTypeTransformation}
    211 \end{figure}
    212 
    213 \begin{figure}
     177
    214178\begin{cfa}
    215179void main(Example & this) {
     
    217181}
    218182\end{cfa}
    219 
    220 \transformline[appends...]
    221183
    222184\begin{cfa}
     
    229191        &_default_vtable_object_declaration;
    230192\end{cfa}
    231 \caption{Concurrency Main Transformation}
    232 \label{f:ConcurrencyMainTransformation}
     193\caption{Concurrency Transformations}
     194\label{f:ConcurrencyTransformations}
    233195\end{figure}
     196\todo{Improve Concurrency Transformations figure.}
    234197
    235198\subsection{Virtual Cast}
     
    248211the cast target is passed in as @child@.
    249212
    250 For generated C code wraps both arguments and the result with type casts.
    251 There is also an internal check inside the compiler to make sure that the
     213For C generation both arguments and the result are wrapped with type casts.
     214There is also an internal store inside the compiler to make sure that the
    252215target type is a virtual type.
    253216% It also checks for conflicting definitions.
    254217
    255 The virtual cast either returns the original pointer or the null pointer
    256 as the new type.
    257 So the function does the parent check and returns the appropriate value.
     218The virtual cast either returns the original pointer as a new type or null.
     219So the function just does the parent check and returns the approprate value.
    258220The parent check is a simple linear search of child's ancestors using the
    259221type information.
     
    267229% resumption doesn't as well.
    268230
    269 % Many modern languages work with an internal stack that function push and pop
     231% Many modern languages work with an interal stack that function push and pop
    270232% their local data to. Stack unwinding removes large sections of the stack,
    271233% often across functions.
     
    274236stack. On function entry and return, unwinding is handled directly by the
    275237call/return code embedded in the function.
    276 In many cases, the position of the instruction pointer (relative to parameter
     238In many cases the position of the instruction pointer (relative to parameter
    277239and local declarations) is enough to know the current size of the stack
    278240frame.
    279241
    280242Usually, the stack-frame size is known statically based on parameter and
    281 local variable declarations. Even with dynamic stack-size, the information
    282 to determine how much of the stack has to be removed is still contained
     243local variable declarations. Even with dynamic stack-size the information
     244to determain how much of the stack has to be removed is still contained
    283245within the function.
    284246Allocating/deallocating stack space is usually an $O(1)$ operation achieved by
    285247bumping the hardware stack-pointer up or down as needed.
    286 Constructing/destructing values within a stack frame has
    287 a similar complexity but can add additional work and take longer.
     248Constructing/destructing values on the stack takes longer put in terms of
     249figuring out what needs to be done is of similar complexity.
    288250
    289251Unwinding across multiple stack frames is more complex because that
     
    299261reseting to a snap-shot of an arbitrary but existing function frame on the
    300262stack. It is up to the programmer to ensure the snap-shot is valid when it is
    301 reset and that all required clean-up from the unwound stacks is performed.
    302 This approach is fragile and requires extra work in the surrounding code.
    303 
    304 With respect to the extra work in the surounding code,
     263reset and that all required clean-up from the unwound stacks is preformed.
     264This approach is fragile and forces a work onto the surounding code.
     265
     266With respect to that work forced onto the surounding code,
    305267many languages define clean-up actions that must be taken when certain
    306268sections of the stack are removed. Such as when the storage for a variable
    307269is removed from the stack or when a try statement with a finally clause is
    308270(conceptually) popped from the stack.
    309 None of these should be handled by the user --- that would contradict the
    310 intention of these features --- so they need to be handled automatically.
    311 
    312 To safely remove sections of the stack, the language must be able to find and
     271None of these should be handled by the user, that would contradict the
     272intention of these features, so they need to be handled automatically.
     273
     274To safely remove sections of the stack the language must be able to find and
    313275run these clean-up actions even when removing multiple functions unknown at
    314276the beginning of the unwinding.
     
    332294current stack frame, and what handlers should be checked. Theoretically, the
    333295LSDA can contain any information but conventionally it is a table with entries
    334 representing regions of a function and what has to be done there during
     296representing regions of the function and what has to be done there during
    335297unwinding. These regions are bracketed by instruction addresses. If the
    336298instruction pointer is within a region's start/end, then execution is currently
     
    352314int avar __attribute__(( cleanup(clean_up) ));
    353315\end{cfa}
    354 The attribute is used on a variable and specifies a function,
     316The attribue is used on a variable and specifies a function,
    355317in this case @clean_up@, run when the variable goes out of scope.
    356 This feature is enough to mimic destructors,
    357 but not try statements which can effect
     318This is enough to mimic destructors, but not try statements which can effect
    358319the unwinding.
    359320
    360 To get full unwinding support, all of these features must be handled directly
    361 in assembly and assembler directives; partiularly the cfi directives
     321To get full unwinding support all of this has to be done directly with
     322assembly and assembler directives. Partiularly the cfi directives
    362323\snake{.cfi_lsda} and \snake{.cfi_personality}.
    363324
     
    366327section covers some of the important parts of the interface.
    367328
    368 A personality function can perform different actions depending on how it is
     329A personality function can preform different actions depending on how it is
    369330called.
    370331\begin{lstlisting}
     
    403364
    404365The @exception_class@ argument is a copy of the
    405 \code{C}{exception}'s @exception_class@ field,
    406 which is a number that identifies the exception handling mechanism
    407 that created the exception.
    408 
    409 The \code{C}{exception} argument is a pointer to a user
     366\code{C}{exception}'s @exception_class@ field.
     367This a number that identifies the exception handling mechanism that created
     368the
     369
     370The \code{C}{exception} argument is a pointer to the user
    410371provided storage object. It has two public fields: the @exception_class@,
    411372which is described above, and the @exception_cleanup@ function.
    412 The clean-up function is used by the EHM to clean-up the exception, if it
     373The clean-up function is used by the EHM to clean-up the exception if it
    413374should need to be freed at an unusual time, it takes an argument that says
    414375why it had to be cleaned up.
     
    421382messages for special cases (some of which should never be used by the
    422383personality function) and error codes. However, unless otherwise noted, the
    423 personality function always returns @_URC_CONTINUE_UNWIND@.
     384personality function should always return @_URC_CONTINUE_UNWIND@.
    424385
    425386\subsection{Raise Exception}
    426 Raising an exception is the central function of libunwind and it performs
     387Raising an exception is the central function of libunwind and it performs a
    427388two-staged unwinding.
    428389\begin{cfa}
     
    511472% catches. Talk about GCC nested functions.
    512473
    513 \CFA termination exceptions use libunwind heavily because they match
     474\CFA termination exceptions use libunwind heavily because they match \Cpp
    514475\Cpp exceptions closely. The main complication for \CFA is that the
    515476compiler generates C code, making it very difficult to generate the assembly to
     
    524485
    525486\begin{figure}
    526 \centering
    527487\input{exception-layout}
    528488\caption{Exception Layout}
    529489\label{f:ExceptionLayout}
    530490\end{figure}
    531 
    532 Exceptions are stored in variable-sized blocks
    533 (see \autoref{f:ExceptionLayout}).
     491\todo*{Convert the exception layout to an actual diagram.}
     492
     493Exceptions are stored in variable-sized blocks (see \vref{f:ExceptionLayout}).
    534494The first component is a fixed-sized data structure that contains the
    535495information for libunwind and the exception system. The second component is an
     
    538498@_Unwind_Exception@ to the entire node.
    539499
    540 Multiple exceptions can exist at the same time because exceptions can be
     500Multipe exceptions can exist at the same time because exceptions can be
    541501raised inside handlers, destructors and finally blocks.
    542502Figure~\vref{f:MultipleExceptions} shows a program that has multiple
    543503exceptions active at one time.
    544504Each time an exception is thrown and caught the stack unwinds and the finally
    545 clause runs. This handler throws another exception (until @num_exceptions@ gets
    546 high enough), which must be allocated. The previous exceptions may not be
     505clause runs. This will throw another exception (until @num_exceptions@ gets
     506high enough) which must be allocated. The previous exceptions may not be
    547507freed because the handler/catch clause has not been run.
    548 Therefore, the EHM must keep all unhandled exceptions alive
    549 while it allocates exceptions for new throws.
     508So the EHM must keep them alive while it allocates exceptions for new throws.
    550509
    551510\begin{figure}
     
    600559\todo*{Work on multiple exceptions code sample.}
    601560
    602 All exceptions are stored in nodes, which are then linked together in lists
     561All exceptions are stored in nodes which are then linked together in lists,
    603562one list per stack, with the
    604563list head stored in the exception context. Within each linked list, the most
     
    607566exception is being handled. The exception at the head of the list is currently
    608567being handled, while other exceptions wait for the exceptions before them to be
    609 handled and removed.
     568removed.
    610569
    611570The virtual members in the exception's virtual table provide the size of the
     
    614573exception into managed memory. After the exception is handled, the free
    615574function is used to clean up the exception and then the entire node is
    616 passed to free, returning the memory back to the heap.
     575passed to free so the memory can be given back to the heap.
    617576
    618577\subsection{Try Statements and Catch Clauses}
    619578The try statement with termination handlers is complex because it must
    620 compensate for the C code-generation versus
    621 assembly-code generated from \CFA. Libunwind
     579compensate for the lack of assembly-code generated from \CFA. Libunwind
    622580requires an LSDA and personality function for control to unwind across a
    623581function. The LSDA in particular is hard to mimic in generated C code.
     
    634592embedded assembly. This assembly code is handcrafted using C @asm@ statements
    635593and contains
    636 enough information for a single try statement the function repersents.
     594enough information for the single try statement the function repersents.
    637595
    638596The three functions passed to try terminate are:
    639597\begin{description}
    640 \item[try function:] This function is the try block, it is where all the code
    641 from inside the try block is placed. It takes no parameters and has no
     598\item[try function:] This function is the try block, all the code inside the
     599try block is placed inside the try function. It takes no parameters and has no
    642600return value. This function is called during regular execution to run the try
    643601block.
     
    651609handler that matches the exception.
    652610
    653 \item[handler function:] This function handles the exception, and contains
    654 all the code from the handlers in the try statement, joined with a switch
    655 statement on the handler's id.
    656 It takes a
     611\item[handler function:] This function handles the exception. It takes a
    657612pointer to the exception and the handler's id and returns nothing. It is called
    658 after the cleanup phase.
     613after the cleanup phase. It is constructed by stitching together the bodies of
     614each handler and dispatches to the selected handler.
    659615\end{description}
    660616All three functions are created with GCC nested functions. GCC nested functions
    661 can be used to create closures,
    662 in other words functions that can refer to the state of other
     617can be used to create closures, functions that can refer to the state of other
    663618functions on the stack. This approach allows the functions to refer to all the
    664619variables in scope for the function containing the @try@ statement. These
     
    668623Using this pattern, \CFA implements destructors with the cleanup attribute.
    669624
    670 \autoref{f:TerminationTransformation} shows the pattern used to transform
    671 a \CFA try statement with catch clauses into the approprate C functions.
    672 \todo{Explain the Termination Transformation figure.}
    673 
    674625\begin{figure}
    675626\begin{cfa}
     
    682633}
    683634\end{cfa}
    684 
    685 \transformline
    686635
    687636\begin{cfa}
     
    734683% The stack-local data, the linked list of nodes.
    735684
    736 Resumption is simpler to implement than termination
     685Resumption simpler to implement than termination
    737686because there is no stack unwinding.
    738687Instead of storing the data in a special area using assembly,
     
    743692The nodes are stored in order, with the more recent try statements closer
    744693to the head of the list.
    745 Instead of traversing the stack, resumption handling traverses the list.
    746 At each node, the EHM checks to see if the try statement the node repersents
     694Instead of traversing the stack resumption handling traverses the list.
     695At each node the EHM checks to see if the try statement the node repersents
    747696can handle the exception. If it can, then the exception is handled and
    748697the operation finishes, otherwise the search continues to the next node.
    749698If the search reaches the end of the list without finding a try statement
    750 that can handle the exception, the default handler is executed and the
     699that can handle the exception the default handler is executed and the
    751700operation finishes.
    752701
    753 Each node has a handler function that does most of the work.
    754 The handler function is passed the raised exception and returns true
    755 if the exception is handled and false otherwise.
    756 
    757 The handler function checks each of its internal handlers in order,
    758 top-to-bottom, until it funds a match. If a match is found that handler is
    759 run, after which the function returns true, ignoring all remaining handlers.
    760 If no match is found the function returns false.
    761 The match is performed in two steps, first a virtual cast is used to see
    762 if the thrown exception is an instance of the declared exception or one of
    763 its descendant type, then check to see if passes the custom predicate if one
    764 is defined. This ordering gives the type guarantee used in the predicate.
    765 
    766 \autoref{f:ResumptionTransformation} shows the pattern used to transform
    767 a \CFA try statement with catch clauses into the approprate C functions.
    768 \todo{Explain the Resumption Transformation figure.}
     702In each node is a handler function which does most of the work there.
     703The handler function is passed the raised the exception and returns true
     704if the exception is handled and false if it cannot be handled here.
     705
     706For each @catchResume@ clause the handler function will:
     707check to see if the raised exception is a descendant type of the declared
     708exception type, if it is and there is a conditional expression then it will
     709run the test, if both checks pass the handling code for the clause is run
     710and the function returns true, otherwise it moves onto the next clause.
     711If this is the last @catchResume@ clause then instead of moving onto
     712the next clause the function returns false as no handler could be found.
    769713
    770714\begin{figure}
     
    778722}
    779723\end{cfa}
    780 
    781 \transformline
    782724
    783725\begin{cfa}
     
    811753
    812754% Recursive Resumption Stuff:
    813 \autoref{f:ResumptionMarking} shows search skipping
    814 (see \vpageref{s:ResumptionMarking}), which ignores parts of
     755Search skipping (see \vpageref{s:ResumptionMarking}), which ignores parts of
    815756the stack
    816757already examined, is accomplished by updating the front of the list as the
     
    818759is updated to the next node of the current node. After the search is complete,
    819760successful or not, the head of the list is reset.
    820 % No paragraph?
     761
    821762This mechanism means the current handler and every handler that has already
    822763been checked are not on the list while a handler is run. If a resumption is
    823 thrown during the handling of another resumption, the active handlers and all
     764thrown during the handling of another resumption the active handlers and all
    824765the other handler checked up to this point are not checked again.
    825 % No paragraph?
    826 This structure also supports new handlers added while the resumption is being
     766
     767This structure also supports new handler added while the resumption is being
    827768handled. These are added to the front of the list, pointing back along the
    828 stack --- the first one points over all the checked handlers ---
    829 and the ordering is maintained.
     769stack -- the first one points over all the checked handlers -- and the ordering
     770is maintained.
    830771
    831772\begin{figure}
     
    833774\caption{Resumption Marking}
    834775\label{f:ResumptionMarking}
    835 \todo*{Label Resumption Marking to aid clarity.}
     776\todo*{Convert Resumption Marking into a line figure.}
    836777\end{figure}
    837778
    838779\label{p:zero-cost}
    839 Finally, the resumption implementation has a cost for entering/exiting a try
    840 statement with @catchResume@ clauses, whereas a try statement with @catch@
     780Note, the resumption implementation has a cost for entering/exiting a @try@
     781statement with @catchResume@ clauses, whereas a @try@ statement with @catch@
    841782clauses has zero-cost entry/exit. While resumption does not need the stack
    842783unwinding and cleanup provided by libunwind, it could use the search phase to
     
    869810
    870811The first step of cancellation is to find the cancelled stack and its type:
    871 coroutine, thread or main thread.
    872 In \CFA, a thread (the construct the user works with) is a user-level thread
    873 (point of execution) paired with a coroutine, the thread's main coroutine.
    874 The thread library also stores pointers to the main thread and the current
    875 thread.
    876 If the current thread's main and current coroutines are the same then the
    877 current stack is a thread stack, otherwise it is a coroutine stack.
    878 If the current stack is a thread stack, it is also the main thread stack
    879 if and only if the main and current threads are the same.
     812coroutine or thread. Fortunately, the thread library stores the main thread
     813pointer and the current thread pointer, and every thread stores a pointer to
     814its main coroutine and the coroutine it is currently executing.
     815\todo*{Consider adding a description of how threads are coroutines.}
     816
     817If a the current thread's main and current coroutines are the same then the
     818current stack is a thread stack. Furthermore it is easy to compare the
     819current thread to the main thread to see if they are the same. And if this
     820is not a thread stack then it must be a coroutine stack.
    880821
    881822However, if the threading library is not linked, the sequential execution is on
    882823the main stack. Hence, the entire check is skipped because the weak-symbol
    883 function is loaded. Therefore, main thread cancellation is unconditionally
     824function is loaded. Therefore, a main thread cancellation is unconditionally
    884825performed.
    885826
    886827Regardless of how the stack is chosen, the stop function and parameter are
    887828passed to the forced-unwind function. The general pattern of all three stop
    888 functions is the same: continue unwinding until the end of stack and
    889 then preform the appropriate transfer.
     829functions is the same: they continue unwinding until the end of stack and
     830then preform their transfer.
    890831
    891832For main stack cancellation, the transfer is just a program abort.
     
    893834For coroutine cancellation, the exception is stored on the coroutine's stack,
    894835and the coroutine context switches to its last resumer. The rest is handled on
    895 the backside of the resume, which checks if the resumed coroutine is
     836the backside of the resume, which check if the resumed coroutine is
    896837cancelled. If cancelled, the exception is retrieved from the resumed coroutine,
    897838and a @CoroutineCancelled@ exception is constructed and loaded with the
  • doc/theses/andrew_beach_MMath/intro.tex

    r660665f r5a46e09  
    11\chapter{Introduction}
    22
    3 % The highest level overview of Cforall and EHMs. Get this done right away.
    4 This thesis goes over the design and implementation of the exception handling
    5 mechanism (EHM) of
    6 \CFA (pronounced sea-for-all and may be written Cforall or CFA).
    7 \CFA is a new programming language that extends C, that maintains
    8 backwards-compatibility while introducing modern programming features.
    9 Adding exception handling to \CFA gives it new ways to handle errors and
    10 make other large control-flow jumps.
     3\PAB{Stay in the present tense. \newline
     4\url{https://plg.uwaterloo.ca/~pabuhr/technicalWriting.shtml}}
     5\newline
     6\PAB{Note, \lstinline{lstlisting} normally bolds keywords. None of the keywords in your thesis are bolded.}
    117
    12 % Now take a step back and explain what exceptions are generally.
    13 Exception handling provides dynamic inter-function control flow.
     8% Talk about Cforall and exceptions generally.
     9%This thesis goes over the design and implementation of the exception handling
     10%mechanism (EHM) of
     11%\CFA (pernounced sea-for-all and may be written Cforall or CFA).
     12Exception handling provides alternative dynamic inter-function control flow.
    1413There are two forms of exception handling covered in this thesis:
    1514termination, which acts as a multi-level return,
    1615and resumption, which is a dynamic function call.
    17 Termination handling is much more common,
    18 to the extent that it is often seen
    19 This seperation is uncommon because termination exception handling is so
    20 much more common that it is often assumed.
    21 % WHY: Mention other forms of continuation and \cite{CommonLisp} here?
    22 A language's EHM is the combination of language syntax and run-time
    23 components that are used to construct, raise and handle exceptions,
    24 including all control flow.
     16Note, termination exception handling is so common it is often assumed to be the only form.
     17Lesser know derivations of inter-function control flow are continuation passing in Lisp~\cite{CommonLisp}.
    2518
    2619Termination exception handling allows control to return to any previous
     
    3124\end{center}
    3225
    33 Resumption exception handling seaches the stack for a handler and then calls
    34 it without adding or removing any other stack frames.
     26Resumption exception handling calls a function, but asks the functions on the
     27stack what function that is.
    3528\todo{Add a diagram showing control flow for resumption.}
    3629
     
    4235most of the cost only when the error actually occurs.
    4336
     37% Overview of exceptions in Cforall.
     38
     39\PAB{You need section titles here. Don't take them out.}
     40
    4441\section{Thesis Overview}
    45 This work describes the design and implementation of the \CFA EHM.
     42
     43This thesis goes over the design and implementation of the exception handling
     44mechanism (EHM) of
     45\CFA (pernounced sea-for-all and may be written Cforall or CFA).
     46%This thesis describes the design and implementation of the \CFA EHM.
    4647The \CFA EHM implements all of the common exception features (or an
    4748equivalent) found in most other EHMs and adds some features of its own.
     
    7677harder to replicate in other programming languages.
    7778
     79\section{Background}
     80
    7881% Talk about other programming languages.
    7982Some existing programming languages that include EHMs/exception handling
     
    8184exceptions which unwind the stack as part of the
    8285Exceptions also can replace return codes and return unions.
     86In functional languages will also sometimes fold exceptions into monads.
     87
     88\PAB{You must demonstrate knowledge of background material here.
     89It should be at least a full page.}
     90
     91\section{Contributions}
    8392
    8493The contributions of this work are:
     
    93102\end{enumerate}
    94103
    95 \todo{I can't figure out a good lead-in to the roadmap.}
    96 The next section covers the existing state of exceptions.
    97 The existing state of \CFA is also covered in \autoref{c:existing}.
    98 The new features are introduced in \autoref{c:features},
    99 which explains their usage and design.
     104\todo{I can't figure out a good lead-in to the overview.}
     105Covering the existing \CFA features in \autoref{c:existing}.
     106Then the new features are introduce in \autoref{c:features}, explaining their
     107usage and design.
    100108That is followed by the implementation of those features in
    101109\autoref{c:implement}.
    102 The performance results are examined in \autoref{c:performance}.
    103 Possibilities to extend this project are discussed in \autoref{c:future}.
    104 
    105 \section{Background}
    106 \label{s:background}
    107 
    108 Exception handling is not a new concept,
    109 with papers on the subject dating back 70s.
    110 
    111 Their were popularised by \Cpp,
    112 which added them in its first major wave of non-object-orientated features
    113 in 1990.
    114 % https://en.cppreference.com/w/cpp/language/history
    115 
    116 Java was the next popular language to use exceptions. It is also the most
    117 popular language with checked exceptions.
    118 Checked exceptions are part of the function interface they are raised from.
    119 This includes functions they propogate through, until a handler for that
    120 type of exception is found.
    121 This makes exception information explicit, which can improve clarity and
    122 safety, but can slow down programming.
    123 Some of these, such as dealing with high-order methods or an overly specified
    124 throws clause, are technical. However some of the issues are much more
    125 human, in that writing/updating all the exception signatures can be enough
    126 of a burden people will hack the system to avoid them.
    127 Including the ``catch-and-ignore" pattern where a catch block is used without
    128 anything to repair or recover from the exception.
    129 
    130 %\subsection
    131 Resumption exceptions have been much less popular.
    132 Although resumption has a history as old as termination's, very few
    133 programming languages have implement them.
    134 % http://bitsavers.informatik.uni-stuttgart.de/pdf/xerox/parc/techReports/
    135 %   CSL-79-3_Mesa_Language_Manual_Version_5.0.pdf
    136 Mesa is one programming languages that did and experiance with that
    137 languages is quoted as being one of the reasons resumptions were not
    138 included in the \Cpp standard.
    139 % https://en.wikipedia.org/wiki/Exception_handling
    140 \todo{A comment about why we did include them when they are so unpopular
    141 might be approprate.}
    142 
    143 %\subsection
    144 Functional languages, tend to use solutions like the return union, but some
    145 exception-like constructs still appear.
    146 
    147 For instance Haskell's built in error mechanism can make the result of any
    148 expression, including function calls. Any expression that examines an
    149 error value will in-turn produce an error. This continues until the main
    150 function produces an error or until it is handled by one of the catch
    151 functions.
    152 
    153 %\subsection
    154 More recently exceptions seem to be vanishing from newer programming
    155 languages.
    156 Rust and Go reduce this feature to panics.
    157 Panicing is somewhere between a termination exception and a program abort.
    158 Notably in Rust a panic can trigger either, a panic may unwind the stack or
    159 simply kill the process.
    160 % https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
    161 Go's panic is much more similar to a termination exception but there is
    162 only a catch-all function with \code{Go}{recover()}.
    163 So exceptions still are appearing, just in reduced forms.
    164 
    165 %\subsection
    166 Exception handling's most common use cases are in error handling.
    167 Here are some other ways to handle errors and comparisons with exceptions.
    168 \begin{itemize}
    169 \item\emph{Error Codes}:
    170 This pattern uses an enumeration (or just a set of fixed values) to indicate
    171 that an error has occured and which error it was.
    172 
    173 There are some issues if a function wants to return an error code and another
    174 value. The main issue is that it can be easy to forget checking the error
    175 code, which can lead to an error being quitely and implicitly ignored.
    176 Some new languages have tools that raise warnings if the return value is
    177 discarded to avoid this.
    178 It also puts more code on the main execution path.
    179 \item\emph{Special Return with Global Store}:
    180 A function that encounters an error returns some value indicating that it
    181 encountered a value but store which error occured in a fixed global location.
    182 
    183 Perhaps the C standard @errno@ is the most famous example of this,
    184 where some standard library functions will return some non-value (often a
    185 NULL pointer) and set @errno@.
    186 
    187 This avoids the multiple results issue encountered with straight error codes
    188 but otherwise many of the same advantages and disadvantages.
    189 It does however introduce one other major disadvantage:
    190 Everything that uses that global location must agree on all possible errors.
    191 \item\emph{Return Union}:
    192 Replaces error codes with a tagged union.
    193 Success is one tag and the errors are another.
    194 It is also possible to make each possible error its own tag and carry its own
    195 additional information, but the two branch format is easy to make generic
    196 so that one type can be used everywhere in error handling code.
    197 
    198 This pattern is very popular in functional or semi-functional language,
    199 anything with primitive support for tagged unions (or algebraic data types).
    200 % We need listing Rust/rust to format code snipits from it.
    201 % Rust's \code{rust}{Result<T, E>}
    202 
    203 The main disadvantage is again it puts code on the main execution path.
    204 This is also the first technique that allows for more information about an
    205 error, other than one of a fix-set of ids, to be sent.
    206 They can be missed but some languages can force that they are checked.
    207 It is also implicitly forced in any languages with checked union access.
    208 \item\emph{Handler Functions}:
    209 On error the function that produced the error calls another function to
    210 handle it.
    211 The handler function can be provided locally (passed in as an argument,
    212 either directly as as a field of a structure/object) or globally (a global
    213 variable).
    214 
    215 C++ uses this as its fallback system if exception handling fails.
    216 \snake{std::terminate_handler} and for a time \snake{std::unexpected_handler}
    217 
    218 Handler functions work a lot like resumption exceptions.
    219 The difference is they are more expencive to set up but cheaper to use, and
    220 so are more suited to more fequent errors.
    221 The exception being global handlers if they are rarely change as the time
    222 in both cases strinks towards zero.
    223 \end{itemize}
    224 
    225 %\subsection
    226 Because of their cost exceptions are rarely used for hot paths of execution.
    227 There is an element of self-fulfilling prophocy here as implementation
    228 techniques have been designed to make exceptions cheap to set-up at the cost
    229 of making them expencive to use.
    230 Still, use of exceptions for other tasks is more common in higher-level
    231 scripting languages.
    232 An iconic example is Python's StopIteration exception which is thrown by
    233 an iterator to indicate that it is exausted. Combined with Python's heavy
    234 use of the iterator based for-loop.
    235 % https://docs.python.org/3/library/exceptions.html#StopIteration
     110% Future Work \autoref{c:future}
  • doc/theses/andrew_beach_MMath/uw-ethesis.tex

    r660665f r5a46e09  
    244244\input{features}
    245245\input{implement}
    246 \input{performance}
    247246\input{future}
    248247
  • doc/theses/mubeen_zulfiqar_MMath/.gitignore

    r660665f r5a46e09  
    11# Intermediate Results:
    2 build/
     2out/
    33
    44# Final Files:
  • doc/theses/mubeen_zulfiqar_MMath/allocator.tex

    r660665f r5a46e09  
    77\begin{itemize}
    88\item
    9 Objective of uHeapLmmm.
     9Objective of @uHeapLmmm@.
    1010\item
    1111Design philosophy.
    1212\item
    13 Background and previous design of uHeapLmmm.
     13Background and previous design of @uHeapLmmm@.
    1414\item
    15 Distributed design of uHeapLmmm.
     15Distributed design of @uHeapLmmm@.
    1616
    1717----- SHOULD WE GIVE IMPLEMENTATION DETAILS HERE? -----
     
    2424\end{itemize}
    2525
    26 The new features added to uHeapLmmm (incl. @malloc_size@ routine)
     26The new features added to @uHeapLmmm@ (incl. @malloc_size@ routine)
    2727\CFA alloc interface with examples.
    2828\begin{itemize}
     
    3333\end{itemize}
    3434
     35----- SHOULD WE GIVE PERFORMANCE AND USABILITY COMPARISON OF DIFFERENT INTERFACES THAT WE TRIED? -----
    3536
    36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% uHeapLmmm Design
    39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     37\PAB{Often Performance is its own chapter. I added one for now.}
    4138
    42 \section{Objective of uHeapLmmm}
    43 UHeapLmmm is a lightweight memory allocator. The objective behind uHeapLmmm is to design a minimal concurrent memory allocator that has new features and also fulfills GNU C Library requirements (FIX ME: cite requirements).
    44 
    45 \subsection{Design philosophy}
    46 
    47 
    48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    49 
    50 \section{Background and previous design of uHeapLmmm}
    51 
    52 
    53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    54 
    55 \section{Distributed design of uHeapLmmm}
    56 
    57 
    58 \subsection{Advantages of distributed design}
    59 
    60 
    61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    62 
    63 \section{Added Features}
    64 
    65 
    66 \subsection{Methods}
    67 Why did we need it?
    68 The added benefits.
    69 
    70 
    71 \subsection{Alloc Interface}
    72 Why did we need it?
    73 The added benefits.
    74 
    75 
    76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    77 % Following is added by Peter
     39Performance evaluation using u-benchmark suite.
    7840
    7941\noindent
  • doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex

    r660665f r5a46e09  
    3434\noindent
    3535====================
    36 
    37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Performance Matrices
    40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    42 
    43 \section{Performance Matrices of Memory Allocators}
    44 
    45 When it comes to memory allocators, there are no set standards of performance. Performance of a memory allocator depends highly on the usage pattern of the application. A memory allocator that is the best performer for a certain application X might be the worst for some other application which has completely different memory usage pattern compared to the application X. It is extremely difficult to make one universally best memory allocator which will outperform every other memory allocator for every usage pattern. So, there is a lack of a set of standard benchmarks that are used to evaluate a memory allocators's performance.
    46 
    47 If we breakdown the goals of a memory allocator, there are two basic matrices on which a memory allocator's performance is evaluated.
    48 \begin{enumerate}
    49 \item
    50 Memory Overhead
    51 \item
    52 Speed
    53 \end{enumerate}
    54 
    55 \subsection{Memory Overhead}
    56 Memory overhead is the extra memory that a memory allocator takes from OS which is not requested by the application. Ideally, an allocator should get just enough memory from OS that can fulfill application's request and should return this memory to OS as soon as applications frees it. But, allocators retain more memory compared to what application has asked for which causes memory overhead. Memory overhead can happen for various reasons.
    57 
    58 \subsubsection{Fragmentation}
    59 Fragmentation is one of the major reasons behind memory overhead. Fragmentation happens because of situations that are either necassary for proper functioning of the allocator such as internal memory management and book-keeping or are out of allocator's control such as application's usage pattern.
    60 
    61 \paragraph{Internal Fragmentation}
    62 For internal book-keeping, allocators divide raw memory given by OS into chunks, blocks, or lists that can fulfill application's requested size. Allocators use memory given by OS for creating headers, footers etc. to store information about these chunks, blocks, or lists. This increases usage of memory in-addition to the memory requested by application as the allocators need to store their book-keeping information. This extra usage of memory for allocator's own book-keeping is called Internal Fragmentation. Although it cases memory overhead but this overhead is necassary for an allocator's proper funtioning.
    63 
    64 *** FIX ME: Insert a figure of internal fragmentation with explanation
    65 
    66 \paragraph{External Fragmentation}
    67 External fragmentation is the free bits of memory between or around chunks of memory that are currently in-use of the application. Segmentation in memory due to application's usage pattern causes external fragmentation. The memory which is part of external fragmentation is completely free as it is neither used by allocator's internal book-keeping nor by the application. Ideally, an allocator should return a segment of memory back to the OS as soon as application frees it. But, this is not always the case. Allocators get memory from OS in one of the two ways.
    68 
    69 \begin{itemize}
    70 \item
    71 MMap: an allocator can ask OS for whole pages in mmap area. Then, the allocator segments the page internally and fulfills application's request.
    72 \item
    73 Heap: an allocator can ask OS for memory in heap area using system calls such as sbrk. Heap are grows downwards and shrinks upwards.
    74 \begin{itemize}
    75 \item
    76 If an allocator uses mmap area, it can only return extra memory back to OS if the whole page is free i.e. no chunk on the page is in-use of the application. Even if one chunk on the whole page is currently in-use of the application, the allocator has to retain the whole page.
    77 \item
    78 If an allocator uses the heap area, it can only return the continous free memory at the end of the heap area that is currently in allocator's possession as heap area shrinks upwards. If there are free bits of memory in-between chunks of memory that are currently in-use of the application, the allocator can not return these free bits.
    79 
    80 *** FIX ME: Insert a figure of above scenrio with explanation
    81 \item
    82 Even if the entire heap area is free except one small chunk at the end of heap area that is being used by the application, the allocator cannot return the free heap area back to the OS as it is not a continous region at the end of heap area.
    83 
    84 *** FIX ME: Insert a figure of above scenrio with explanation
    85 
    86 \item
    87 Such scenerios cause external fragmentation but it is out of the allocator's control and depend on application's usage pattern.
    88 \end{itemize}
    89 \end{itemize}
    90 
    91 \subsubsection{Internal Memory Management}
    92 Allocators such as je-malloc (FIX ME: insert reference) pro-actively get some memory from the OS and divide it into chunks of certain sizes that can be used in-future to fulfill application's request. This causes memory overhead as these chunks are made before application's request. There is also the possibility that an application may not even request memory of these sizes during their whole life-time.
    93 
    94 *** FIX ME: Insert a figure of above scenrio with explanation
    95 
    96 Allocators such as rp-malloc (FIX ME: insert reference) maintain lists or blocks of sized memory segments that is freed by the application for future use. These lists are maintained without any guarantee that application will even request these sizes again.
    97 
    98 Such tactics are usually used to gain speed as allocator will not have to get raw memory from OS and manage it at the time of application's request but they do cause memory overhead.
    99 
    100 Fragmentation and managed sized chunks of free memory can lead to Heap Blowup as the allocator may not be able to use the fragments or sized free chunks of free memory to fulfill application's requests of other sizes.
    101 
    102 \subsection{Speed}
    103 When it comes to performance evaluation of any piece of software, its runtime is usually the first thing that is evaluated. The same is true for memory allocators but, in case of memory allocators, speed does not only mean the runtime of memory allocator's routines but there are other factors too.
    104 
    105 \subsubsection{Runtime Speed}
    106 Low runtime is the main goal of a memory allocator when it comes it proving its speed. Runtime is the time that it takes for a routine of memory allocator to complete its execution. As mentioned in (FIX ME: refernce to routines' list), there four basic routines that are used in memory allocation. Ideally, each routine of a memory allocator should be fast. Some memory allocator designs use pro-active measures (FIX ME: local refernce) to gain speed when allocating some memory to the application. Some memory allocators do memory allocation faster than memory freeing (FIX ME: graph refernce) while others show similar speed whether memory is allocated or freed.
    107 
    108 \subsubsection{Memory Access Speed}
    109 Runtime speed is not the only speed matrix in memory allocators. The memory that a memory allocator has allocated to the application also needs to be accessible as quick as possible. The application should be able to read/write allocated memory quickly. The allocation method of a memory allocator may introduce some delays when it comes to memory access speed, which is specially important in concurrent applications. Ideally, a memory allocator should allocate all memory on a cache-line to only one thread and no cache-line should be shared among multiple threads. If a memory allocator allocates memory to multple threads on a same cache line, then cache may get invalidated more frequesntly when two different threads running on two different processes will try to read/write the same memory region. On the other hand, if one cache-line is used by only one thread then the cache may get invalidated less frequently. This sharing of one cache-line among multiple threads is called false sharing (FIX ME: cite wasik).
    110 
    111 \paragraph{Active False Sharing}
    112 Active false sharing is the sharing of one cache-line among multiple threads that is caused by memory allocator. It happens when two threads request memory from memory allocator and the allocator allocates memory to both of them on the same cache-line. After that, if the threads are running on different processes who have their own caches and both threads start reading/writing the allocated memory simultanously, their caches will start getting invalidated every time the other thread writes something to the memory. This will cause the application to slow down as the process has to load cache much more frequently.
    113 
    114 *** FIX ME: Insert a figure of above scenrio with explanation
    115 
    116 \paragraph{Passive False Sharing}
    117 Passive false sharing is the kind of false sharing which is caused by the application and not the memory allocator. The memory allocator may preservce passive false sharing in future instead of eradicating it. But, passive false sharing is initiated by the application.
    118 
    119 \subparagraph{Program Induced Passive False Sharing}
    120 Program induced false sharing is completely out of memory allocator's control and is purely caused by the application. When a thread in the application creates multiple objects in the dynamic area and allocator allocates memory for these objects on the same cache-line as the objects are created by the same thread. Passive false sharing will occur if this thread passes one of these objects to another thread but it retains the rest of these objects or it passes some/all of the remaining objects to some third thread(s). Now, one cache-line is shared among multiple threads but it is caused by the application and not the allocator. It is out of allocator's control and has the similar performance impact as Active False Sharing (FIX ME: cite local) if these threads, who are sharing the same cache-line, start reading/writing the given objects simultanously.
    121 
    122 *** FIX ME: Insert a figure of above scenrio 1 with explanation
    123 
    124 *** FIX ME: Insert a figure of above scenrio 2 with explanation
    125 
    126 \subparagraph{Program Induced Allocator Preserved Passive False Sharing}
    127 Program induced allocator preserved passive false sharing is another interesting case of passive false sharing. Both the application and the allocator are partially responsible for it. It starts the same as Program Induced False Sharing (FIX ME: cite local). Once, an application thread has created multiple dynamic objects on the same cache-line and ditributed these objects among multiple threads causing sharing of one cache-line among multiple threads (Program Induced Passive False Sharing). This kind of false sharing occurs when one of these threads, which got the object on the shared cache-line, frees the passed object then re-allocates another object but the allocator returns the same object (on the shared cache-line) that this thread just freed. Although, the application caused the false sharing to happen in the frst place however, to prevent furthur false sharing, the allocator should have returned the new object on some other cache-line which is only shared by the allocating thread. When it comes to performnce impact, this passive false sharing will slow down the application just like any other kind of false sharing if the threads sharing the cache-line start reading/writing the objects simultanously.
    128 
    129 
    130 *** FIX ME: Insert a figure of above scenrio with explanation
    131 
    132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Micro Benchmark Suite
    135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    137 
    138 \section{Micro Benchmark Suite}
    139 The aim of micro benchmark suite is to create a set of programs that can evaluate a memory allocator based on the performance matrices described in (FIX ME: local cite). These programs can be taken as a standard to benchmark an allocator's basic goals. These programs give details of an allocator's memory overhead and speed under a certain allocation pattern. The speed of the allocator is benchmarked in different ways. Similarly, false sharing happening in an allocator is also measured in multiple ways. These benchmarks evalute the allocator under a certain allocation pattern which is configurable and can be changed using a few knobs to benchmark observe an allocator's performance under a desired allocation pattern.
    140 
    141 Micro Benchmark Suite benchmarks an allocator's performance by allocating dynamic objects and, then, measuring specifc matrices. The benchmark suite evaluates an allocator with a certain allocation pattern. Bnechmarks have different knobs that can be used to change allocation pattern and evaluate an allocator under desired conditions. These can be set by giving commandline arguments to the benchmark on execution.
    142 
    143 Following is the list of avalable knobs.
    144 
    145 *** FIX ME: Add knobs items after finalize
    146 
    147 \subsection{Memory Benchmark}
    148 Memory benchmark measures memory overhead of an allocator. It allocates a number of dynamic objects. Then, by reading /self/proc/maps, gets the total memory that the allocator has reuested from the OS. Finally, it calculates the memory head by taking the difference between the memory the allocator has requested from the OS and the memory that program has allocated.
    149 *** FIX ME: Insert a figure of above benchmark with description
    150 
    151 \subsubsection{Relevant Knobs}
    152 *** FIX ME: Insert Relevant Knobs
    153 
    154 \subsection{Speed Benchmark}
    155 Speed benchmark calculates the runtime speed of an allocator's functions (FIX ME: cite allocator routines). It does by measuring the runtime of allocator routines in two different ways.
    156 
    157 \subsubsection{Speed Time}
    158 The time method does a certain amount of work by calling each routine of the allocator (FIX ME: cite allocator routines) a specific time. It calculates the total time it took to perform this workload. Then, it divides the time it took by the workload and calculates the average time taken by the allocator's routine.
    159 *** FIX ME: Insert a figure of above benchmark with description
    160 
    161 \paragraph{Relevant Knobs}
    162 *** FIX ME: Insert Relevant Knobs
    163 
    164 \subsubsection{Speed Workload}
    165 The worload method uses the opposite approach. It calls the allocator's routines for a specific amount of time and measures how much work was done during that time. Then, similar to the time method, it divides the time by the workload done during that time and calculates the average time taken by the allocator's routine.
    166 *** FIX ME: Insert a figure of above benchmark with description
    167 
    168 \paragraph{Relevant Knobs}
    169 *** FIX ME: Insert Relevant Knobs
    170 
    171 \subsection{Cache Scratch}
    172 Cache Scratch benchmark measures program induced allocator preserved passive false sharing (FIX ME CITE) in an allocator. It does so in two ways.
    173 
    174 \subsubsection{Cache Scratch Time}
    175 Cache Scratch Time allocates dynamic objects. Then, it benchmarks program induced allocator preserved passive false sharing (FIX ME CITE) in an allocator by measuring the time it takes to read/write these objects.
    176 *** FIX ME: Insert a figure of above benchmark with description
    177 
    178 \paragraph{Relevant Knobs}
    179 *** FIX ME: Insert Relevant Knobs
    180 
    181 \subsubsection{Cache Scratch Layout}
    182 Cache Scratch Layout also allocates dynamic objects. Then, it benchmarks program induced allocator preserved passive false sharing (FIX ME CITE) by using heap addresses returned by the allocator. It calculates how many objects were allocated to different threads on the same cache line.
    183 *** FIX ME: Insert a figure of above benchmark with description
    184 
    185 \paragraph{Relevant Knobs}
    186 *** FIX ME: Insert Relevant Knobs
    187 
    188 \subsection{Cache Thrash}
    189 Cache Thrash benchmark measures allocator induced passive false sharing (FIX ME CITE) in an allocator. It also does so in two ways.
    190 
    191 \subsubsection{Cache Thrash Time}
    192 Cache Thrash Time allocates dynamic objects. Then, it benchmarks allocator induced false sharing (FIX ME CITE) in an allocator by measuring the time it takes to read/write these objects.
    193 *** FIX ME: Insert a figure of above benchmark with description
    194 
    195 \paragraph{Relevant Knobs}
    196 *** FIX ME: Insert Relevant Knobs
    197 
    198 \subsubsection{Cache Thrash Layout}
    199 Cache Thrash Layout also allocates dynamic objects. Then, it benchmarks allocator induced false sharing (FIX ME CITE) by using heap addresses returned by the allocator. It calculates how many objects were allocated to different threads on the same cache line.
    200 *** FIX ME: Insert a figure of above benchmark with description
    201 
    202 \paragraph{Relevant Knobs}
    203 *** FIX ME: Insert Relevant Knobs
    204 
    205 \section{Results}
    206 *** FIX ME: add configuration details of memory allocators
    207 
    208 \subsection{Memory Benchmark}
    209 
    210 \subsubsection{Relevant Knobs}
    211 
    212 \subsection{Speed Benchmark}
    213 
    214 \subsubsection{Speed Time}
    215 
    216 \paragraph{Relevant Knobs}
    217 
    218 \subsubsection{Speed Workload}
    219 
    220 \paragraph{Relevant Knobs}
    221 
    222 \subsection{Cache Scratch}
    223 
    224 \subsubsection{Cache Scratch Time}
    225 
    226 \paragraph{Relevant Knobs}
    227 
    228 \subsubsection{Cache Scratch Layout}
    229 
    230 \paragraph{Relevant Knobs}
    231 
    232 \subsection{Cache Thrash}
    233 
    234 \subsubsection{Cache Thrash Time}
    235 
    236 \paragraph{Relevant Knobs}
    237 
    238 \subsubsection{Cache Thrash Layout}
    239 
    240 \paragraph{Relevant Knobs}
  • doc/theses/mubeen_zulfiqar_MMath/uw-ethesis.tex

    r660665f r5a46e09  
    165165% cfa macros used in the document
    166166\input{common}
    167 %\usepackageinput{common}
    168167\CFAStyle                                               % CFA code-style for all languages
    169 \lstset{basicstyle=\linespread{0.9}\tt}                 % CFA typewriter font
     168\lstset{language=CFA,basicstyle=\linespread{0.9}\tt}    % CFA default language
    170169\newcommand{\PAB}[1]{{\color{red}PAB: #1}}
    171170
  • libcfa/configure.ac

    r660665f r5a46e09  
    131131#io_uring 5.5 uses enum values
    132132#io_uring 5.6 and later uses probes
    133 
    134 AH_TEMPLATE([CFA_HAVE_LINUX_RSEQ_H],[Defined if rseq support is present when compiling libcfathread.])
    135 AC_CHECK_HEADERS([linux/rseq.h], [AC_DEFINE(CFA_HAVE_LINUX_RSEQ_H)])
    136 
    137 AH_TEMPLATE([CFA_HAVE_LINUX_LIBRSEQ],[Defined if librseq support is present when compiling libcfathread.])
    138 AC_CHECK_LIB([rseq], [rseq_available], [AC_DEFINE(CFA_HAVE_LINUX_RSEQ_H)], [])
    139133
    140134AH_TEMPLATE([CFA_HAVE_LINUX_IO_URING_H],[Defined if io_uring support is present when compiling libcfathread.])
  • libcfa/prelude/defines.hfa.in

    r660665f r5a46e09  
    171171#undef CFA_HAVE_LINUX_IO_URING_H
    172172
    173 /* Defined if librseq support is present when compiling libcfathread. */
    174 #undef CFA_HAVE_LINUX_LIBRSEQ
    175 
    176 /* Defined if rseq support is present when compiling libcfathread. */
    177 #undef CFA_HAVE_LINUX_RSEQ_H
    178 
    179173/* Defined if openat2 support is present when compiling libcfathread. */
    180174#undef CFA_HAVE_OPENAT2
     
    211205#undef HAVE_LINUX_IO_URING_H
    212206
    213 /* Define to 1 if you have the <linux/rseq.h> header file. */
    214 #undef HAVE_LINUX_RSEQ_H
    215 
    216207/* Define to 1 if you have the <memory.h> header file. */
    217208#undef HAVE_MEMORY_H
  • libcfa/src/Makefile.am

    r660665f r5a46e09  
    6161        containers/queueLockFree.hfa \
    6262        containers/stackLockFree.hfa \
    63         containers/vector2.hfa \
    6463        vec/vec.hfa \
    6564        vec/vec2.hfa \
     
    7069        common.hfa \
    7170        fstream.hfa \
     71        strstream.hfa \
    7272        heap.hfa \
    7373        iostream.hfa \
     
    7878        rational.hfa \
    7979        stdlib.hfa \
    80         strstream.hfa \
    8180        time.hfa \
    8281        bits/weakso_locks.hfa \
     
    8483        containers/pair.hfa \
    8584        containers/result.hfa \
    86         containers/vector.hfa \
    87         device/cpu.hfa
     85        containers/vector.hfa
    8886
    8987libsrc = ${inst_headers_src} ${inst_headers_src:.hfa=.cfa} \
  • libcfa/src/bits/signal.hfa

    r660665f r5a46e09  
    2020
    2121#include <errno.h>
     22#define __USE_GNU
    2223#include <signal.h>
     24#undef __USE_GNU
    2325#include <stdlib.h>
    2426#include <string.h>
  • libcfa/src/concurrency/coroutine.cfa

    r660665f r5a46e09  
    1515
    1616#define __cforall_thread__
    17 #define _GNU_SOURCE
    1817
    1918#include "coroutine.hfa"
  • libcfa/src/concurrency/io.cfa

    r660665f r5a46e09  
    1515
    1616#define __cforall_thread__
    17 #define _GNU_SOURCE
    1817
    1918#if defined(__CFA_DEBUG__)
     
    2423
    2524#if defined(CFA_HAVE_LINUX_IO_URING_H)
     25        #define _GNU_SOURCE         /* See feature_test_macros(7) */
    2626        #include <errno.h>
    2727        #include <signal.h>
  • libcfa/src/concurrency/io/setup.cfa

    r660665f r5a46e09  
    1515
    1616#define __cforall_thread__
    17 #define _GNU_SOURCE
     17#define _GNU_SOURCE         /* See feature_test_macros(7) */
    1818
    1919#if defined(__CFA_DEBUG__)
  • libcfa/src/concurrency/kernel.cfa

    r660665f r5a46e09  
    1515
    1616#define __cforall_thread__
    17 #define _GNU_SOURCE
    18 
    1917// #define __CFA_DEBUG_PRINT_RUNTIME_CORE__
    2018
     
    280278
    281279                                // Spin a little on I/O, just in case
    282                                 for(5) {
     280                                        for(5) {
    283281                                        __maybe_io_drain( this );
    284282                                        readyThread = pop_fast( this->cltr );
     
    287285
    288286                                // no luck, try stealing a few times
    289                                 for(5) {
     287                                        for(5) {
    290288                                        if( __maybe_io_drain( this ) ) {
    291289                                                readyThread = pop_fast( this->cltr );
     
    424422                __cfactx_switch( &proc_cor->context, &thrd_dst->context );
    425423                // when __cfactx_switch returns we are back in the processor coroutine
    426 
    427 
    428424
    429425                /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary );
     
    526522
    527523        /* paranoid */ verify( ! __preemption_enabled() );
    528         /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ) || thrd_src->corctx_flag, "ERROR : Returning $thread %p has been corrupted.\n StackPointer too small.\n", thrd_src );
    529         /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit) || thrd_src->corctx_flag, "ERROR : Returning $thread %p has been corrupted.\n StackPointer too large.\n", thrd_src );
     524        /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ), "ERROR : Returning $thread %p has been corrupted.\n StackPointer too small.\n", thrd_src );
     525        /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit), "ERROR : Returning $thread %p has been corrupted.\n StackPointer too large.\n", thrd_src );
    530526}
    531527
  • libcfa/src/concurrency/kernel.hfa

    r660665f r5a46e09  
    6666                unsigned id;
    6767                unsigned target;
    68                 unsigned last;
    6968                unsigned long long int cutoff;
    7069        } rdq;
  • libcfa/src/concurrency/kernel/startup.cfa

    r660665f r5a46e09  
    1515
    1616#define __cforall_thread__
    17 #define _GNU_SOURCE
    1817
    1918// C Includes
    2019#include <errno.h>              // errno
    21 #include <signal.h>
    2220#include <string.h>             // strerror
    2321#include <unistd.h>             // sysconf
    24 
    2522extern "C" {
    2623      #include <limits.h>       // PTHREAD_STACK_MIN
    27         #include <unistd.h>       // syscall
    2824        #include <sys/eventfd.h>  // eventfd
    2925      #include <sys/mman.h>     // mprotect
     
    140136};
    141137
    142 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    143         // No data needed
    144 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    145         extern "Cforall" {
    146                 __attribute__((aligned(128))) thread_local volatile struct rseq __cfaabi_rseq @= {
    147                         .cpu_id : RSEQ_CPU_ID_UNINITIALIZED,
    148                 };
    149         }
    150 #else
    151         // No data needed
    152 #endif
    153 
    154138//-----------------------------------------------------------------------------
    155139// Struct to steal stack
     
    484468        self_mon_p = &self_mon;
    485469        link.next = 0p;
    486         link.ts   = -1llu;
     470        link.ts   = 0;
    487471        preferred = -1u;
    488472        last_proc = 0p;
     
    513497        this.rdq.id  = -1u;
    514498        this.rdq.target = -1u;
    515         this.rdq.last = -1u;
    516499        this.rdq.cutoff = 0ull;
    517500        do_terminate = false;
  • libcfa/src/concurrency/kernel_private.hfa

    r660665f r5a46e09  
    1616#pragma once
    1717
    18 #if !defined(__cforall_thread__)
    19         #error kernel_private.hfa should only be included in libcfathread source
    20 #endif
    21 
    2218#include "kernel.hfa"
    2319#include "thread.hfa"
     
    2622#include "stats.hfa"
    2723
    28 extern "C" {
    29 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    30         #include <rseq/rseq.h>
    31 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    32         #include <linux/rseq.h>
    33 #else
    34         #ifndef _GNU_SOURCE
    35         #error kernel_private requires gnu_source
    36         #endif
    37         #include <sched.h>
    38 #endif
    39 }
    40 
    4124//-----------------------------------------------------------------------------
    4225// Scheduler
     26
     27
    4328extern "C" {
    4429        void disable_interrupts() OPTIONAL_THREAD;
     
    5439
    5540//-----------------------------------------------------------------------------
    56 // Hardware
    57 
    58 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    59         // No data needed
    60 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    61         extern "Cforall" {
    62                 extern __attribute__((aligned(128))) thread_local volatile struct rseq __cfaabi_rseq;
    63         }
    64 #else
    65         // No data needed
    66 #endif
    67 
    68 static inline int __kernel_getcpu() {
    69         /* paranoid */ verify( ! __preemption_enabled() );
    70 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    71         return rseq_current_cpu();
    72 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    73         int r = __cfaabi_rseq.cpu_id;
    74         /* paranoid */ verify( r >= 0 );
    75         return r;
    76 #else
    77         return sched_getcpu();
    78 #endif
    79 }
    80 
    81 //-----------------------------------------------------------------------------
    8241// Processor
    8342void main(processorCtx_t *);
     
    8544void * __create_pthread( pthread_t *, void * (*)(void *), void * );
    8645void __destroy_pthread( pthread_t pthread, void * stack, void ** retval );
     46
     47
    8748
    8849extern cluster * mainCluster;
  • libcfa/src/concurrency/locks.cfa

    r660665f r5a46e09  
    1616
    1717#define __cforall_thread__
    18 #define _GNU_SOURCE
    1918
    2019#include "locks.hfa"
  • libcfa/src/concurrency/locks.hfa

    r660665f r5a46e09  
    2424#include "containers/list.hfa"
    2525
    26 #include "limits.hfa"
    2726#include "thread.hfa"
    2827
     
    8887        bool tryP(BinaryBenaphore & this) {
    8988                ssize_t c = this.counter;
    90                 /* paranoid */ verify( c > MIN );
    9189                return (c >= 1) && __atomic_compare_exchange_n(&this.counter, &c, c-1, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
    9290        }
     
    9694                ssize_t c = 0;
    9795                for () {
    98                         /* paranoid */ verify( this.counter < MAX );
    9996                        if (__atomic_compare_exchange_n(&this.counter, &c, c+1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    10097                                if (c == 0) return true;
     
    176173        ThreadBenaphore sem;
    177174};
    178 
    179 static inline void ?{}(fast_lock & this) { this.owner = 0p; }
    180175
    181176static inline bool $try_lock(fast_lock & this, $thread * thrd) {
  • libcfa/src/concurrency/monitor.cfa

    r660665f r5a46e09  
    1515
    1616#define __cforall_thread__
    17 #define _GNU_SOURCE
    1817
    1918#include "monitor.hfa"
  • libcfa/src/concurrency/mutex.cfa

    r660665f r5a46e09  
    1717
    1818#define __cforall_thread__
    19 #define _GNU_SOURCE
    2019
    2120#include "mutex.hfa"
  • libcfa/src/concurrency/preemption.cfa

    r660665f r5a46e09  
    1515
    1616#define __cforall_thread__
    17 #define _GNU_SOURCE
    18 
    1917// #define __CFA_DEBUG_PRINT_PREEMPTION__
    2018
  • libcfa/src/concurrency/ready_queue.cfa

    r660665f r5a46e09  
    1515
    1616#define __cforall_thread__
    17 #define _GNU_SOURCE
    18 
    1917// #define __CFA_DEBUG_PRINT_READY_QUEUE__
    2018
     
    2220#define USE_RELAXED_FIFO
    2321// #define USE_WORK_STEALING
    24 // #define USE_CPU_WORK_STEALING
    2522
    2623#include "bits/defs.hfa"
    27 #include "device/cpu.hfa"
    2824#include "kernel_private.hfa"
    2925
     26#define _GNU_SOURCE
    3027#include "stdlib.hfa"
    3128#include "math.hfa"
    3229
    33 #include <errno.h>
    3430#include <unistd.h>
    35 
    36 extern "C" {
    37         #include <sys/syscall.h>  // __NR_xxx
    38 }
    3931
    4032#include "ready_subqueue.hfa"
     
    5446#endif
    5547
    56 #if   defined(USE_CPU_WORK_STEALING)
    57         #define READYQ_SHARD_FACTOR 2
    58 #elif defined(USE_RELAXED_FIFO)
     48#if   defined(USE_RELAXED_FIFO)
    5949        #define BIAS 4
    6050        #define READYQ_SHARD_FACTOR 4
     
    9585}
    9686
    97 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    98         // No forward declaration needed
    99         #define __kernel_rseq_register rseq_register_current_thread
    100         #define __kernel_rseq_unregister rseq_unregister_current_thread
    101 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    102         void __kernel_raw_rseq_register  (void);
    103         void __kernel_raw_rseq_unregister(void);
    104 
    105         #define __kernel_rseq_register __kernel_raw_rseq_register
    106         #define __kernel_rseq_unregister __kernel_raw_rseq_unregister
    107 #else
    108         // No forward declaration needed
    109         // No initialization needed
    110         static inline void noop(void) {}
    111 
    112         #define __kernel_rseq_register noop
    113         #define __kernel_rseq_unregister noop
    114 #endif
    115 
    11687//=======================================================================
    11788// Cluster wide reader-writer lock
     
    136107// Lock-Free registering/unregistering of threads
    137108unsigned register_proc_id( void ) with(*__scheduler_lock) {
    138         __kernel_rseq_register();
    139 
    140109        __cfadbg_print_safe(ready_queue, "Kernel : Registering proc %p for RW-Lock\n", proc);
    141110        bool * handle = (bool *)&kernelTLS().sched_lock;
     
    192161
    193162        __cfadbg_print_safe(ready_queue, "Kernel : Unregister proc %p\n", proc);
    194 
    195         __kernel_rseq_unregister();
    196163}
    197164
     
    247214//=======================================================================
    248215void ?{}(__ready_queue_t & this) with (this) {
    249         #if defined(USE_CPU_WORK_STEALING)
    250                 lanes.count = cpu_info.hthrd_count * READYQ_SHARD_FACTOR;
    251                 lanes.data = alloc( lanes.count );
    252                 lanes.tscs = alloc( lanes.count );
    253 
    254                 for( idx; (size_t)lanes.count ) {
    255                         (lanes.data[idx]){};
    256                         lanes.tscs[idx].tv = rdtscl();
    257                 }
    258         #else
    259                 lanes.data  = 0p;
    260                 lanes.tscs  = 0p;
    261                 lanes.count = 0;
    262         #endif
     216        lanes.data  = 0p;
     217        lanes.tscs  = 0p;
     218        lanes.count = 0;
    263219}
    264220
    265221void ^?{}(__ready_queue_t & this) with (this) {
    266         #if !defined(USE_CPU_WORK_STEALING)
    267                 verify( SEQUENTIAL_SHARD == lanes.count );
    268         #endif
    269 
     222        verify( SEQUENTIAL_SHARD == lanes.count );
    270223        free(lanes.data);
    271224        free(lanes.tscs);
     
    273226
    274227//-----------------------------------------------------------------------
    275 #if defined(USE_CPU_WORK_STEALING)
    276         __attribute__((hot)) void push(struct cluster * cltr, struct $thread * thrd, bool push_local) with (cltr->ready_queue) {
    277                 __cfadbg_print_safe(ready_queue, "Kernel : Pushing %p on cluster %p\n", thrd, cltr);
    278 
    279                 processor * const proc = kernelTLS().this_processor;
    280                 const bool external = !push_local || (!proc) || (cltr != proc->cltr);
    281 
    282                 const int cpu = __kernel_getcpu();
    283                 /* paranoid */ verify(cpu >= 0);
    284                 /* paranoid */ verify(cpu < cpu_info.hthrd_count);
    285                 /* paranoid */ verify(cpu * READYQ_SHARD_FACTOR < lanes.count);
    286 
    287                 const cpu_map_entry_t & map = cpu_info.llc_map[cpu];
    288                 /* paranoid */ verify(map.start * READYQ_SHARD_FACTOR < lanes.count);
    289                 /* paranoid */ verify(map.self * READYQ_SHARD_FACTOR < lanes.count);
    290                 /* paranoid */ verifyf((map.start + map.count) * READYQ_SHARD_FACTOR <= lanes.count, "have %zu lanes but map can go up to %u", lanes.count, (map.start + map.count) * READYQ_SHARD_FACTOR);
    291 
    292                 const int start = map.self * READYQ_SHARD_FACTOR;
    293                 unsigned i;
    294                 do {
    295                         unsigned r;
    296                         if(unlikely(external)) { r = __tls_rand(); }
    297                         else { r = proc->rdq.its++; }
    298                         i = start + (r % READYQ_SHARD_FACTOR);
    299                         // If we can't lock it retry
    300                 } while( !__atomic_try_acquire( &lanes.data[i].lock ) );
    301 
    302                 // Actually push it
    303                 push(lanes.data[i], thrd);
    304 
    305                 // Unlock and return
    306                 __atomic_unlock( &lanes.data[i].lock );
    307 
    308                 #if !defined(__CFA_NO_STATISTICS__)
    309                         if(unlikely(external)) __atomic_fetch_add(&cltr->stats->ready.push.extrn.success, 1, __ATOMIC_RELAXED);
    310                         else __tls_stats()->ready.push.local.success++;
    311                 #endif
    312 
    313                 __cfadbg_print_safe(ready_queue, "Kernel : Pushed %p on cluster %p (idx: %u, mask %llu, first %d)\n", thrd, cltr, i, used.mask[0], lane_first);
    314 
    315         }
    316 
    317         // Pop from the ready queue from a given cluster
    318         __attribute__((hot)) $thread * pop_fast(struct cluster * cltr) with (cltr->ready_queue) {
    319                 /* paranoid */ verify( lanes.count > 0 );
    320                 /* paranoid */ verify( kernelTLS().this_processor );
    321 
    322                 const int cpu = __kernel_getcpu();
    323                 /* paranoid */ verify(cpu >= 0);
    324                 /* paranoid */ verify(cpu < cpu_info.hthrd_count);
    325                 /* paranoid */ verify(cpu * READYQ_SHARD_FACTOR < lanes.count);
    326 
    327                 const cpu_map_entry_t & map = cpu_info.llc_map[cpu];
    328                 /* paranoid */ verify(map.start * READYQ_SHARD_FACTOR < lanes.count);
    329                 /* paranoid */ verify(map.self * READYQ_SHARD_FACTOR < lanes.count);
    330                 /* paranoid */ verifyf((map.start + map.count) * READYQ_SHARD_FACTOR <= lanes.count, "have %zu lanes but map can go up to %u", lanes.count, (map.start + map.count) * READYQ_SHARD_FACTOR);
    331 
    332                 processor * const proc = kernelTLS().this_processor;
    333                 const int start = map.self * READYQ_SHARD_FACTOR;
    334 
    335                 // Did we already have a help target
    336                 if(proc->rdq.target == -1u) {
    337                         // if We don't have a
    338                         unsigned long long min = ts(lanes.data[start]);
    339                         for(i; READYQ_SHARD_FACTOR) {
    340                                 unsigned long long tsc = ts(lanes.data[start + i]);
    341                                 if(tsc < min) min = tsc;
    342                         }
    343                         proc->rdq.cutoff = min;
    344 
    345                         /* paranoid */ verify(lanes.count < 65536); // The following code assumes max 65536 cores.
    346                         /* paranoid */ verify(map.count < 65536); // The following code assumes max 65536 cores.
    347                         uint64_t chaos = __tls_rand();
    348                         uint64_t high_chaos = (chaos >> 32);
    349                         uint64_t  mid_chaos = (chaos >> 16) & 0xffff;
    350                         uint64_t  low_chaos = chaos & 0xffff;
    351 
    352                         unsigned me = map.self;
    353                         unsigned cpu_chaos = map.start + (mid_chaos % map.count);
    354                         bool global = cpu_chaos == me;
    355 
    356                         if(global) {
    357                                 proc->rdq.target = high_chaos % lanes.count;
    358                         } else {
    359                                 proc->rdq.target = (cpu_chaos * READYQ_SHARD_FACTOR) + (low_chaos % READYQ_SHARD_FACTOR);
    360                                 /* paranoid */ verify(proc->rdq.target >= (map.start * READYQ_SHARD_FACTOR));
    361                                 /* paranoid */ verify(proc->rdq.target <  ((map.start + map.count) * READYQ_SHARD_FACTOR));
    362                         }
    363 
    364                         /* paranoid */ verify(proc->rdq.target != -1u);
    365                 }
    366                 else {
    367                         const unsigned long long bias = 0; //2_500_000_000;
    368                         const unsigned long long cutoff = proc->rdq.cutoff > bias ? proc->rdq.cutoff - bias : proc->rdq.cutoff;
    369                         {
    370                                 unsigned target = proc->rdq.target;
    371                                 proc->rdq.target = -1u;
    372                                 if(lanes.tscs[target].tv < cutoff && ts(lanes.data[target]) < cutoff) {
    373                                         $thread * t = try_pop(cltr, target __STATS(, __tls_stats()->ready.pop.help));
    374                                         proc->rdq.last = target;
    375                                         if(t) return t;
    376                                 }
    377                         }
    378 
    379                         unsigned last = proc->rdq.last;
    380                         if(last != -1u && lanes.tscs[last].tv < cutoff && ts(lanes.data[last]) < cutoff) {
    381                                 $thread * t = try_pop(cltr, last __STATS(, __tls_stats()->ready.pop.help));
    382                                 if(t) return t;
    383                         }
    384                         else {
    385                                 proc->rdq.last = -1u;
    386                         }
    387                 }
    388 
    389                 for(READYQ_SHARD_FACTOR) {
    390                         unsigned i = start + (proc->rdq.itr++ % READYQ_SHARD_FACTOR);
    391                         if($thread * t = try_pop(cltr, i __STATS(, __tls_stats()->ready.pop.local))) return t;
    392                 }
    393 
    394                 // All lanes where empty return 0p
    395                 return 0p;
    396         }
    397 
    398         __attribute__((hot)) struct $thread * pop_slow(struct cluster * cltr) with (cltr->ready_queue) {
    399                 processor * const proc = kernelTLS().this_processor;
    400                 unsigned last = proc->rdq.last;
    401                 if(last != -1u) {
    402                         struct $thread * t = try_pop(cltr, last __STATS(, __tls_stats()->ready.pop.steal));
    403                         if(t) return t;
    404                         proc->rdq.last = -1u;
    405                 }
    406 
    407                 unsigned i = __tls_rand() % lanes.count;
    408                 return try_pop(cltr, i __STATS(, __tls_stats()->ready.pop.steal));
    409         }
    410         __attribute__((hot)) struct $thread * pop_search(struct cluster * cltr) {
    411                 return search(cltr);
    412         }
    413 #endif
    414228#if defined(USE_RELAXED_FIFO)
    415229        //-----------------------------------------------------------------------
     
    705519                                        if(is_empty(sl)) {
    706520                                                assert( sl.anchor.next == 0p );
    707                                                 assert( sl.anchor.ts   == -1llu );
     521                                                assert( sl.anchor.ts   == 0 );
    708522                                                assert( mock_head(sl)  == sl.prev );
    709523                                        } else {
    710524                                                assert( sl.anchor.next != 0p );
    711                                                 assert( sl.anchor.ts   != -1llu );
     525                                                assert( sl.anchor.ts   != 0 );
    712526                                                assert( mock_head(sl)  != sl.prev );
    713527                                        }
     
    759573                lanes.tscs = alloc(lanes.count, lanes.tscs`realloc);
    760574                for(i; lanes.count) {
    761                         unsigned long long tsc1 = ts(lanes.data[i]);
    762                         unsigned long long tsc2 = rdtscl();
    763                         lanes.tscs[i].tv = min(tsc1, tsc2);
     575                        unsigned long long tsc = ts(lanes.data[i]);
     576                        lanes.tscs[i].tv = tsc != 0 ? tsc : rdtscl();
    764577                }
    765578        #endif
    766579}
    767580
    768 #if defined(USE_CPU_WORK_STEALING)
    769         // ready_queue size is fixed in this case
    770         void ready_queue_grow(struct cluster * cltr) {}
    771         void ready_queue_shrink(struct cluster * cltr) {}
    772 #else
    773         // Grow the ready queue
    774         void ready_queue_grow(struct cluster * cltr) {
    775                 size_t ncount;
    776                 int target = cltr->procs.total;
    777 
    778                 /* paranoid */ verify( ready_mutate_islocked() );
    779                 __cfadbg_print_safe(ready_queue, "Kernel : Growing ready queue\n");
    780 
    781                 // Make sure that everything is consistent
    782                 /* paranoid */ check( cltr->ready_queue );
    783 
    784                 // grow the ready queue
    785                 with( cltr->ready_queue ) {
    786                         // Find new count
    787                         // Make sure we always have atleast 1 list
    788                         if(target >= 2) {
    789                                 ncount = target * READYQ_SHARD_FACTOR;
    790                         } else {
    791                                 ncount = SEQUENTIAL_SHARD;
     581// Grow the ready queue
     582void ready_queue_grow(struct cluster * cltr) {
     583        size_t ncount;
     584        int target = cltr->procs.total;
     585
     586        /* paranoid */ verify( ready_mutate_islocked() );
     587        __cfadbg_print_safe(ready_queue, "Kernel : Growing ready queue\n");
     588
     589        // Make sure that everything is consistent
     590        /* paranoid */ check( cltr->ready_queue );
     591
     592        // grow the ready queue
     593        with( cltr->ready_queue ) {
     594                // Find new count
     595                // Make sure we always have atleast 1 list
     596                if(target >= 2) {
     597                        ncount = target * READYQ_SHARD_FACTOR;
     598                } else {
     599                        ncount = SEQUENTIAL_SHARD;
     600                }
     601
     602                // Allocate new array (uses realloc and memcpies the data)
     603                lanes.data = alloc( ncount, lanes.data`realloc );
     604
     605                // Fix the moved data
     606                for( idx; (size_t)lanes.count ) {
     607                        fix(lanes.data[idx]);
     608                }
     609
     610                // Construct new data
     611                for( idx; (size_t)lanes.count ~ ncount) {
     612                        (lanes.data[idx]){};
     613                }
     614
     615                // Update original
     616                lanes.count = ncount;
     617        }
     618
     619        fix_times(cltr);
     620
     621        reassign_cltr_id(cltr);
     622
     623        // Make sure that everything is consistent
     624        /* paranoid */ check( cltr->ready_queue );
     625
     626        __cfadbg_print_safe(ready_queue, "Kernel : Growing ready queue done\n");
     627
     628        /* paranoid */ verify( ready_mutate_islocked() );
     629}
     630
     631// Shrink the ready queue
     632void ready_queue_shrink(struct cluster * cltr) {
     633        /* paranoid */ verify( ready_mutate_islocked() );
     634        __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue\n");
     635
     636        // Make sure that everything is consistent
     637        /* paranoid */ check( cltr->ready_queue );
     638
     639        int target = cltr->procs.total;
     640
     641        with( cltr->ready_queue ) {
     642                // Remember old count
     643                size_t ocount = lanes.count;
     644
     645                // Find new count
     646                // Make sure we always have atleast 1 list
     647                lanes.count = target >= 2 ? target * READYQ_SHARD_FACTOR: SEQUENTIAL_SHARD;
     648                /* paranoid */ verify( ocount >= lanes.count );
     649                /* paranoid */ verify( lanes.count == target * READYQ_SHARD_FACTOR || target < 2 );
     650
     651                // for printing count the number of displaced threads
     652                #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_READY_QUEUE__)
     653                        __attribute__((unused)) size_t displaced = 0;
     654                #endif
     655
     656                // redistribute old data
     657                for( idx; (size_t)lanes.count ~ ocount) {
     658                        // Lock is not strictly needed but makes checking invariants much easier
     659                        __attribute__((unused)) bool locked = __atomic_try_acquire(&lanes.data[idx].lock);
     660                        verify(locked);
     661
     662                        // As long as we can pop from this lane to push the threads somewhere else in the queue
     663                        while(!is_empty(lanes.data[idx])) {
     664                                struct $thread * thrd;
     665                                unsigned long long _;
     666                                [thrd, _] = pop(lanes.data[idx]);
     667
     668                                push(cltr, thrd, true);
     669
     670                                // for printing count the number of displaced threads
     671                                #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_READY_QUEUE__)
     672                                        displaced++;
     673                                #endif
    792674                        }
    793675
    794                         // Allocate new array (uses realloc and memcpies the data)
    795                         lanes.data = alloc( ncount, lanes.data`realloc );
    796 
    797                         // Fix the moved data
    798                         for( idx; (size_t)lanes.count ) {
    799                                 fix(lanes.data[idx]);
    800                         }
    801 
    802                         // Construct new data
    803                         for( idx; (size_t)lanes.count ~ ncount) {
    804                                 (lanes.data[idx]){};
    805                         }
    806 
    807                         // Update original
    808                         lanes.count = ncount;
    809                 }
    810 
    811                 fix_times(cltr);
    812 
    813                 reassign_cltr_id(cltr);
    814 
    815                 // Make sure that everything is consistent
    816                 /* paranoid */ check( cltr->ready_queue );
    817 
    818                 __cfadbg_print_safe(ready_queue, "Kernel : Growing ready queue done\n");
    819 
    820                 /* paranoid */ verify( ready_mutate_islocked() );
    821         }
    822 
    823         // Shrink the ready queue
    824         void ready_queue_shrink(struct cluster * cltr) {
    825                 /* paranoid */ verify( ready_mutate_islocked() );
    826                 __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue\n");
    827 
    828                 // Make sure that everything is consistent
    829                 /* paranoid */ check( cltr->ready_queue );
    830 
    831                 int target = cltr->procs.total;
    832 
    833                 with( cltr->ready_queue ) {
    834                         // Remember old count
    835                         size_t ocount = lanes.count;
    836 
    837                         // Find new count
    838                         // Make sure we always have atleast 1 list
    839                         lanes.count = target >= 2 ? target * READYQ_SHARD_FACTOR: SEQUENTIAL_SHARD;
    840                         /* paranoid */ verify( ocount >= lanes.count );
    841                         /* paranoid */ verify( lanes.count == target * READYQ_SHARD_FACTOR || target < 2 );
    842 
    843                         // for printing count the number of displaced threads
    844                         #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_READY_QUEUE__)
    845                                 __attribute__((unused)) size_t displaced = 0;
    846                         #endif
    847 
    848                         // redistribute old data
    849                         for( idx; (size_t)lanes.count ~ ocount) {
    850                                 // Lock is not strictly needed but makes checking invariants much easier
    851                                 __attribute__((unused)) bool locked = __atomic_try_acquire(&lanes.data[idx].lock);
    852                                 verify(locked);
    853 
    854                                 // As long as we can pop from this lane to push the threads somewhere else in the queue
    855                                 while(!is_empty(lanes.data[idx])) {
    856                                         struct $thread * thrd;
    857                                         unsigned long long _;
    858                                         [thrd, _] = pop(lanes.data[idx]);
    859 
    860                                         push(cltr, thrd, true);
    861 
    862                                         // for printing count the number of displaced threads
    863                                         #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_READY_QUEUE__)
    864                                                 displaced++;
    865                                         #endif
    866                                 }
    867 
    868                                 // Unlock the lane
    869                                 __atomic_unlock(&lanes.data[idx].lock);
    870 
    871                                 // TODO print the queue statistics here
    872 
    873                                 ^(lanes.data[idx]){};
    874                         }
    875 
    876                         __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue displaced %zu threads\n", displaced);
    877 
    878                         // Allocate new array (uses realloc and memcpies the data)
    879                         lanes.data = alloc( lanes.count, lanes.data`realloc );
    880 
    881                         // Fix the moved data
    882                         for( idx; (size_t)lanes.count ) {
    883                                 fix(lanes.data[idx]);
    884                         }
    885                 }
    886 
    887                 fix_times(cltr);
    888 
    889                 reassign_cltr_id(cltr);
    890 
    891                 // Make sure that everything is consistent
    892                 /* paranoid */ check( cltr->ready_queue );
    893 
    894                 __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue done\n");
    895                 /* paranoid */ verify( ready_mutate_islocked() );
    896         }
    897 #endif
     676                        // Unlock the lane
     677                        __atomic_unlock(&lanes.data[idx].lock);
     678
     679                        // TODO print the queue statistics here
     680
     681                        ^(lanes.data[idx]){};
     682                }
     683
     684                __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue displaced %zu threads\n", displaced);
     685
     686                // Allocate new array (uses realloc and memcpies the data)
     687                lanes.data = alloc( lanes.count, lanes.data`realloc );
     688
     689                // Fix the moved data
     690                for( idx; (size_t)lanes.count ) {
     691                        fix(lanes.data[idx]);
     692                }
     693        }
     694
     695        fix_times(cltr);
     696
     697        reassign_cltr_id(cltr);
     698
     699        // Make sure that everything is consistent
     700        /* paranoid */ check( cltr->ready_queue );
     701
     702        __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue done\n");
     703        /* paranoid */ verify( ready_mutate_islocked() );
     704}
    898705
    899706#if !defined(__CFA_NO_STATISTICS__)
     
    903710        }
    904711#endif
    905 
    906 
    907 #if   defined(CFA_HAVE_LINUX_LIBRSEQ)
    908         // No definition needed
    909 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
    910 
    911         #if defined( __x86_64 ) || defined( __i386 )
    912                 #define RSEQ_SIG        0x53053053
    913         #elif defined( __ARM_ARCH )
    914                 #ifdef __ARMEB__
    915                 #define RSEQ_SIG    0xf3def5e7      /* udf    #24035    ; 0x5de3 (ARMv6+) */
    916                 #else
    917                 #define RSEQ_SIG    0xe7f5def3      /* udf    #24035    ; 0x5de3 */
    918                 #endif
    919         #endif
    920 
    921         extern void __disable_interrupts_hard();
    922         extern void __enable_interrupts_hard();
    923 
    924         void __kernel_raw_rseq_register  (void) {
    925                 /* paranoid */ verify( __cfaabi_rseq.cpu_id == RSEQ_CPU_ID_UNINITIALIZED );
    926 
    927                 // int ret = syscall(__NR_rseq, &__cfaabi_rseq, sizeof(struct rseq), 0, (sigset_t *)0p, _NSIG / 8);
    928                 int ret = syscall(__NR_rseq, &__cfaabi_rseq, sizeof(struct rseq), 0, RSEQ_SIG);
    929                 if(ret != 0) {
    930                         int e = errno;
    931                         switch(e) {
    932                         case EINVAL: abort("KERNEL ERROR: rseq register invalid argument");
    933                         case ENOSYS: abort("KERNEL ERROR: rseq register no supported");
    934                         case EFAULT: abort("KERNEL ERROR: rseq register with invalid argument");
    935                         case EBUSY : abort("KERNEL ERROR: rseq register already registered");
    936                         case EPERM : abort("KERNEL ERROR: rseq register sig  argument  on unregistration does not match the signature received on registration");
    937                         default: abort("KERNEL ERROR: rseq register unexpected return %d", e);
    938                         }
    939                 }
    940         }
    941 
    942         void __kernel_raw_rseq_unregister(void) {
    943                 /* paranoid */ verify( __cfaabi_rseq.cpu_id >= 0 );
    944 
    945                 // int ret = syscall(__NR_rseq, &__cfaabi_rseq, sizeof(struct rseq), RSEQ_FLAG_UNREGISTER, (sigset_t *)0p, _NSIG / 8);
    946                 int ret = syscall(__NR_rseq, &__cfaabi_rseq, sizeof(struct rseq), RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
    947                 if(ret != 0) {
    948                         int e = errno;
    949                         switch(e) {
    950                         case EINVAL: abort("KERNEL ERROR: rseq unregister invalid argument");
    951                         case ENOSYS: abort("KERNEL ERROR: rseq unregister no supported");
    952                         case EFAULT: abort("KERNEL ERROR: rseq unregister with invalid argument");
    953                         case EBUSY : abort("KERNEL ERROR: rseq unregister already registered");
    954                         case EPERM : abort("KERNEL ERROR: rseq unregister sig  argument  on unregistration does not match the signature received on registration");
    955                         default: abort("KERNEL ERROR: rseq unregisteunexpected return %d", e);
    956                         }
    957                 }
    958         }
    959 #else
    960         // No definition needed
    961 #endif
  • libcfa/src/concurrency/ready_subqueue.hfa

    r660665f r5a46e09  
    3232        this.prev = mock_head(this);
    3333        this.anchor.next = 0p;
    34         this.anchor.ts   = -1llu;
     34        this.anchor.ts   = 0;
    3535        #if !defined(__CFA_NO_STATISTICS__)
    3636                this.cnt  = 0;
     
    4444        /* paranoid */ verify( &mock_head(this)->link.ts   == &this.anchor.ts   );
    4545        /* paranoid */ verify( mock_head(this)->link.next == 0p );
    46         /* paranoid */ verify( mock_head(this)->link.ts   == -1llu  );
     46        /* paranoid */ verify( mock_head(this)->link.ts   == 0  );
    4747        /* paranoid */ verify( mock_head(this) == this.prev );
    4848        /* paranoid */ verify( __alignof__(__intrusive_lane_t) == 128 );
     
    5555        // Make sure the list is empty
    5656        /* paranoid */ verify( this.anchor.next == 0p );
    57         /* paranoid */ verify( this.anchor.ts   == -1llu );
     57        /* paranoid */ verify( this.anchor.ts   == 0 );
    5858        /* paranoid */ verify( mock_head(this)  == this.prev );
    5959}
     
    6464        /* paranoid */ verify( this.lock );
    6565        /* paranoid */ verify( node->link.next == 0p );
    66         /* paranoid */ verify( node->link.ts   == -1llu  );
     66        /* paranoid */ verify( node->link.ts   == 0  );
    6767        /* paranoid */ verify( this.prev->link.next == 0p );
    68         /* paranoid */ verify( this.prev->link.ts   == -1llu  );
     68        /* paranoid */ verify( this.prev->link.ts   == 0  );
    6969        if( this.anchor.next == 0p ) {
    7070                /* paranoid */ verify( this.anchor.next == 0p );
    71                 /* paranoid */ verify( this.anchor.ts   == -1llu );
    72                 /* paranoid */ verify( this.anchor.ts   != 0  );
     71                /* paranoid */ verify( this.anchor.ts   == 0  );
    7372                /* paranoid */ verify( this.prev == mock_head( this ) );
    7473        } else {
    7574                /* paranoid */ verify( this.anchor.next != 0p );
    76                 /* paranoid */ verify( this.anchor.ts   != -1llu );
    7775                /* paranoid */ verify( this.anchor.ts   != 0  );
    7876                /* paranoid */ verify( this.prev != mock_head( this ) );
     
    9492        /* paranoid */ verify( this.lock );
    9593        /* paranoid */ verify( this.anchor.next != 0p );
    96         /* paranoid */ verify( this.anchor.ts   != -1llu );
    9794        /* paranoid */ verify( this.anchor.ts   != 0  );
    9895
     
    10299        this.anchor.next = node->link.next;
    103100        this.anchor.ts   = node->link.ts;
    104         bool is_empty = this.anchor.next == 0p;
     101        bool is_empty = this.anchor.ts == 0;
    105102        node->link.next = 0p;
    106         node->link.ts   = -1llu;
     103        node->link.ts   = 0;
    107104        #if !defined(__CFA_NO_STATISTICS__)
    108105                this.cnt--;
     
    113110
    114111        /* paranoid */ verify( node->link.next == 0p );
    115         /* paranoid */ verify( node->link.ts   == -1llu  );
    116         /* paranoid */ verify( node->link.ts   != 0  );
    117         /* paranoid */ verify( this.anchor.ts  != 0  );
     112        /* paranoid */ verify( node->link.ts   == 0  );
    118113        return [node, ts];
    119114}
     
    121116// Check whether or not list is empty
    122117static inline bool is_empty(__intrusive_lane_t & this) {
    123         return this.anchor.next == 0p;
     118        return this.anchor.ts == 0;
    124119}
    125120
     
    127122static inline unsigned long long ts(__intrusive_lane_t & this) {
    128123        // Cannot verify here since it may not be locked
    129         /* paranoid */ verify(this.anchor.ts != 0);
    130124        return this.anchor.ts;
    131125}
  • libcfa/src/concurrency/thread.cfa

    r660665f r5a46e09  
    1515
    1616#define __cforall_thread__
    17 #define _GNU_SOURCE
    1817
    1918#include "thread.hfa"
     
    4039        curr_cluster = &cl;
    4140        link.next = 0p;
    42         link.ts   = -1llu;
     41        link.ts   = 0;
    4342        preferred = -1u;
    4443        last_proc = 0p;
  • libcfa/src/containers/array.hfa

    r660665f r5a46e09  
    11
    22
    3 forall( __CFA_tysys_id_only_X & ) struct tag {};
     3// a type whose size is n
     4#define Z(n) char[n]
     5
     6// the inverse of Z(-)
     7#define z(N) sizeof(N)
     8
     9forall( T & ) struct tag {};
    410#define ttag(T) ((tag(T)){})
    5 #define ztag(n) ttag(n)
     11#define ztag(n) ttag(Z(n))
    612
    713
     
    1218forall( [N], S & | sized(S), Timmed &, Tbase & ) {
    1319    struct arpk {
    14         S strides[N];
     20        S strides[z(N)];
    1521    };
    1622
     
    5056
    5157    static inline size_t ?`len( arpk(N, S, Timmed, Tbase) & a ) {
    52         return N;
     58        return z(N);
    5359    }
    5460
    5561    // workaround #226 (and array relevance thereof demonstrated in mike102/otype-slow-ndims.cfa)
    5662    static inline void ?{}( arpk(N, S, Timmed, Tbase) & this ) {
    57         void ?{}( S (&inner)[N] ) {}
     63        void ?{}( S (&inner)[z(N)] ) {}
    5864        ?{}(this.strides);
    5965    }
    6066    static inline void ^?{}( arpk(N, S, Timmed, Tbase) & this ) {
    61         void ^?{}( S (&inner)[N] ) {}
     67        void ^?{}( S (&inner)[z(N)] ) {}
    6268        ^?{}(this.strides);
    6369    }
     
    137143// Base
    138144forall( [Nq], Sq & | sized(Sq), Tbase & )
    139 static inline tag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) {
    140     tag(arpk(Nq, Sq, Tbase, Tbase)) ret;
    141     return ret;
    142 }
     145static inline tag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) {}
    143146
    144147// Rec
    145148forall( [Nq], Sq & | sized(Sq), [N], S & | sized(S), recq &, recr &, Tbase & | { tag(recr) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(recq) ); } )
    146 static inline tag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) {
    147     tag(arpk(N, S, recr, Tbase)) ret;
    148     return ret;
    149 }
     149static inline tag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) {}
    150150
    151151// Wrapper
  • libcfa/src/exception.c

    r660665f r5a46e09  
    2727#include "stdhdr/assert.h"
    2828#include "virtual.h"
     29
     30#if defined( __ARM_ARCH )
     31#warning FIX ME: temporary hack to keep ARM build working
     32#ifndef _URC_FATAL_PHASE1_ERROR
     33#define _URC_FATAL_PHASE1_ERROR 3
     34#endif // ! _URC_FATAL_PHASE1_ERROR
     35#ifndef _URC_FATAL_PHASE2_ERROR
     36#define _URC_FATAL_PHASE2_ERROR 2
     37#endif // ! _URC_FATAL_PHASE2_ERROR
     38#endif // __ARM_ARCH
     39
    2940#include "lsda.h"
    3041
     
    256267        // the whole stack.
    257268
    258 #if defined( __x86_64 ) || defined( __i386 )
    259269        // We did not simply reach the end of the stack without finding a handler. This is an error.
    260270        if ( ret != _URC_END_OF_STACK ) {
    261 #else // defined( __ARM_ARCH )
    262         // The return code from _Unwind_RaiseException seems to be corrupt on ARM at end of stack.
    263         // This workaround tries to keep default exception handling working.
    264         if ( ret == _URC_FATAL_PHASE1_ERROR || ret == _URC_FATAL_PHASE2_ERROR ) {
    265 #endif
    266271                printf("UNWIND ERROR %d after raise exception\n", ret);
    267272                abort();
     
    296301}
    297302
    298 #if defined( __x86_64 ) || defined( __i386 ) || defined( __ARM_ARCH )
     303#if defined( __x86_64 ) || defined( __i386 )
    299304// This is our personality routine. For every stack frame annotated with
    300305// ".cfi_personality 0x3,__gcfa_personality_v0" this function will be called twice when unwinding.
     
    414419                                    _Unwind_GetCFA(unwind_context) + 24;
    415420#                               elif defined( __ARM_ARCH )
    416                                     _Unwind_GetCFA(unwind_context) + 40;
     421#                                   warning FIX ME: check if anything needed for ARM
     422                                    42;
    417423#                               endif
    418424                                int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos;
     
    531537        // HEADER
    532538        ".LFECFA1:\n"
    533 #if defined( __x86_64 ) || defined( __i386 )
    534539        "       .globl  __gcfa_personality_v0\n"
    535 #else // defined( __ARM_ARCH )
    536         "       .global __gcfa_personality_v0\n"
    537 #endif
    538540        "       .section        .gcc_except_table,\"a\",@progbits\n"
    539541        // TABLE HEADER (important field is the BODY length at the end)
     
    567569        // No clue what this does specifically
    568570        "       .section        .data.rel.local.CFA.ref.__gcfa_personality_v0,\"awG\",@progbits,CFA.ref.__gcfa_personality_v0,comdat\n"
    569 #if defined( __x86_64 ) || defined( __i386 )
    570571        "       .align 8\n"
    571 #else // defined( __ARM_ARCH )
    572         "       .align 3\n"
    573 #endif
    574572        "       .type CFA.ref.__gcfa_personality_v0, @object\n"
    575573        "       .size CFA.ref.__gcfa_personality_v0, 8\n"
     
    577575#if defined( __x86_64 )
    578576        "       .quad __gcfa_personality_v0\n"
    579 #elif defined( __i386 )
     577#else // then __i386
    580578        "       .long __gcfa_personality_v0\n"
    581 #else // defined( __ARM_ARCH )
    582         "       .xword __gcfa_personality_v0\n"
    583579#endif
    584580);
     
    587583        // HEADER
    588584        ".LFECFA1:\n"
    589 #if defined( __x86_64 ) || defined( __i386 )
    590585        "       .globl  __gcfa_personality_v0\n"
    591 #else // defined( __ARM_ARCH )
    592         "       .global __gcfa_personality_v0\n"
    593 #endif
    594586        "       .section        .gcc_except_table,\"a\",@progbits\n"
    595587        // TABLE HEADER (important field is the BODY length at the end)
     
    620612#pragma GCC pop_options
    621613
     614#elif defined( __ARM_ARCH )
     615_Unwind_Reason_Code __gcfa_personality_v0(
     616                int version,
     617                _Unwind_Action actions,
     618                unsigned long long exception_class,
     619                struct _Unwind_Exception * unwind_exception,
     620                struct _Unwind_Context * unwind_context) {
     621        return _URC_CONTINUE_UNWIND;
     622}
     623
     624__attribute__((noinline))
     625void __cfaehm_try_terminate(void (*try_block)(),
     626                void (*catch_block)(int index, exception_t * except),
     627                __attribute__((unused)) int (*match_block)(exception_t * except)) {
     628}
    622629#else
    623630        #error unsupported hardware architecture
    624 #endif // __x86_64 || __i386 || __ARM_ARCH
     631#endif // __x86_64 || __i386
  • libcfa/src/interpose.cfa

    r660665f r5a46e09  
    9595
    9696extern "C" {
     97        void __cfaabi_interpose_startup(void)  __attribute__(( constructor( STARTUP_PRIORITY_CORE ) ));
    9798        void __cfaabi_interpose_startup( void ) {
    9899                const char *version = 0p;
  • libcfa/src/startup.cfa

    r660665f r5a46e09  
    2020
    2121extern "C" {
    22         void __cfaabi_appready_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_APPREADY ) ));
    23         void __cfaabi_appready_startup( void ) {
     22    void __cfaabi_appready_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_APPREADY ) ));
     23    void __cfaabi_appready_startup( void ) {
    2424                tzset();                                                                                // initialize time global variables
    2525                setlocale( LC_NUMERIC, getenv("LANG") );
     
    2828                heapAppStart();
    2929                #endif // __CFA_DEBUG__
    30         } // __cfaabi_appready_startup
     30    } // __cfaabi_appready_startup
    3131
    32         void __cfaabi_appready_shutdown( void ) __attribute__(( destructor( STARTUP_PRIORITY_APPREADY ) ));
    33         void __cfaabi_appready_shutdown( void ) {
     32    void __cfaabi_appready_shutdown( void ) __attribute__(( destructor( STARTUP_PRIORITY_APPREADY ) ));
     33    void __cfaabi_appready_shutdown( void ) {
    3434                #ifdef __CFA_DEBUG__
    3535                extern void heapAppStop();
    3636                heapAppStop();
    3737                #endif // __CFA_DEBUG__
    38         } // __cfaabi_appready_shutdown
     38    } // __cfaabi_appready_shutdown
    3939
    40         void disable_interrupts() __attribute__(( weak )) {}
    41         void enable_interrupts() __attribute__(( weak )) {}
    42 
    43 
    44         extern void __cfaabi_interpose_startup( void );
    45         extern void __cfaabi_device_startup   ( void );
    46         extern void __cfaabi_device_shutdown  ( void );
    47 
    48         void __cfaabi_core_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) ));
    49         void __cfaabi_core_startup( void ) {
    50                 __cfaabi_interpose_startup();
    51                 __cfaabi_device_startup();
    52         } // __cfaabi_core_startup
    53 
    54         void __cfaabi_core_shutdown( void ) __attribute__(( destructor( STARTUP_PRIORITY_CORE ) ));
    55         void __cfaabi_core_shutdown( void ) {
    56                 __cfaabi_device_shutdown();
    57         } // __cfaabi_core_shutdown
     40    void disable_interrupts() __attribute__(( weak )) {}
     41    void enable_interrupts() __attribute__(( weak )) {}
    5842} // extern "C"
    5943
  • src/AST/Convert.cpp

    r660665f r5a46e09  
    24152415        }
    24162416
    2417         virtual void visit( const DimensionExpr * old ) override final {
    2418                 // DimensionExpr gets desugared away in Validate.
    2419                 // As long as new-AST passes don't use it, this cheap-cheerful error
    2420                 // detection helps ensure that these occurrences have been compiled
    2421                 // away, as expected.  To move the DimensionExpr boundary downstream
    2422                 // or move the new-AST translation boundary upstream, implement
    2423                 // DimensionExpr in the new AST and implement a conversion.
    2424                 (void) old;
    2425                 assert(false && "DimensionExpr should not be present at new-AST boundary");
    2426         }
    2427 
    24282417        virtual void visit( const AsmExpr * old ) override final {
    24292418                this->node = visitBaseExpr( old,
  • src/AST/Decl.cpp

    r660665f r5a46e09  
    7878
    7979const char * TypeDecl::typeString() const {
    80         static const char * kindNames[] = { "sized data type", "sized data type", "sized object type", "sized function type", "sized tuple type", "sized length value" };
     80        static const char * kindNames[] = { "sized data type", "sized data type", "sized object type", "sized function type", "sized tuple type", "sized array length type" };
    8181        static_assert( sizeof(kindNames) / sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." );
    8282        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
  • src/AST/Decl.hpp

    r660665f r5a46e09  
    175175class TypeDecl final : public NamedTypeDecl {
    176176  public:
    177         enum Kind { Dtype, DStype, Otype, Ftype, Ttype, Dimension, NUMBER_OF_KINDS };
     177        enum Kind { Dtype, DStype, Otype, Ftype, Ttype, ALtype, NUMBER_OF_KINDS };
    178178
    179179        Kind kind;
  • src/AST/Pass.impl.hpp

    r660665f r5a46e09  
    479479                        guard_symtab guard { *this };
    480480                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    481                         static ast::ptr< ast::ObjectDecl > func{ new ast::ObjectDecl{
     481                        static ast::ptr< ast::ObjectDecl > func{ new ast::ObjectDecl{ 
    482482                                CodeLocation{}, "__func__",
    483483                                new ast::ArrayType{
     
    522522        VISIT({
    523523                guard_symtab guard { * this };
    524                 maybe_accept( node, &StructDecl::params     );
    525                 maybe_accept( node, &StructDecl::members    );
    526                 maybe_accept( node, &StructDecl::attributes );
     524                maybe_accept( node, &StructDecl::params  );
     525                maybe_accept( node, &StructDecl::members );
    527526        })
    528527
     
    544543        VISIT({
    545544                guard_symtab guard { * this };
    546                 maybe_accept( node, &UnionDecl::params     );
    547                 maybe_accept( node, &UnionDecl::members    );
    548                 maybe_accept( node, &UnionDecl::attributes );
     545                maybe_accept( node, &UnionDecl::params  );
     546                maybe_accept( node, &UnionDecl::members );
    549547        })
    550548
     
    564562        VISIT(
    565563                // unlike structs, traits, and unions, enums inject their members into the global scope
    566                 maybe_accept( node, &EnumDecl::params     );
    567                 maybe_accept( node, &EnumDecl::members    );
    568                 maybe_accept( node, &EnumDecl::attributes );
     564                maybe_accept( node, &EnumDecl::params  );
     565                maybe_accept( node, &EnumDecl::members );
    569566        )
    570567
     
    580577        VISIT({
    581578                guard_symtab guard { *this };
    582                 maybe_accept( node, &TraitDecl::params     );
    583                 maybe_accept( node, &TraitDecl::members    );
    584                 maybe_accept( node, &TraitDecl::attributes );
     579                maybe_accept( node, &TraitDecl::params  );
     580                maybe_accept( node, &TraitDecl::members );
    585581        })
    586582
  • src/CodeGen/CodeGenerator.cc

    r660665f r5a46e09  
    589589                        output << nameExpr->get_name();
    590590                } // if
    591         }
    592 
    593         void CodeGenerator::postvisit( DimensionExpr * dimensionExpr ) {
    594                 extension( dimensionExpr );
    595                 output << "/*non-type*/" << dimensionExpr->get_name();
    596591        }
    597592
  • src/CodeGen/CodeGenerator.h

    r660665f r5a46e09  
    9292                void postvisit( TupleIndexExpr * tupleExpr );
    9393                void postvisit( TypeExpr *typeExpr );
    94                 void postvisit( DimensionExpr *dimensionExpr );
    9594                void postvisit( AsmExpr * );
    9695                void postvisit( StmtExpr * );
  • src/Common/PassVisitor.h

    r660665f r5a46e09  
    167167        virtual void visit( TypeExpr * typeExpr ) override final;
    168168        virtual void visit( const TypeExpr * typeExpr ) override final;
    169         virtual void visit( DimensionExpr * dimensionExpr ) override final;
    170         virtual void visit( const DimensionExpr * dimensionExpr ) override final;
    171169        virtual void visit( AsmExpr * asmExpr ) override final;
    172170        virtual void visit( const AsmExpr * asmExpr ) override final;
     
    311309        virtual Expression * mutate( CommaExpr * commaExpr ) override final;
    312310        virtual Expression * mutate( TypeExpr * typeExpr ) override final;
    313         virtual Expression * mutate( DimensionExpr * dimensionExpr ) override final;
    314311        virtual Expression * mutate( AsmExpr * asmExpr ) override final;
    315312        virtual Expression * mutate( ImplicitCopyCtorExpr * impCpCtorExpr ) override final;
     
    545542class WithIndexer {
    546543protected:
    547         WithIndexer( bool trackIdentifiers = true ) : indexer(trackIdentifiers) {}
     544        WithIndexer() {}
    548545        ~WithIndexer() {}
    549546
  • src/Common/PassVisitor.impl.h

    r660665f r5a46e09  
    636636                maybeAccept_impl( node->parameters, *this );
    637637                maybeAccept_impl( node->members   , *this );
    638                 maybeAccept_impl( node->attributes, *this );
    639638        }
    640639
     
    657656                maybeAccept_impl( node->parameters, *this );
    658657                maybeAccept_impl( node->members   , *this );
    659                 maybeAccept_impl( node->attributes, *this );
    660658        }
    661659
     
    678676                maybeMutate_impl( node->parameters, *this );
    679677                maybeMutate_impl( node->members   , *this );
    680                 maybeMutate_impl( node->attributes, *this );
    681678        }
    682679
     
    700697                maybeAccept_impl( node->parameters, *this );
    701698                maybeAccept_impl( node->members   , *this );
    702                 maybeAccept_impl( node->attributes, *this );
    703699        }
    704700
     
    718714                maybeAccept_impl( node->parameters, *this );
    719715                maybeAccept_impl( node->members   , *this );
    720                 maybeAccept_impl( node->attributes, *this );
    721716        }
    722717
     
    737732                maybeMutate_impl( node->parameters, *this );
    738733                maybeMutate_impl( node->members   , *this );
    739                 maybeMutate_impl( node->attributes, *this );
    740734        }
    741735
     
    756750        maybeAccept_impl( node->parameters, *this );
    757751        maybeAccept_impl( node->members   , *this );
    758         maybeAccept_impl( node->attributes, *this );
    759752
    760753        VISIT_END( node );
     
    770763        maybeAccept_impl( node->parameters, *this );
    771764        maybeAccept_impl( node->members   , *this );
    772         maybeAccept_impl( node->attributes, *this );
    773765
    774766        VISIT_END( node );
     
    784776        maybeMutate_impl( node->parameters, *this );
    785777        maybeMutate_impl( node->members   , *this );
    786         maybeMutate_impl( node->attributes, *this );
    787778
    788779        MUTATE_END( Declaration, node );
     
    799790                maybeAccept_impl( node->parameters, *this );
    800791                maybeAccept_impl( node->members   , *this );
    801                 maybeAccept_impl( node->attributes, *this );
    802792        }
    803793
     
    815805                maybeAccept_impl( node->parameters, *this );
    816806                maybeAccept_impl( node->members   , *this );
    817                 maybeAccept_impl( node->attributes, *this );
    818807        }
    819808
     
    831820                maybeMutate_impl( node->parameters, *this );
    832821                maybeMutate_impl( node->members   , *this );
    833                 maybeMutate_impl( node->attributes, *this );
    834822        }
    835823
     
    25192507
    25202508//--------------------------------------------------------------------------
    2521 // DimensionExpr
    2522 template< typename pass_type >
    2523 void PassVisitor< pass_type >::visit( DimensionExpr * node ) {
    2524         VISIT_START( node );
    2525 
    2526         indexerScopedAccept( node->result, *this );
    2527 
    2528         VISIT_END( node );
    2529 }
    2530 
    2531 template< typename pass_type >
    2532 void PassVisitor< pass_type >::visit( const DimensionExpr * node ) {
    2533         VISIT_START( node );
    2534 
    2535         indexerScopedAccept( node->result, *this );
    2536 
    2537         VISIT_END( node );
    2538 }
    2539 
    2540 template< typename pass_type >
    2541 Expression * PassVisitor< pass_type >::mutate( DimensionExpr * node ) {
    2542         MUTATE_START( node );
    2543 
    2544         indexerScopedMutate( node->env   , *this );
    2545         indexerScopedMutate( node->result, *this );
    2546 
    2547         MUTATE_END( Expression, node );
    2548 }
    2549 
    2550 //--------------------------------------------------------------------------
    25512509// AsmExpr
    25522510template< typename pass_type >
     
    31873145
    31883146        maybeAccept_impl( node->forall, *this );
    3189         maybeAccept_impl( node->dimension, *this );
     3147        // xxx - should PointerType visit/mutate dimension?
    31903148        maybeAccept_impl( node->base, *this );
    31913149
     
    31983156
    31993157        maybeAccept_impl( node->forall, *this );
    3200         maybeAccept_impl( node->dimension, *this );
     3158        // xxx - should PointerType visit/mutate dimension?
    32013159        maybeAccept_impl( node->base, *this );
    32023160
     
    32093167
    32103168        maybeMutate_impl( node->forall, *this );
    3211         maybeMutate_impl( node->dimension, *this );
     3169        // xxx - should PointerType visit/mutate dimension?
    32123170        maybeMutate_impl( node->base, *this );
    32133171
     
    38983856
    38993857//--------------------------------------------------------------------------
    3900 // Constant
     3858// Attribute
    39013859template< typename pass_type >
    39023860void PassVisitor< pass_type >::visit( Constant * node ) {
  • src/InitTweak/InitTweak.cc

    r660665f r5a46e09  
    1010// Created On       : Fri May 13 11:26:36 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 16 20:57:22 2021
    13 // Update Count     : 18
     12// Last Modified On : Fri Dec 13 23:15:52 2019
     13// Update Count     : 8
    1414//
    1515
     
    12171217        void addDataSectonAttribute( ObjectDecl * objDecl ) {
    12181218                objDecl->attributes.push_back(new Attribute("section", {
    1219                         new ConstantExpr( Constant::from_string(".data"
    1220 #if defined( __x86_64 ) || defined( __i386 ) // assembler comment to prevent assembler warning message
    1221                                         "#"
    1222 #else // defined( __ARM_ARCH )
    1223                                         "//"
    1224 #endif
    1225                                 ))}));
     1219                        new ConstantExpr( Constant::from_string(".data#") ),
     1220                }));
    12261221        }
    12271222
    12281223        void addDataSectionAttribute( ast::ObjectDecl * objDecl ) {
    12291224                objDecl->attributes.push_back(new ast::Attribute("section", {
    1230                         ast::ConstantExpr::from_string(objDecl->location, ".data"
    1231 #if defined( __x86_64 ) || defined( __i386 ) // assembler comment to prevent assembler warning message
    1232                                         "#"
    1233 #else // defined( __ARM_ARCH )
    1234                                         "//"
    1235 #endif
    1236                                 )}));
     1225                        ast::ConstantExpr::from_string(objDecl->location, ".data#"),
     1226                }));
    12371227        }
    12381228
  • src/Parser/DeclarationNode.cc

    r660665f r5a46e09  
    10761076        if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
    10771077                // otype is internally converted to dtype + otype parameters
    1078                 static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::Dimension };
     1078                static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::DStype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::Dtype };
    10791079                static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." );
    10801080                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    1081                 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype || variable.tyClass == TypeDecl::DStype, variable.initializer ? variable.initializer->buildType() : nullptr );
     1081                TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype || variable.tyClass == TypeDecl::ALtype, variable.initializer ? variable.initializer->buildType() : nullptr );
    10821082                buildList( variable.assertions, ret->get_assertions() );
    10831083                return ret;
  • src/Parser/ExpressionNode.cc

    r660665f r5a46e09  
    509509} // build_varref
    510510
    511 DimensionExpr * build_dimensionref( const string * name ) {
    512         DimensionExpr * expr = new DimensionExpr( *name );
    513         delete name;
    514         return expr;
    515 } // build_varref
    516511// TODO: get rid of this and OperKinds and reuse code from OperatorTable
    517512static const char * OperName[] = {                                              // must harmonize with OperKinds
  • src/Parser/ParseNode.h

    r660665f r5a46e09  
    183183
    184184NameExpr * build_varref( const std::string * name );
    185 DimensionExpr * build_dimensionref( const std::string * name );
    186185
    187186Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
  • src/Parser/TypedefTable.cc

    r660665f r5a46e09  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 19 08:30:14 2021
    13 // Update Count     : 262
     12// Last Modified On : Mon Mar 15 20:56:47 2021
     13// Update Count     : 260
    1414//
    1515
     
    3131        switch ( kind ) {
    3232          case IDENTIFIER: return "identifier";
    33           case TYPEDIMname: return "typedim";
    3433          case TYPEDEFname: return "typedef";
    3534          case TYPEGENname: return "typegen";
  • src/Parser/lex.ll

    r660665f r5a46e09  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Sun Jun 20 18:41:09 2021
    13  * Update Count     : 759
     12 * Last Modified On : Thu Apr  1 13:22:31 2021
     13 * Update Count     : 754
    1414 */
    1515
     
    117117hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt}
    118118
    119                                 // GCC: floating D (double), imaginary iI, and decimal floating DF, DD, DL
     119                                // GCC: D (double) and iI (imaginary) suffixes, and DL (long double)
    120120exponent "_"?[eE]"_"?[+-]?{decimal_digits}
    121121floating_size 16|32|32x|64|64x|80|128|128x
    122122floating_length ([fFdDlLwWqQ]|[fF]{floating_size})
    123123floating_suffix ({floating_length}?[iI]?)|([iI]{floating_length})
    124 decimal_floating_suffix [dD][fFdDlL]
    125 floating_suffix_opt ("_"?({floating_suffix}|{decimal_floating_suffix}))?
     124floating_suffix_opt ("_"?({floating_suffix}|"DL"))?
    126125decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal})
    127126floating_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt}
     
    235234continue                { KEYWORD_RETURN(CONTINUE); }
    236235coroutine               { KEYWORD_RETURN(COROUTINE); }                  // CFA
    237 _Decimal32              { KEYWORD_RETURN(DECIMAL32); }                  // GCC
    238 _Decimal64              { KEYWORD_RETURN(DECIMAL64); }                  // GCC
    239 _Decimal128             { KEYWORD_RETURN(DECIMAL128); }                 // GCC
    240236default                 { KEYWORD_RETURN(DEFAULT); }
    241237disable                 { KEYWORD_RETURN(DISABLE); }                    // CFA
  • src/Parser/parser.yy

    r660665f r5a46e09  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jun 29 09:12:47 2021
    13 // Update Count     : 5027
     12// Last Modified On : Mon Apr 26 18:41:54 2021
     13// Update Count     : 4990
    1414//
    1515
     
    2626// The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for:
    2727//
    28 //   designation with '=' (use ':' instead)
    29 //
    30 // This incompatibility is discussed in detail before the "designation" grammar rule.  Most of the syntactic extensions
    31 // from ANSI90 to ANSI11 C are marked with the comment "C99/C11".
    32 
    33 // This grammar also has two levels of extensions. The first extensions cover most of the GCC C extensions All of the
    34 // syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall (CFA), which
    35 // fixes several of C's outstanding problems and extends C with many modern language concepts. All of the syntactic
    36 // extensions for CFA C are marked with the comment "CFA".
     28// 1. designation with '=' (use ':' instead)
     29//
     30// Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This grammar also has
     31// two levels of extensions. The first extensions cover most of the GCC C extensions, except for:
     32//
     33// 1. designation with and without '=' (use ':' instead)
     34
     35//
     36// All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall
     37// (CFA), which fixes several of C's outstanding problems and extends C with many modern language concepts. All of the
     38// syntactic extensions for CFA C are marked with the comment "CFA". As noted above, there is one unreconcileable
     39// parsing problem between C99 and CFA with respect to designators; this is discussed in detail before the "designation"
     40// grammar rule.
    3741
    3842%{
     
    265269%token INT128 UINT128 uuFLOAT80 uuFLOAT128                              // GCC
    266270%token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC
    267 %token DECIMAL32 DECIMAL64 DECIMAL128                                   // GCC
    268271%token ZERO_T ONE_T                                                                             // CFA
    269272%token SIZEOF TYPEOF VALIST AUTO_TYPE                                   // GCC
     
    284287
    285288// names and constants: lexer differentiates between identifier and typedef names
    286 %token<tok> IDENTIFIER          QUOTED_IDENTIFIER       TYPEDIMname             TYPEDEFname             TYPEGENname
     289%token<tok> IDENTIFIER          QUOTED_IDENTIFIER       TYPEDEFname             TYPEGENname
    287290%token<tok> TIMEOUT                     WOR                                     CATCH                   RECOVER                 CATCHRESUME             FIXUP           FINALLY         // CFA
    288291%token<tok> INTEGERconstant     CHARACTERconstant       STRINGliteral
     
    583586        | quasi_keyword
    584587                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    585         | TYPEDIMname                                                                           // CFA, generic length argument
    586                 // { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( DeclarationNode::newFromTypedef( $1 ) ) ) ); }
    587                 // { $$ = new ExpressionNode( build_varref( $1 ) ); }
    588                 { $$ = new ExpressionNode( build_dimensionref( $1 ) ); }
    589588        | tuple
    590589        | '(' comma_expression ')'
     
    631630postfix_expression:
    632631        primary_expression
    633         | postfix_expression '[' assignment_expression ',' tuple_expression_list ']'
    634                         // Historic, transitional: Disallow commas in subscripts.
    635                         // Switching to this behaviour may help check if a C compatibilty case uses comma-exprs in subscripts.
    636                 // { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }
    637                         // Current: Commas in subscripts make tuples.
    638                 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $5 ) ) )) ) ); }
     632        | postfix_expression '[' assignment_expression ',' comma_expression ']'
     633                // { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_binary_val( OperKinds::Index, $3, $5 ) ) ) ); }
     634                { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }
    639635        | postfix_expression '[' assignment_expression ']'
    640636                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
     
    18911887        | uFLOAT128
    18921888                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat128 ); }
    1893         | DECIMAL32
    1894                 { SemanticError( yylloc, "_Decimal32 is currently unimplemented." ); $$ = nullptr; }
    1895         | DECIMAL64
    1896                 { SemanticError( yylloc, "_Decimal64 is currently unimplemented." ); $$ = nullptr; }
    1897         | DECIMAL128
    1898                 { SemanticError( yylloc, "_Decimal128 is currently unimplemented." ); $$ = nullptr; }
    18991889        | COMPLEX                                                                                       // C99
    19001890                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
     
    19191909        // empty
    19201910                { $$ = nullptr; }
    1921         | vtable
     1911        | vtable;
    19221912        ;
    19231913
     
    25452535        | '[' identifier_or_type_name ']'
    25462536                {
    2547                         typedefTable.addToScope( *$2, TYPEDIMname, "9" );
    2548                         $$ = DeclarationNode::newTypeParam( TypeDecl::Dimension, $2 );
     2537                        typedefTable.addToScope( *$2, TYPEDEFname, "9" );
     2538                        $$ = DeclarationNode::newTypeParam( TypeDecl::ALtype, $2 );
    25492539                }
    25502540        // | type_specifier identifier_parameter_declarator
     
    25602550        | '*'
    25612551                { $$ = TypeDecl::DStype; }                                              // dtype + sized
    2562         // | '(' '*' ')'
    2563         //      { $$ = TypeDecl::Ftype; }
    25642552        | ELLIPSIS
    25652553                { $$ = TypeDecl::Ttype; }
     
    26022590                { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); }
    26032591        | assignment_expression
     2592                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }
    26042593        | type_list ',' type
    26052594                { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); }
    26062595        | type_list ',' assignment_expression
    2607                 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     2596                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; }
     2597                // { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    26082598        ;
    26092599
  • src/SymTab/Indexer.cc

    r660665f r5a46e09  
    7474        }
    7575
    76         Indexer::Indexer( bool trackIdentifiers )
     76        Indexer::Indexer()
    7777        : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(),
    78           prevScope(), scope( 0 ), repScope( 0 ), trackIdentifiers( trackIdentifiers ) { ++* stats().count; }
     78          prevScope(), scope( 0 ), repScope( 0 ) { ++* stats().count; }
    7979
    8080        Indexer::~Indexer() {
     
    110110
    111111        void Indexer::lookupId( const std::string & id, std::list< IdData > &out ) const {
    112                 assert( trackIdentifiers );
    113 
    114112                ++* stats().lookup_calls;
    115113                if ( ! idTable ) return;
     
    436434                        const Declaration * deleteStmt ) {
    437435                ++* stats().add_calls;
    438                 if ( ! trackIdentifiers ) return;
    439436                const std::string &name = decl->name;
    440437                if ( name == "" ) return;
  • src/SymTab/Indexer.h

    r660665f r5a46e09  
    3131        class Indexer : public std::enable_shared_from_this<SymTab::Indexer> {
    3232        public:
    33                 explicit Indexer( bool trackIdentifiers = true );
     33                explicit Indexer();
    3434                virtual ~Indexer();
    3535
     
    180180                /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
    181181                bool hasIncompatibleCDecl( const std::string & id, const std::string & mangleName ) const;
    182 
    183             bool trackIdentifiers;
    184182        };
    185183} // namespace SymTab
  • src/SymTab/Validate.cc

    r660665f r5a46e09  
    105105
    106106        struct FixQualifiedTypes final : public WithIndexer {
    107                 FixQualifiedTypes() : WithIndexer(false) {}
    108107                Type * postmutate( QualifiedType * );
    109108        };
     
    175174        };
    176175
    177         /// Does early resolution on the expressions that give enumeration constants their values
    178         struct ResolveEnumInitializers final : public WithIndexer, public WithGuards, public WithVisitorRef<ResolveEnumInitializers>, public WithShortCircuiting {
    179                 ResolveEnumInitializers( const Indexer * indexer );
    180                 void postvisit( EnumDecl * enumDecl );
    181 
    182           private:
    183                 const Indexer * local_indexer;
    184 
    185         };
    186 
    187176        /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID.
    188177        struct ForallPointerDecay_old final {
     
    271260                void previsit( StructInstType * inst );
    272261                void previsit( UnionInstType * inst );
    273         };
    274 
    275         /// desugar declarations and uses of dimension paramaters like [N],
    276         /// from type-system managed values, to tunnneling via ordinary types,
    277         /// as char[-] in and sizeof(-) out
    278         struct TranslateDimensionGenericParameters : public WithIndexer, public WithGuards {
    279                 static void translateDimensions( std::list< Declaration * > &translationUnit );
    280                 TranslateDimensionGenericParameters();
    281 
    282                 bool nextVisitedNodeIsChildOfSUIT = false; // SUIT = Struct or Union -Inst Type
    283                 bool visitingChildOfSUIT = false;
    284                 void changeState_ChildOfSUIT( bool newVal );
    285                 void premutate( StructInstType * sit );
    286                 void premutate( UnionInstType * uit );
    287                 void premutate( BaseSyntaxNode * node );
    288 
    289                 TypeDecl * postmutate( TypeDecl * td );
    290                 Expression * postmutate( DimensionExpr * de );
    291                 Expression * postmutate( Expression * e );
    292262        };
    293263
     
    337307                PassVisitor<EnumAndPointerDecay_old> epc;
    338308                PassVisitor<LinkReferenceToTypes_old> lrt( nullptr );
    339                 PassVisitor<ResolveEnumInitializers> rei( nullptr );
    340309                PassVisitor<ForallPointerDecay_old> fpd;
    341310                PassVisitor<CompoundLiteral> compoundliteral;
     
    357326                        Stats::Heap::newPass("validate-B");
    358327                        Stats::Time::BlockGuard guard("validate-B");
    359                         acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
    360                         mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes_old, because aggregate members are accessed
    361                         HoistStruct::hoistStruct( translationUnit );
    362                         EliminateTypedef::eliminateTypedef( translationUnit );
     328                        Stats::Time::TimeBlock("Link Reference To Types", [&]() {
     329                                acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
     330                        });
     331                        Stats::Time::TimeBlock("Fix Qualified Types", [&]() {
     332                                mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes_old, because aggregate members are accessed
     333                        });
     334                        Stats::Time::TimeBlock("Hoist Structs", [&]() {
     335                                HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order
     336                        });
     337                        Stats::Time::TimeBlock("Eliminate Typedefs", [&]() {
     338                                EliminateTypedef::eliminateTypedef( translationUnit ); //
     339                        });
    363340                }
    364341                {
    365342                        Stats::Heap::newPass("validate-C");
    366343                        Stats::Time::BlockGuard guard("validate-C");
    367                         Stats::Time::TimeBlock("Validate Generic Parameters", [&]() {
    368                                 acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes_old; observed failing when attempted before eliminateTypedef
    369                         });
    370                         Stats::Time::TimeBlock("Translate Dimensions", [&]() {
    371                                 TranslateDimensionGenericParameters::translateDimensions( translationUnit );
    372                         });
    373                         Stats::Time::TimeBlock("Resolve Enum Initializers", [&]() {
    374                                 acceptAll( translationUnit, rei ); // must happen after translateDimensions because rei needs identifier lookup, which needs name mangling
    375                         });
    376                         Stats::Time::TimeBlock("Check Function Returns", [&]() {
    377                                 ReturnChecker::checkFunctionReturns( translationUnit );
    378                         });
    379                         Stats::Time::TimeBlock("Fix Return Statements", [&]() {
    380                                 InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen
    381                         });
     344                        acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes_old
     345                        ReturnChecker::checkFunctionReturns( translationUnit );
     346                        InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen
    382347                }
    383348                {
     
    679644        }
    680645
    681         LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer * other_indexer ) : WithIndexer( false ) {
     646        LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer * other_indexer ) {
    682647                if ( other_indexer ) {
    683648                        local_indexer = other_indexer;
     
    699664        }
    700665
     666        void checkGenericParameters( ReferenceToType * inst ) {
     667                for ( Expression * param : inst->parameters ) {
     668                        if ( ! dynamic_cast< TypeExpr * >( param ) ) {
     669                                SemanticError( inst, "Expression parameters for generic types are currently unsupported: " );
     670                        }
     671                }
     672        }
     673
    701674        void LinkReferenceToTypes_old::postvisit( StructInstType * structInst ) {
    702675                const StructDecl * st = local_indexer->lookupStruct( structInst->name );
     
    709682                        forwardStructs[ structInst->name ].push_back( structInst );
    710683                } // if
     684                checkGenericParameters( structInst );
    711685        }
    712686
     
    721695                        forwardUnions[ unionInst->name ].push_back( unionInst );
    722696                } // if
     697                checkGenericParameters( unionInst );
    723698        }
    724699
     
    832807                                forwardEnums.erase( fwds );
    833808                        } // if
     809
     810                        for ( Declaration * member : enumDecl->members ) {
     811                                ObjectDecl * field = strict_dynamic_cast<ObjectDecl *>( member );
     812                                if ( field->init ) {
     813                                        // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information.
     814                                        SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init );
     815                                        ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
     816                                }
     817                        }
    834818                } // if
    835819        }
     
    894878                                typeInst->set_isFtype( typeDecl->kind == TypeDecl::Ftype );
    895879                        } // if
    896                 } // if
    897         }
    898 
    899         ResolveEnumInitializers::ResolveEnumInitializers( const Indexer * other_indexer ) : WithIndexer( true ) {
    900                 if ( other_indexer ) {
    901                         local_indexer = other_indexer;
    902                 } else {
    903                         local_indexer = &indexer;
    904                 } // if
    905         }
    906 
    907         void ResolveEnumInitializers::postvisit( EnumDecl * enumDecl ) {
    908                 if ( enumDecl->body ) {
    909                         for ( Declaration * member : enumDecl->members ) {
    910                                 ObjectDecl * field = strict_dynamic_cast<ObjectDecl *>( member );
    911                                 if ( field->init ) {
    912                                         // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information.
    913                                         SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init );
    914                                         ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
    915                                 }
    916                         }
    917880                } // if
    918881        }
     
    11891152                GuardScope( typedeclNames );
    11901153                mutateAll( aggr->parameters, * visitor );
    1191                 mutateAll( aggr->attributes, * visitor );
    11921154
    11931155                // unroll mutateAll for aggr->members so that implicit typedefs for nested types are added to the aggregate body.
     
    12581220                        }
    12591221                }
    1260         }
    1261 
    1262         // Test for special name on a generic parameter.  Special treatment for the
    1263         // special name is a bootstrapping hack.  In most cases, the worlds of T's
    1264         // and of N's don't overlap (normal treamtemt).  The foundations in
    1265         // array.hfa use tagging for both types and dimensions.  Tagging treats
    1266         // its subject parameter even more opaquely than T&, which assumes it is
    1267         // possible to have a pointer/reference to such an object.  Tagging only
    1268         // seeks to identify the type-system resident at compile time.  Both N's
    1269         // and T's can make tags.  The tag definition uses the special name, which
    1270         // is treated as "an N or a T."  This feature is not inteded to be used
    1271         // outside of the definition and immediate uses of a tag.
    1272         static inline bool isReservedTysysIdOnlyName( const std::string & name ) {
    1273                 // name's prefix was __CFA_tysys_id_only, before it got wrapped in __..._generic
    1274                 int foundAt = name.find("__CFA_tysys_id_only");
    1275                 if (foundAt == 0) return true;
    1276                 if (foundAt == 2 && name[0] == '_' && name[1] == '_') return true;
    1277                 return false;
    12781222        }
    12791223
     
    12941238                        TypeSubstitution sub;
    12951239                        auto paramIter = params->begin();
    1296                         auto argIter = args.begin();
    1297                         for ( ; paramIter != params->end(); ++paramIter, ++argIter ) {
    1298                                 if ( argIter != args.end() ) {
    1299                                         TypeExpr * expr = dynamic_cast< TypeExpr * >( * argIter );
    1300                                         if ( expr ) {
    1301                                                 sub.add( (* paramIter)->get_name(), expr->get_type()->clone() );
    1302                                         }
    1303                                 } else {
     1240                        for ( size_t i = 0; paramIter != params->end(); ++paramIter, ++i ) {
     1241                                if ( i < args.size() ) {
     1242                                        TypeExpr * expr = strict_dynamic_cast< TypeExpr * >( * std::next( args.begin(), i ) );
     1243                                        sub.add( (* paramIter)->get_name(), expr->get_type()->clone() );
     1244                                } else if ( i == args.size() ) {
    13041245                                        Type * defaultType = (* paramIter)->get_init();
    13051246                                        if ( defaultType ) {
    13061247                                                args.push_back( new TypeExpr( defaultType->clone() ) );
    13071248                                                sub.add( (* paramIter)->get_name(), defaultType->clone() );
    1308                                                 argIter = std::prev(args.end());
    1309                                         } else {
    1310                                                 SemanticError( inst, "Too few type arguments in generic type " );
    13111249                                        }
    13121250                                }
    1313                                 assert( argIter != args.end() );
    1314                                 bool typeParamDeclared = (*paramIter)->kind != TypeDecl::Kind::Dimension;
    1315                                 bool typeArgGiven;
    1316                                 if ( isReservedTysysIdOnlyName( (*paramIter)->name ) ) {
    1317                                         // coerce a match when declaration is reserved name, which means "either"
    1318                                         typeArgGiven = typeParamDeclared;
    1319                                 } else {
    1320                                         typeArgGiven = dynamic_cast< TypeExpr * >( * argIter );
    1321                                 }
    1322                                 if ( ! typeParamDeclared &&   typeArgGiven ) SemanticError( inst, "Type argument given for value parameter: " );
    1323                                 if (   typeParamDeclared && ! typeArgGiven ) SemanticError( inst, "Expression argument given for type parameter: " );
    13241251                        }
    13251252
    13261253                        sub.apply( inst );
     1254                        if ( args.size() < params->size() ) SemanticError( inst, "Too few type arguments in generic type " );
    13271255                        if ( args.size() > params->size() ) SemanticError( inst, "Too many type arguments in generic type " );
    13281256                }
     
    13351263        void ValidateGenericParameters::previsit( UnionInstType * inst ) {
    13361264                validateGeneric( inst );
    1337         }
    1338 
    1339         void TranslateDimensionGenericParameters::translateDimensions( std::list< Declaration * > &translationUnit ) {
    1340                 PassVisitor<TranslateDimensionGenericParameters> translator;
    1341                 mutateAll( translationUnit, translator );
    1342         }
    1343 
    1344         TranslateDimensionGenericParameters::TranslateDimensionGenericParameters() : WithIndexer( false ) {}
    1345 
    1346         // Declaration of type variable:           forall( [N] )          ->  forall( N & | sized( N ) )
    1347         TypeDecl * TranslateDimensionGenericParameters::postmutate( TypeDecl * td ) {
    1348                 if ( td->kind == TypeDecl::Dimension ) {
    1349                         td->kind = TypeDecl::Dtype;
    1350                         if ( ! isReservedTysysIdOnlyName( td->name ) ) {
    1351                                 td->sized = true;
    1352                         }
    1353                 }
    1354                 return td;
    1355         }
    1356 
    1357         // Situational awareness:
    1358         // array( float, [[currentExpr]]     )  has  visitingChildOfSUIT == true
    1359         // array( float, [[currentExpr]] - 1 )  has  visitingChildOfSUIT == false
    1360         // size_t x =    [[currentExpr]]        has  visitingChildOfSUIT == false
    1361         void TranslateDimensionGenericParameters::changeState_ChildOfSUIT( bool newVal ) {
    1362                 GuardValue( nextVisitedNodeIsChildOfSUIT );
    1363                 GuardValue( visitingChildOfSUIT );
    1364                 visitingChildOfSUIT = nextVisitedNodeIsChildOfSUIT;
    1365                 nextVisitedNodeIsChildOfSUIT = newVal;
    1366         }
    1367         void TranslateDimensionGenericParameters::premutate( StructInstType * sit ) {
    1368                 (void) sit;
    1369                 changeState_ChildOfSUIT(true);
    1370         }
    1371         void TranslateDimensionGenericParameters::premutate( UnionInstType * uit ) {
    1372                 (void) uit;
    1373                 changeState_ChildOfSUIT(true);
    1374         }
    1375         void TranslateDimensionGenericParameters::premutate( BaseSyntaxNode * node ) {
    1376                 (void) node;
    1377                 changeState_ChildOfSUIT(false);
    1378         }
    1379 
    1380         // Passing values as dimension arguments:  array( float,     7 )  -> array( float, char[             7 ] )
    1381         // Consuming dimension parameters:         size_t x =    N - 1 ;  -> size_t x =          sizeof(N) - 1   ;
    1382         // Intertwined reality:                    array( float, N     )  -> array( float,              N        )
    1383         //                                         array( float, N - 1 )  -> array( float, char[ sizeof(N) - 1 ] )
    1384         // Intertwined case 1 is not just an optimization.
    1385         // Avoiding char[sizeof(-)] is necessary to enable the call of f to bind the value of N, in:
    1386         //   forall([N]) void f( array(float, N) & );
    1387         //   array(float, 7) a;
    1388         //   f(a);
    1389 
    1390         Expression * TranslateDimensionGenericParameters::postmutate( DimensionExpr * de ) {
    1391                 // Expression de is an occurrence of N in LHS of above examples.
    1392                 // Look up the name that de references.
    1393                 // If we are in a struct body, then this reference can be to an entry of the stuct's forall list.
    1394                 // Whether or not we are in a struct body, this reference can be to an entry of a containing function's forall list.
    1395                 // If we are in a struct body, then the stuct's forall declarations are innermost (functions don't occur in structs).
    1396                 // Thus, a potential struct's declaration is highest priority.
    1397                 // A struct's forall declarations are already renamed with _generic_ suffix.  Try that name variant first.
    1398 
    1399                 std::string useName = "__" + de->name + "_generic_";
    1400                 TypeDecl * namedParamDecl = const_cast<TypeDecl *>( strict_dynamic_cast<const TypeDecl *, nullptr >( indexer.lookupType( useName ) ) );
    1401 
    1402                 if ( ! namedParamDecl ) {
    1403                         useName = de->name;
    1404                         namedParamDecl = const_cast<TypeDecl *>( strict_dynamic_cast<const TypeDecl *, nullptr >( indexer.lookupType( useName ) ) );
    1405                 }
    1406 
    1407                 // Expect to find it always.  A misspelled name would have been parsed as an identifier.
    1408                 assert( namedParamDecl && "Type-system-managed value name not found in symbol table" );
    1409 
    1410                 delete de;
    1411 
    1412                 TypeInstType * refToDecl = new TypeInstType( 0, useName, namedParamDecl );
    1413 
    1414                 if ( visitingChildOfSUIT ) {
    1415                         // As in postmutate( Expression * ), topmost expression needs a TypeExpr wrapper
    1416                         // But avoid ArrayType-Sizeof
    1417                         return new TypeExpr( refToDecl );
    1418                 } else {
    1419                         // the N occurrence is being used directly as a runtime value,
    1420                         // if we are in a type instantiation, then the N is within a bigger value computation
    1421                         return new SizeofExpr( refToDecl );
    1422                 }
    1423         }
    1424 
    1425         Expression * TranslateDimensionGenericParameters::postmutate( Expression * e ) {
    1426                 if ( visitingChildOfSUIT ) {
    1427                         // e is an expression used as an argument to instantiate a type
    1428                         if (! dynamic_cast< TypeExpr * >( e ) ) {
    1429                                 // e is a value expression
    1430                                 // but not a DimensionExpr, which has a distinct postmutate
    1431                                 Type * typeExprContent = new ArrayType( 0, new BasicType( 0, BasicType::Char ), e, true, false );
    1432                                 TypeExpr * result = new TypeExpr( typeExprContent );
    1433                                 return result;
    1434                         }
    1435                 }
    1436                 return e;
    14371265        }
    14381266
  • src/SynTree/Declaration.h

    r660665f r5a46e09  
    201201        typedef NamedTypeDecl Parent;
    202202  public:
    203         enum Kind { Dtype, DStype, Otype, Ftype, Ttype, Dimension, NUMBER_OF_KINDS };
     203        enum Kind { Dtype, DStype, Otype, Ftype, Ttype, ALtype, NUMBER_OF_KINDS };
    204204
    205205        Kind kind;
  • src/SynTree/Expression.h

    r660665f r5a46e09  
    587587};
    588588
    589 /// DimensionExpr represents a type-system provided value used in an expression ( forrall([N]) ... N + 1 )
    590 class DimensionExpr : public Expression {
    591   public:
    592         std::string name;
    593 
    594         DimensionExpr( std::string name );
    595         DimensionExpr( const DimensionExpr & other );
    596         virtual ~DimensionExpr();
    597 
    598         const std::string & get_name() const { return name; }
    599         void set_name( std::string newValue ) { name = newValue; }
    600 
    601         virtual DimensionExpr * clone() const override { return new DimensionExpr( * this ); }
    602         virtual void accept( Visitor & v ) override { v.visit( this ); }
    603         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    604         virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    605         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    606 };
    607 
    608589/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
    609590class AsmExpr : public Expression {
  • src/SynTree/Mutator.h

    r660665f r5a46e09  
    8080        virtual Expression * mutate( CommaExpr * commaExpr ) = 0;
    8181        virtual Expression * mutate( TypeExpr * typeExpr ) = 0;
    82         virtual Expression * mutate( DimensionExpr * dimensionExpr ) = 0;
    8382        virtual Expression * mutate( AsmExpr * asmExpr ) = 0;
    8483        virtual Expression * mutate( ImplicitCopyCtorExpr * impCpCtorExpr ) = 0;
  • src/SynTree/SynTree.h

    r660665f r5a46e09  
    8585class CommaExpr;
    8686class TypeExpr;
    87 class DimensionExpr;
    8887class AsmExpr;
    8988class ImplicitCopyCtorExpr;
  • src/SynTree/TypeDecl.cc

    r660665f r5a46e09  
    3333
    3434const char * TypeDecl::typeString() const {
    35         static const char * kindNames[] = { "sized data type", "sized data type", "sized object type", "sized function type", "sized tuple type", "sized length value" };
     35        static const char * kindNames[] = { "sized data type", "sized data type", "sized object type", "sized function type", "sized tuple type", "sized array length type" };
    3636        static_assert( sizeof(kindNames) / sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." );
    3737        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
  • src/SynTree/TypeExpr.cc

    r660665f r5a46e09  
    3535}
    3636
    37 DimensionExpr::DimensionExpr( std::string name ) : Expression(), name(name) {
    38         assertf(name != "0", "Zero is not a valid name");
    39         assertf(name != "1", "One is not a valid name");
    40 }
    41 
    42 DimensionExpr::DimensionExpr( const DimensionExpr & other ) : Expression( other ), name( other.name ) {
    43 }
    44 
    45 DimensionExpr::~DimensionExpr() {}
    46 
    47 void DimensionExpr::print( std::ostream & os, Indenter indent ) const {
    48         os << "Type-Sys Value: " << get_name();
    49         Expression::print( os, indent );
    50 }
    5137// Local Variables: //
    5238// tab-width: 4 //
  • src/SynTree/Visitor.h

    r660665f r5a46e09  
    135135        virtual void visit( TypeExpr * node ) { visit( const_cast<const TypeExpr *>(node) ); }
    136136        virtual void visit( const TypeExpr * typeExpr ) = 0;
    137         virtual void visit( DimensionExpr * node ) { visit( const_cast<const DimensionExpr *>(node) ); }
    138         virtual void visit( const DimensionExpr * typeExpr ) = 0;
    139137        virtual void visit( AsmExpr * node ) { visit( const_cast<const AsmExpr *>(node) ); }
    140138        virtual void visit( const AsmExpr * asmExpr ) = 0;
  • tests/.expect/forall.txt

    r660665f r5a46e09  
    1 forall.cfa:242:25: warning: Compiled
     1forall.cfa:216:25: warning: Compiled
  • tests/.expect/typedefRedef-ERR1.txt

    r660665f r5a46e09  
    1 typedefRedef.cfa:75:25: warning: Compiled
     1typedefRedef.cfa:69:25: warning: Compiled
    22typedefRedef.cfa:4:1 error: Cannot redefine typedef: Foo
    3 typedefRedef.cfa:65:1 error: Cannot redefine typedef: ARR
     3typedefRedef.cfa:59:1 error: Cannot redefine typedef: ARR
  • tests/.expect/typedefRedef.txt

    r660665f r5a46e09  
    1 typedefRedef.cfa:75:25: warning: Compiled
     1typedefRedef.cfa:69:25: warning: Compiled
  • tests/array-container/array-basic.cfa

    r660665f r5a46e09  
    6161forall( [Nw], [Nx], [Ny], [Nz] )
    6262void fillHelloData( array( float, Nw, Nx, Ny, Nz ) & wxyz ) {
    63     for (w; Nw)
    64     for (x; Nx)
    65     for (y; Ny)
    66     for (z; Nz)
     63    for (w; z(Nw))
     64    for (x; z(Nx))
     65    for (y; z(Ny))
     66    for (z; z(Nz))
    6767        wxyz[w][x][y][z] = getMagicNumber(w, x, y, z);
    6868}
    6969
    70 forall( [N]
     70forall( [Zn]
    7171      , S & | sized(S)
    7272      )
    73 float total1d_low( arpk(N, S, float, float ) & a ) {
     73float total1d_low( arpk(Zn, S, float, float ) & a ) {
    7474    float total = 0.0f;
    75     for (i; N)
     75    for (i; z(Zn))
    7676        total += a[i];
    7777    return total;
     
    9898
    9999    expect = 0;
    100     for (i; Nw)
     100    for (i; z(Nw))
    101101        expect += getMagicNumber( i, slice_ix, slice_ix, slice_ix );
    102102    printf("expect Ws             = %f\n", expect);
     
    105105    printf("result Ws [][][][] lo = %f\n", result);
    106106
    107     result = total1d_low( wxyz[all, slice_ix, slice_ix, slice_ix] );
     107    result = total1d_low( wxyz[[all, slice_ix, slice_ix, slice_ix]] );
    108108    printf("result Ws [,,,]    lo = %f\n", result);
    109109
     
    111111    printf("result Ws [][][][] hi = %f\n", result);
    112112
    113     result = total1d_hi( wxyz[all, slice_ix, slice_ix, slice_ix] );
     113    result = total1d_hi( wxyz[[all, slice_ix, slice_ix, slice_ix]] );
    114114    printf("result Ws [,,,]    hi = %f\n", result);
    115115
     
    117117
    118118    expect = 0;
    119     for (i; Nx)
     119    for (i; z(Nx))
    120120        expect += getMagicNumber( slice_ix, i, slice_ix, slice_ix );
    121121    printf("expect Xs             = %f\n", expect);
     
    124124    printf("result Xs [][][][] lo = %f\n", result);
    125125
    126     result = total1d_low( wxyz[slice_ix, all, slice_ix, slice_ix] );
     126    result = total1d_low( wxyz[[slice_ix, all, slice_ix, slice_ix]] );
    127127    printf("result Xs [,,,]    lo = %f\n", result);
    128128
     
    130130    printf("result Xs [][][][] hi = %f\n", result);
    131131
    132     result = total1d_hi( wxyz[slice_ix, all, slice_ix, slice_ix] );
     132    result = total1d_hi( wxyz[[slice_ix, all, slice_ix, slice_ix]] );
    133133    printf("result Xs [,,,]    hi = %f\n", result);
    134134
  • tests/array-container/array-md-sbscr-cases.cfa

    r660665f r5a46e09  
    2020forall( [Nw], [Nx], [Ny], [Nz] )
    2121void fillHelloData( array( float, Nw, Nx, Ny, Nz ) & wxyz ) {
    22     for (w; Nw)
    23     for (x; Nx)
    24     for (y; Ny)
    25     for (z; Nz)
     22    for (w; z(Nw))
     23    for (x; z(Nx))
     24    for (y; z(Ny))
     25    for (z; z(Nz))
    2626        wxyz[w][x][y][z] = getMagicNumber(w, x, y, z);
    2727}
     
    5353    // order wxyz, natural split (4-0 or 0-4, no intermediate to declare)
    5454
    55     assert(( wxyz[iw, ix, iy, iz] == valExpected ));
     55    assert(( wxyz[[iw, ix, iy, iz]] == valExpected ));
    5656
    5757    // order wxyz, unnatural split 1-3  (three ways declared)
    5858
    5959    typeof( wxyz[iw] ) xyz1 = wxyz[iw];
    60     assert(( xyz1[ix, iy, iz]  == valExpected ));
     60    assert(( xyz1[[ix, iy, iz]]  == valExpected ));
    6161
    6262    typeof( wxyz[iw] ) xyz2;
    6363    &xyz2 = &wxyz[iw];
    64     assert(( xyz2[ix, iy, iz] == valExpected ));
    65 
    66     assert(( wxyz[iw][ix, iy, iz] == valExpected ));
     64    assert(( xyz2[[ix, iy, iz]] == valExpected ));
     65
     66    assert(( wxyz[iw][[ix, iy, iz]] == valExpected ));
    6767
    6868    // order wxyz, unnatural split 2-2  (three ways declared)
    6969
    70     typeof( wxyz[iw, ix] ) yz1 = wxyz[iw,ix];
    71     assert(( yz1[iy, iz]  == valExpected ));
    72 
    73     typeof( wxyz[iw, ix] ) yz2;
    74     &yz2 = &wxyz[iw, ix];
    75     assert(( yz2[iy, iz]  == valExpected ));
    76 
    77     assert(( wxyz[iw, ix][iy, iz] == valExpected ));
     70    typeof( wxyz[[iw, ix]] ) yz1 = wxyz[[iw,ix]];
     71    assert(( yz1[[iy, iz]]  == valExpected ));
     72
     73    typeof( wxyz[[iw, ix]] ) yz2;
     74    &yz2 = &wxyz[[iw, ix]];
     75    assert(( yz2[[iy, iz]]  == valExpected ));
     76
     77    assert(( wxyz[[iw, ix]][[iy, iz]] == valExpected ));
    7878
    7979    // order wxyz, unnatural split 3-1  (three ways declared)
    8080
    81     typeof( wxyz[iw, ix, iy] ) z1 = wxyz[iw, ix, iy];
     81    typeof( wxyz[[iw, ix, iy]] ) z1 = wxyz[[iw, ix, iy]];
    8282    assert(( z1[iz]  == valExpected ));
    8383
    84     typeof( wxyz[iw, ix, iy] ) z2;
    85     &z2 = &wxyz[iw, ix, iy];
     84    typeof( wxyz[[iw, ix, iy]] ) z2;
     85    &z2 = &wxyz[[iw, ix, iy]];
    8686    assert(( z2[iz] == valExpected ));
    8787
    88     assert(( wxyz[iw, ix, iy][iz] == valExpected ));
     88    assert(( wxyz[[iw, ix, iy]][iz] == valExpected ));
    8989}
    9090
     
    104104    // order wxyz (no intermediates to declare)
    105105
    106     assert(( wxyz[iw  , ix  , iy  , iz  ]       == valExpected ));
    107     assert(( wxyz[iw-1, ix  , iy  , iz  ]       != valExpected ));
     106    assert(( wxyz[[iw  , ix  , iy  , iz  ]]       == valExpected ));
     107    assert(( wxyz[[iw-1, ix  , iy  , iz  ]]       != valExpected ));
    108108
    109109    // order xyzw: *xyz, w
    110110
    111     assert(( wxyz[all , ix  , iy  , iz  ][iw  ] == valExpected ));
    112     assert(( wxyz[all , ix-1, iy  , iz  ][iw  ] != valExpected ));
    113     assert(( wxyz[all , ix  , iy  , iz  ][iw-1] != valExpected ));
     111    assert(( wxyz[[all , ix  , iy  , iz  ]][iw  ] == valExpected ));
     112    assert(( wxyz[[all , ix-1, iy  , iz  ]][iw  ] != valExpected ));
     113    assert(( wxyz[[all , ix  , iy  , iz  ]][iw-1] != valExpected ));
    114114
    115115    // order wyzx: w*yz, x
    116116
    117     assert(( wxyz[iw  , all , iy  , iz  ][ix  ] == valExpected ));
    118     assert(( wxyz[iw  , all , iy-1, iz  ][ix  ] != valExpected ));
    119     assert(( wxyz[iw  , all , iy  , iz  ][ix-1] != valExpected ));
     117    assert(( wxyz[[iw  , all , iy  , iz  ]][ix  ] == valExpected ));
     118    assert(( wxyz[[iw  , all , iy-1, iz  ]][ix  ] != valExpected ));
     119    assert(( wxyz[[iw  , all , iy  , iz  ]][ix-1] != valExpected ));
    120120
    121121    // order wxzy: wx*z, y
    122122  #if 0
    123123    // not working on 32-bit
    124     assert(( wxyz[iw  , ix  , all , iz  ][iy  ] == valExpected ));
    125     assert(( wxyz[iw  , ix  , all , iz-1][iy  ] != valExpected ));
    126     assert(( wxyz[iw  , ix  , all , iz  ][iy-1] != valExpected ));
     124    assert(( wxyz[[iw  , ix  , all , iz  ]][iy  ] == valExpected ));
     125    assert(( wxyz[[iw  , ix  , all , iz-1]][iy  ] != valExpected ));
     126    assert(( wxyz[[iw  , ix  , all , iz  ]][iy-1] != valExpected ));
    127127  #endif
    128128}
     
    131131// The comments specify a covering set of orders, each in its most natural split.
    132132// Covering means that each edge on the lattice of dimesnions-provided is used.
    133 // Natural split means the arity of every -[-,...] tuple equals the dimensionality of its "this" operand, then that the fewest "all" subscripts are given.
     133// Natural split means the arity of every -[[-,...]] tuple equals the dimensionality of its "this" operand, then that the fewest "all" subscripts are given.
    134134// The commented-out test code shows cases that don't work.  We wish all the comment-coverd cases worked.
    135135forall( [Nw], [Nx], [Ny], [Nz] )
     
    147147    // order wxyz (no intermediates to declare)
    148148
    149     assert(( wxyz[iw, ix, iy, iz] == valExpected ));
     149    assert(( wxyz[[iw, ix, iy, iz]] == valExpected ));
    150150
    151151    {
     
    153153        assert( wxyz[iw][all][iy][all] [ix][iz] == valExpected );
    154154
    155         typeof( wxyz[iw, all, iy, all] ) xz1 = wxyz[iw, all, iy, all];
    156         assert(( xz1[ix, iz]  == valExpected ));
    157 
    158         typeof( wxyz[iw, all, iy, all] ) xz2;
    159         &xz2 = &wxyz[iw, all, iy, all];
    160         assert(( xz2[ix, iz]  == valExpected ));
    161 
    162         assert(( wxyz[iw  , all, iy  , all][ix  , iz  ] == valExpected ));
    163         assert(( wxyz[iw-1, all, iy  , all][ix  , iz  ] != valExpected ));
    164         assert(( wxyz[iw  , all, iy-1, all][ix  , iz  ] != valExpected ));
    165         assert(( wxyz[iw  , all, iy  , all][ix-1, iz  ] != valExpected ));
    166         assert(( wxyz[iw  , all, iy  , all][ix  , iz-1] != valExpected ));
     155        typeof( wxyz[[iw, all, iy, all]] ) xz1 = wxyz[[iw, all, iy, all]];
     156        assert(( xz1[[ix, iz]]  == valExpected ));
     157
     158        typeof( wxyz[[iw, all, iy, all]] ) xz2;
     159        &xz2 = &wxyz[[iw, all, iy, all]];
     160        assert(( xz2[[ix, iz]]  == valExpected ));
     161
     162        assert(( wxyz[[iw  , all, iy  , all]][[ix  , iz  ]] == valExpected ));
     163        assert(( wxyz[[iw-1, all, iy  , all]][[ix  , iz  ]] != valExpected ));
     164        assert(( wxyz[[iw  , all, iy-1, all]][[ix  , iz  ]] != valExpected ));
     165        assert(( wxyz[[iw  , all, iy  , all]][[ix-1, iz  ]] != valExpected ));
     166        assert(( wxyz[[iw  , all, iy  , all]][[ix  , iz-1]] != valExpected ));
    167167    }
    168168    {
     
    170170        assert( wxyz[iw][all][all][iz] [ix][iy] == valExpected );
    171171
    172         // typeof( wxyz[iw, all, all, iz] ) xy1 = wxyz[iw, all, all, iz];
    173         // assert(( xy1[ix, iy]  == valExpected ));
    174 
    175         // typeof(  wxyz[iw, all, all, iz] ) xy2;
    176         // &xy2 = &wxyz[iw, all, all, iz];
    177         // assert(( xy2[ix, iy]  == valExpected ));
    178 
    179         // assert(( wxyz[iw  , all, all, iz  ][ix  , iy  ] == valExpected ));
    180         // assert(( wxyz[iw-1, all, all, iz  ][ix  , iy  ] != valExpected ));
    181         // assert(( wxyz[iw  , all, all, iz-1][ix  , iy  ] != valExpected ));
    182         // assert(( wxyz[iw  , all, all, iz  ][ix-1, iy  ] != valExpected ));
    183         // assert(( wxyz[iw  , all, all, iz  ][ix  , iy-1] != valExpected ));
     172        // typeof( wxyz[[iw, all, all, iz]] ) xy1 = wxyz[[iw, all, all, iz]];
     173        // assert(( xy1[[ix, iy]]  == valExpected ));
     174
     175        // typeof(  wxyz[[iw, all, all, iz]] ) xy2;
     176        // &xy2 = &wxyz[[iw, all, all, iz]];
     177        // assert(( xy2[[ix, iy]]  == valExpected ));
     178
     179        // assert(( wxyz[[iw  , all, all, iz  ]][[ix  , iy  ]] == valExpected ));
     180        // assert(( wxyz[[iw-1, all, all, iz  ]][[ix  , iy  ]] != valExpected ));
     181        // assert(( wxyz[[iw  , all, all, iz-1]][[ix  , iy  ]] != valExpected ));
     182        // assert(( wxyz[[iw  , all, all, iz  ]][[ix-1, iy  ]] != valExpected ));
     183        // assert(( wxyz[[iw  , all, all, iz  ]][[ix  , iy-1]] != valExpected ));
    184184    }
    185185    {
     
    187187        assert( wxyz[all][ix][iy][all] [iw][iz] == valExpected );
    188188
    189         typeof( wxyz[all, ix, iy, all] ) wz1 = wxyz[all, ix, iy, all];
    190         assert(( wz1[iw, iz]  == valExpected ));
    191 
    192         assert(( wxyz[all  , ix, iy  , all][iw  , iz  ] == valExpected ));
     189        typeof( wxyz[[all, ix, iy, all]] ) wz1 = wxyz[[all, ix, iy, all]];
     190        assert(( wz1[[iw, iz]]  == valExpected ));
     191
     192        assert(( wxyz[[all  , ix, iy  , all]][[iw  , iz  ]] == valExpected ));
    193193    }
    194194    {
     
    196196        assert( wxyz[all][ix][all][iz] [iw][iy] == valExpected );
    197197
    198         // assert(( wxyz[all , ix  , all , iz  ][iw  , iy  ] == valExpected ));
     198        // assert(( wxyz[[all , ix  , all , iz  ]][[iw  , iy  ]] == valExpected ));
    199199    }
    200200    {
     
    202202        assert( wxyz[all][all][iy][iz] [iw][ix] == valExpected );
    203203
    204         // assert(( wxyz[all , all , iy  , iz  ][iw  , ix  ] == valExpected ));
     204        // assert(( wxyz[[all , all , iy  , iz  ]][[iw  , ix  ]] == valExpected ));
    205205    }
    206206    {
     
    208208        assert( wxyz[all][ix][all][all] [iw][all][iz] [iy] == valExpected );
    209209
    210         typeof( wxyz[all][ix][all][all] ) wyz_workaround = wxyz[all , ix , all  , all  ];
    211         typeof( wyz_workaround[iw][all][iz] ) y_workaround = wyz_workaround[iw , all , iz  ];
     210        typeof( wxyz[all][ix][all][all] ) wyz_workaround = wxyz[[all , ix , all  , all  ]];
     211        typeof( wyz_workaround[iw][all][iz] ) y_workaround = wyz_workaround[[iw , all , iz  ]];
    212212        assert( y_workaround[iy] == valExpected );
    213213
    214         // assert(( wxyz[all , ix , all  , all  ][iw  , all , iz  ][iy  ] == valExpected ));
     214        // assert(( wxyz[[all , ix , all  , all  ]][[iw  , all , iz  ]][iy  ] == valExpected ));
    215215    }
    216216    {
     
    239239    valExpected = getMagicNumber(2, 3, 4, 5);
    240240    assert(( wxyz [2] [3] [4] [5]  == valExpected ));
    241     assert(( wxyz[2,  3][4] [5]  == valExpected ));
    242     assert(( wxyz [2][3,  4][5]  == valExpected ));
    243     assert(( wxyz [2] [3][4,  5] == valExpected ));
    244     assert(( wxyz[2,  3,  4][5]  == valExpected ));
    245     assert(( wxyz [2][3,  4,  5] == valExpected ));
    246     assert(( wxyz[2,  3,  4,  5] == valExpected ));
    247 
    248     for ( i; Nw ) {
    249         assert(( wxyz[ i, 3, 4, 5 ] == getMagicNumber(i, 3, 4, 5) ));
    250     }
    251 
    252     for ( i; Nx ) {
    253         assert(( wxyz[ 2, i, 4, 5 ] == getMagicNumber(2, i, 4, 5) ));
    254     }
    255 
    256     for ( i; Ny ) {
    257         assert(( wxyz[ 2, 3, i, 5 ] == getMagicNumber(2, 3, i, 5) ));
    258     }
    259 
    260     for ( i; Nz ) {
    261         assert(( wxyz[ 2, 3, 4, i ] == getMagicNumber(2, 3, 4, i) ));
    262     }
    263 
    264     for ( i; Nw ) {
    265         assert(( wxyz[ i, all, 4, 5 ][3] == getMagicNumber(i, 3, 4, 5) ));
    266     }
    267 
    268     for ( i; Nw ) {
    269         assert(( wxyz[ all, 3, 4, 5 ][i] == getMagicNumber(i, 3, 4, 5) ));
     241    assert(( wxyz[[2,  3]][4] [5]  == valExpected ));
     242    assert(( wxyz [2][[3,  4]][5]  == valExpected ));
     243    assert(( wxyz [2] [3][[4,  5]] == valExpected ));
     244    assert(( wxyz[[2,  3,  4]][5]  == valExpected ));
     245    assert(( wxyz [2][[3,  4,  5]] == valExpected ));
     246    assert(( wxyz[[2,  3,  4,  5]] == valExpected ));
     247
     248    for ( i; z(Nw) ) {
     249        assert(( wxyz[[ i, 3, 4, 5 ]] == getMagicNumber(i, 3, 4, 5) ));
     250    }
     251
     252    for ( i; z(Nx) ) {
     253        assert(( wxyz[[ 2, i, 4, 5 ]] == getMagicNumber(2, i, 4, 5) ));
     254    }
     255
     256    for ( i; z(Ny) ) {
     257        assert(( wxyz[[ 2, 3, i, 5 ]] == getMagicNumber(2, 3, i, 5) ));
     258    }
     259
     260    for ( i; z(Nz) ) {
     261        assert(( wxyz[[ 2, 3, 4, i ]] == getMagicNumber(2, 3, 4, i) ));
     262    }
     263
     264    for ( i; z(Nw) ) {
     265        assert(( wxyz[[ i, all, 4, 5 ]][3] == getMagicNumber(i, 3, 4, 5) ));
     266    }
     267
     268    for ( i; z(Nw) ) {
     269        assert(( wxyz[[ all, 3, 4, 5 ]][i] == getMagicNumber(i, 3, 4, 5) ));
    270270    }
    271271}
  • tests/concurrent/signal/disjoint.cfa

    r660665f r5a46e09  
    7777        wait( cond );
    7878        if( d.state != SIGNAL ) {
    79                 abort | "ERROR barging!";
     79                sout | "ERROR barging!";
    8080        }
    8181
     
    113113        bool running = TEST(globals.data.counter < N) && globals.data.counter > 0;
    114114        if( globals.data.state != SIGNAL && running ) {
    115                 abort | "ERROR Eager signal" | globals.data.state;
     115                sout | "ERROR Eager signal" | globals.data.state;
    116116        }
    117117}
  • tests/coroutine/fibonacci.cfa

    r660665f r5a46e09  
    3131}
    3232
     33int next( Fibonacci & fib ) with( fib ) {
     34        resume( fib );                                                                          // restart last suspend
     35        return fn;
     36}
     37
    3338int main() {
    3439        Fibonacci f1, f2;
    3540        for ( 10 ) {                                                                            // print N Fibonacci values
    36                 sout | resume( f1 ).fn | resume( f2 ).fn;
     41                sout | next( f1 ) | next( f2 );
    3742        } // for
    3843}
  • tests/forall.cfa

    r660665f r5a46e09  
    199199}
    200200
    201 forall( T ) void check_otype() {
    202         T & tr = *0p;
    203         T * tp = 0p;
    204 
    205         &tr += 1;
    206         tp += 1;
    207         T & tx = tp[1];
    208 
    209         T t;
    210         T t2 = t;
    211 }
    212 
    213 forall( T * ) void check_dstype() {
    214         T & tr = *0p;
    215         T * tp = 0p;
    216 
    217         &tr += 1;
    218         tp += 1;
    219         T & tx = tp[1];
    220 }
    221 
    222 forall( T & ) void check_dtype() {
    223         T & tr = *0p;
    224         T * tp = 0p;
    225 }
    226 
    227201//otype T1 | { void xxx( T1 ); };
    228202
  • tests/generator/fibonacci.cfa

    r660665f r5a46e09  
    88//
    99// Author           : Thierry Delisle
    10 // Created On       : Mon Mar 1 16:54:23 2020
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 10 21:54:14 2021
    13 // Update Count     : 3
     10// Created On       : Mon Mar  1 16:54:23 2020
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     :
    1414//
    15 
    16 #include <fstream.hfa>
    1715
    1816generator Fib {
     
    2018};
    2119
    22 void main(Fib & fib) with (fib) {
     20void main(Fib & b) with (b) {
    2321        [fn1, fn] = [1, 0];
    2422        for () {
     
    3129        Fib f1, f2;
    3230        for ( 10 ) {
    33                 resume( f1 ); resume( f2 );
    34                 sout | f1.fn | f2.fn;
    35                 // sout | resume( f1 ).fn | resume( f2 ).fn; // compiler bug
     31                resume( f1 );
     32                resume( f2 );
     33                printf("%d %d\n", f1.fn, f2.fn);
    3634        }
     35
    3736}
    3837
  • tests/generator/fmtLines.cfa

    r660665f r5a46e09  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu Mar  5 16:09:08 2020
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 10 21:56:22 2021
    13 // Update Count     : 2
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     :
    1414//
    1515
  • tests/generator/suspend_then.cfa

    r660665f r5a46e09  
    99// Author           : Peter A. Buhr
    1010// Created On       : Mon Apr 29 12:01:35 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 10 21:55:51 2021
    13 // Update Count     : 1
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     :
    1414//
    1515
  • tests/literals.cfa

    r660665f r5a46e09  
    1010// Created On       : Sat Sep  9 16:34:38 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun 19 15:47:49 2021
    13 // Update Count     : 237
     12// Last Modified On : Sat Aug 29 10:57:56 2020
     13// Update Count     : 226
    1414//
    1515
     
    6363        -0X0123456789ABCDEF;  -0X0123456789ABCDEFu;  -0X0123456789ABCDEFl;  -0X0123456789ABCDEFll;  -0X0123456789ABCDEFul;  -0X0123456789ABCDEFlu;  -0X0123456789ABCDEFull;  -0X0123456789ABCDEFllu;
    6464
    65 // floating literals
    66 
    67          0123456789.;   0123456789.f;   0123456789.d;   0123456789.l;   0123456789.F;   0123456789.D;   0123456789.L;
    68         +0123456789.;  +0123456789.f;  +0123456789.d;  +0123456789.l;  +0123456789.F;  +0123456789.D;  +0123456789.L;
    69         -0123456789.;  -0123456789.f;  -0123456789.d;  -0123456789.l;  -0123456789.F;  -0123456789.D;  -0123456789.L;
    70 
    71          0123456789.e09;   0123456789.e09f;   0123456789.e09d;   0123456789.e09l;   0123456789.e09F;   0123456789.e09D;   0123456789.e09L;
    72         +0123456789.e09;  +0123456789.e09f;  +0123456789.e09d;  +0123456789.e09l;  +0123456789.e09F;  +0123456789.e09D;  +0123456789.e09L;
    73         -0123456789.e09;  -0123456789.e09f;  -0123456789.e09d;  -0123456789.e09l;  -0123456789.e09F;  -0123456789.e09D;  -0123456789.e09L;
    74                                                              
    75          0123456789.e+09;   0123456789.e+09f;   0123456789.e+09d;   0123456789.e+09l;   0123456789.e+09F;   0123456789.e+09D;   0123456789.e+09L;
    76         +0123456789.e+09;  +0123456789.e+09f;  +0123456789.e+09d;  +0123456789.e+09l;  +0123456789.e+09F;  +0123456789.e+09D;  +0123456789.e+09L;
    77         -0123456789.e+09;  -0123456789.e+09f;  -0123456789.e+09d;  -0123456789.e+09l;  -0123456789.e+09F;  -0123456789.e+09D;  -0123456789.e+09L;
    78                                                              
    79          0123456789.e-09;   0123456789.e-09f;   0123456789.e-09d;   0123456789.e-09l;   0123456789.e-09F;   0123456789.e-09D;   0123456789.e-09L;
    80         +0123456789.e-09;  +0123456789.e-09f;  +0123456789.e-09d;  +0123456789.e-09l;  +0123456789.e-09F;  +0123456789.e-09D;  +0123456789.e-09L;
    81         -0123456789.e-09;  -0123456789.e-09f;  -0123456789.e-09d;  -0123456789.e-09l;  -0123456789.e-09F;  -0123456789.e-09D;  -0123456789.e-09L;
    82 
    83          .0123456789;   .0123456789f;   .0123456789d;   .0123456789l;   .0123456789F;   .0123456789D;   .0123456789L;
    84         +.0123456789;  +.0123456789f;  +.0123456789d;  +.0123456789l;  +.0123456789F;  +.0123456789D;  +.0123456789L;
    85         -.0123456789;  -.0123456789f;  -.0123456789d;  -.0123456789l;  -.0123456789F;  -.0123456789D;  -.0123456789L;
    86 
    87          .0123456789e09;   .0123456789e09f;   .0123456789e09d;   .0123456789e09l;   .0123456789e09F;   .0123456789e09D;   .0123456789e09L;
    88         +.0123456789e09;  +.0123456789e09f;  +.0123456789e09d;  +.0123456789e09l;  +.0123456789e09F;  +.0123456789e09D;  +.0123456789e09L;
    89         -.0123456789e09;  -.0123456789e09f;  -.0123456789e09d;  -.0123456789e09l;  -.0123456789e09F;  -.0123456789e09D;  -.0123456789e09L;
    90                                                              
    91          .0123456789E+09;   .0123456789E+09f;   .0123456789E+09d;   .0123456789E+09l;   .0123456789E+09F;   .0123456789E+09D;   .0123456789E+09L;
    92         +.0123456789E+09;  +.0123456789E+09f;  +.0123456789E+09d;  +.0123456789E+09l;  +.0123456789E+09F;  +.0123456789E+09D;  +.0123456789E+09L;
    93         -.0123456789E+09;  -.0123456789E+09f;  -.0123456789E+09d;  -.0123456789E+09l;  -.0123456789E+09F;  -.0123456789E+09D;  -.0123456789E+09L;
    94                                                              
    95          .0123456789E-09;   .0123456789E-09f;   .0123456789E-09d;   .0123456789E-09l;   .0123456789E-09F;   .0123456789E-09D;   .0123456789E-09L;
    96         -.0123456789E-09;  -.0123456789E-09f;  -.0123456789E-09d;  -.0123456789E-09l;  -.0123456789E-09F;  -.0123456789E-09D;  -.0123456789E-09L;
    97         -.0123456789E-09;  -.0123456789E-09f;  -.0123456789E-09d;  -.0123456789E-09l;  -.0123456789E-09F;  -.0123456789E-09D;  -.0123456789E-09L;
    98 
    99          0123456789.0123456789;   0123456789.0123456789f;   0123456789.0123456789d;   0123456789.0123456789l;   0123456789.0123456789F;   0123456789.0123456789D;   0123456789.0123456789L;
    100         +0123456789.0123456789;  +0123456789.0123456789f;  +0123456789.0123456789d;  +0123456789.0123456789l;  +0123456789.0123456789F;  +0123456789.0123456789D;  +0123456789.0123456789L;
    101         -0123456789.0123456789;  -0123456789.0123456789f;  -0123456789.0123456789d;  -0123456789.0123456789l;  -0123456789.0123456789F;  -0123456789.0123456789D;  -0123456789.0123456789L;
    102 
    103          0123456789.0123456789E09;   0123456789.0123456789E09f;   0123456789.0123456789E09d;   0123456789.0123456789E09l;   0123456789.0123456789E09F;   0123456789.0123456789E09D;   0123456789.0123456789E09L;
    104         +0123456789.0123456789E09;  +0123456789.0123456789E09f;  +0123456789.0123456789E09d;  +0123456789.0123456789E09l;  +0123456789.0123456789E09F;  +0123456789.0123456789E09D;  +0123456789.0123456789E09L;
    105         -0123456789.0123456789E09;  -0123456789.0123456789E09f;  -0123456789.0123456789E09d;  -0123456789.0123456789E09l;  -0123456789.0123456789E09F;  -0123456789.0123456789E09D;  -0123456789.0123456789E09L;
    106                                                                                          
    107          0123456789.0123456789E+09;   0123456789.0123456789E+09f;   0123456789.0123456789E+09d;   0123456789.0123456789E+09l;   0123456789.0123456789E+09F;   0123456789.0123456789E+09D;   0123456789.0123456789E+09L;
    108         +0123456789.0123456789E+09;  +0123456789.0123456789E+09f;  +0123456789.0123456789E+09d;  +0123456789.0123456789E+09l;  +0123456789.0123456789E+09F;  +0123456789.0123456789E+09D;  +0123456789.0123456789E+09L;
    109         -0123456789.0123456789E+09;  -0123456789.0123456789E+09f;  -0123456789.0123456789E+09d;  -0123456789.0123456789E+09l;  -0123456789.0123456789E+09F;  -0123456789.0123456789E+09D;  -0123456789.0123456789E+09L;
    110                                                                                          
    111          0123456789.0123456789E-09;   0123456789.0123456789E-09f;   0123456789.0123456789E-09d;   0123456789.0123456789E-09l;   0123456789.0123456789E-09F;   0123456789.0123456789E-09D;   0123456789.0123456789E-09L;
    112         +0123456789.0123456789E-09;  +0123456789.0123456789E-09f;  +0123456789.0123456789E-09d;  +0123456789.0123456789E-09l;  +0123456789.0123456789E-09F;  +0123456789.0123456789E-09D;  +0123456789.0123456789E-09L;
    113         -0123456789.0123456789E-09;  -0123456789.0123456789E-09f;  -0123456789.0123456789E-09d;  -0123456789.0123456789E-09l;  -0123456789.0123456789E-09F;  -0123456789.0123456789E-09D;  -0123456789.0123456789E-09L;
    114 
    11565// decimal floating literals
    11666
    117 #if ! defined( __aarch64__ )                                                    // unsupported on ARM after gcc-9
    118          0123456789.df;   0123456789.dd;   0123456789.dl;   0123456789.DF;   0123456789.DD;   0123456789.DL;
    119         +0123456789.df;  +0123456789.dd;  +0123456789.dl;  +0123456789.DF;  +0123456789.DD;  +0123456789.DL;
    120         -0123456789.df;  -0123456789.dd;  -0123456789.dl;  -0123456789.DF;  -0123456789.DD;  -0123456789.DL;
    121 
    122          0123456789.e09df;   0123456789.e09dd;   0123456789.e09dl;   0123456789.e09DF;   0123456789.e09DD;   0123456789.e09DL;
    123         +0123456789.e09df;  +0123456789.e09dd;  +0123456789.e09dl;  +0123456789.e09DF;  +0123456789.e09DD;  +0123456789.e09DL;
    124         -0123456789.e09df;  -0123456789.e09dd;  -0123456789.e09dl;  -0123456789.e09DF;  -0123456789.e09DD;  -0123456789.e09DL;
    125                                                                      
    126          0123456789.e+09df;   0123456789.e+09dd;  0123456789.e+09dl;   0123456789.e+09DF;   0123456789.e+09DD;   0123456789.e+09DL;
    127         +0123456789.e+09df;  +0123456789.e+09dd; +0123456789.e+09dl;  +0123456789.e+09DF;  +0123456789.e+09DD;  +0123456789.e+09DL;
    128         -0123456789.e+09df;  -0123456789.e+09dd; -0123456789.e+09dl;  -0123456789.e+09DF;  -0123456789.e+09DD;  -0123456789.e+09DL;
    129                                                                      
    130          0123456789.e-09df;   0123456789.e-09dd;  0123456789.e-09dl;   0123456789.e-09DF;   0123456789.e-09DD;   0123456789.e-09DL;
    131         +0123456789.e-09df;  +0123456789.e-09dd; +0123456789.e-09dl;  +0123456789.e-09DF;  +0123456789.e-09DD;  +0123456789.e-09DL;
    132         -0123456789.e-09df;  -0123456789.e-09dd; -0123456789.e-09dl;  -0123456789.e-09DF;  -0123456789.e-09DD;  -0123456789.e-09DL;
    133 
    134          .0123456789df;   .0123456789dd;   .0123456789dl;   .0123456789DF;   .0123456789DD;   .0123456789DL;
    135         +.0123456789df;  +.0123456789dd;  +.0123456789dl;  +.0123456789DF;  +.0123456789DD;  +.0123456789DL;
    136         -.0123456789df;  -.0123456789dd;  -.0123456789dl;  -.0123456789DF;  -.0123456789DD;  -.0123456789DL;
    137 
    138          .0123456789e09df;   .0123456789e09dd;   .0123456789e09dl;   .0123456789e09DF;   .0123456789e09DD;   .0123456789e09DL;
    139         +.0123456789e09df;  +.0123456789e09dd;  +.0123456789e09dl;  +.0123456789e09DF;  +.0123456789e09DD;  +.0123456789e09DL;
    140         -.0123456789e09df;  -.0123456789e09dd;  -.0123456789e09dl;  -.0123456789e09DF;  -.0123456789e09DD;  -.0123456789e09DL;
    141                                                                
    142          .0123456789E+09df;   .0123456789E+09dd;   .0123456789E+09dl;   .0123456789E+09DF;   .0123456789E+09DD;   .0123456789E+09DL;
    143         +.0123456789E+09df;  +.0123456789E+09dd;  +.0123456789E+09dl;  +.0123456789E+09DF;  +.0123456789E+09DD;  +.0123456789E+09DL;
    144         -.0123456789E+09df;  -.0123456789E+09dd;  -.0123456789E+09dl;  -.0123456789E+09DF;  -.0123456789E+09DD;  -.0123456789E+09DL;
    145                                                                
    146          .0123456789E-09df;   .0123456789E-09dd;   .0123456789E-09dl;   .0123456789E-09DF;   .0123456789E-09DD;   .0123456789E-09DL;
    147         -.0123456789E-09df;  -.0123456789E-09dd;  -.0123456789E-09dl;  -.0123456789E-09DF;  -.0123456789E-09DD;  -.0123456789E-09DL;
    148         -.0123456789E-09df;  -.0123456789E-09dd;  -.0123456789E-09dl;  -.0123456789E-09DF;  -.0123456789E-09DD;  -.0123456789E-09DL;
    149 
    150          0123456789.0123456789df;   0123456789.0123456789dd;   0123456789.0123456789dl;   0123456789.0123456789DF;   0123456789.0123456789DD;   0123456789.0123456789DL;
    151         +0123456789.0123456789df;  +0123456789.0123456789dd;  +0123456789.0123456789dl;  +0123456789.0123456789DF;  +0123456789.0123456789DD;  +0123456789.0123456789DL;
    152         -0123456789.0123456789df;  -0123456789.0123456789dd;  -0123456789.0123456789dl;  -0123456789.0123456789DF;  -0123456789.0123456789DD;  -0123456789.0123456789DL;
    153 
    154          0123456789.0123456789E09df;   0123456789.0123456789E09dd;   0123456789.0123456789E09dl;   0123456789.0123456789E09DF;   0123456789.0123456789E09DD;   0123456789.0123456789E09DL;
    155         +0123456789.0123456789E09df;  +0123456789.0123456789E09dd;  +0123456789.0123456789E09dl;  +0123456789.0123456789E09DF;  +0123456789.0123456789E09DD;  +0123456789.0123456789E09DL;
    156         -0123456789.0123456789E09df;  -0123456789.0123456789E09dd;  -0123456789.0123456789E09dl;  -0123456789.0123456789E09DF;  -0123456789.0123456789E09DD;  -0123456789.0123456789E09DL;
    157                                                                                                
    158          0123456789.0123456789E+09df;   0123456789.0123456789E+09dd;   0123456789.0123456789E+09dl;   0123456789.0123456789E+09DF;   0123456789.0123456789E+09DD;   0123456789.0123456789E+09DL;
    159         +0123456789.0123456789E+09df;  +0123456789.0123456789E+09dd;  +0123456789.0123456789E+09dl;  +0123456789.0123456789E+09DF;  +0123456789.0123456789E+09DD;  +0123456789.0123456789E+09DL;
    160         -0123456789.0123456789E+09df;  -0123456789.0123456789E+09dd;  -0123456789.0123456789E+09dl;  -0123456789.0123456789E+09DF;  -0123456789.0123456789E+09DD;  -0123456789.0123456789E+09DL;
    161                                                                                                
    162          0123456789.0123456789E-09df;   0123456789.0123456789E-09dd;   0123456789.0123456789E-09dl;   0123456789.0123456789E-09DF;   0123456789.0123456789E-09DD;   0123456789.0123456789E-09DL;
    163         +0123456789.0123456789E-09df;  +0123456789.0123456789E-09dd;  +0123456789.0123456789E-09dl;  +0123456789.0123456789E-09DF;  +0123456789.0123456789E-09DD;  +0123456789.0123456789E-09DL;
    164         -0123456789.0123456789E-09df;  -0123456789.0123456789E-09dd;  -0123456789.0123456789E-09dl;  -0123456789.0123456789E-09DF;  -0123456789.0123456789E-09DD;  -0123456789.0123456789E-09DL;
    165 #endif // ! __aarch64__
     67         0123456789.;   0123456789.f;   0123456789.l;   0123456789.F;   0123456789.L;   0123456789.DL;
     68        +0123456789.;  +0123456789.f;  +0123456789.l;  +0123456789.F;  +0123456789.L;  +0123456789.DL;
     69        -0123456789.;  -0123456789.f;  -0123456789.l;  -0123456789.F;  -0123456789.L;  -0123456789.DL;
     70
     71         0123456789.e09;   0123456789.e09f;   0123456789.e09l;   0123456789.e09F;   0123456789.e09L;   0123456789.e09DL;
     72        +0123456789.e09;  +0123456789.e09f;  +0123456789.e09l;  +0123456789.e09F;  +0123456789.e09L;  +0123456789.e09DL;
     73        -0123456789.e09;  -0123456789.e09f;  -0123456789.e09l;  -0123456789.e09F;  -0123456789.e09L;  -0123456789.e09DL;
     74
     75         0123456789.e+09;   0123456789.e+09f;   0123456789.e+09l;   0123456789.e+09F;   0123456789.e+09L;   0123456789.e+09DL;
     76        +0123456789.e+09;  +0123456789.e+09f;  +0123456789.e+09l;  +0123456789.e+09F;  +0123456789.e+09L;  +0123456789.e+09DL;
     77        -0123456789.e+09;  -0123456789.e+09f;  -0123456789.e+09l;  -0123456789.e+09F;  -0123456789.e+09L;  -0123456789.e+09DL;
     78
     79         0123456789.e-09;   0123456789.e-09f;   0123456789.e-09l;   0123456789.e-09F;   0123456789.e-09L;   0123456789.e-09DL;
     80        +0123456789.e-09;  +0123456789.e-09f;  +0123456789.e-09l;  +0123456789.e-09F;  +0123456789.e-09L;  +0123456789.e-09DL;
     81        -0123456789.e-09;  -0123456789.e-09f;  -0123456789.e-09l;  -0123456789.e-09F;  -0123456789.e-09L;  -0123456789.e-09DL;
     82
     83         .0123456789;   .0123456789f;   .0123456789l;   .0123456789F;   .0123456789L;   .0123456789DL;
     84        +.0123456789;  +.0123456789f;  +.0123456789l;  +.0123456789F;  +.0123456789L;  +.0123456789DL;
     85        -.0123456789;  -.0123456789f;  -.0123456789l;  -.0123456789F;  -.0123456789L;  -.0123456789DL;
     86
     87         .0123456789e09;   .0123456789e09f;   .0123456789e09l;   .0123456789e09F;   .0123456789e09L;   .0123456789e09DL;
     88        +.0123456789e09;  +.0123456789e09f;  +.0123456789e09l;  +.0123456789e09F;  +.0123456789e09L;  +.0123456789e09DL;
     89        -.0123456789e09;  -.0123456789e09f;  -.0123456789e09l;  -.0123456789e09F;  -.0123456789e09L;  -.0123456789e09DL;
     90
     91         .0123456789E+09;   .0123456789E+09f;   .0123456789E+09l;   .0123456789E+09F;   .0123456789E+09L;   .0123456789E+09DL;
     92        +.0123456789E+09;  +.0123456789E+09f;  +.0123456789E+09l;  +.0123456789E+09F;  +.0123456789E+09L;  +.0123456789E+09DL;
     93        -.0123456789E+09;  -.0123456789E+09f;  -.0123456789E+09l;  -.0123456789E+09F;  -.0123456789E+09L;  -.0123456789E+09DL;
     94
     95         .0123456789E-09;   .0123456789E-09f;   .0123456789E-09l;   .0123456789E-09F;   .0123456789E-09L;   .0123456789E-09DL;
     96        -.0123456789E-09;  -.0123456789E-09f;  -.0123456789E-09l;  -.0123456789E-09F;  -.0123456789E-09L;  -.0123456789E-09DL;
     97        -.0123456789E-09;  -.0123456789E-09f;  -.0123456789E-09l;  -.0123456789E-09F;  -.0123456789E-09L;  -.0123456789E-09DL;
     98
     99         0123456789.0123456789;   0123456789.0123456789f;   0123456789.0123456789l;   0123456789.0123456789F;   0123456789.0123456789L;   0123456789.0123456789DL;
     100        +0123456789.0123456789;  +0123456789.0123456789f;  +0123456789.0123456789l;  +0123456789.0123456789F;  +0123456789.0123456789L;  +0123456789.0123456789DL;
     101        -0123456789.0123456789;  -0123456789.0123456789f;  -0123456789.0123456789l;  -0123456789.0123456789F;  -0123456789.0123456789L;  -0123456789.0123456789DL;
     102
     103         0123456789.0123456789E09;   0123456789.0123456789E09f;   0123456789.0123456789E09l;   0123456789.0123456789E09F;   0123456789.0123456789E09L;   0123456789.0123456789E09DL;
     104        +0123456789.0123456789E09;  +0123456789.0123456789E09f;  +0123456789.0123456789E09l;  +0123456789.0123456789E09F;  +0123456789.0123456789E09L;  +0123456789.0123456789E09DL;
     105        -0123456789.0123456789E09;  -0123456789.0123456789E09f;  -0123456789.0123456789E09l;  -0123456789.0123456789E09F;  -0123456789.0123456789E09L;  -0123456789.0123456789E09DL;
     106
     107         0123456789.0123456789E+09;   0123456789.0123456789E+09f;   0123456789.0123456789E+09l;   0123456789.0123456789E+09F;   0123456789.0123456789E+09L;   0123456789.0123456789E+09DL;
     108        +0123456789.0123456789E+09;  +0123456789.0123456789E+09f;  +0123456789.0123456789E+09l;  +0123456789.0123456789E+09F;  +0123456789.0123456789E+09L;  +0123456789.0123456789E+09DL;
     109        -0123456789.0123456789E+09;  -0123456789.0123456789E+09f;  -0123456789.0123456789E+09l;  -0123456789.0123456789E+09F;  -0123456789.0123456789E+09L;  -0123456789.0123456789E+09DL;
     110
     111         0123456789.0123456789E-09;   0123456789.0123456789E-09f;   0123456789.0123456789E-09l;   0123456789.0123456789E-09F;   0123456789.0123456789E-09L;   0123456789.0123456789E-09DL;
     112        +0123456789.0123456789E-09;  +0123456789.0123456789E-09f;  +0123456789.0123456789E-09l;  +0123456789.0123456789E-09F;  +0123456789.0123456789E-09L;  +0123456789.0123456789E-09DL;
     113        -0123456789.0123456789E-09;  -0123456789.0123456789E-09f;  -0123456789.0123456789E-09l;  -0123456789.0123456789E-09F;  -0123456789.0123456789E-09L;  -0123456789.0123456789E-09DL;
    166114
    167115// hexadecimal floating literals, must have exponent
  • tests/math.cfa

    r660665f r5a46e09  
    1010// Created On       : Fri Apr 22 14:59:21 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun 18 17:02:44 2021
    13 // Update Count     : 124
     12// Last Modified On : Tue Apr 13 21:04:48 2021
     13// Update Count     : 123
    1414//
    1515
     
    4040
    4141        sout | "exp:" | exp( 1.0F ) | exp( 1.0D ) | exp( 1.0L ) | nonl;
    42         sout | exp( 1.0F+1.0FI ) | exp( 1.0D+1.0DI ) | exp( 1.0L+1.0LI );
     42        sout | exp( 1.0F+1.0FI ) | exp( 1.0D+1.0DI ) | exp( 1.0DL+1.0LI );
    4343        sout | "exp2:" | exp2( 1.0F ) | exp2( 1.0D ) | exp2( 1.0L );
    4444        sout | "expm1:" | expm1( 1.0F ) | expm1( 1.0D ) | expm1( 1.0L );
    4545        sout | "pow:" | pow( 1.0F, 1.0F ) | pow( 1.0D, 1.0D ) | pow( 1.0L, 1.0L ) | nonl;
    46         sout | pow( 1.0F+1.0FI, 1.0F+1.0FI ) | pow( 1.0D+1.0DI, 1.0D+1.0DI ) | pow( 1.5L+1.5LI, 1.5L+1.5LI );
     46        sout | pow( 1.0F+1.0FI, 1.0F+1.0FI ) | pow( 1.0D+1.0DI, 1.0D+1.0DI ) | pow( 1.5DL+1.5LI, 1.5DL+1.5LI );
    4747
    4848        int b = 4;
     
    6868
    6969        sout | "log:" | log( 1.0F ) | log( 1.0D ) | log( 1.0L ) | nonl;
    70         sout | log( 1.0F+1.0FI ) | log( 1.0D+1.0DI ) | log( 1.0L+1.0LI );
     70        sout | log( 1.0F+1.0FI ) | log( 1.0D+1.0DI ) | log( 1.0DL+1.0LI );
    7171        sout | "log2:" | log2( 1024 ) | log2( 2 \ 17u ) | log2( 2 \ 23u );
    7272        sout | "log2:" | log2( 1024l ) | log2( 2l \ 17u ) | log2( 2l \ 23u );
     
    8282
    8383        sout | "sqrt:" | sqrt( 1.0F ) | sqrt( 1.0D ) | sqrt( 1.0L ) | nonl;
    84         sout | sqrt( 1.0F+1.0FI ) | sqrt( 1.0D+1.0DI ) | sqrt( 1.0L+1.0LI );
     84        sout | sqrt( 1.0F+1.0FI ) | sqrt( 1.0D+1.0DI ) | sqrt( 1.0DL+1.0LI );
    8585        sout | "cbrt:" | cbrt( 27.0F ) | cbrt( 27.0D ) | cbrt( 27.0L );
    8686        sout | "hypot:" | hypot( 1.0F, -1.0F ) | hypot( 1.0D, -1.0D ) | hypot( 1.0L, -1.0L );
     
    8989
    9090        sout | "sin:" | sin( 1.0F ) | sin( 1.0D ) | sin( 1.0L ) | nonl;
    91         sout | sin( 1.0F+1.0FI ) | sin( 1.0D+1.0DI ) | sin( 1.0L+1.0LI );
     91        sout | sin( 1.0F+1.0FI ) | sin( 1.0D+1.0DI ) | sin( 1.0DL+1.0LI );
    9292        sout | "cos:" | cos( 1.0F ) | cos( 1.0D ) | cos( 1.0L ) | nonl;
    93         sout | cos( 1.0F+1.0FI ) | cos( 1.0D+1.0DI ) | cos( 1.0L+1.0LI );
     93        sout | cos( 1.0F+1.0FI ) | cos( 1.0D+1.0DI ) | cos( 1.0DL+1.0LI );
    9494        sout | "tan:" | tan( 1.0F ) | tan( 1.0D ) | tan( 1.0L ) | nonl;
    95         sout | tan( 1.0F+1.0FI ) | tan( 1.0D+1.0DI ) | tan( 1.0L+1.0LI );
     95        sout | tan( 1.0F+1.0FI ) | tan( 1.0D+1.0DI ) | tan( 1.0DL+1.0LI );
    9696        sout | "asin:" | asin( 1.0F ) | asin( 1.0D ) | asin( 1.0L ) | nonl;
    97         sout | asin( 1.0F+1.0FI ) | asin( 1.0D+1.0DI ) | asin( 1.0L+1.0LI );
     97        sout | asin( 1.0F+1.0FI ) | asin( 1.0D+1.0DI ) | asin( 1.0DL+1.0LI );
    9898        sout | "acos:" | acos( 1.0F ) | acos( 1.0D ) | acos( 1.0L ) | nonl;
    99         sout | acos( 1.0F+1.0FI ) | acos( 1.0D+1.0DI ) | acos( 1.0L+1.0LI );
     99        sout | acos( 1.0F+1.0FI ) | acos( 1.0D+1.0DI ) | acos( 1.0DL+1.0LI );
    100100        sout | "atan:" | atan( 1.0F ) | atan( 1.0D ) | atan( 1.0L ) | nonl;
    101         sout | atan( 1.0F+1.0FI ) | atan( 1.0D+1.0DI ) | atan( 1.0L+1.0LI );
     101        sout | atan( 1.0F+1.0FI ) | atan( 1.0D+1.0DI ) | atan( 1.0DL+1.0LI );
    102102        sout | "atan2:" | atan2( 1.0F, 1.0F ) | atan2( 1.0D, 1.0D ) | atan2( 1.0L, 1.0L ) | nonl;
    103103        sout | "atan:" | atan( 1.0F, 1.0F ) | atan( 1.0D, 1.0D ) | atan( 1.0L, 1.0L );
     
    106106
    107107        sout | "sinh:" | sinh( 1.0F ) | sinh( 1.0D ) | sinh( 1.0L ) | nonl;
    108         sout | sinh( 1.0F+1.0FI ) | sinh( 1.0D+1.0DI ) | sinh( 1.0L+1.0LI );
     108        sout | sinh( 1.0F+1.0FI ) | sinh( 1.0D+1.0DI ) | sinh( 1.0DL+1.0LI );
    109109        sout | "cosh:" | cosh( 1.0F ) | cosh( 1.0D ) | cosh( 1.0L ) | nonl;
    110         sout | cosh( 1.0F+1.0FI ) | cosh( 1.0D+1.0DI ) | cosh( 1.0L+1.0LI );
     110        sout | cosh( 1.0F+1.0FI ) | cosh( 1.0D+1.0DI ) | cosh( 1.0DL+1.0LI );
    111111        sout | "tanh:" | tanh( 1.0F ) | tanh( 1.0D ) | tanh( 1.0L ) | nonl;
    112         sout | tanh( 1.0F+1.0FI ) | tanh( 1.0D+1.0DI ) | tanh( 1.0L+1.0LI );
     112        sout | tanh( 1.0F+1.0FI ) | tanh( 1.0D+1.0DI ) | tanh( 1.0DL+1.0LI );
    113113        sout | "acosh:" | acosh( 1.0F ) | acosh( 1.0D ) | acosh( 1.0L ) | nonl;
    114         sout | acosh( 1.0F+1.0FI ) | acosh( 1.0D+1.0DI ) | acosh( 1.0L+1.0LI );
     114        sout | acosh( 1.0F+1.0FI ) | acosh( 1.0D+1.0DI ) | acosh( 1.0DL+1.0LI );
    115115        sout | "asinh:" | asinh( 1.0F ) | asinh( 1.0D ) | asinh( 1.0L ) | nonl;
    116         sout | asinh( 1.0F+1.0FI ) | asinh( 1.0D+1.0DI ) | asinh( 1.0L+1.0LI );
     116        sout | asinh( 1.0F+1.0FI ) | asinh( 1.0D+1.0DI ) | asinh( 1.0DL+1.0LI );
    117117        sout | "atanh:" | atanh( 1.0F ) | atanh( 1.0D ) | atanh( 1.0L ) | nonl;
    118         sout | atanh( 1.0F+1.0FI ) | atanh( 1.0D+1.0DI ) | atanh( 1.0L+1.0LI );
     118        sout | atanh( 1.0F+1.0FI ) | atanh( 1.0D+1.0DI ) | atanh( 1.0DL+1.0LI );
    119119
    120120        //---------------------- Error / Gamma ----------------------
  • tests/pybin/tools.py

    r660665f r5a46e09  
    376376                return 1, "ERR No core dump"
    377377
    378         try:
    379                 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE)
    380         except:
    381                 return 1, "ERR Could not read core with gdb"
     378        return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE)
    382379
    383380def core_archive(dst, name, exe):
  • tests/test.py

    r660665f r5a46e09  
    1313
    1414import os
     15import psutil
    1516import signal
    1617
  • tests/typedefRedef.cfa

    r660665f r5a46e09  
    4545typedef int X2;
    4646
    47 X2 value  __attribute__((aligned(4 * sizeof(X2))));
    48 
    49 __attribute__((aligned(4 * sizeof(X2)))) struct rseq_cs {
    50         int foo;
    51 };
    52 
    5347// xxx - this doesn't work yet due to parsing problems with generic types
    5448// #ifdef __CFA__
  • tests/unified_locking/fast.cfa

    r660665f r5a46e09  
    2222uint32_t cs() {
    2323        $thread * me = active_thread();
    24         uint32_t value;
     24        uint32_t value = (uint32_t)me;
    2525        lock(mo.l);
    2626        {
     
    2828                mo.id = me;
    2929                yield(random(5));
    30                 value = ((uint32_t)random()) ^ ((uint32_t)me);
    3130                if(mo.id != me) sout | "Intruder!";
    3231                mo.sum = tsum + value;
Note: See TracChangeset for help on using the changeset viewer.