Changeset 660665f
- Timestamp:
- Jun 29, 2021, 5:35:19 PM (21 months ago)
- Branches:
- enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- dcad80a
- Parents:
- 5a46e09 (diff), d02e547 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 24 added
- 84 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
INSTALL
r5a46e09 r660665f 1 cfa-cc: The Cforall->C Compiler System1 cfa-cc: Cforall to C Trans-compiler 2 2 ====================================== 3 3 4 4 Cforall is built using GNU Make and the GNU Autoconf system. It also requires 5 g++ version >= 4.6, bison and flex. On systems where GNU Make is the default5 g++ version >= 6, bison and flex. On systems where GNU Make is the default 6 6 make, the system is built by entering the commands: 7 7 8 For dev s using the root git:8 For developers using the root git: 9 9 10 ./autogen.sh 11 ./configure 12 make 13 make install 10 $ ./autogen.sh 11 $ ./configure [ --prefix=/some/directory ] 12 $ make -j 8 install 14 13 15 For users using the distributed tarball :14 For users using the distributed tarball / github: 16 15 17 ./configure 18 make 19 make install 16 $ ./configure 17 $ make -j 8 install 20 18 21 Options for 'configure' 22 ----------------------- 23 The 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 25 most useful arguments. 19 where 8 is the number of CPUs on your computer. 26 20 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. 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. -
Jenkins/Distribute
r5a46e09 r660665f 2 2 3 3 import groovy.transform.Field 4 5 // For skipping stages6 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils7 4 8 5 //=========================================================================================================== … … 10 7 //=========================================================================================================== 11 8 12 node('master') { 13 // Globals 14 BuildDir = pwd tmp: true 15 SrcDir = pwd tmp: false 16 Settings = null 17 Version = '' 9 // Globals 10 BuildDir = null 11 SrcDir = null 12 Settings = null 13 Version = '' 18 14 19 20 21 15 // Local variables 16 def err = null 17 def log_needed = false 22 18 23 currentBuild.result = "SUCCESS" 19 currentBuild.result = "SUCCESS" 20 21 final commit, build 22 node { 24 23 25 24 //Wrap build to add timestamp to command line 26 25 wrap([$class: 'TimestamperBuildWrapper']) { 26 (commit, build) = prepare_build() 27 } 28 } 27 29 28 final commit, build 29 (commit, build) = prepare_build() 30 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 30 node('x64') { 31 //Wrap build to add timestamp to command line 32 wrap([$class: 'TimestamperBuildWrapper']) { 51 33 BuildDir = pwd tmp: true 52 34 SrcDir = pwd tmp: false 35 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() 53 49 } 54 55 50 } 56 51 -
Jenkins/FullBuild
r5a46e09 r660665f 5 5 //=========================================================================================================== 6 6 7 node ('master'){7 node { 8 8 def err = null 9 9 … … 18 18 19 19 parallel ( 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' ) },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' ) }, 29 29 ) 30 30 } … … 106 106 107 107 if(result.result != 'SUCCESS') { 108 sh("wget -q -O - http ://localhost:8084/jenkins/job/Cforall/job/master/${result.number}/consoleText")108 sh("wget -q -O - https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/${result.number}/consoleText") 109 109 error(result.result) 110 110 } … … 144 144 //Email notification on a full build failure 145 145 def promote_email(boolean success) { 146 echo('notifying users') 146 node { 147 echo('notifying users') 147 148 148 def result = success ? "PROMOTE - SUCCESS" : "PROMOTE - FAILURE"149 def result = success ? "PROMOTE - SUCCESS" : "PROMOTE - FAILURE" 149 150 150 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line151 //Configurations for email format152 def email_subject = "[cforall git][${result}]"153 def email_body = """<p>This is an automated email from the Jenkins build machine. It was154 generated following the result of the C\u2200 nightly build.</p>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> 155 156 156 <p>Check console output at ${env.BUILD_URL} to view the results.</p>157 <p>Check console output at ${env.BUILD_URL} to view the results.</p> 157 158 158 <p>- Status --------------------------------------------------------------</p>159 <p>- Status --------------------------------------------------------------</p> 159 160 160 <p>${result}</p>161 <p>${result}</p> 161 162 162 <p>- Performance ---------------------------------------------------------</p>163 <p>- Performance ---------------------------------------------------------</p> 163 164 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" >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" > 166 167 167 <p>- Logs ----------------------------------------------------------------</p>168 """168 <p>- Logs ----------------------------------------------------------------</p> 169 """ 169 170 170 def email_to = "cforall@lists.uwaterloo.ca"171 def email_to = "cforall@lists.uwaterloo.ca" 171 172 172 //send email notification 173 emailext body: email_body, subject: email_subject, to: email_to, attachLog: !success 173 //send email notification 174 emailext body: email_body, subject: email_subject, to: email_to, attachLog: !success 175 } 174 176 } -
Jenkins/tools.groovy
r5a46e09 r660665f 61 61 } 62 62 63 PrevGitOldRef = '' 64 PrevGitNewRef = '' 65 def 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 63 def ConstructGitLogMessage(String oldRef, String newRef) { 69 64 def revText = sh(returnStdout: true, script: "git rev-list ${oldRef}..${newRef}").trim() 70 65 def revList = SplitLines( revText ) … … 87 82 gitDiff = gitDiff.replace('[m', '</span>') 88 83 89 PrevGitOldRef = oldRef90 PrevGitNewRef = newRef 84 return """ 85 <p>- Changes -------------------------------------------------------------</p> 91 86 92 return """93 87 <pre> 94 88 The branch ${env.BRANCH_NAME} has been updated. 95 89 ${gitUpdate} 96 90 </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>103 91 104 92 <p>- Log -----------------------------------------------------------------</p> … … 116 104 } 117 105 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 118 122 return this; -
Jenkinsfile
r5a46e09 r660665f 7 7 //=========================================================================================================== 8 8 9 node('master') { 10 // Globals 11 BuildDir = pwd tmp: true 12 SrcDir = pwd tmp: false 13 Settings= null14 Tools = null 15 16 // Local variables 17 def err = null 18 def log_needed = false 19 20 currentBuild.result = "SUCCESS" 21 22 try{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 { 23 23 //Wrap build to add timestamp to command line 24 24 wrap([$class: 'TimestamperBuildWrapper']) { 25 26 25 Settings = prepare_build() 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 26 } 27 } 28 29 node(Settings.Architecture.node) { 30 //Wrap build to add timestamp to command line 31 wrap([$class: 'TimestamperBuildWrapper']) { 49 32 BuildDir = pwd tmp: true 50 33 SrcDir = pwd tmp: false 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 } 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 80 78 } 81 79 } … … 228 226 //Standard build email notification 229 227 def email(boolean log) { 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 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 237 236 generated because of a git hooks/post-receive script following 238 237 a 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> 239 243 """ + Tools.GitLogMessage() 240 244 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}" 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 } 250 255 } 251 256 } … … 300 305 BuildSettings(java.util.Collections$UnmodifiableMap param, String branch) { 301 306 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 302 313 case 'gcc-9': 303 314 this.Compiler = new CC_Desc('gcc-9', 'g++-9', 'gcc-9', '-flto=auto') … … 319 330 break 320 331 case 'clang': 321 this.Compiler = new CC_Desc('clang', 'clang++-10', 'gcc- 9', '-flto=thin -flto-jobs=0')332 this.Compiler = new CC_Desc('clang', 'clang++-10', 'gcc-10', '-flto=thin -flto-jobs=0') 322 333 break 323 334 default : … … 390 401 description: 'Which compiler to use', \ 391 402 name: 'Compiler', \ 392 choices: 'gcc- 9\ngcc-8\ngcc-7\ngcc-6\ngcc-5\ngcc-4.9\nclang', \403 choices: 'gcc-11\ngcc-10\ngcc-9\ngcc-8\ngcc-7\ngcc-6\ngcc-5\ngcc-4.9\nclang', \ 393 404 defaultValue: 'gcc-8', \ 394 405 ], \ -
README
r5a46e09 r660665f 1 cfa-cc: The Cforall->C Compiler System1 cfa-cc: Cforall to C Trans-compiler 2 2 ====================================== 3 3 … … 6 6 responsibility for the consequences of any malfunction of the software, 7 7 including the malfunction of any programs compiled using the software. 8 8 9 9 10 What is Cforall? … … 25 26 into a modern programming language. 26 27 28 27 29 What is cfa-cc? 28 30 --------------- 29 cfa-cc is a collection of programs centred around a translator that takes30 Cforall code as input and outputs corresponding C code. This is complemented 31 by a compiler driver in the style of "gcc", which handles preprocessing, 32 compiling, assembling, and linking and invokes the translator at appropriate 33 moments.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. 34 36 35 What is required in order to use cfa-cc? 37 cfa-cc is currently written in C++, but will be eventually rewritten in Cforall. 38 39 40 How to download and build cfa-cc? 36 41 ---------------------------------------- 37 Building cfa-cc requires GNU Make and gcc/g++ 4. cfa-cc is written in C++. 42 Download cfa-cc using 38 43 39 The compiler driver uses an installed version of gcc to handle all aspects of 40 the compilation process except for the Cforall->C translation. Currently, only 41 gcc 4.x is supported. 44 $ git clone https://github.com/cforall/cforall.git 42 45 43 How is cfa-cc used? 46 Read the ./INSTALL file for build instructions. 47 48 49 How to use cfa-cc? 44 50 ------------------- 45 The compiler driver "cfa" accepts all of the arguments ofgcc, and is used in51 The compiler driver "cfa" accepts all of the arguments for gcc, and is used in 46 52 the same way. For example: 47 53 48 49 54 cfa -c test.c 55 cfa test.o 50 56 51 Cforall source files must end with '.c' in order to be compiled by the compiler 52 driver. In addition, the flag "-CFA" causes cfa to invoke the preprocessor and 53 translator and send the translator output to standard output. 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. 54 61 55 It is possible to invoke the translator directly. The translator is installed56 by default as /usr/local/lib/cfa-cpp. A typical invocation is:57 62 58 /usr/local/lib/cfa-cpp -cp infile outfile 63 How to use C code with cfa-cc? 64 ----------------------------------- 65 cfa-cc should be able to compile and link most ANSI C programs with associated 66 C standard libraries. 59 67 60 If outfile is omitted, output goes to standard output; if infile is also 61 omitted, 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 63 translator. 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: 64 72 65 How can C code be used with cfa-cc? 66 ----------------------------------- 67 cfa-cc should be able to compile most ANSI C programs. It is also possible to 68 link against C libraries in most cases. Since Cforall supports overloading, 69 however, names used in Cforall code are mangled in the output C code. This 70 caused linker failures when the names refer to functions and objects in code 71 compiled with a standard C compiler. For this reason, it is necessary to 72 enclose the declarations of these functions and objects in extern "C" {} 73 blocks. For example: 74 75 extern "C" { 76 #include <stdio.h> 77 #include <stdlib.h> 78 } 73 extern "C" { 74 #include <curses.h> 75 #include <getopt.h> 76 } 79 77 80 78 The extern "C" turns off name mangling for functions and objects declared 81 within the block. As a result, it is not possible to overload their names. 79 within the block. All C standard headers are pre-wrapped, so most wrapping is 80 unnecessary. 81 82 82 83 83 What's wrong with cfa-cc? 84 84 ------------------------- 85 85 86 The authors consider this software to be in an unstable state. It is quite 87 likely that there are many reasonable programs that will fail to compile. We 88 encourage users to report their experiences to cforall@plg.uwaterloo.ca, but we 89 make no promises regarding support. 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. 90 91 91 We have fixed most of the problems that we are aware of. There are some 92 exceptions: 92 Also, the Cforall features web-page https://cforall.uwaterloo.ca/features lists 93 small syntactic and semantic differences with standard C. 93 94 94 - initializers are poorly implemented; in particular, file-scope initializers95 may result in the generation of invalid C code96 97 - the ISO C99 designated initialization syntax '[n] = m' or '.n = m' is not98 supported; use a colon in place of the equal sign99 100 - some legitimate programs will produce warnings from the C compiler; these are101 harmless (in particular, the creation of libcfa.a in the build process should102 cause four warnings from gcc)103 104 - abstract types introduced using the keyword 'type' are not implemented105 (although 'type' can be used to introduce type parameters)106 107 - the implicit coercion of structure types to the type of their first member is108 not implemented109 95 110 96 Who is responsible for cfa-cc? 111 97 ------------------------------ 112 cfa-cc was written by Peter Buhr, Richard Bilson, and Rodolfo Esteves. 113 Questions and comments can be sent to cforall@plg.uwaterloo.ca. 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. 114 101 115 The Cforall project maintains a web page: 116 117 https://cforall.uwaterloo.ca 102 Check the Cforall web site https://cforall.uwaterloo.ca for news and updates. -
benchmark/io/io_uring.h
r5a46e09 r660665f 1 1 extern "C" { 2 #ifndef _GNU_SOURCE /* See feature_test_macros(7) */3 #define _GNU_SOURCE /* See feature_test_macros(7) */4 #endif5 2 #include <errno.h> 6 3 #include <stdio.h> -
doc/bibliography/pl.bib
r5a46e09 r660665f 1673 1673 address = {Waterloo Ontario, Canada}, 1674 1674 month = sep, 1675 year = 20 18,1675 year = 2020, 1676 1676 note = {\href{https://plg.uwaterloo.ca/~usystem/pub/uSystem/uC++.pdf}{https://\-plg.uwaterloo.ca/\-$\sim$usystem/\-pub/\-uSystem/uC++.pdf}}, 1677 1677 } … … 4552 4552 author = {Martin Karsten}, 4553 4553 title = {{libfibre:~User-Level Threading Runtime}}, 4554 howpublished= {\href{https://git.uwaterloo.ca/mkarsten/libfibre} 4555 {https://\-git.uwaterloo.ca/\-mkarsten/\-libfibre}}, 4554 howpublished= {\href{https://git.uwaterloo.ca/mkarsten/libfibre}{https://\-git.uwaterloo.ca/\-mkarsten/\-libfibre}}, 4556 4555 note = {[Online; accessed 2020-04-15]}, 4557 4556 } -
doc/theses/andrew_beach_MMath/cfalab.sty
r5a46e09 r660665f 143 143 } 144 144 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 145 154 % common.tex Compatablity =================================================== 146 155 % Below this line is for compatability with the old common.tex file. -
doc/theses/andrew_beach_MMath/existing.tex
r5a46e09 r660665f 1 \chapter{\CFA Existing Features}1 \chapter{\CFA{} Existing Features} 2 2 \label{c:existing} 3 3 … … 9 9 existing C code-base allowing programmers to learn \CFA on an as-needed basis. 10 10 11 Only those \CFA features pertaining to this thesis are discussed. Many of the12 \CFA syntactic and semantic features used in the thesis should be fairly 13 obvious to the reader.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. 14 14 15 15 \section{Overloading and \lstinline{extern}} … … 29 29 // name mangling on by default 30 30 int i; // _X1ii_1 31 @extern "C"@{ // disables name mangling31 extern "C" { // disables name mangling 32 32 int j; // j 33 @extern "Cforall"@{ // enables name mangling33 extern "Cforall" { // enables name mangling 34 34 int k; // _X1ki_1 35 35 } … … 47 47 Reference-types are written the same way as a pointer-type but each 48 48 asterisk (@*@) is replaced with a ampersand (@&@); 49 this includes cv-qualifiers and multiple levels of reference, \eg: 50 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. 51 57 \begin{minipage}{0,5\textwidth} 52 58 With references: … … 56 62 int && rri = ri; 57 63 rri = 3; 58 &ri = &j; // reference assignment64 &ri = &j; 59 65 ri = 5; 60 66 \end{cfa} … … 67 73 int ** ppi = π 68 74 **ppi = 3; 69 pi = &j; // pointer assignment75 pi = &j; 70 76 *pi = 5; 71 77 \end{cfa} 72 78 \end{minipage} 73 79 74 References are intended for cases where you would want touse pointers but would80 References are intended to be used when you would use pointers but would 75 81 be dereferencing them (almost) every usage. 76 In most cases a reference can just be thought of as a pointer that 77 automatically puts a dereference in front of each of its uses (per-level of 78 reference). 79 The address-of operator (@&@) acts as an escape and removes one of the 80 automatic dereference operations. 81 Mutable references may be assigned by converting them to a pointer 82 with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above. 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 83 84 84 85 \section{Operators} 85 86 86 In general, operator names in \CFA are constructed by bracketing an operator 87 token with @?@, which indicates the position of the arguments. For example, 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, 88 92 infixed multiplication is @?*?@ while prefix dereference is @*?@. 89 93 This syntax make it easy to tell the difference between prefix operations 90 94 (such as @++?@) and post-fix operations (@?++@). 91 95 92 An operator name may describe any function signature (it is just a name) but 93 only certain signatures may be called in operator form. 94 \begin{cfa} 95 int ?+?( int i, int j, int k ) { return i + j + k; } 96 { 97 sout | ?+?( 3, 4, 5 ); // no infix form 98 } 99 \end{cfa} 100 Some ``near-misses" for unary/binary operator prototypes generate warnings. 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} 101 110 102 111 Both constructors and destructors are operators, which means they are 103 112 functions with special operator names rather than type names in \Cpp. The 104 special operator names may be used to call the functions explicitly (not 105 allowed in \Cpp for constructors). 106 107 The special name for a constructor is @?{}@, where the name @{}@ comes from the 108 initialization 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, 111 passing the initialization arguments to the constructor. 112 \begin{cfa} 113 struct Structure { ... }; 114 void ?{}(Structure & this) { ... } 115 { 116 Structure a; 117 Structure b = {}; 118 } 119 void ?{}(Structure & this, char first, int num) { ... } 120 { 121 Structure c = {'a', 2}; 122 } 123 \end{cfa} 124 Both @a@ and @b@ are initialized with the first constructor, 125 while @c@ is initialized with the second. 126 Currently, there is no general way to skip initialization. 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. 127 135 128 136 % I don't like the \^{} symbol but $^\wedge$ isn't better. 129 Similarly, destructors use the special name @^?{}@ (the @^@ has no special 130 meaning). Normally, they are implicitly called on a variable when it goes out 131 of scope but they can be called explicitly as well. 132 \begin{cfa} 133 void ^?{}(Structure & this) { ... } 134 { 135 Structure d; 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; 136 145 } // <- implicit destructor call 137 146 \end{cfa} 138 147 139 Whenever a type is defined, \CFA createsa default zero-argument148 Whenever a type is defined, \CFA will create a default zero-argument 140 149 constructor, a copy constructor, a series of argument-per-field constructors 141 150 and a destructor. All user constructors are defined after this. … … 198 207 void do_once(double y) { ... } 199 208 int quadruple(int 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 209 void do_once(int & y) { y = y * 2; } 210 do_twice(x); 203 211 return x; 204 212 } 205 213 \end{cfa} 206 214 Specifically, the complier deduces that @do_twice@'s T is an integer from the 207 argument @x@. It then looks for the most \emph{specific}definition matching the215 argument @x@. It then looks for the most specific definition matching the 208 216 assertion, which is the nested integral @do_once@ defined within the 209 217 function. The matched assertion function is then passed as a function pointer 210 to @do_twice@ and called within it. The global definition of @do_once@ is used 211 for the second call because the float-point argument is a better match. 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. 212 223 213 224 To avoid typing long lists of assertions, constraints can be collect into … … 279 290 Each coroutine has a @main@ function, which takes a reference to a coroutine 280 291 object and returns @void@. 281 \begin{cfa}[numbers=left] 292 %[numbers=left] Why numbers on this one? 293 \begin{cfa} 282 294 void main(CountUp & this) { 283 295 for (unsigned int next = 0 ; true ; ++next) { -
doc/theses/andrew_beach_MMath/features.tex
r5a46e09 r660665f 2 2 \label{c:features} 3 3 4 This chapter covers the design and user interface of the \CFA 5 EHM, % or exception system. 4 This chapter covers the design and user interface of the \CFA EHM 6 5 and begins with a general overview of EHMs. It is not a strict 7 6 definition of all EHMs nor an exhaustive list of all possible features. 8 However it does cover the most common structures and features found in them. 9 7 However it does cover the most common structure and features found in them. 8 9 \section{Overview of EHMs} 10 10 % We should cover what is an exception handling mechanism and what is an 11 11 % exception before this. Probably in the introduction. Some of this could 12 12 % move there. 13 \s ection{Raise / Handle}13 \subsection{Raise / Handle} 14 14 An exception operation has two main parts: raise and handle. 15 These terms are sometimes alsoknown as throw and catch but this work uses15 These terms are sometimes known as throw and catch but this work uses 16 16 throw/catch as a particular kind of raise/handle. 17 17 These are the two parts that the user writes and may … … 24 24 25 25 Some well known examples include the @throw@ statements of \Cpp and Java and 26 the \code{Python}{raise} statement from Python. Araise may27 p erform some other work (such as memory management) but for the26 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 28 28 purposes of this overview that can be ignored. 29 29 … … 33 33 34 34 A handler has three common features: the previously mentioned user code, a 35 region of code they guard ,and an exception label/condition that matches35 region of code they guard and an exception label/condition that matches 36 36 certain exceptions. 37 37 Only raises inside the guarded region and raising exceptions that match the 38 38 label can be handled by a given handler. 39 Different EHMs have different rules to pick a handler,40 if multiple handlers could be used, such as ``best match" or ``first found".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". 41 41 42 42 The @try@ statements of \Cpp, Java and Python are common examples. All three … … 44 44 region. 45 45 46 \s ection{Propagation}46 \subsection{Propagation} 47 47 After an exception is raised comes what is usually the biggest step for the 48 48 EHM: finding and setting up the handler. The propagation from raise to 49 49 handler can be broken up into three different tasks: searching for a handler, 50 matching against the handler ,and installing the handler.50 matching against the handler and installing the handler. 51 51 52 52 \paragraph{Searching} … … 55 55 thrown as it looks for handlers that have the raise site in their guarded 56 56 region. 57 Th is search includes handlers in the current function, as well as any in callers58 on the stack that have the function call in their guarded region.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. 59 59 60 60 \paragraph{Matching} 61 61 Each handler found has to be matched with the raised exception. The exception 62 label defines a condition that is used with the exception to decideif62 label defines a condition that is used with exception and decides if 63 63 there is a match or not. 64 64 65 65 In languages where the first match is used, this step is intertwined with 66 searching : a match check is performed immediately after the search finds66 searching; a match check is preformed immediately after the search finds 67 67 a possible handler. 68 68 69 \ section{Installing}69 \paragraph{Installing} 70 70 After a handler is chosen it must be made ready to run. 71 71 The implementation can vary widely to fit with the rest of the … … 74 74 case when stack unwinding is involved. 75 75 76 If a matching handler is not guarant ied to be found, the EHM needs a76 If a matching handler is not guaranteed to be found, the EHM needs a 77 77 different course of action for the case where no handler matches. 78 78 This situation only occurs with unchecked exceptions as checked exceptions 79 79 (such as in Java) can make the guarantee. 80 This unhandled action can abort the program or install a very general handler.80 This unhandled action is usually very general, such as aborting the program. 81 81 82 82 \paragraph{Hierarchy} 83 83 A common way to organize exceptions is in a hierarchical structure. 84 This organization is often used inobject-orientated languages where the84 This pattern comes from object-orientated languages where the 85 85 exception hierarchy is a natural extension of the object hierarchy. 86 86 … … 90 90 \end{center} 91 91 92 A handler label led with any given exception can handle exceptions of that92 A handler labeled with any given exception can handle exceptions of that 93 93 type or any child type of that exception. The root of the exception hierarchy 94 94 (here \code{C}{exception}) acts as a catch-all, leaf types catch single types … … 104 104 % Could I cite the rational for the Python IO exception rework? 105 105 106 \ paragraph{Completion}107 After the handler has finished the entire exception operation has to complete106 \subsection{Completion} 107 After the handler has finished, the entire exception operation has to complete 108 108 and continue executing somewhere else. This step is usually simple, 109 109 both logically and in its implementation, as the installation of the handler … … 111 111 112 112 The EHM can return control to many different places, 113 the most common are after the handler definition (termination) and after the raise (resumption). 114 115 \paragraph{Communication} 113 the most common are after the handler definition (termination) 114 and after the raise (resumption). 115 116 \subsection{Communication} 116 117 For effective exception handling, additional information is often passed 117 118 from the raise to the handler and back again. 118 119 So far only communication of the exceptions' identity has been covered. 119 A common communication method is putting fields into the exception instance and giving the 120 handler access to them. References in the exception instance can push data back to the raise. 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. 121 124 122 125 \section{Virtuals} 123 126 Virtual types and casts are not part of \CFA's EHM nor are they required for 124 127 any EHM. 125 However, one of the best ways to support an exception hierarchy is via a virtual system126 among exceptions and used for exception matching.128 However, it is one of the best ways to support an exception hierarchy 129 is via a virtual hierarchy and dispatch system. 127 130 128 131 Ideally, the virtual system would have been part of \CFA before the work 129 132 on exception handling began, but unfortunately it was not. 130 Therefore, only the features and framework needed for the EHM were133 Hence, only the features and framework needed for the EHM were 131 134 designed and implemented. Other features were considered to ensure that 132 the structure could accommodate other desirable features in the future but they were not133 implemented.134 The rest of this section discusses the implemented subset of the135 virtual -system design.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. 136 139 137 140 The virtual system supports multiple ``trees" of types. Each tree is … … 143 146 % A type's ancestors are its parent and its parent's ancestors. 144 147 % The root type has no ancestors. 145 % A type's de cedents are its children and its children's decedents.148 % A type's descendants are its children and its children's descendants. 146 149 147 150 Every virtual type also has a list of virtual members. Children inherit … … 150 153 of object-orientated programming, and can be of any type. 151 154 152 \PAB{I do not understand these sentences. Can you add an example? $\Rightarrow$153 155 \CFA still supports virtual methods as a special case of virtual members. 154 156 Function pointers that take a pointer to the virtual type are modified 155 157 with each level of inheritance so that refers to the new type. 156 158 This means an object can always be passed to a function in its virtual table 157 as if it were a method.} 159 as if it were a method. 160 \todo{Clarify (with an example) virtual methods.} 158 161 159 162 Each virtual type has a unique id. … … 161 164 into a virtual table type. Each virtual type has a pointer to a virtual table 162 165 as a hidden field. 163 164 \PAB{God forbid, maybe you need a UML diagram to relate these entities.} 166 \todo{Might need a diagram for virtual structure.} 165 167 166 168 Up until this point the virtual system is similar to ones found in … … 173 175 types can begin to satisfy a trait, stop satisfying a trait or satisfy the same 174 176 trait in a different way at any lexical location in the program. 175 In this sense, they are ``open" as they can change at any time. This capability means it176 is impossible to pick a single set of functions that represent the type's177 implementation across 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. 178 180 179 181 \CFA side-steps this issue by not having a single virtual table for each 180 182 type. A user can define virtual tables that are filled in at their 181 declaration and given a name. Anywhere that name is visible, even if 183 declaration and given a name. Anywhere that name is visible, even if it is 182 184 defined locally inside a function (although that means it does not have a 183 185 static lifetime), it can be used. … … 186 188 through the object. 187 189 188 \PAB{The above explanation is very good!}189 190 190 While much of the virtual infrastructure is created, it is currently only used 191 191 internally for exception handling. The only user-level feature is the virtual 192 cast 192 cast, which is the same as the \Cpp \code{C++}{dynamic_cast}. 193 193 \label{p:VirtualCast} 194 194 \begin{cfa} 195 195 (virtual TYPE)EXPRESSION 196 196 \end{cfa} 197 which is the same as the \Cpp \code{C++}{dynamic_cast}.198 197 Note, the syntax and semantics matches a C-cast, rather than the function-like 199 198 \Cpp syntax for special casts. Both the type of @EXPRESSION@ and @TYPE@ must be … … 218 217 The trait is defined over two types, the exception type and the virtual table 219 218 type. Each exception type should have a single virtual table type. 220 There are no actual assertions in this trait because currentlythe trait system221 cannot express them (adding such assertions would be part of219 There are no actual assertions in this trait because the trait system 220 cannot express them yet (adding such assertions would be part of 222 221 completing the virtual system). The imaginary assertions would probably come 223 222 from a trait defined by the virtual system, and state that the exception type 224 is a virtual type, is a descend ent of @exception_t@ (the base exception type)223 is a virtual type, is a descendant of @exception_t@ (the base exception type) 225 224 and note its virtual table type. 226 225 … … 241 240 }; 242 241 \end{cfa} 243 Both traits ensure a pair of types are an exception type and its virtual table, 242 Both traits ensure a pair of types are an exception type, its virtual table 243 type 244 244 and defines one of the two default handlers. The default handlers are used 245 245 as fallbacks and are discussed in detail in \vref{s:ExceptionHandling}. … … 269 269 \section{Exception Handling} 270 270 \label{s:ExceptionHandling} 271 As stated, \CFA provides two kinds of exception handling: termination and resumption. 271 As stated, 272 \CFA provides two kinds of exception handling: termination and resumption. 272 273 These twin operations are the core of \CFA's exception handling mechanism. 273 This section coversthe general patterns shared by the two operations and274 then go on to cover the details ofeach individual operation.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. 275 276 276 277 Both operations follow the same set of steps. 277 Both start with the user p erforming a raise on an exception.278 Both start with the user preforming a raise on an exception. 278 279 Then the exception propagates up the stack. 279 280 If a handler is found the exception is caught and the handler is run. 280 After that control returns to a point specific to the kind of exception.281 If the search fails a default handler is run , and if it returns,control282 continues after the raise. Note, the default handler may further change control flow rather than return.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. 283 284 284 285 This general description covers what the two kinds have in common. 285 Differences include how propagation is p erformed, where exception continues286 Differences include how propagation is preformed, where exception continues 286 287 after an exception is caught and handled and which default handler is run. 287 288 288 289 \subsection{Termination} 289 290 \label{s:Termination} 290 291 291 Termination handling is the familiar kind and used in most programming 292 292 languages with exception handling. … … 313 313 314 314 The throw copies the provided exception into managed memory to ensure 315 the exception is not destroyed whenthe stack is unwound.315 the exception is not destroyed if the stack is unwound. 316 316 It is the user's responsibility to ensure the original exception is cleaned 317 317 up whether the stack is unwound or not. Allocating it on the stack is 318 318 usually sufficient. 319 319 320 Then propagation starts the search. \CFA uses a ``first match" rule so 321 matching is performed with the copied exception as the search continues. 322 It starts from the throwing function and proceeds towards the base of the stack, 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, 323 324 from callee to caller. 324 325 At each stack frame, a check is made for resumption handlers defined by the … … 334 335 \end{cfa} 335 336 When viewed on its own, a try statement simply executes the statements 336 in \snake{GUARDED_BLOCK} and when those are finished, the try statement finishes. 337 in \snake{GUARDED_BLOCK} and when those are finished, 338 the try statement finishes. 337 339 338 340 However, while the guarded statements are being executed, including any 339 invoked functions, all the handlers in these statements are included on the search 340 path. Hence, if a termination exception is raised, the search includes the added handlers associated with the guarded block and those further up the 341 stack from the guarded block. 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. 342 345 343 346 Exception matching checks the handler in each catch clause in the order 344 347 they appear, top to bottom. If the representation of the raised exception type 345 348 is the same or a descendant of @EXCEPTION_TYPE@$_i$ then @NAME@$_i$ 346 (if provided) is bound to a pointer to the exception and the statements in347 @HANDLER_BLOCK@$_i$ are executed. 348 If control reaches the end of the handler, the exception is349 (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 349 352 freed and control continues after the try statement. 350 353 351 If no termination handler is found during the search ,the default handler352 (\defaultTerminationHandler) visible at the raise statement is called.353 Through \CFA's trait system , the best match at the raise sight isused.354 This function is run and is passed the copied exception. If the default355 handler returns, control continues after the throwstatement.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. 356 359 357 360 There is a global @defaultTerminationHandler@ that is polymorphic over all 358 termination exception types. Since it is so general, a more specific handler can be 361 termination exception types. 362 Since it is so general a more specific handler can be 359 363 defined and is used for those types, effectively overriding the handler 360 364 for a particular exception type. … … 370 374 matched a closure is taken from up the stack and executed, 371 375 after which the raising function continues executing. 372 These are most often used when a potentially repairable error occurs, some handler is found on the stack to fix it, and 373 the raising function can continue with the correction. 374 Another common usage is dynamic event analysis, \eg logging, without disrupting control flow. 375 Note, 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}. 378 You may or may not want to mention it. You can still stick with \lstinline{catch} and \lstinline{throw/catchResume} in the thesis.} 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. 379 381 380 382 A resumption raise is started with the @throwResume@ statement: … … 382 384 throwResume EXPRESSION; 383 385 \end{cfa} 386 \todo{Decide on a final set of keywords and use them everywhere.} 384 387 It works much the same way as the termination throw. 385 388 The expression must return a reference to a resumption exception, … … 387 390 @is_resumption_exception@ at the call site. 388 391 The assertions from this trait are available to 389 the exception system, while handling the exception. 390 391 Resumption does not need to copy the raised exception, as the stack is not unwound. 392 The exception and 393 any values on the stack remain in scope, while the resumption is handled. 394 395 The EHM then begins propogation. The search starts from the raise in the 396 resuming function and proceeds towards the base of the stack, from callee to caller. 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. 397 401 At each stack frame, a check is made for resumption handlers defined by the 398 402 @catchResume@ clauses of a @try@ statement. … … 412 416 kind of raise. 413 417 When a try statement is executed, it simply executes the statements in the 414 @GUARDED_BLOCK@ and then returns.418 @GUARDED_BLOCK@ and then finishes. 415 419 416 420 However, while the guarded statements are being executed, including any 417 invoked functions, all the handlers in these statements are included on the search 418 path. Hence, if a resumption exception is raised the search includes the added handlers associated with the guarded block and those further up the 419 stack from the guarded block. 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. 420 425 421 426 Exception matching checks the handler in each catch clause in the order … … 427 432 the raise statement that raised the handled exception. 428 433 429 Like termination, if no resumption handler is found during the search, the default handler430 (\defaultResumptionHandler) visible at the raise statement is called. 431 It uses the best match at the 432 raise sight accordingto \CFA's overloading rules. The default handler is433 passed the exception given to the throw. When the default handler finishes434 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 434 439 execution continues after the raise statement. 435 440 436 There is a global \defaultResumptionHandler{} thatis polymorphic over all437 resumption exception types and preforms a termination throw on the exception.438 The \defaultTerminationHandler{} can be 439 customized by introducing a new or better match as well.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. 440 445 441 446 \subsubsection{Resumption Marking} 442 447 \label{s:ResumptionMarking} 443 444 448 A key difference between resumption and termination is that resumption does 445 449 not unwind the stack. A side effect that is that when a handler is matched 446 and run , its try block (the guarded statements) and every try statement447 searched before it are still on the stack. The ir existence can lead to the recursive448 resumption problem.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. 449 453 450 454 The recursive resumption problem is any situation where a resumption handler … … 459 463 \end{cfa} 460 464 When this code is executed, the guarded @throwResume@ starts a 461 search and match s the handler in the @catchResume@ clause. This462 call is placed on the top of stack above the try-block. The second throw463 search s the same try block and puts callanother instance of the464 same handler on the stack leading to aninfinite recursion.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. 465 469 466 470 While this situation is trivial and easy to avoid, much more complex cycles 467 471 can form with multiple handlers and different exception types. 468 472 469 To prevent all of these cases, the exception search marks the try statements it visits.470 A try statement is marked when a match check is preformed with it and an 471 exception. The statement is unmarked when the handling of that exception 472 is completed or the search completes without finding a handler.473 While a try statement is marked, its handlers are never matched, effecti fy474 skipping over themto the next try statement.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. 475 479 476 480 \begin{center} … … 478 482 \end{center} 479 483 480 These rules mirror what happens with termination. 481 When a termination throw happens in a handler, the search does not look at 482 any handlers from the original throw to the original catch because that 483 part of the stack is unwound. 484 A resumption raise in the same situation wants to search the entire stack, 485 but with marking, the search does match exceptions for try statements at equivalent sections 486 that would have been unwound by termination. 487 488 The symmetry between resumption termination is why this pattern is picked. 489 Other patterns, such as marking just the handlers that caught the exception, also work but 490 lack the symmetry, meaning there are more rules to remember. 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. 491 497 492 498 \section{Conditional Catch} 493 494 499 Both termination and resumption handler clauses can be given an additional 495 500 condition to further control which exceptions they handle: … … 504 509 did not match. 505 510 506 The condition matching allows finer matching to check511 The condition matching allows finer matching by checking 507 512 more kinds of information than just the exception type. 508 513 \begin{cfa} … … 519 524 // Can't handle a failure relating to f2 here. 520 525 \end{cfa} 521 In this example , the file that experianced the IO error is used to decide526 In this example the file that experienced the IO error is used to decide 522 527 which handler should be run, if any at all. 523 528 … … 548 553 549 554 \subsection{Comparison with Reraising} 550 551 555 A more popular way to allow handlers to match in more detail is to reraise 552 556 the exception after it has been caught, if it could not be handled here. 553 On the surface these two features seem interchangable. 554 555 If @throw@ is used to start a termination reraise then these two statements 556 have the same behaviour: 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: 557 562 \begin{cfa} 558 563 try { … … 574 579 } 575 580 \end{cfa} 576 However, if there are further handlers after this handler only the first is 577 check. For multiple handlers on a single try block that could handle the 578 same exception, the equivalent translations to conditional catch becomes more complex, resulting is multiple nested try blocks for all possible reraises. 579 So 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. 582 A conditional catch CAN happen with the stack unwound. 583 Roy talked about this issue in Section 2.3.3 here: \newline 584 \url{http://plg.uwaterloo.ca/theses/KrischerThesis.pdf}} 585 586 Specifically for termination handling, a 587 conditional catch happens before the stack is unwound, but a reraise happens 588 afterwards. Normally this might only cause you to loose some debug 589 information you could get from a stack trace (and that can be side stepped 590 entirely by collecting information during the unwind). But for \CFA there is 591 another issue, if the exception is not handled the default handler should be 592 run at the site of the original raise. 593 594 There are two problems with this: the site of the original raise does not 595 exist anymore and the default handler might not exist anymore. The site is 596 always removed as part of the unwinding, often with the entirety of the 597 function it was in. The default handler could be a stack allocated nested 598 function removed during the unwind. 599 600 This means actually trying to pretend the catch didn't happening, continuing 601 the original raise instead of starting a new one, is infeasible. 602 That is the expected behaviour for most languages and we can't replicate 603 that behaviour. 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/ 604 639 605 640 \section{Finally Clauses} 606 641 \label{s:FinallyClauses} 607 608 642 Finally clauses are used to preform unconditional clean-up when leaving a 609 643 scope and are placed at the end of a try statement after any handler clauses: … … 618 652 The @FINALLY_BLOCK@ is executed when the try statement is removed from the 619 653 stack, including when the @GUARDED_BLOCK@ finishes, any termination handler 620 finishes ,or during an unwind.654 finishes or during an unwind. 621 655 The only time the block is not executed is if the program is exited before 622 656 the stack is unwound. … … 634 668 635 669 Not all languages with unwinding have finally clauses. Notably \Cpp does 636 without it as destructors with RAII serve a similar role. Although destructors and 637 finally clauses have overlapping usage cases, they have their own 638 specializations, like top-level functions and lambda functions with closures. 639 Destructors take more work if a number of unrelated, local variables without destructors or dynamically allocated variables must be passed for de-intialization. 640 Maintaining this destructor during local-block modification is a source of errors. 641 A finally clause places local de-intialization inline with direct access to all local variables. 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. 642 681 643 682 \section{Cancellation} … … 652 691 raise, this exception is not used in matching only to pass information about 653 692 the cause of the cancellation. 654 (This restrictionalso means matching cannot fail so there is no default handler.)693 (This also means matching cannot fail so there is no default handler.) 655 694 656 695 After @cancel_stack@ is called the exception is copied into the EHM's memory 657 and the current stack is 658 unwound. 659 The result of a cancellation depends on the kind of stack that is being unwound. 696 and the current stack is unwound. 697 The behaviour after that depends on the kind of stack being cancelled. 660 698 661 699 \paragraph{Main Stack} … … 664 702 After the main stack is unwound there is a program-level abort. 665 703 666 There are two reasons for this semantics. The first is that it obviously had to do the abort 704 There are two reasons for these semantics. 705 The first is that it had to do this abort. 667 706 in a sequential program as there is nothing else to notify and the simplicity 668 707 of keeping the same behaviour in sequential and concurrent programs is good. 669 \PAB{I do not understand this sentence. $\Rightarrow$ Also, even in concurrent programs, there is no stack that an innate connection 670 to, so it would have be explicitly managed.} 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. 671 710 672 711 \paragraph{Thread Stack} … … 680 719 and an implicit join (from a destructor call). The explicit join takes the 681 720 default handler (@defaultResumptionHandler@) from its calling context while 682 the implicit join provides its own ,which does a program abort if the721 the implicit join provides its own; which does a program abort if the 683 722 @ThreadCancelled@ exception cannot be handled. 684 723 685 \PAB{Communication can occur during the lifetime of a thread using shared variable and \lstinline{waitfor} statements. 686 Are 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 687 communication with other threads: start and join.}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. 688 727 Since a thread must be running to perform a cancellation (and cannot be 689 728 cancelled from another stack), the cancellation must be after start and 690 before the join, so join is use .729 before the join, so join is used. 691 730 692 731 % TODO: Find somewhere to discuss unwind collisions. … … 695 734 a destructor and prevents cascading the error across multiple threads if 696 735 the user is not equipped to deal with it. 697 Also you can always add an explicit join if that is the desired behaviour. 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. 698 741 699 742 \paragraph{Coroutine Stack} … … 701 744 satisfies the @is_coroutine@ trait. 702 745 After a coroutine stack is unwound, control returns to the @resume@ function 703 that most recently resumed it. The resumereports a704 @CoroutineCancelled@ exception, which contains references to the cancelled746 that most recently resumed it. @resume@ reports a 747 @CoroutineCancelled@ exception, which contains a references to the cancelled 705 748 coroutine and the exception used to cancel it. 706 749 The @resume@ function also takes the \defaultResumptionHandler{} from the 707 caller's context and passes it to the internal cancellation.750 caller's context and passes it to the internal report. 708 751 709 752 A coroutine knows of two other coroutines, its starter and its last resumer. … … 711 754 (in terms of coroutine state) called resume on this coroutine, so the message 712 755 is 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
r5a46e09 r660665f 3 3 4 4 \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.} 5 8 \CFA is a developing programming language. As such, there are partially or 6 9 unimplemented features of the language (including several broken components) 7 10 that I had to workaround while building an exception handling system largely in 8 11 the \CFA language (some C components). The following are a few of these 9 issues, and once implemented/fixed, how th iswould affect the exception system.12 issues, and once implemented/fixed, how they would affect the exception system. 10 13 \begin{itemize} 11 14 \item 12 15 The implementation of termination is not portable because it includes 13 hand-crafted assembly statements. These sections must be ported by hand to 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 14 19 support more hardware architectures, such as the ARM processor. 15 20 \item … … 17 22 reference instead of a pointer. Since \CFA has a very general reference 18 23 capability, programmers will want to use it. Once fixed, this capability should 19 result in little or no change in the exception system .24 result in little or no change in the exception system but simplify usage. 20 25 \item 21 26 Termination handlers cannot use local control-flow transfers, \eg by @break@, … … 41 46 The virtual system should be completed. It was not supposed to be part of this 42 47 project, but was thrust upon it to do exception inheritance; hence, only 43 minimal work was done. A draft for a complete virtual system is available but48 minimal work is done. A draft for a complete virtual system is available but 44 49 it is not finalized. A future \CFA project is to complete that work and then 45 50 update the exception system that uses the current version. … … 67 72 bad software engineering. 68 73 69 Non-local/concurrent requires more coordination between the concurrency system 74 Non-local/concurrent raise requires more 75 coordination between the concurrency system 70 76 and the exception system. Many of the interesting design decisions centre 71 around masking (controlling which exceptions may be thrown at a stack). It77 around masking, \ie controlling which exceptions may be thrown at a stack. It 72 78 would likely require more of the virtual system and would also effect how 73 79 default handlers are set. … … 85 91 86 92 \section{Checked Exceptions} 87 Checked exceptions make exceptions part of a function's type by adding the93 Checked exceptions make exceptions part of a function's type by adding an 88 94 exception signature. An exception signature must declare all checked 89 exceptions that could prop ogate from the function (either because they were95 exceptions that could propagate from the function (either because they were 90 96 raised inside the function or came from a sub-function). This improves safety 91 97 by making sure every checked exception is either handled or consciously … … 93 99 94 100 However checked exceptions were never seriously considered for this project 95 for two reasons. The first is due to time constraints, even copying an 96 existing checked exception system would be pushing the remaining time and 97 trying to address the second problem would take even longer. The second 98 problem is that checked exceptions have some real usability trade-offs in 101 because they have significant trade-offs in usablity and code reuse in 99 102 exchange for the increased safety. 100 101 103 These trade-offs are most problematic when trying to pass exceptions through 102 104 higher-order functions from the functions the user passed into the 103 105 higher-order function. There are no well known solutions to this problem 104 that were s tatifactory for \CFA (which carries some of C's flexability105 over safety design) so one would have to be researched and developed.106 that were satisfactory for \CFA (which carries some of C's flexibility 107 over safety design) so additional research is needed. 106 108 107 Follow-up work might add checked exceptions to \CFA, possibly using 108 polymorphic exception signatures, a form of tunneling\cite{Zhang19} or 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 109 112 checked and unchecked raises. 110 113 … … 150 153 For instance, resumption could be extended to cover this use by allowing local 151 154 control flow out of it. This approach would require an unwind as part of the 152 transition as there are stack frames that have to be removed. This approach 153 means there is no notify raise, but because \CFA does not have exception 154 signatures, a termination can be thrown from within any resumption handler so 155 there is already a way to do mimic this in existing \CFA. 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. 156 161 157 162 % Maybe talk about the escape; and escape CONTROL_STMT; statements or how -
doc/theses/andrew_beach_MMath/implement.tex
r5a46e09 r660665f 2 2 \label{c:implement} 3 3 4 The implementation work for this thesis covers two components: the virtual 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 5 11 system and exceptions. Each component is discussed in detail. 6 12 … … 21 27 \todo{Talk about constructors for virtual types (after they are working).} 22 28 23 This is what binds an instance of a virtual type to a virtual table. This 24 pointer can be used as an identity check. It can also be used to access the 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 25 32 virtual table and the virtual members there. 26 33 27 34 \subsection{Type Id} 28 35 Every virtual type has a unique id. 29 Type ids can be compared for equality (the types reperented are the same) 36 Type ids can be compared for equality, 37 which checks if the types reperented are the same, 30 38 or used to access the type's type information. 31 39 The type information currently is only the parent's type id or, if the 32 type has no parent, zero.40 type has no parent, the null pointer. 33 41 34 42 The id's are implemented as pointers to the type's type information instance. 35 Derefe ncing the pointer gets the type information.36 By going back-and-forth between the type id and 37 the type info one can find every ancestor of a virtual type.38 It alsopushes the issue of creating a unique value (for43 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 39 47 the type id) to the problem of creating a unique instance (for type 40 information) which the linker can solve. 41 42 Advanced linker support is required because there is no place that appears 43 only once to attach the type information to. There should be one structure 44 definition but it is included in multiple translation units. Each virtual 45 table definition should be unique but there are an arbitrary number of thoses. 46 So the special section prefix \texttt{.gnu.linkonce} is used. 47 With a unique suffix (making the entire section name unique) the linker will 48 remove multiple definition making sure only one version exists after linking. 49 Then it is just a matter of making sure there is a unique name for each type. 50 51 This is done in three phases. 52 The first phase is to generate a new structure definition to store the 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 53 70 information. The layout is the same in each case, just the parent's type id, 54 but the types are changed.55 The structure's name is change, it is based off the virtual type's name, and56 the type of 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. 57 74 If the virtual type is polymorphic then the type information structure is 58 75 polymorphic as well, with the same polymorphic arguments. 59 60 The second phase is to generate an instance of the type information with a 61 almost unique name, generated by mangling the virtual type name. 62 63 The third phase is implicit with \CFA's overloading scheme. \CFA mangles 64 names with type information so that all of the symbols exported to the linker 65 are unique even if in \CFA code they are the same. Having two declarations 66 with the same name and same type is forbidden because it is impossible for 67 overload resolution to pick between them. This is why a unique type is 68 generated for each virtual type. 69 Polymorphic information is included in this mangling so polymorphic 70 types will have seperate instances for each set of polymorphic arguments. 71 72 \begin{cfa} 73 struct TYPE_ID_TYPE { 74 PARENT_ID_TYPE const * parent; 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; 75 94 }; 76 95 77 96 __attribute__((cfa_linkonce)) 78 TYPE_ID_TYPE const TYPE_ID_NAME= {79 & PARENT_ID_NAME,97 INFO_TYPE(TYPE) const INFO_NAME(TYPE) = { 98 &INFO_NAME(PARENT), 80 99 }; 81 100 \end{cfa} 82 101 83 \subsubsection{cfa\_linkonce Attribute} 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. 84 105 Another feature added to \CFA is a new attribute: \texttt{cfa\_linkonce}. 85 This attribute can be put on an object or function definition 86 (any global declaration with a name and a type). 87 This allows you to define that object or function multiple times. 88 All definitions should have the link-once attribute on them and all should 89 be identical. 90 91 The simplist way to use it is to put a definition in a header where the 92 forward declaration would usually go. 93 This is how it is used for type-id instances. There was is no unique location 94 associated with a type except for the type definition which is in a header. 95 This allows the unique type-id object to be generated there. 96 97 Internally @cfa_linkonce@ removes all @section@ attributes 98 from the declaration (as well as itself) and replaces them with 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 99 121 @section(".gnu.linkonce.NAME")@ where \texttt{NAME} is replaced by the 100 122 mangled name of the object. 123 Any other @section@ attributes are removed from the declaration. 101 124 The prefix \texttt{.gnu.linkonce} in section names is recognized by the 102 linker. If two of these sections with the same name, including everything103 that comes after the special prefix, then only one will be used and the other 104 will bediscarded.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. 105 128 106 129 \subsection{Virtual Table} 130 \label{ss:VirtualTable} 107 131 Each virtual type has a virtual table type that stores its type id and 108 132 virtual members. … … 113 137 114 138 The layout always comes in three parts. 139 \todo{Add labels to the virtual table layout figure.} 115 140 The first section is just the type id at the head of the table. It is always 116 there to ensure that 141 there to ensure that it can be found even when the accessing code does not 142 know which virtual type it has. 117 143 The second section are all the virtual members of the parent, in the same 118 144 order as they appear in the parent's virtual table. Note that the type may … … 133 159 prefix that has the same layout and types as its parent virtual table. 134 160 This, combined with the fixed offset to the virtual table pointer, means that 135 for any virtual type it doesn't matter if we have it or any of its 136 descendants, it is still always safe to access the virtual table through 137 the virtual table pointer. 138 From there it is safe to check the type id to identify the exact type of the 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 139 163 underlying object, access any of the virtual members and pass the object to 140 164 any of the method-like virtual members. 141 165 142 When a virtual table is declared the user decides where to declare it and its166 When a virtual table is declared, the user decides where to declare it and its 143 167 name. The initialization of the virtual table is entirely automatic based on 144 168 the context of the declaration. 145 169 146 The type id is always fixed , each virtual table type will always have one170 The type id is always fixed; with each virtual table type having 147 171 exactly one possible type id. 148 The virtual members are usually filled in by resolution. The best match for149 a given name and type at the declaration site is filled in.150 There are two exceptions to that rule: the @size@ field is the type's size151 and is set to the result of a @sizeof@ expression, the @align@ field isthe152 type's alignment and similarly usesan @alignof@ expression.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. 153 177 154 178 \subsubsection{Concurrency Integration} 155 179 Coroutines and threads need instances of @CoroutineCancelled@ and 156 180 @ThreadCancelled@ respectively to use all of their functionality. When a new 157 data type is declared with @coroutine@ or @thread@ theforward declaration for181 data type is declared with @coroutine@ or @thread@, a forward declaration for 158 182 the instance is created as well. The definition of the virtual table is created 159 183 at 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. 160 190 161 191 \begin{figure} … … 165 195 }; 166 196 \end{cfa} 197 198 \transformline[appends...] 167 199 168 200 \begin{cfa} … … 175 207 extern CoroutineCancelled_vtable & _default_vtable; 176 208 \end{cfa} 177 209 \caption{Concurrency Type Transformation} 210 \label{f:ConcurrencyTypeTransformation} 211 \end{figure} 212 213 \begin{figure} 178 214 \begin{cfa} 179 215 void main(Example & this) { … … 181 217 } 182 218 \end{cfa} 219 220 \transformline[appends...] 183 221 184 222 \begin{cfa} … … 191 229 &_default_vtable_object_declaration; 192 230 \end{cfa} 193 \caption{Concurrency Transformations}194 \label{f:Concurrency Transformations}231 \caption{Concurrency Main Transformation} 232 \label{f:ConcurrencyMainTransformation} 195 233 \end{figure} 196 \todo{Improve Concurrency Transformations figure.}197 234 198 235 \subsection{Virtual Cast} … … 211 248 the cast target is passed in as @child@. 212 249 213 For C generation both arguments and the result are wrappedwith type casts.214 There is also an internal storeinside the compiler to make sure that the250 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 215 252 target type is a virtual type. 216 253 % It also checks for conflicting definitions. 217 254 218 The virtual cast either returns the original pointer as a new type or null. 219 So the function just does the parent check and returns the approprate value. 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. 220 258 The parent check is a simple linear search of child's ancestors using the 221 259 type information. … … 229 267 % resumption doesn't as well. 230 268 231 % Many modern languages work with an inter al stack that function push and pop269 % Many modern languages work with an internal stack that function push and pop 232 270 % their local data to. Stack unwinding removes large sections of the stack, 233 271 % often across functions. … … 236 274 stack. On function entry and return, unwinding is handled directly by the 237 275 call/return code embedded in the function. 238 In many cases the position of the instruction pointer (relative to parameter276 In many cases, the position of the instruction pointer (relative to parameter 239 277 and local declarations) is enough to know the current size of the stack 240 278 frame. 241 279 242 280 Usually, the stack-frame size is known statically based on parameter and 243 local variable declarations. Even with dynamic stack-size the information244 to determ ainhow much of the stack has to be removed is still contained281 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 245 283 within the function. 246 284 Allocating/deallocating stack space is usually an $O(1)$ operation achieved by 247 285 bumping the hardware stack-pointer up or down as needed. 248 Constructing/destructing values on the stack takes longer put in terms of249 figuring out what needs to be done is of similar complexity.286 Constructing/destructing values within a stack frame has 287 a similar complexity but can add additional work and take longer. 250 288 251 289 Unwinding across multiple stack frames is more complex because that … … 261 299 reseting to a snap-shot of an arbitrary but existing function frame on the 262 300 stack. It is up to the programmer to ensure the snap-shot is valid when it is 263 reset and that all required clean-up from the unwound stacks is p reformed.264 This approach is fragile and forces a work onto the surounding code.265 266 With respect to th at work forced ontothe surounding code,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, 267 305 many languages define clean-up actions that must be taken when certain 268 306 sections of the stack are removed. Such as when the storage for a variable 269 307 is removed from the stack or when a try statement with a finally clause is 270 308 (conceptually) popped from the stack. 271 None of these should be handled by the user ,that would contradict the272 intention of these features ,so they need to be handled automatically.273 274 To safely remove sections of the stack the language must be able to find and309 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 275 313 run these clean-up actions even when removing multiple functions unknown at 276 314 the beginning of the unwinding. … … 294 332 current stack frame, and what handlers should be checked. Theoretically, the 295 333 LSDA can contain any information but conventionally it is a table with entries 296 representing regions of thefunction and what has to be done there during334 representing regions of a function and what has to be done there during 297 335 unwinding. These regions are bracketed by instruction addresses. If the 298 336 instruction pointer is within a region's start/end, then execution is currently … … 314 352 int avar __attribute__(( cleanup(clean_up) )); 315 353 \end{cfa} 316 The attribu e is used on a variable and specifies a function,354 The attribute is used on a variable and specifies a function, 317 355 in this case @clean_up@, run when the variable goes out of scope. 318 This is enough to mimic destructors, but not try statements which can effect 356 This feature is enough to mimic destructors, 357 but not try statements which can effect 319 358 the unwinding. 320 359 321 To get full unwinding support all of this has to be done directly with322 assembly and assembler directives. Partiularly the cfi directives360 To get full unwinding support, all of these features must be handled directly 361 in assembly and assembler directives; partiularly the cfi directives 323 362 \snake{.cfi_lsda} and \snake{.cfi_personality}. 324 363 … … 327 366 section covers some of the important parts of the interface. 328 367 329 A personality function can p reform different actions depending on how it is368 A personality function can perform different actions depending on how it is 330 369 called. 331 370 \begin{lstlisting} … … 364 403 365 404 The @exception_class@ argument is a copy of the 366 \code{C}{exception}'s @exception_class@ field .367 This a number that identifies the exception handling mechanism that created 368 th e369 370 The \code{C}{exception} argument is a pointer to theuser405 \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 371 410 provided storage object. It has two public fields: the @exception_class@, 372 411 which is described above, and the @exception_cleanup@ function. 373 The clean-up function is used by the EHM to clean-up the exception if it412 The clean-up function is used by the EHM to clean-up the exception, if it 374 413 should need to be freed at an unusual time, it takes an argument that says 375 414 why it had to be cleaned up. … … 382 421 messages for special cases (some of which should never be used by the 383 422 personality function) and error codes. However, unless otherwise noted, the 384 personality function should always return@_URC_CONTINUE_UNWIND@.423 personality function always returns @_URC_CONTINUE_UNWIND@. 385 424 386 425 \subsection{Raise Exception} 387 Raising an exception is the central function of libunwind and it performs a426 Raising an exception is the central function of libunwind and it performs 388 427 two-staged unwinding. 389 428 \begin{cfa} … … 472 511 % catches. Talk about GCC nested functions. 473 512 474 \CFA termination exceptions use libunwind heavily because they match \Cpp513 \CFA termination exceptions use libunwind heavily because they match 475 514 \Cpp exceptions closely. The main complication for \CFA is that the 476 515 compiler generates C code, making it very difficult to generate the assembly to … … 485 524 486 525 \begin{figure} 526 \centering 487 527 \input{exception-layout} 488 528 \caption{Exception Layout} 489 529 \label{f:ExceptionLayout} 490 530 \end{figure} 491 \todo*{Convert the exception layout to an actual diagram.} 492 493 Exceptions are stored in variable-sized blocks (see \vref{f:ExceptionLayout}).531 532 Exceptions are stored in variable-sized blocks 533 (see \autoref{f:ExceptionLayout}). 494 534 The first component is a fixed-sized data structure that contains the 495 535 information for libunwind and the exception system. The second component is an … … 498 538 @_Unwind_Exception@ to the entire node. 499 539 500 Multip e exceptions can exist at the same time because exceptions can be540 Multiple exceptions can exist at the same time because exceptions can be 501 541 raised inside handlers, destructors and finally blocks. 502 542 Figure~\vref{f:MultipleExceptions} shows a program that has multiple 503 543 exceptions active at one time. 504 544 Each time an exception is thrown and caught the stack unwinds and the finally 505 clause runs. This will throwanother exception (until @num_exceptions@ gets506 high enough) which must be allocated. The previous exceptions may not be545 clause runs. This handler throws another exception (until @num_exceptions@ gets 546 high enough), which must be allocated. The previous exceptions may not be 507 547 freed because the handler/catch clause has not been run. 508 So the EHM must keep them alive while it allocates exceptions for new throws. 548 Therefore, the EHM must keep all unhandled exceptions alive 549 while it allocates exceptions for new throws. 509 550 510 551 \begin{figure} … … 559 600 \todo*{Work on multiple exceptions code sample.} 560 601 561 All exceptions are stored in nodes which are then linked together in lists,602 All exceptions are stored in nodes, which are then linked together in lists 562 603 one list per stack, with the 563 604 list head stored in the exception context. Within each linked list, the most … … 566 607 exception is being handled. The exception at the head of the list is currently 567 608 being handled, while other exceptions wait for the exceptions before them to be 568 removed.609 handled and removed. 569 610 570 611 The virtual members in the exception's virtual table provide the size of the … … 573 614 exception into managed memory. After the exception is handled, the free 574 615 function is used to clean up the exception and then the entire node is 575 passed to free so the memory can be givenback to the heap.616 passed to free, returning the memory back to the heap. 576 617 577 618 \subsection{Try Statements and Catch Clauses} 578 619 The try statement with termination handlers is complex because it must 579 compensate for the lack of assembly-code generated from \CFA. Libunwind 620 compensate for the C code-generation versus 621 assembly-code generated from \CFA. Libunwind 580 622 requires an LSDA and personality function for control to unwind across a 581 623 function. The LSDA in particular is hard to mimic in generated C code. … … 592 634 embedded assembly. This assembly code is handcrafted using C @asm@ statements 593 635 and contains 594 enough information for thesingle try statement the function repersents.636 enough information for a single try statement the function repersents. 595 637 596 638 The three functions passed to try terminate are: 597 639 \begin{description} 598 \item[try function:] This function is the try block, all the code inside the599 try block is placed inside the try function. It takes no parameters and has no640 \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 600 642 return value. This function is called during regular execution to run the try 601 643 block. … … 609 651 handler that matches the exception. 610 652 611 \item[handler function:] This function handles the exception. It takes a 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 612 657 pointer to the exception and the handler's id and returns nothing. It is called 613 after the cleanup phase. It is constructed by stitching together the bodies of 614 each handler and dispatches to the selected handler. 658 after the cleanup phase. 615 659 \end{description} 616 660 All three functions are created with GCC nested functions. GCC nested functions 617 can be used to create closures, functions that can refer to the state of other 661 can be used to create closures, 662 in other words functions that can refer to the state of other 618 663 functions on the stack. This approach allows the functions to refer to all the 619 664 variables in scope for the function containing the @try@ statement. These … … 623 668 Using this pattern, \CFA implements destructors with the cleanup attribute. 624 669 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 625 674 \begin{figure} 626 675 \begin{cfa} … … 633 682 } 634 683 \end{cfa} 684 685 \transformline 635 686 636 687 \begin{cfa} … … 683 734 % The stack-local data, the linked list of nodes. 684 735 685 Resumption simpler to implement than termination736 Resumption is simpler to implement than termination 686 737 because there is no stack unwinding. 687 738 Instead of storing the data in a special area using assembly, … … 692 743 The nodes are stored in order, with the more recent try statements closer 693 744 to the head of the list. 694 Instead of traversing the stack resumption handling traverses the list.695 At each node the EHM checks to see if the try statement the node repersents745 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 696 747 can handle the exception. If it can, then the exception is handled and 697 748 the operation finishes, otherwise the search continues to the next node. 698 749 If the search reaches the end of the list without finding a try statement 699 that can handle the exception the default handler is executed and the750 that can handle the exception, the default handler is executed and the 700 751 operation finishes. 701 752 702 In each node is a handler function which does most of the work there. 703 The handler function is passed the raised the exception and returns true 704 if the exception is handled and false if it cannot be handled here. 705 706 For each @catchResume@ clause the handler function will: 707 check to see if the raised exception is a descendant type of the declared 708 exception type, if it is and there is a conditional expression then it will 709 run the test, if both checks pass the handling code for the clause is run 710 and the function returns true, otherwise it moves onto the next clause. 711 If this is the last @catchResume@ clause then instead of moving onto 712 the next clause the function returns false as no handler could be found. 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.} 713 769 714 770 \begin{figure} … … 722 778 } 723 779 \end{cfa} 780 781 \transformline 724 782 725 783 \begin{cfa} … … 753 811 754 812 % Recursive Resumption Stuff: 755 Search skipping (see \vpageref{s:ResumptionMarking}), which ignores parts of 813 \autoref{f:ResumptionMarking} shows search skipping 814 (see \vpageref{s:ResumptionMarking}), which ignores parts of 756 815 the stack 757 816 already examined, is accomplished by updating the front of the list as the … … 759 818 is updated to the next node of the current node. After the search is complete, 760 819 successful or not, the head of the list is reset. 761 820 % No paragraph? 762 821 This mechanism means the current handler and every handler that has already 763 822 been checked are not on the list while a handler is run. If a resumption is 764 thrown during the handling of another resumption the active handlers and all823 thrown during the handling of another resumption, the active handlers and all 765 824 the other handler checked up to this point are not checked again. 766 767 This structure also supports new handler added while the resumption is being825 % No paragraph? 826 This structure also supports new handlers added while the resumption is being 768 827 handled. These are added to the front of the list, pointing back along the 769 stack -- the first one points over all the checked handlers -- and the ordering770 is maintained.828 stack --- the first one points over all the checked handlers --- 829 and the ordering is maintained. 771 830 772 831 \begin{figure} … … 774 833 \caption{Resumption Marking} 775 834 \label{f:ResumptionMarking} 776 \todo*{ Convert Resumption Marking into a line figure.}835 \todo*{Label Resumption Marking to aid clarity.} 777 836 \end{figure} 778 837 779 838 \label{p:zero-cost} 780 Note, the resumption implementation has a cost for entering/exiting a @try@ 781 statement with @catchResume@ clauses, whereas a @try@statement with @catch@839 Finally, the resumption implementation has a cost for entering/exiting a try 840 statement with @catchResume@ clauses, whereas a try statement with @catch@ 782 841 clauses has zero-cost entry/exit. While resumption does not need the stack 783 842 unwinding and cleanup provided by libunwind, it could use the search phase to … … 810 869 811 870 The first step of cancellation is to find the cancelled stack and its type: 812 coroutine or thread. Fortunately, the thread library stores the main thread813 pointer and the current thread pointer, and every thread stores a pointer to 814 its main coroutine and the coroutine it is currently executing.815 \todo*{Consider adding a description of how threads are coroutines.} 816 817 If athe current thread's main and current coroutines are the same then the818 current stack is a thread stack . Furthermore it is easy to compare the819 current thread to the main thread to see if they are the same. And if this 820 i s not a thread stack then it must be a coroutine stack.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. 821 880 822 881 However, if the threading library is not linked, the sequential execution is on 823 882 the main stack. Hence, the entire check is skipped because the weak-symbol 824 function is loaded. Therefore, amain thread cancellation is unconditionally883 function is loaded. Therefore, main thread cancellation is unconditionally 825 884 performed. 826 885 827 886 Regardless of how the stack is chosen, the stop function and parameter are 828 887 passed to the forced-unwind function. The general pattern of all three stop 829 functions is the same: theycontinue unwinding until the end of stack and830 then preform the irtransfer.888 functions is the same: continue unwinding until the end of stack and 889 then preform the appropriate transfer. 831 890 832 891 For main stack cancellation, the transfer is just a program abort. … … 834 893 For coroutine cancellation, the exception is stored on the coroutine's stack, 835 894 and the coroutine context switches to its last resumer. The rest is handled on 836 the backside of the resume, which check if the resumed coroutine is895 the backside of the resume, which checks if the resumed coroutine is 837 896 cancelled. If cancelled, the exception is retrieved from the resumed coroutine, 838 897 and a @CoroutineCancelled@ exception is constructed and loaded with the -
doc/theses/andrew_beach_MMath/intro.tex
r5a46e09 r660665f 1 1 \chapter{Introduction} 2 2 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.} 7 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). 12 Exception handling provides alternative dynamic inter-function control flow. 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. 11 12 % Now take a step back and explain what exceptions are generally. 13 Exception handling provides dynamic inter-function control flow. 13 14 There are two forms of exception handling covered in this thesis: 14 15 termination, which acts as a multi-level return, 15 16 and resumption, which is a dynamic function call. 16 Note, termination exception handling is so common it is often assumed to be the only form. 17 Lesser know derivations of inter-function control flow are continuation passing in Lisp~\cite{CommonLisp}. 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. 18 25 19 26 Termination exception handling allows control to return to any previous … … 24 31 \end{center} 25 32 26 Resumption exception handling calls a function, but asks the functions on the27 stack what function that is.33 Resumption exception handling seaches the stack for a handler and then calls 34 it without adding or removing any other stack frames. 28 35 \todo{Add a diagram showing control flow for resumption.} 29 36 … … 35 42 most of the cost only when the error actually occurs. 36 43 37 % Overview of exceptions in Cforall.38 39 \PAB{You need section titles here. Don't take them out.}40 41 44 \section{Thesis Overview} 42 43 This thesis goes over the design and implementation of the exception handling 44 mechanism (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. 45 This work describes the design and implementation of the \CFA EHM. 47 46 The \CFA EHM implements all of the common exception features (or an 48 47 equivalent) found in most other EHMs and adds some features of its own. … … 77 76 harder to replicate in other programming languages. 78 77 79 \section{Background}80 81 78 % Talk about other programming languages. 82 79 Some existing programming languages that include EHMs/exception handling … … 84 81 exceptions which unwind the stack as part of the 85 82 Exceptions also can replace return codes and return unions. 86 In functional languages will also sometimes fold exceptions into monads.87 88 \PAB{You must demonstrate knowledge of background material here.89 It should be at least a full page.}90 91 \section{Contributions}92 83 93 84 The contributions of this work are: … … 102 93 \end{enumerate} 103 94 104 \todo{I can't figure out a good lead-in to the overview.} 105 Covering the existing \CFA features in \autoref{c:existing}. 106 Then the new features are introduce in \autoref{c:features}, explaining their 107 usage and design. 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. 108 100 That is followed by the implementation of those features in 109 101 \autoref{c:implement}. 110 % Future Work \autoref{c:future} 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 -
doc/theses/andrew_beach_MMath/uw-ethesis.tex
r5a46e09 r660665f 244 244 \input{features} 245 245 \input{implement} 246 \input{performance} 246 247 \input{future} 247 248 -
doc/theses/mubeen_zulfiqar_MMath/.gitignore
r5a46e09 r660665f 1 1 # Intermediate Results: 2 out/2 build/ 3 3 4 4 # Final Files: -
doc/theses/mubeen_zulfiqar_MMath/allocator.tex
r5a46e09 r660665f 7 7 \begin{itemize} 8 8 \item 9 Objective of @uHeapLmmm@.9 Objective of uHeapLmmm. 10 10 \item 11 11 Design philosophy. 12 12 \item 13 Background and previous design of @uHeapLmmm@.13 Background and previous design of uHeapLmmm. 14 14 \item 15 Distributed design of @uHeapLmmm@.15 Distributed design of uHeapLmmm. 16 16 17 17 ----- SHOULD WE GIVE IMPLEMENTATION DETAILS HERE? ----- … … 24 24 \end{itemize} 25 25 26 The new features added to @uHeapLmmm@(incl. @malloc_size@ routine)26 The new features added to uHeapLmmm (incl. @malloc_size@ routine) 27 27 \CFA alloc interface with examples. 28 28 \begin{itemize} … … 33 33 \end{itemize} 34 34 35 ----- SHOULD WE GIVE PERFORMANCE AND USABILITY COMPARISON OF DIFFERENT INTERFACES THAT WE TRIED? -----36 35 37 \PAB{Often Performance is its own chapter. I added one for now.} 36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% uHeapLmmm Design 39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 38 41 39 Performance evaluation using u-benchmark suite. 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 40 78 41 79 \noindent -
doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex
r5a46e09 r660665f 34 34 \noindent 35 35 ==================== 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
r5a46e09 r660665f 165 165 % cfa macros used in the document 166 166 \input{common} 167 %\usepackageinput{common} 167 168 \CFAStyle % CFA code-style for all languages 168 \lstset{ language=CFA,basicstyle=\linespread{0.9}\tt} % CFA default language169 \lstset{basicstyle=\linespread{0.9}\tt} % CFA typewriter font 169 170 \newcommand{\PAB}[1]{{\color{red}PAB: #1}} 170 171 -
libcfa/configure.ac
r5a46e09 r660665f 131 131 #io_uring 5.5 uses enum values 132 132 #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)], []) 133 139 134 140 AH_TEMPLATE([CFA_HAVE_LINUX_IO_URING_H],[Defined if io_uring support is present when compiling libcfathread.]) -
libcfa/prelude/defines.hfa.in
r5a46e09 r660665f 171 171 #undef CFA_HAVE_LINUX_IO_URING_H 172 172 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 173 179 /* Defined if openat2 support is present when compiling libcfathread. */ 174 180 #undef CFA_HAVE_OPENAT2 … … 205 211 #undef HAVE_LINUX_IO_URING_H 206 212 213 /* Define to 1 if you have the <linux/rseq.h> header file. */ 214 #undef HAVE_LINUX_RSEQ_H 215 207 216 /* Define to 1 if you have the <memory.h> header file. */ 208 217 #undef HAVE_MEMORY_H -
libcfa/src/Makefile.am
r5a46e09 r660665f 61 61 containers/queueLockFree.hfa \ 62 62 containers/stackLockFree.hfa \ 63 containers/vector2.hfa \ 63 64 vec/vec.hfa \ 64 65 vec/vec2.hfa \ … … 69 70 common.hfa \ 70 71 fstream.hfa \ 71 strstream.hfa \72 72 heap.hfa \ 73 73 iostream.hfa \ … … 78 78 rational.hfa \ 79 79 stdlib.hfa \ 80 strstream.hfa \ 80 81 time.hfa \ 81 82 bits/weakso_locks.hfa \ … … 83 84 containers/pair.hfa \ 84 85 containers/result.hfa \ 85 containers/vector.hfa 86 containers/vector.hfa \ 87 device/cpu.hfa 86 88 87 89 libsrc = ${inst_headers_src} ${inst_headers_src:.hfa=.cfa} \ -
libcfa/src/bits/signal.hfa
r5a46e09 r660665f 20 20 21 21 #include <errno.h> 22 #define __USE_GNU23 22 #include <signal.h> 24 #undef __USE_GNU25 23 #include <stdlib.h> 26 24 #include <string.h> -
libcfa/src/concurrency/coroutine.cfa
r5a46e09 r660665f 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE 17 18 18 19 #include "coroutine.hfa" -
libcfa/src/concurrency/io.cfa
r5a46e09 r660665f 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE 17 18 18 19 #if defined(__CFA_DEBUG__) … … 23 24 24 25 #if defined(CFA_HAVE_LINUX_IO_URING_H) 25 #define _GNU_SOURCE /* See feature_test_macros(7) */26 26 #include <errno.h> 27 27 #include <signal.h> -
libcfa/src/concurrency/io/setup.cfa
r5a46e09 r660665f 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE /* See feature_test_macros(7) */17 #define _GNU_SOURCE 18 18 19 19 #if defined(__CFA_DEBUG__) -
libcfa/src/concurrency/kernel.cfa
r5a46e09 r660665f 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE 18 17 19 // #define __CFA_DEBUG_PRINT_RUNTIME_CORE__ 18 20 … … 278 280 279 281 // Spin a little on I/O, just in case 280 282 for(5) { 281 283 __maybe_io_drain( this ); 282 284 readyThread = pop_fast( this->cltr ); … … 285 287 286 288 // no luck, try stealing a few times 287 289 for(5) { 288 290 if( __maybe_io_drain( this ) ) { 289 291 readyThread = pop_fast( this->cltr ); … … 422 424 __cfactx_switch( &proc_cor->context, &thrd_dst->context ); 423 425 // when __cfactx_switch returns we are back in the processor coroutine 426 427 424 428 425 429 /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary ); … … 522 526 523 527 /* paranoid */ verify( ! __preemption_enabled() ); 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 );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 ); 526 530 } 527 531 -
libcfa/src/concurrency/kernel.hfa
r5a46e09 r660665f 66 66 unsigned id; 67 67 unsigned target; 68 unsigned last; 68 69 unsigned long long int cutoff; 69 70 } rdq; -
libcfa/src/concurrency/kernel/startup.cfa
r5a46e09 r660665f 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE 17 18 18 19 // C Includes 19 20 #include <errno.h> // errno 21 #include <signal.h> 20 22 #include <string.h> // strerror 21 23 #include <unistd.h> // sysconf 24 22 25 extern "C" { 23 26 #include <limits.h> // PTHREAD_STACK_MIN 27 #include <unistd.h> // syscall 24 28 #include <sys/eventfd.h> // eventfd 25 29 #include <sys/mman.h> // mprotect … … 136 140 }; 137 141 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 138 154 //----------------------------------------------------------------------------- 139 155 // Struct to steal stack … … 468 484 self_mon_p = &self_mon; 469 485 link.next = 0p; 470 link.ts = 0;486 link.ts = -1llu; 471 487 preferred = -1u; 472 488 last_proc = 0p; … … 497 513 this.rdq.id = -1u; 498 514 this.rdq.target = -1u; 515 this.rdq.last = -1u; 499 516 this.rdq.cutoff = 0ull; 500 517 do_terminate = false; -
libcfa/src/concurrency/kernel_private.hfa
r5a46e09 r660665f 16 16 #pragma once 17 17 18 #if !defined(__cforall_thread__) 19 #error kernel_private.hfa should only be included in libcfathread source 20 #endif 21 18 22 #include "kernel.hfa" 19 23 #include "thread.hfa" … … 22 26 #include "stats.hfa" 23 27 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 24 41 //----------------------------------------------------------------------------- 25 42 // Scheduler 26 27 28 43 extern "C" { 29 44 void disable_interrupts() OPTIONAL_THREAD; … … 39 54 40 55 //----------------------------------------------------------------------------- 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 //----------------------------------------------------------------------------- 41 82 // Processor 42 83 void main(processorCtx_t *); … … 44 85 void * __create_pthread( pthread_t *, void * (*)(void *), void * ); 45 86 void __destroy_pthread( pthread_t pthread, void * stack, void ** retval ); 46 47 48 87 49 88 extern cluster * mainCluster; -
libcfa/src/concurrency/locks.cfa
r5a46e09 r660665f 16 16 17 17 #define __cforall_thread__ 18 #define _GNU_SOURCE 18 19 19 20 #include "locks.hfa" -
libcfa/src/concurrency/locks.hfa
r5a46e09 r660665f 24 24 #include "containers/list.hfa" 25 25 26 #include "limits.hfa" 26 27 #include "thread.hfa" 27 28 … … 87 88 bool tryP(BinaryBenaphore & this) { 88 89 ssize_t c = this.counter; 90 /* paranoid */ verify( c > MIN ); 89 91 return (c >= 1) && __atomic_compare_exchange_n(&this.counter, &c, c-1, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); 90 92 } … … 94 96 ssize_t c = 0; 95 97 for () { 98 /* paranoid */ verify( this.counter < MAX ); 96 99 if (__atomic_compare_exchange_n(&this.counter, &c, c+1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 97 100 if (c == 0) return true; … … 173 176 ThreadBenaphore sem; 174 177 }; 178 179 static inline void ?{}(fast_lock & this) { this.owner = 0p; } 175 180 176 181 static inline bool $try_lock(fast_lock & this, $thread * thrd) { -
libcfa/src/concurrency/monitor.cfa
r5a46e09 r660665f 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE 17 18 18 19 #include "monitor.hfa" -
libcfa/src/concurrency/mutex.cfa
r5a46e09 r660665f 17 17 18 18 #define __cforall_thread__ 19 #define _GNU_SOURCE 19 20 20 21 #include "mutex.hfa" -
libcfa/src/concurrency/preemption.cfa
r5a46e09 r660665f 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE 18 17 19 // #define __CFA_DEBUG_PRINT_PREEMPTION__ 18 20 -
libcfa/src/concurrency/ready_queue.cfa
r5a46e09 r660665f 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE 18 17 19 // #define __CFA_DEBUG_PRINT_READY_QUEUE__ 18 20 … … 20 22 #define USE_RELAXED_FIFO 21 23 // #define USE_WORK_STEALING 24 // #define USE_CPU_WORK_STEALING 22 25 23 26 #include "bits/defs.hfa" 27 #include "device/cpu.hfa" 24 28 #include "kernel_private.hfa" 25 29 26 #define _GNU_SOURCE27 30 #include "stdlib.hfa" 28 31 #include "math.hfa" 29 32 33 #include <errno.h> 30 34 #include <unistd.h> 35 36 extern "C" { 37 #include <sys/syscall.h> // __NR_xxx 38 } 31 39 32 40 #include "ready_subqueue.hfa" … … 46 54 #endif 47 55 48 #if defined(USE_RELAXED_FIFO) 56 #if defined(USE_CPU_WORK_STEALING) 57 #define READYQ_SHARD_FACTOR 2 58 #elif defined(USE_RELAXED_FIFO) 49 59 #define BIAS 4 50 60 #define READYQ_SHARD_FACTOR 4 … … 85 95 } 86 96 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 87 116 //======================================================================= 88 117 // Cluster wide reader-writer lock … … 107 136 // Lock-Free registering/unregistering of threads 108 137 unsigned register_proc_id( void ) with(*__scheduler_lock) { 138 __kernel_rseq_register(); 139 109 140 __cfadbg_print_safe(ready_queue, "Kernel : Registering proc %p for RW-Lock\n", proc); 110 141 bool * handle = (bool *)&kernelTLS().sched_lock; … … 161 192 162 193 __cfadbg_print_safe(ready_queue, "Kernel : Unregister proc %p\n", proc); 194 195 __kernel_rseq_unregister(); 163 196 } 164 197 … … 214 247 //======================================================================= 215 248 void ?{}(__ready_queue_t & this) with (this) { 216 lanes.data = 0p; 217 lanes.tscs = 0p; 218 lanes.count = 0; 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 219 263 } 220 264 221 265 void ^?{}(__ready_queue_t & this) with (this) { 222 verify( SEQUENTIAL_SHARD == lanes.count ); 266 #if !defined(USE_CPU_WORK_STEALING) 267 verify( SEQUENTIAL_SHARD == lanes.count ); 268 #endif 269 223 270 free(lanes.data); 224 271 free(lanes.tscs); … … 226 273 227 274 //----------------------------------------------------------------------- 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 228 414 #if defined(USE_RELAXED_FIFO) 229 415 //----------------------------------------------------------------------- … … 519 705 if(is_empty(sl)) { 520 706 assert( sl.anchor.next == 0p ); 521 assert( sl.anchor.ts == 0);707 assert( sl.anchor.ts == -1llu ); 522 708 assert( mock_head(sl) == sl.prev ); 523 709 } else { 524 710 assert( sl.anchor.next != 0p ); 525 assert( sl.anchor.ts != 0);711 assert( sl.anchor.ts != -1llu ); 526 712 assert( mock_head(sl) != sl.prev ); 527 713 } … … 573 759 lanes.tscs = alloc(lanes.count, lanes.tscs`realloc); 574 760 for(i; lanes.count) { 575 unsigned long long tsc = ts(lanes.data[i]); 576 lanes.tscs[i].tv = tsc != 0 ? tsc : rdtscl(); 761 unsigned long long tsc1 = ts(lanes.data[i]); 762 unsigned long long tsc2 = rdtscl(); 763 lanes.tscs[i].tv = min(tsc1, tsc2); 577 764 } 578 765 #endif 579 766 } 580 767 581 // Grow the ready queue 582 void 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 632 void 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 674 } 675 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 } 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; 792 } 793 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 705 898 706 899 #if !defined(__CFA_NO_STATISTICS__) … … 710 903 } 711 904 #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
r5a46e09 r660665f 32 32 this.prev = mock_head(this); 33 33 this.anchor.next = 0p; 34 this.anchor.ts = 0;34 this.anchor.ts = -1llu; 35 35 #if !defined(__CFA_NO_STATISTICS__) 36 36 this.cnt = 0; … … 44 44 /* paranoid */ verify( &mock_head(this)->link.ts == &this.anchor.ts ); 45 45 /* paranoid */ verify( mock_head(this)->link.next == 0p ); 46 /* paranoid */ verify( mock_head(this)->link.ts == 0);46 /* paranoid */ verify( mock_head(this)->link.ts == -1llu ); 47 47 /* paranoid */ verify( mock_head(this) == this.prev ); 48 48 /* paranoid */ verify( __alignof__(__intrusive_lane_t) == 128 ); … … 55 55 // Make sure the list is empty 56 56 /* paranoid */ verify( this.anchor.next == 0p ); 57 /* paranoid */ verify( this.anchor.ts == 0);57 /* paranoid */ verify( this.anchor.ts == -1llu ); 58 58 /* paranoid */ verify( mock_head(this) == this.prev ); 59 59 } … … 64 64 /* paranoid */ verify( this.lock ); 65 65 /* paranoid */ verify( node->link.next == 0p ); 66 /* paranoid */ verify( node->link.ts == 0);66 /* paranoid */ verify( node->link.ts == -1llu ); 67 67 /* paranoid */ verify( this.prev->link.next == 0p ); 68 /* paranoid */ verify( this.prev->link.ts == 0);68 /* paranoid */ verify( this.prev->link.ts == -1llu ); 69 69 if( this.anchor.next == 0p ) { 70 70 /* paranoid */ verify( this.anchor.next == 0p ); 71 /* paranoid */ verify( this.anchor.ts == 0 ); 71 /* paranoid */ verify( this.anchor.ts == -1llu ); 72 /* paranoid */ verify( this.anchor.ts != 0 ); 72 73 /* paranoid */ verify( this.prev == mock_head( this ) ); 73 74 } else { 74 75 /* paranoid */ verify( this.anchor.next != 0p ); 76 /* paranoid */ verify( this.anchor.ts != -1llu ); 75 77 /* paranoid */ verify( this.anchor.ts != 0 ); 76 78 /* paranoid */ verify( this.prev != mock_head( this ) ); … … 92 94 /* paranoid */ verify( this.lock ); 93 95 /* paranoid */ verify( this.anchor.next != 0p ); 96 /* paranoid */ verify( this.anchor.ts != -1llu ); 94 97 /* paranoid */ verify( this.anchor.ts != 0 ); 95 98 … … 99 102 this.anchor.next = node->link.next; 100 103 this.anchor.ts = node->link.ts; 101 bool is_empty = this.anchor. ts == 0;104 bool is_empty = this.anchor.next == 0p; 102 105 node->link.next = 0p; 103 node->link.ts = 0;106 node->link.ts = -1llu; 104 107 #if !defined(__CFA_NO_STATISTICS__) 105 108 this.cnt--; … … 110 113 111 114 /* paranoid */ verify( node->link.next == 0p ); 112 /* paranoid */ verify( node->link.ts == 0 ); 115 /* paranoid */ verify( node->link.ts == -1llu ); 116 /* paranoid */ verify( node->link.ts != 0 ); 117 /* paranoid */ verify( this.anchor.ts != 0 ); 113 118 return [node, ts]; 114 119 } … … 116 121 // Check whether or not list is empty 117 122 static inline bool is_empty(__intrusive_lane_t & this) { 118 return this.anchor. ts == 0;123 return this.anchor.next == 0p; 119 124 } 120 125 … … 122 127 static inline unsigned long long ts(__intrusive_lane_t & this) { 123 128 // Cannot verify here since it may not be locked 129 /* paranoid */ verify(this.anchor.ts != 0); 124 130 return this.anchor.ts; 125 131 } -
libcfa/src/concurrency/thread.cfa
r5a46e09 r660665f 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE 17 18 18 19 #include "thread.hfa" … … 39 40 curr_cluster = &cl; 40 41 link.next = 0p; 41 link.ts = 0;42 link.ts = -1llu; 42 43 preferred = -1u; 43 44 last_proc = 0p; -
libcfa/src/containers/array.hfa
r5a46e09 r660665f 1 1 2 2 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 9 forall( T & ) struct tag {}; 3 forall( __CFA_tysys_id_only_X & ) struct tag {}; 10 4 #define ttag(T) ((tag(T)){}) 11 #define ztag(n) ttag( Z(n))5 #define ztag(n) ttag(n) 12 6 13 7 … … 18 12 forall( [N], S & | sized(S), Timmed &, Tbase & ) { 19 13 struct arpk { 20 S strides[ z(N)];14 S strides[N]; 21 15 }; 22 16 … … 56 50 57 51 static inline size_t ?`len( arpk(N, S, Timmed, Tbase) & a ) { 58 return z(N);52 return N; 59 53 } 60 54 61 55 // workaround #226 (and array relevance thereof demonstrated in mike102/otype-slow-ndims.cfa) 62 56 static inline void ?{}( arpk(N, S, Timmed, Tbase) & this ) { 63 void ?{}( S (&inner)[ z(N)] ) {}57 void ?{}( S (&inner)[N] ) {} 64 58 ?{}(this.strides); 65 59 } 66 60 static inline void ^?{}( arpk(N, S, Timmed, Tbase) & this ) { 67 void ^?{}( S (&inner)[ z(N)] ) {}61 void ^?{}( S (&inner)[N] ) {} 68 62 ^?{}(this.strides); 69 63 } … … 143 137 // Base 144 138 forall( [Nq], Sq & | sized(Sq), Tbase & ) 145 static inline tag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(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 } 146 143 147 144 // Rec 148 145 forall( [Nq], Sq & | sized(Sq), [N], S & | sized(S), recq &, recr &, Tbase & | { tag(recr) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(recq) ); } ) 149 static inline tag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) {} 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 } 150 150 151 151 // Wrapper -
libcfa/src/exception.c
r5a46e09 r660665f 27 27 #include "stdhdr/assert.h" 28 28 #include "virtual.h" 29 30 #if defined( __ARM_ARCH )31 #warning FIX ME: temporary hack to keep ARM build working32 #ifndef _URC_FATAL_PHASE1_ERROR33 #define _URC_FATAL_PHASE1_ERROR 334 #endif // ! _URC_FATAL_PHASE1_ERROR35 #ifndef _URC_FATAL_PHASE2_ERROR36 #define _URC_FATAL_PHASE2_ERROR 237 #endif // ! _URC_FATAL_PHASE2_ERROR38 #endif // __ARM_ARCH39 40 29 #include "lsda.h" 41 30 … … 267 256 // the whole stack. 268 257 258 #if defined( __x86_64 ) || defined( __i386 ) 269 259 // We did not simply reach the end of the stack without finding a handler. This is an error. 270 260 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 271 266 printf("UNWIND ERROR %d after raise exception\n", ret); 272 267 abort(); … … 301 296 } 302 297 303 #if defined( __x86_64 ) || defined( __i386 ) 298 #if defined( __x86_64 ) || defined( __i386 ) || defined( __ARM_ARCH ) 304 299 // This is our personality routine. For every stack frame annotated with 305 300 // ".cfi_personality 0x3,__gcfa_personality_v0" this function will be called twice when unwinding. … … 419 414 _Unwind_GetCFA(unwind_context) + 24; 420 415 # elif defined( __ARM_ARCH ) 421 # warning FIX ME: check if anything needed for ARM 422 42; 416 _Unwind_GetCFA(unwind_context) + 40; 423 417 # endif 424 418 int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos; … … 537 531 // HEADER 538 532 ".LFECFA1:\n" 533 #if defined( __x86_64 ) || defined( __i386 ) 539 534 " .globl __gcfa_personality_v0\n" 535 #else // defined( __ARM_ARCH ) 536 " .global __gcfa_personality_v0\n" 537 #endif 540 538 " .section .gcc_except_table,\"a\",@progbits\n" 541 539 // TABLE HEADER (important field is the BODY length at the end) … … 569 567 // No clue what this does specifically 570 568 " .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 ) 571 570 " .align 8\n" 571 #else // defined( __ARM_ARCH ) 572 " .align 3\n" 573 #endif 572 574 " .type CFA.ref.__gcfa_personality_v0, @object\n" 573 575 " .size CFA.ref.__gcfa_personality_v0, 8\n" … … 575 577 #if defined( __x86_64 ) 576 578 " .quad __gcfa_personality_v0\n" 577 #el se // then __i386579 #elif defined( __i386 ) 578 580 " .long __gcfa_personality_v0\n" 581 #else // defined( __ARM_ARCH ) 582 " .xword __gcfa_personality_v0\n" 579 583 #endif 580 584 ); … … 583 587 // HEADER 584 588 ".LFECFA1:\n" 589 #if defined( __x86_64 ) || defined( __i386 ) 585 590 " .globl __gcfa_personality_v0\n" 591 #else // defined( __ARM_ARCH ) 592 " .global __gcfa_personality_v0\n" 593 #endif 586 594 " .section .gcc_except_table,\"a\",@progbits\n" 587 595 // TABLE HEADER (important field is the BODY length at the end) … … 612 620 #pragma GCC pop_options 613 621 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))625 void __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 }629 622 #else 630 623 #error unsupported hardware architecture 631 #endif // __x86_64 || __i386 624 #endif // __x86_64 || __i386 || __ARM_ARCH -
libcfa/src/interpose.cfa
r5a46e09 r660665f 95 95 96 96 extern "C" { 97 void __cfaabi_interpose_startup(void) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) ));98 97 void __cfaabi_interpose_startup( void ) { 99 98 const char *version = 0p; -
libcfa/src/startup.cfa
r5a46e09 r660665f 20 20 21 21 extern "C" { 22 23 22 void __cfaabi_appready_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_APPREADY ) )); 23 void __cfaabi_appready_startup( void ) { 24 24 tzset(); // initialize time global variables 25 25 setlocale( LC_NUMERIC, getenv("LANG") ); … … 28 28 heapAppStart(); 29 29 #endif // __CFA_DEBUG__ 30 30 } // __cfaabi_appready_startup 31 31 32 33 32 void __cfaabi_appready_shutdown( void ) __attribute__(( destructor( STARTUP_PRIORITY_APPREADY ) )); 33 void __cfaabi_appready_shutdown( void ) { 34 34 #ifdef __CFA_DEBUG__ 35 35 extern void heapAppStop(); 36 36 heapAppStop(); 37 37 #endif // __CFA_DEBUG__ 38 38 } // __cfaabi_appready_shutdown 39 39 40 void disable_interrupts() __attribute__(( weak )) {} 41 void enable_interrupts() __attribute__(( weak )) {} 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 42 58 } // extern "C" 43 59 -
src/AST/Convert.cpp
r5a46e09 r660665f 2415 2415 } 2416 2416 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 2417 2428 virtual void visit( const AsmExpr * old ) override final { 2418 2429 this->node = visitBaseExpr( old, -
src/AST/Decl.cpp
r5a46e09 r660665f 78 78 79 79 const 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 array length type" };80 static const char * kindNames[] = { "sized data type", "sized data type", "sized object type", "sized function type", "sized tuple type", "sized length value" }; 81 81 static_assert( sizeof(kindNames) / sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." ); 82 82 assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." ); -
src/AST/Decl.hpp
r5a46e09 r660665f 175 175 class TypeDecl final : public NamedTypeDecl { 176 176 public: 177 enum Kind { Dtype, DStype, Otype, Ftype, Ttype, ALtype, NUMBER_OF_KINDS };177 enum Kind { Dtype, DStype, Otype, Ftype, Ttype, Dimension, NUMBER_OF_KINDS }; 178 178 179 179 Kind kind; -
src/AST/Pass.impl.hpp
r5a46e09 r660665f 479 479 guard_symtab guard { *this }; 480 480 // 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{ 482 482 CodeLocation{}, "__func__", 483 483 new ast::ArrayType{ … … 522 522 VISIT({ 523 523 guard_symtab guard { * this }; 524 maybe_accept( node, &StructDecl::params ); 525 maybe_accept( node, &StructDecl::members ); 524 maybe_accept( node, &StructDecl::params ); 525 maybe_accept( node, &StructDecl::members ); 526 maybe_accept( node, &StructDecl::attributes ); 526 527 }) 527 528 … … 543 544 VISIT({ 544 545 guard_symtab guard { * this }; 545 maybe_accept( node, &UnionDecl::params ); 546 maybe_accept( node, &UnionDecl::members ); 546 maybe_accept( node, &UnionDecl::params ); 547 maybe_accept( node, &UnionDecl::members ); 548 maybe_accept( node, &UnionDecl::attributes ); 547 549 }) 548 550 … … 562 564 VISIT( 563 565 // unlike structs, traits, and unions, enums inject their members into the global scope 564 maybe_accept( node, &EnumDecl::params ); 565 maybe_accept( node, &EnumDecl::members ); 566 maybe_accept( node, &EnumDecl::params ); 567 maybe_accept( node, &EnumDecl::members ); 568 maybe_accept( node, &EnumDecl::attributes ); 566 569 ) 567 570 … … 577 580 VISIT({ 578 581 guard_symtab guard { *this }; 579 maybe_accept( node, &TraitDecl::params ); 580 maybe_accept( node, &TraitDecl::members ); 582 maybe_accept( node, &TraitDecl::params ); 583 maybe_accept( node, &TraitDecl::members ); 584 maybe_accept( node, &TraitDecl::attributes ); 581 585 }) 582 586 -
src/CodeGen/CodeGenerator.cc
r5a46e09 r660665f 589 589 output << nameExpr->get_name(); 590 590 } // if 591 } 592 593 void CodeGenerator::postvisit( DimensionExpr * dimensionExpr ) { 594 extension( dimensionExpr ); 595 output << "/*non-type*/" << dimensionExpr->get_name(); 591 596 } 592 597 -
src/CodeGen/CodeGenerator.h
r5a46e09 r660665f 92 92 void postvisit( TupleIndexExpr * tupleExpr ); 93 93 void postvisit( TypeExpr *typeExpr ); 94 void postvisit( DimensionExpr *dimensionExpr ); 94 95 void postvisit( AsmExpr * ); 95 96 void postvisit( StmtExpr * ); -
src/Common/PassVisitor.h
r5a46e09 r660665f 167 167 virtual void visit( TypeExpr * typeExpr ) override final; 168 168 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; 169 171 virtual void visit( AsmExpr * asmExpr ) override final; 170 172 virtual void visit( const AsmExpr * asmExpr ) override final; … … 309 311 virtual Expression * mutate( CommaExpr * commaExpr ) override final; 310 312 virtual Expression * mutate( TypeExpr * typeExpr ) override final; 313 virtual Expression * mutate( DimensionExpr * dimensionExpr ) override final; 311 314 virtual Expression * mutate( AsmExpr * asmExpr ) override final; 312 315 virtual Expression * mutate( ImplicitCopyCtorExpr * impCpCtorExpr ) override final; … … 542 545 class WithIndexer { 543 546 protected: 544 WithIndexer( ) {}547 WithIndexer( bool trackIdentifiers = true ) : indexer(trackIdentifiers) {} 545 548 ~WithIndexer() {} 546 549 -
src/Common/PassVisitor.impl.h
r5a46e09 r660665f 636 636 maybeAccept_impl( node->parameters, *this ); 637 637 maybeAccept_impl( node->members , *this ); 638 maybeAccept_impl( node->attributes, *this ); 638 639 } 639 640 … … 656 657 maybeAccept_impl( node->parameters, *this ); 657 658 maybeAccept_impl( node->members , *this ); 659 maybeAccept_impl( node->attributes, *this ); 658 660 } 659 661 … … 676 678 maybeMutate_impl( node->parameters, *this ); 677 679 maybeMutate_impl( node->members , *this ); 680 maybeMutate_impl( node->attributes, *this ); 678 681 } 679 682 … … 697 700 maybeAccept_impl( node->parameters, *this ); 698 701 maybeAccept_impl( node->members , *this ); 702 maybeAccept_impl( node->attributes, *this ); 699 703 } 700 704 … … 714 718 maybeAccept_impl( node->parameters, *this ); 715 719 maybeAccept_impl( node->members , *this ); 720 maybeAccept_impl( node->attributes, *this ); 716 721 } 717 722 … … 732 737 maybeMutate_impl( node->parameters, *this ); 733 738 maybeMutate_impl( node->members , *this ); 739 maybeMutate_impl( node->attributes, *this ); 734 740 } 735 741 … … 750 756 maybeAccept_impl( node->parameters, *this ); 751 757 maybeAccept_impl( node->members , *this ); 758 maybeAccept_impl( node->attributes, *this ); 752 759 753 760 VISIT_END( node ); … … 763 770 maybeAccept_impl( node->parameters, *this ); 764 771 maybeAccept_impl( node->members , *this ); 772 maybeAccept_impl( node->attributes, *this ); 765 773 766 774 VISIT_END( node ); … … 776 784 maybeMutate_impl( node->parameters, *this ); 777 785 maybeMutate_impl( node->members , *this ); 786 maybeMutate_impl( node->attributes, *this ); 778 787 779 788 MUTATE_END( Declaration, node ); … … 790 799 maybeAccept_impl( node->parameters, *this ); 791 800 maybeAccept_impl( node->members , *this ); 801 maybeAccept_impl( node->attributes, *this ); 792 802 } 793 803 … … 805 815 maybeAccept_impl( node->parameters, *this ); 806 816 maybeAccept_impl( node->members , *this ); 817 maybeAccept_impl( node->attributes, *this ); 807 818 } 808 819 … … 820 831 maybeMutate_impl( node->parameters, *this ); 821 832 maybeMutate_impl( node->members , *this ); 833 maybeMutate_impl( node->attributes, *this ); 822 834 } 823 835 … … 2507 2519 2508 2520 //-------------------------------------------------------------------------- 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 //-------------------------------------------------------------------------- 2509 2551 // AsmExpr 2510 2552 template< typename pass_type > … … 3145 3187 3146 3188 maybeAccept_impl( node->forall, *this ); 3147 // xxx - should PointerType visit/mutate dimension?3189 maybeAccept_impl( node->dimension, *this ); 3148 3190 maybeAccept_impl( node->base, *this ); 3149 3191 … … 3156 3198 3157 3199 maybeAccept_impl( node->forall, *this ); 3158 // xxx - should PointerType visit/mutate dimension?3200 maybeAccept_impl( node->dimension, *this ); 3159 3201 maybeAccept_impl( node->base, *this ); 3160 3202 … … 3167 3209 3168 3210 maybeMutate_impl( node->forall, *this ); 3169 // xxx - should PointerType visit/mutate dimension?3211 maybeMutate_impl( node->dimension, *this ); 3170 3212 maybeMutate_impl( node->base, *this ); 3171 3213 … … 3856 3898 3857 3899 //-------------------------------------------------------------------------- 3858 // Attribute3900 // Constant 3859 3901 template< typename pass_type > 3860 3902 void PassVisitor< pass_type >::visit( Constant * node ) { -
src/InitTweak/InitTweak.cc
r5a46e09 r660665f 10 10 // Created On : Fri May 13 11:26:36 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:15:52 201913 // Update Count : 812 // Last Modified On : Wed Jun 16 20:57:22 2021 13 // Update Count : 18 14 14 // 15 15 … … 1217 1217 void addDataSectonAttribute( ObjectDecl * objDecl ) { 1218 1218 objDecl->attributes.push_back(new Attribute("section", { 1219 new ConstantExpr( Constant::from_string(".data#") ), 1220 })); 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 ))})); 1221 1226 } 1222 1227 1223 1228 void addDataSectionAttribute( ast::ObjectDecl * objDecl ) { 1224 1229 objDecl->attributes.push_back(new ast::Attribute("section", { 1225 ast::ConstantExpr::from_string(objDecl->location, ".data#"), 1226 })); 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 )})); 1227 1237 } 1228 1238 -
src/Parser/DeclarationNode.cc
r5a46e09 r660665f 1076 1076 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) { 1077 1077 // otype is internally converted to dtype + otype parameters 1078 static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::D Stype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::Dtype};1078 static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::Dimension }; 1079 1079 static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." ); 1080 1080 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:: ALtype, 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::DStype, variable.initializer ? variable.initializer->buildType() : nullptr ); 1082 1082 buildList( variable.assertions, ret->get_assertions() ); 1083 1083 return ret; -
src/Parser/ExpressionNode.cc
r5a46e09 r660665f 509 509 } // build_varref 510 510 511 DimensionExpr * build_dimensionref( const string * name ) { 512 DimensionExpr * expr = new DimensionExpr( *name ); 513 delete name; 514 return expr; 515 } // build_varref 511 516 // TODO: get rid of this and OperKinds and reuse code from OperatorTable 512 517 static const char * OperName[] = { // must harmonize with OperKinds -
src/Parser/ParseNode.h
r5a46e09 r660665f 183 183 184 184 NameExpr * build_varref( const std::string * name ); 185 DimensionExpr * build_dimensionref( const std::string * name ); 185 186 186 187 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); -
src/Parser/TypedefTable.cc
r5a46e09 r660665f 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 15 20:56:47202113 // Update Count : 26 012 // Last Modified On : Wed May 19 08:30:14 2021 13 // Update Count : 262 14 14 // 15 15 … … 31 31 switch ( kind ) { 32 32 case IDENTIFIER: return "identifier"; 33 case TYPEDIMname: return "typedim"; 33 34 case TYPEDEFname: return "typedef"; 34 35 case TYPEGENname: return "typegen"; -
src/Parser/lex.ll
r5a46e09 r660665f 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Thu Apr 1 13:22:31202113 * Update Count : 75 412 * Last Modified On : Sun Jun 20 18:41:09 2021 13 * Update Count : 759 14 14 */ 15 15 … … 117 117 hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt} 118 118 119 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double)119 // GCC: floating D (double), imaginary iI, and decimal floating DF, DD, DL 120 120 exponent "_"?[eE]"_"?[+-]?{decimal_digits} 121 121 floating_size 16|32|32x|64|64x|80|128|128x 122 122 floating_length ([fFdDlLwWqQ]|[fF]{floating_size}) 123 123 floating_suffix ({floating_length}?[iI]?)|([iI]{floating_length}) 124 floating_suffix_opt ("_"?({floating_suffix}|"DL"))? 124 decimal_floating_suffix [dD][fFdDlL] 125 floating_suffix_opt ("_"?({floating_suffix}|{decimal_floating_suffix}))? 125 126 decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal}) 126 127 floating_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt} … … 234 235 continue { KEYWORD_RETURN(CONTINUE); } 235 236 coroutine { KEYWORD_RETURN(COROUTINE); } // CFA 237 _Decimal32 { KEYWORD_RETURN(DECIMAL32); } // GCC 238 _Decimal64 { KEYWORD_RETURN(DECIMAL64); } // GCC 239 _Decimal128 { KEYWORD_RETURN(DECIMAL128); } // GCC 236 240 default { KEYWORD_RETURN(DEFAULT); } 237 241 disable { KEYWORD_RETURN(DISABLE); } // CFA -
src/Parser/parser.yy
r5a46e09 r660665f 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Apr 26 18:41:54202113 // Update Count : 499012 // Last Modified On : Tue Jun 29 09:12:47 2021 13 // Update Count : 5027 14 14 // 15 15 … … 26 26 // The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for: 27 27 // 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. 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". 41 37 42 38 %{ … … 269 265 %token INT128 UINT128 uuFLOAT80 uuFLOAT128 // GCC 270 266 %token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC 267 %token DECIMAL32 DECIMAL64 DECIMAL128 // GCC 271 268 %token ZERO_T ONE_T // CFA 272 269 %token SIZEOF TYPEOF VALIST AUTO_TYPE // GCC … … 287 284 288 285 // names and constants: lexer differentiates between identifier and typedef names 289 %token<tok> IDENTIFIER QUOTED_IDENTIFIER TYPED EFname TYPEGENname286 %token<tok> IDENTIFIER QUOTED_IDENTIFIER TYPEDIMname TYPEDEFname TYPEGENname 290 287 %token<tok> TIMEOUT WOR CATCH RECOVER CATCHRESUME FIXUP FINALLY // CFA 291 288 %token<tok> INTEGERconstant CHARACTERconstant STRINGliteral … … 586 583 | quasi_keyword 587 584 { $$ = 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 ) ); } 588 589 | tuple 589 590 | '(' comma_expression ')' … … 630 631 postfix_expression: 631 632 primary_expression 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; } 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 ) ) )) ) ); } 635 639 | postfix_expression '[' assignment_expression ']' 636 640 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a … … 1887 1891 | uFLOAT128 1888 1892 { $$ = 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; } 1889 1899 | COMPLEX // C99 1890 1900 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); } … … 1909 1919 // empty 1910 1920 { $$ = nullptr; } 1911 | vtable ;1921 | vtable 1912 1922 ; 1913 1923 … … 2535 2545 | '[' identifier_or_type_name ']' 2536 2546 { 2537 typedefTable.addToScope( *$2, TYPED EFname, "9" );2538 $$ = DeclarationNode::newTypeParam( TypeDecl:: ALtype, $2 );2547 typedefTable.addToScope( *$2, TYPEDIMname, "9" ); 2548 $$ = DeclarationNode::newTypeParam( TypeDecl::Dimension, $2 ); 2539 2549 } 2540 2550 // | type_specifier identifier_parameter_declarator … … 2550 2560 | '*' 2551 2561 { $$ = TypeDecl::DStype; } // dtype + sized 2562 // | '(' '*' ')' 2563 // { $$ = TypeDecl::Ftype; } 2552 2564 | ELLIPSIS 2553 2565 { $$ = TypeDecl::Ttype; } … … 2590 2602 { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); } 2591 2603 | assignment_expression 2592 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }2593 2604 | type_list ',' type 2594 2605 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); } 2595 2606 | type_list ',' assignment_expression 2596 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } 2597 // { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2607 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2598 2608 ; 2599 2609 -
src/SymTab/Indexer.cc
r5a46e09 r660665f 74 74 } 75 75 76 Indexer::Indexer( )76 Indexer::Indexer( bool trackIdentifiers ) 77 77 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 78 prevScope(), scope( 0 ), repScope( 0 ) { ++* stats().count; }78 prevScope(), scope( 0 ), repScope( 0 ), trackIdentifiers( trackIdentifiers ) { ++* stats().count; } 79 79 80 80 Indexer::~Indexer() { … … 110 110 111 111 void Indexer::lookupId( const std::string & id, std::list< IdData > &out ) const { 112 assert( trackIdentifiers ); 113 112 114 ++* stats().lookup_calls; 113 115 if ( ! idTable ) return; … … 434 436 const Declaration * deleteStmt ) { 435 437 ++* stats().add_calls; 438 if ( ! trackIdentifiers ) return; 436 439 const std::string &name = decl->name; 437 440 if ( name == "" ) return; -
src/SymTab/Indexer.h
r5a46e09 r660665f 31 31 class Indexer : public std::enable_shared_from_this<SymTab::Indexer> { 32 32 public: 33 explicit Indexer( );33 explicit Indexer( bool trackIdentifiers = true ); 34 34 virtual ~Indexer(); 35 35 … … 180 180 /// returns true if there exists a declaration with C linkage and the given name with a different mangled name 181 181 bool hasIncompatibleCDecl( const std::string & id, const std::string & mangleName ) const; 182 183 bool trackIdentifiers; 182 184 }; 183 185 } // namespace SymTab -
src/SymTab/Validate.cc
r5a46e09 r660665f 105 105 106 106 struct FixQualifiedTypes final : public WithIndexer { 107 FixQualifiedTypes() : WithIndexer(false) {} 107 108 Type * postmutate( QualifiedType * ); 108 109 }; … … 174 175 }; 175 176 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(