Changes in / [660665f:5a46e09]
- Files:
-
- 1 added
- 25 deleted
- 84 edited
-
INSTALL (modified) (1 diff)
-
Jenkins/Distribute (modified) (2 diffs)
-
Jenkins/FullBuild (modified) (4 diffs)
-
Jenkins/Promote (deleted)
-
Jenkins/tools.groovy (modified) (3 diffs)
-
Jenkinsfile (modified) (5 diffs)
-
README (modified) (3 diffs)
-
benchmark/io/io_uring.h (modified) (1 diff)
-
doc/bibliography/pl.bib (modified) (2 diffs)
-
doc/theses/andrew_beach_MMath/cfalab.sty (modified) (1 diff)
-
doc/theses/andrew_beach_MMath/existing.tex (modified) (8 diffs)
-
doc/theses/andrew_beach_MMath/features.tex (modified) (38 diffs)
-
doc/theses/andrew_beach_MMath/future.tex (modified) (7 diffs)
-
doc/theses/andrew_beach_MMath/implement.tex (modified) (35 diffs)
-
doc/theses/andrew_beach_MMath/intro.tex (modified) (6 diffs)
-
doc/theses/andrew_beach_MMath/performance.tex (deleted)
-
doc/theses/andrew_beach_MMath/uw-ethesis.tex (modified) (1 diff)
-
doc/theses/mubeen_zulfiqar_MMath/.gitignore (modified) (1 diff)
-
doc/theses/mubeen_zulfiqar_MMath/allocator.tex (modified) (3 diffs)
-
doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex (modified) (1 diff)
-
doc/theses/mubeen_zulfiqar_MMath/uw-ethesis.tex (modified) (1 diff)
-
libcfa/configure.ac (modified) (1 diff)
-
libcfa/prelude/defines.hfa.in (modified) (2 diffs)
-
libcfa/src/Makefile.am (modified) (4 diffs)
-
libcfa/src/bits/signal.hfa (modified) (1 diff)
-
libcfa/src/concurrency/coroutine.cfa (modified) (1 diff)
-
libcfa/src/concurrency/io.cfa (modified) (2 diffs)
-
libcfa/src/concurrency/io/setup.cfa (modified) (1 diff)
-
libcfa/src/concurrency/kernel.cfa (modified) (5 diffs)
-
libcfa/src/concurrency/kernel.hfa (modified) (1 diff)
-
libcfa/src/concurrency/kernel/startup.cfa (modified) (4 diffs)
-
libcfa/src/concurrency/kernel_private.hfa (modified) (4 diffs)
-
libcfa/src/concurrency/locks.cfa (modified) (1 diff)
-
libcfa/src/concurrency/locks.hfa (modified) (4 diffs)
-
libcfa/src/concurrency/monitor.cfa (modified) (1 diff)
-
libcfa/src/concurrency/mutex.cfa (modified) (1 diff)
-
libcfa/src/concurrency/preemption.cfa (modified) (1 diff)
-
libcfa/src/concurrency/ready_queue.cfa (modified) (11 diffs)
-
libcfa/src/concurrency/ready_subqueue.hfa (modified) (9 diffs)
-
libcfa/src/concurrency/thread.cfa (modified) (2 diffs)
-
libcfa/src/containers/array.hfa (modified) (4 diffs)
-
libcfa/src/containers/vector2.hfa (deleted)
-
libcfa/src/device/cpu.cfa (deleted)
-
libcfa/src/device/cpu.hfa (deleted)
-
libcfa/src/exception.c (modified) (9 diffs)
-
libcfa/src/interpose.cfa (modified) (1 diff)
-
libcfa/src/startup.cfa (modified) (2 diffs)
-
libcfa/src/stdhdr/pthread.h (deleted)
-
src/AST/Convert.cpp (modified) (1 diff)
-
src/AST/Decl.cpp (modified) (1 diff)
-
src/AST/Decl.hpp (modified) (1 diff)
-
src/AST/Pass.impl.hpp (modified) (5 diffs)
-
src/CodeGen/CodeGenerator.cc (modified) (1 diff)
-
src/CodeGen/CodeGenerator.h (modified) (1 diff)
-
src/Common/PassVisitor.h (modified) (3 diffs)
-
src/Common/PassVisitor.impl.h (modified) (17 diffs)
-
src/InitTweak/InitTweak.cc (modified) (2 diffs)
-
src/Parser/DeclarationNode.cc (modified) (1 diff)
-
src/Parser/ExpressionNode.cc (modified) (1 diff)
-
src/Parser/ParseNode.h (modified) (1 diff)
-
src/Parser/TypedefTable.cc (modified) (2 diffs)
-
src/Parser/lex.ll (modified) (3 diffs)
-
src/Parser/parser.yy (modified) (11 diffs)
-
src/SymTab/Indexer.cc (modified) (3 diffs)
-
src/SymTab/Indexer.h (modified) (2 diffs)
-
src/SymTab/Validate.cc (modified) (15 diffs)
-
src/SynTree/Declaration.h (modified) (1 diff)
-
src/SynTree/Expression.h (modified) (1 diff)
-
src/SynTree/Mutator.h (modified) (1 diff)
-
src/SynTree/SynTree.h (modified) (1 diff)
-
src/SynTree/TypeDecl.cc (modified) (1 diff)
-
src/SynTree/TypeExpr.cc (modified) (1 diff)
-
src/SynTree/Visitor.h (modified) (1 diff)
-
tests/.expect/forall.txt (modified) (1 diff)
-
tests/.expect/gmp.arm64.txt (deleted)
-
tests/.expect/typedefRedef-ERR1.txt (modified) (1 diff)
-
tests/.expect/typedefRedef.txt (modified) (1 diff)
-
tests/array-container/.expect/array-md-sbscr-cases.arm64.txt (deleted)
-
tests/array-container/.expect/array-md-sbscr-cases.x86.txt (deleted)
-
tests/array-container/.expect/language-dim-mismatch.txt (deleted)
-
tests/array-container/array-basic.cfa (modified) (7 diffs)
-
tests/array-container/array-md-sbscr-cases.cfa (modified) (12 diffs)
-
tests/array-container/language-dim-mismatch.cfa (deleted)
-
tests/collections/.expect/vector-demo.txt (deleted)
-
tests/collections/.expect/vector-err-pass-perm-it-byval.txt (deleted)
-
tests/collections/.expect/vector-err-retn-perm-it-byval.txt (deleted)
-
tests/collections/vector-demo.cfa (deleted)
-
tests/collections/vector-err-mod-with-excl-it.cfa (deleted)
-
tests/collections/vector-err-pass-perm-it-byval.cfa (deleted)
-
tests/collections/vector-err-retn-perm-it-byval.cfa (deleted)
-
tests/concurrent/signal/disjoint.cfa (modified) (2 diffs)
-
tests/coroutine/fibonacci.cfa (modified) (1 diff)
-
tests/device/.expect/cpu.txt (deleted)
-
tests/device/cpu.cfa (deleted)
-
tests/forall.cfa (modified) (1 diff)
-
tests/generator/fibonacci.cfa (modified) (3 diffs)
-
tests/generator/fmtLines.cfa (modified) (1 diff)
-
tests/generator/suspend_then.cfa (modified) (1 diff)
-
tests/literals.cfa (modified) (2 diffs)
-
tests/math.cfa (modified) (6 diffs)
-
tests/pybin/tools.py (modified) (1 diff)
-
tests/test.py (modified) (1 diff)
-
tests/typedefRedef.cfa (modified) (1 diff)
-
tests/unified_locking/fast.cfa (modified) (2 diffs)
-
tests/vector_math/.expect/vec2_ldouble.arm64.txt (deleted)
-
tests/vector_math/.expect/vec2_ldouble.txt (added)
-
tests/vector_math/.expect/vec2_ldouble.x64.txt (deleted)
-
tests/vector_math/.expect/vec2_ldouble.x86.txt (deleted)
-
tests/zombies/vector-perf/iteration-perf.cfa (deleted)
-
tests/zombies/vector-perf/iteration-perf.cpp (deleted)
Legend:
- Unmodified
- Added
- Removed
-
INSTALL
r660665f r5a46e09 1 cfa-cc: Cforall to C Trans-compiler1 cfa-cc: The Cforall->C Compiler System 2 2 ====================================== 3 3 4 4 Cforall is built using GNU Make and the GNU Autoconf system. It also requires 5 g++ version >= 6, bison and flex. On systems where GNU Make is the default5 g++ version >= 4.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 elopers using the root git:8 For devs using the root git: 9 9 10 $ ./autogen.sh 11 $ ./configure [ --prefix=/some/directory ] 12 $ make -j 8 install 10 ./autogen.sh 11 ./configure 12 make 13 make install 13 14 14 For users using the distributed tarball / github:15 For users using the distributed tarball: 15 16 16 $ ./configure 17 $ make -j 8 install 17 ./configure 18 make 19 make install 18 20 19 where 8 is the number of CPUs on your computer. 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. 20 26 21 22 Options for configure 23 ====================================== 24 The script 'configure' accepts many command-line arguments. Run 25 26 $ ./configure --help 27 28 to list them. The most common argument is: 29 30 --prefix=/some/directory controls the path prefix common to all installed 31 cfa-cc components. Components are installed in directories bin and lib. 32 If unspecified, prefix defaults to /usr/local. To use (a subdirectory of) 33 your home directory, ${HOME}/some/dir, but do not put quotes around the 34 directory path; Cforall may appear to build, but the installed version may 35 not work properly. 36 37 38 Build Test 39 ====================================== 40 41 $ cd ./test 42 $ make -j 8 all-tests 43 44 The tests take about 2-5 minutes and can be stopped at any time. 27 --prefix=/some/directory controls the path prefix common to all installed 28 cfa-cc components. Some components are installed in /some/directory/bin, 29 others in /some/directory/lib. If unspecified, this defaults to /usr/local. 30 To use (a subdirectory of) your home directory, ${HOME}/some/dir works, but 31 it is important not to put quotes around the directory path; Cforall may 32 appear to build, but the installed version may not work properly. -
Jenkins/Distribute
r660665f r5a46e09 2 2 3 3 import groovy.transform.Field 4 5 // For skipping stages 6 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils 4 7 5 8 //=========================================================================================================== … … 7 10 //=========================================================================================================== 8 11 9 // Globals 10 BuildDir = null 11 SrcDir = null 12 Settings = null 13 Version = '' 12 node('master') { 13 // Globals 14 BuildDir = pwd tmp: true 15 SrcDir = pwd tmp: false 16 Settings = null 17 Version = '' 14 18 15 // Local variables16 def err = null17 def log_needed = false19 // Local variables 20 def err = null 21 def log_needed = false 18 22 19 currentBuild.result = "SUCCESS" 20 21 final commit, build 22 node { 23 currentBuild.result = "SUCCESS" 23 24 24 25 //Wrap build to add timestamp to command line 25 26 wrap([$class: 'TimestamperBuildWrapper']) { 27 28 final commit, build 26 29 (commit, build) = prepare_build() 27 }28 }29 30 30 node('x64') { 31 //Wrap build to add timestamp to command line 32 wrap([$class: 'TimestamperBuildWrapper']) { 31 node('x64') { 32 BuildDir = pwd tmp: true 33 SrcDir = pwd tmp: false 34 35 Tools.Clean() 36 37 Tools.Checkout( commit ) 38 39 Version = GetVersion( build ) 40 41 Configure() 42 43 Package() 44 45 Test() 46 47 Archive() 48 } 49 50 // Update the build directories when exiting the node 33 51 BuildDir = pwd tmp: true 34 52 SrcDir = pwd tmp: false 53 } 35 54 36 Tools.Clean()37 38 Tools.Checkout( commit )39 40 Version = GetVersion( build )41 42 Configure()43 44 Package()45 46 Test()47 48 Archive()49 }50 55 } 51 56 -
Jenkins/FullBuild
r660665f r5a46e09 5 5 //=========================================================================================================== 6 6 7 node {7 node ('master') { 8 8 def err = null 9 9 … … 18 18 19 19 parallel ( 20 gcc_ 08_x86_new: { trigger_build( 'gcc-8', 'x86' ) },21 gcc_ 07_x86_new: { trigger_build( 'gcc-7', 'x86' ) },22 gcc_ 06_x86_new: { trigger_build( 'gcc-6', 'x86' ) },23 gcc_ 10_x64_new: { trigger_build( 'gcc-10','x64' ) },24 gcc_ 09_x64_new: { trigger_build( 'gcc-9', 'x64' ) },25 gcc_ 08_x64_new: { trigger_build( 'gcc-8', 'x64' ) },26 gcc_ 07_x64_new: { trigger_build( 'gcc-7', 'x64' ) },27 gcc_ 06_x64_new: { trigger_build( 'gcc-6', 'x64' ) },28 clang_x64_new: { trigger_build( 'clang', 'x64' ) },20 gcc_8_x86_new: { trigger_build( 'gcc-8', 'x86' ) }, 21 gcc_7_x86_new: { trigger_build( 'gcc-7', 'x86' ) }, 22 gcc_6_x86_new: { trigger_build( 'gcc-6', 'x86' ) }, 23 gcc_9_x64_new: { trigger_build( 'gcc-9', 'x64' ) }, 24 gcc_8_x64_new: { trigger_build( 'gcc-8', 'x64' ) }, 25 gcc_7_x64_new: { trigger_build( 'gcc-7', 'x64' ) }, 26 gcc_6_x64_new: { trigger_build( 'gcc-6', 'x64' ) }, 27 gcc_5_x64_new: { trigger_build( 'gcc-5', 'x64' ) }, 28 clang_x64_new: { trigger_build( 'clang', 'x64' ) }, 29 29 ) 30 30 } … … 106 106 107 107 if(result.result != 'SUCCESS') { 108 sh("wget -q -O - http s://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/${result.number}/consoleText")108 sh("wget -q -O - http://localhost:8084/jenkins/job/Cforall/job/master/${result.number}/consoleText") 109 109 error(result.result) 110 110 } … … 144 144 //Email notification on a full build failure 145 145 def promote_email(boolean success) { 146 node { 147 echo('notifying users') 146 echo('notifying users') 148 147 149 def result = success ? "PROMOTE - SUCCESS" : "PROMOTE - FAILURE"148 def result = success ? "PROMOTE - SUCCESS" : "PROMOTE - FAILURE" 150 149 151 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line152 //Configurations for email format153 def email_subject = "[cforall git][${result}]"154 def email_body = """<p>This is an automated email from the Jenkins build machine. It was155 generated following the result of the C\u2200 nightly build.</p>150 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line 151 //Configurations for email format 152 def email_subject = "[cforall git][${result}]" 153 def email_body = """<p>This is an automated email from the Jenkins build machine. It was 154 generated following the result of the C\u2200 nightly build.</p> 156 155 157 <p>Check console output at ${env.BUILD_URL} to view the results.</p>156 <p>Check console output at ${env.BUILD_URL} to view the results.</p> 158 157 159 <p>- Status --------------------------------------------------------------</p>158 <p>- Status --------------------------------------------------------------</p> 160 159 161 <p>${result}</p>160 <p>${result}</p> 162 161 163 <p>- Performance ---------------------------------------------------------</p>162 <p>- Performance ---------------------------------------------------------</p> 164 163 165 <img src="https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/plot/Compilation/getPlot?index=0" >166 <img src="https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/plot/Compilation/getPlot?index=1" >164 <img src="https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/plot/Compilation/getPlot?index=0" > 165 <img src="https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/plot/Compilation/getPlot?index=1" > 167 166 168 <p>- Logs ----------------------------------------------------------------</p>169 """167 <p>- Logs ----------------------------------------------------------------</p> 168 """ 170 169 171 def email_to = "cforall@lists.uwaterloo.ca"170 def email_to = "cforall@lists.uwaterloo.ca" 172 171 173 //send email notification 174 emailext body: email_body, subject: email_subject, to: email_to, attachLog: !success 175 } 172 //send email notification 173 emailext body: email_body, subject: email_subject, to: email_to, attachLog: !success 176 174 } -
Jenkins/tools.groovy
r660665f r5a46e09 61 61 } 62 62 63 def ConstructGitLogMessage(String oldRef, String newRef) { 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 64 69 def revText = sh(returnStdout: true, script: "git rev-list ${oldRef}..${newRef}").trim() 65 70 def revList = SplitLines( revText ) … … 82 87 gitDiff = gitDiff.replace('[m', '</span>') 83 88 89 PrevGitOldRef = oldRef 90 PrevGitNewRef = newRef 91 84 92 return """ 85 <p>- Changes -------------------------------------------------------------</p>86 87 93 <pre> 88 94 The branch ${env.BRANCH_NAME} has been updated. 89 95 ${gitUpdate} 90 96 </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> 91 103 92 104 <p>- Log -----------------------------------------------------------------</p> … … 104 116 } 105 117 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 122 118 return this; -
Jenkinsfile
r660665f r5a46e09 7 7 //=========================================================================================================== 8 8 9 // Globals 10 BuildDir = null 11 SrcDir = null 12 Settings = null 13 Tools= null14 15 // Local variables 16 def err = null 17 def log_needed = false 18 19 currentBuild.result = "SUCCESS" 20 21 try { 22 node{9 node('master') { 10 // Globals 11 BuildDir = pwd tmp: true 12 SrcDir = pwd tmp: false 13 Settings = null 14 Tools = null 15 16 // Local variables 17 def err = null 18 def log_needed = false 19 20 currentBuild.result = "SUCCESS" 21 22 try { 23 23 //Wrap build to add timestamp to command line 24 24 wrap([$class: 'TimestamperBuildWrapper']) { 25 25 26 Settings = prepare_build() 26 } 27 } 28 29 node(Settings.Architecture.node) { 30 //Wrap build to add timestamp to command line 31 wrap([$class: 'TimestamperBuildWrapper']) { 27 28 node(Settings.Architecture.node) { 29 BuildDir = pwd tmp: true 30 SrcDir = pwd tmp: false 31 currentBuild.description = "${currentBuild.description} on ${env.NODE_NAME}" 32 33 Tools.Clean() 34 35 Tools.Checkout() 36 37 build() 38 39 test() 40 41 benchmark() 42 43 build_doc() 44 45 publish() 46 } 47 48 // Update the build directories when exiting the node 32 49 BuildDir = pwd tmp: true 33 50 SrcDir = pwd tmp: false 34 currentBuild.description = "${currentBuild.description} on ${env.NODE_NAME}" 35 36 Tools.Clean() 37 38 Tools.Checkout() 39 40 build() 41 42 test() 43 44 benchmark() 45 46 build_doc() 47 48 publish() 49 } 50 } 51 } 52 53 //If an exception is caught we need to change the status and remember to 54 //attach the build log to the email 55 catch (Exception caughtError) { 56 // Store the result of the build log 57 currentBuild.result = "FAILURE" 58 59 // An error has occured, the build log is relevent 60 log_needed = true 61 62 // rethrow error later 63 err = caughtError 64 65 // print the error so it shows in the log 66 echo err.toString() 67 } 68 69 finally { 70 //Send email with final results if this is not a full build 71 email(log_needed) 72 73 echo 'Build Completed' 74 75 /* Must re-throw exception to propagate error */ 76 if (err) { 77 throw err 51 } 52 } 53 54 //If an exception is caught we need to change the status and remember to 55 //attach the build log to the email 56 catch (Exception caughtError) { 57 // Store the result of the build log 58 currentBuild.result = "FAILURE" 59 60 // An error has occured, the build log is relevent 61 log_needed = true 62 63 // rethrow error later 64 err = caughtError 65 66 // print the error so it shows in the log 67 echo err.toString() 68 } 69 70 finally { 71 //Send email with final results if this is not a full build 72 email(log_needed) 73 74 echo 'Build Completed' 75 76 /* Must re-throw exception to propagate error */ 77 if (err) { 78 throw err 79 } 78 80 } 79 81 } … … 226 228 //Standard build email notification 227 229 def email(boolean log) { 228 node { 229 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line 230 //Configurations for email format 231 echo 'Notifying users of result' 232 233 def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase() 234 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}] - branch ${env.BRANCH_NAME}" 235 def email_body = """<p>This is an automated email from the Jenkins build machine. It was 230 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line 231 //Configurations for email format 232 echo 'Notifying users of result' 233 234 def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase() 235 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}] - branch ${env.BRANCH_NAME}" 236 def email_body = """<p>This is an automated email from the Jenkins build machine. It was 236 237 generated because of a git hooks/post-receive script following 237 238 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>243 239 """ + Tools.GitLogMessage() 244 240 245 def email_to = !Settings.IsSandbox ? "cforall@lists.uwaterloo.ca" : "tdelisle@uwaterloo.ca" 246 247 if( Settings && !Settings.Silent ) { 248 //send email notification 249 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log 250 } else { 251 echo "Would send email to: ${email_to}" 252 echo "With title: ${email_subject}" 253 echo "Content: \n${email_body}" 254 } 241 def email_to = !Settings.IsSandbox ? "cforall@lists.uwaterloo.ca" : "tdelisle@uwaterloo.ca" 242 243 if( Settings && !Settings.Silent ) { 244 //send email notification 245 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log 246 } else { 247 echo "Would send email to: ${email_to}" 248 echo "With title: ${email_subject}" 249 echo "Content: \n${email_body}" 255 250 } 256 251 } … … 305 300 BuildSettings(java.util.Collections$UnmodifiableMap param, String branch) { 306 301 switch( param.Compiler ) { 307 case 'gcc-11':308 this.Compiler = new CC_Desc('gcc-11', 'g++-11', 'gcc-11', '-flto=auto')309 break310 case 'gcc-10':311 this.Compiler = new CC_Desc('gcc-10', 'g++-10', 'gcc-10', '-flto=auto')312 break313 302 case 'gcc-9': 314 303 this.Compiler = new CC_Desc('gcc-9', 'g++-9', 'gcc-9', '-flto=auto') … … 330 319 break 331 320 case 'clang': 332 this.Compiler = new CC_Desc('clang', 'clang++-10', 'gcc- 10', '-flto=thin -flto-jobs=0')321 this.Compiler = new CC_Desc('clang', 'clang++-10', 'gcc-9', '-flto=thin -flto-jobs=0') 333 322 break 334 323 default : … … 401 390 description: 'Which compiler to use', \ 402 391 name: 'Compiler', \ 403 choices: 'gcc- 11\ngcc-10\ngcc-9\ngcc-8\ngcc-7\ngcc-6\ngcc-5\ngcc-4.9\nclang', \392 choices: 'gcc-9\ngcc-8\ngcc-7\ngcc-6\ngcc-5\ngcc-4.9\nclang', \ 404 393 defaultValue: 'gcc-8', \ 405 394 ], \ -
README
r660665f r5a46e09 1 cfa-cc: Cforall to C Trans-compiler1 cfa-cc: The Cforall->C Compiler System 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 9 8 10 9 What is Cforall? … … 26 25 into a modern programming language. 27 26 28 29 27 What is cfa-cc? 30 28 --------------- 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.29 cfa-cc is a collection of programs centred around a translator that takes 30 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. 36 34 37 cfa-cc is currently written in C++, but will be eventually rewritten in Cforall. 35 What is required in order to use cfa-cc? 36 ---------------------------------------- 37 Building cfa-cc requires GNU Make and gcc/g++ 4. cfa-cc is written in C++. 38 38 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. 39 42 40 How to download and build cfa-cc? 41 ---------------------------------------- 42 Download cfa-cc using 43 44 $ git clone https://github.com/cforall/cforall.git 45 46 Read the ./INSTALL file for build instructions. 47 48 49 How to use cfa-cc? 43 How is cfa-cc used? 50 44 ------------------- 51 The compiler driver "cfa" accepts all of the arguments forgcc, and is used in45 The compiler driver "cfa" accepts all of the arguments of gcc, and is used in 52 46 the same way. For example: 53 47 54 cfa -c test.c55 cfa test.o48 cfa -c test.c 49 cfa test.o 56 50 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. 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. 61 54 55 It is possible to invoke the translator directly. The translator is installed 56 by default as /usr/local/lib/cfa-cpp. A typical invocation is: 62 57 63 How to use C code with cfa-cc? 58 /usr/local/lib/cfa-cpp -cp infile outfile 59 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. 64 65 How can C code be used with cfa-cc? 64 66 ----------------------------------- 65 cfa-cc should be able to compile and link most ANSI C programs with associated 66 C standard libraries. 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: 67 74 68 Like C++, Cforall supports overloading, resulting in duplicate names that are 69 disambiguated using name mangling in the translated C code. To prevent 70 mangling of C names, it is necessary to wrap C declarations in an extern "C" 71 block, as for C++. For example: 72 73 extern "C" { 74 #include <curses.h> 75 #include <getopt.h> 76 } 75 extern "C" { 76 #include <stdio.h> 77 #include <stdlib.h> 78 } 77 79 78 80 The extern "C" turns off name mangling for functions and objects declared 79 within the block. All C standard headers are pre-wrapped, so most wrapping is 80 unnecessary. 81 81 within the block. As a result, it is not possible to overload their names. 82 82 83 83 What's wrong with cfa-cc? 84 84 ------------------------- 85 85 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. 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. 91 90 92 Also, the Cforall features web-page https://cforall.uwaterloo.ca/features lists 93 small syntactic and semantic differences with standard C. 91 We have fixed most of the problems that we are aware of. There are some 92 exceptions: 94 93 94 - initializers are poorly implemented; in particular, file-scope initializers 95 may result in the generation of invalid C code 96 97 - the ISO C99 designated initialization syntax '[n] = m' or '.n = m' is not 98 supported; use a colon in place of the equal sign 99 100 - some legitimate programs will produce warnings from the C compiler; these are 101 harmless (in particular, the creation of libcfa.a in the build process should 102 cause four warnings from gcc) 103 104 - abstract types introduced using the keyword 'type' are not implemented 105 (although 'type' can be used to introduce type parameters) 106 107 - the implicit coercion of structure types to the type of their first member is 108 not implemented 95 109 96 110 Who is responsible for cfa-cc? 97 111 ------------------------------ 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. 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. 101 114 102 Check the Cforall web site https://cforall.uwaterloo.ca for news and updates. 115 The Cforall project maintains a web page: 116 117 https://cforall.uwaterloo.ca -
benchmark/io/io_uring.h
r660665f r5a46e09 1 1 extern "C" { 2 #ifndef _GNU_SOURCE /* See feature_test_macros(7) */ 3 #define _GNU_SOURCE /* See feature_test_macros(7) */ 4 #endif 2 5 #include <errno.h> 3 6 #include <stdio.h> -
doc/bibliography/pl.bib
r660665f r5a46e09 1673 1673 address = {Waterloo Ontario, Canada}, 1674 1674 month = sep, 1675 year = 20 20,1675 year = 2018, 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}{https://\-git.uwaterloo.ca/\-mkarsten/\-libfibre}}, 4554 howpublished= {\href{https://git.uwaterloo.ca/mkarsten/libfibre} 4555 {https://\-git.uwaterloo.ca/\-mkarsten/\-libfibre}}, 4555 4556 note = {[Online; accessed 2020-04-15]}, 4556 4557 } -
doc/theses/andrew_beach_MMath/cfalab.sty
r660665f r5a46e09 143 143 } 144 144 145 % These somehow control how much of a page can be a floating element before146 % 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 can151 % be on a page before its all removed. (0 for always fix what you can.)152 \renewcommand{\textfraction}{0.0}153 154 145 % common.tex Compatablity =================================================== 155 146 % Below this line is for compatability with the old common.tex file. -
doc/theses/andrew_beach_MMath/existing.tex
r660665f r5a46e09 1 \chapter{\CFA {}Existing Features}1 \chapter{\CFA Existing Features} 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. 12 Also, only new features of \CFA will be discussed, a familiarity with 13 C or C-like languages is assumed.11 Only those \CFA features pertaining to this thesis are discussed. Many of the 12 \CFA syntactic and semantic features used in the thesis should be fairly 13 obvious to the reader. 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. 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. 49 this includes cv-qualifiers and multiple levels of reference, \eg: 50 57 51 \begin{minipage}{0,5\textwidth} 58 52 With references: … … 62 56 int && rri = ri; 63 57 rri = 3; 64 &ri = &j; 58 &ri = &j; // reference assignment 65 59 ri = 5; 66 60 \end{cfa} … … 73 67 int ** ppi = π 74 68 **ppi = 3; 75 pi = &j; 69 pi = &j; // pointer assignment 76 70 *pi = 5; 77 71 \end{cfa} 78 72 \end{minipage} 79 73 80 References are intended to be used when you woulduse pointers but would74 References are intended for cases where you would want to use pointers but would 81 75 be dereferencing them (almost) every usage. 82 Mutable references may be assigned to by converting them to a pointer 83 with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above 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. 84 83 85 84 \section{Operators} 86 85 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, 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, 92 88 infixed multiplication is @?*?@ while prefix dereference is @*?@. 93 89 This syntax make it easy to tell the difference between prefix operations 94 90 (such as @++?@) and post-fix operations (@?++@). 95 91 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} 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. 110 101 111 102 Both constructors and destructors are operators, which means they are 112 103 functions with special operator names rather than type names in \Cpp. The 113 special operator names may be used to call the functions explicitly. 114 % Placement new means that this is actually equivant to C++. 115 116 The special name for a constructor is @?{}@, which comes from the 117 initialization syntax in C, \eg @Example e = { ... }@. 118 \CFA will generate a constructor call each time a variable is declared, 119 passing the initialization arguments to the constructort. 120 \begin{cfa} 121 struct Example { ... }; 122 void ?{}(Example & this) { ... } 123 { 124 Example a; 125 Example b = {}; 126 } 127 void ?{}(Example & this, char first, int num) { ... } 128 { 129 Example c = {'a', 2}; 130 } 131 \end{cfa} 132 Both @a@ and @b@ will be initalized with the first constructor, 133 while @c@ will be initalized with the second. 134 Currently, there is no general way to skip initialation. 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. 135 127 136 128 % I don't like the \^{} symbol but $^\wedge$ isn't better. 137 Similarly destructors use the special name @^?{}@ (the @^@ has no special 138 meaning). 139 These are a normally called implicitly called on a variable when it goes out 140 of scope. They can be called explicitly as well. 141 \begin{cfa} 142 void ^?{}(Example & this) { ... } 143 { 144 Example d; 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; 145 136 } // <- implicit destructor call 146 137 \end{cfa} 147 138 148 Whenever a type is defined, \CFA will createa default zero-argument139 Whenever a type is defined, \CFA creates a default zero-argument 149 140 constructor, a copy constructor, a series of argument-per-field constructors 150 141 and a destructor. All user constructors are defined after this. … … 207 198 void do_once(double y) { ... } 208 199 int quadruple(int x) { 209 void do_once(int & y) { y = y * 2; } 210 do_twice(x); 200 void do_once(int y) { y = y * 2; } // replace global do_once 201 do_twice(x); // use local do_once 202 do_twice(x + 1.5); // use global do_once 211 203 return x; 212 204 } 213 205 \end{cfa} 214 206 Specifically, the complier deduces that @do_twice@'s T is an integer from the 215 argument @x@. It then looks for the most specificdefinition matching the207 argument @x@. It then looks for the most \emph{specific} definition matching the 216 208 assertion, which is the nested integral @do_once@ defined within the 217 209 function. The matched assertion function is then passed as a function pointer 218 to @do_twice@ and called within it. 219 The global definition of @do_once@ is ignored, however if quadruple took a 220 @double@ argument then the global definition would be used instead as it 221 would be a better match. 222 % Aaron's thesis might be a good reference here. 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. 223 212 224 213 To avoid typing long lists of assertions, constraints can be collect into … … 290 279 Each coroutine has a @main@ function, which takes a reference to a coroutine 291 280 object and returns @void@. 292 %[numbers=left] Why numbers on this one? 293 \begin{cfa} 281 \begin{cfa}[numbers=left] 294 282 void main(CountUp & this) { 295 283 for (unsigned int next = 0 ; true ; ++next) { -
doc/theses/andrew_beach_MMath/features.tex
r660665f r5a46e09 2 2 \label{c:features} 3 3 4 This chapter covers the design and user interface of the \CFA EHM 4 This chapter covers the design and user interface of the \CFA 5 EHM, % or exception system. 5 6 and begins with a general overview of EHMs. It is not a strict 6 7 definition of all EHMs nor an exhaustive list of all possible features. 7 However it does cover the most common structure and features found in them. 8 9 \section{Overview of EHMs} 8 However it does cover the most common structures and features found in them. 9 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 ubsection{Raise / Handle}13 \section{Raise / Handle} 14 14 An exception operation has two main parts: raise and handle. 15 These terms are sometimes known as throw and catch but this work uses15 These terms are sometimes also 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. In real systems araise may27 p reform some other work (such as memory management) but for the26 the \code{Python}{raise} statement from Python. A raise may 27 perform 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 If multiple handlers could can handle an exception,40 EHMs will define a rule to pick one, such as ``best match" or ``first found".39 Different EHMs have different rules to pick a handler, 40 if multiple handlers could be used, 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 ubsection{Propagation}46 \section{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 e search includes handlers in the current function, as well as any in58 callerson the stack that have the function call in their guarded region.57 This search includes handlers in the current function, as well as any in callers 58 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 exception and decidesif62 label defines a condition that is used with the exception to decide 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 preformed immediately after the search finds66 searching: a match check is performed immediately after the search finds 67 67 a possible handler. 68 68 69 \ paragraph{Installing}69 \section{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 eed to be found, the EHM needs a76 If a matching handler is not guarantied 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 is usually very general, such as aborting the program.80 This unhandled action can abort the program or install a very general handler. 81 81 82 82 \paragraph{Hierarchy} 83 83 A common way to organize exceptions is in a hierarchical structure. 84 This pattern comes fromobject-orientated languages where the84 This organization is often used in 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 ed with any given exception can handle exceptions of that92 A handler labelled 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 \ subsection{Completion}107 After the handler has finished ,the entire exception operation has to complete106 \paragraph{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) 114 and after the raise (resumption). 115 116 \subsection{Communication} 113 the most common are after the handler definition (termination) and after the raise (resumption). 114 115 \paragraph{Communication} 117 116 For effective exception handling, additional information is often passed 118 117 from the raise to the handler and back again. 119 118 So far only communication of the exceptions' identity has been covered. 120 A common communication method is putting fields into the exception instance 121 and giving the handler access to them. 122 Passing the exception by reference instead of by value can allow data to be 123 passed in both directions. 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. 124 121 125 122 \section{Virtuals} 126 123 Virtual types and casts are not part of \CFA's EHM nor are they required for 127 124 any EHM. 128 However, it is one of the best ways to support an exception hierarchy129 is via a virtual hierarchy and dispatch system.125 However, one of the best ways to support an exception hierarchy is via a virtual system 126 among exceptions and used for exception matching. 130 127 131 128 Ideally, the virtual system would have been part of \CFA before the work 132 129 on exception handling began, but unfortunately it was not. 133 Hence, only the features and framework needed for the EHM were130 Therefore, only the features and framework needed for the EHM were 134 131 designed and implemented. Other features were considered to ensure that 135 the structure could accommodate other desirable features in the future 136 but they were notimplemented.137 The rest of this section will only discuss the implemented subset of the138 virtual system design.132 the structure could accommodate other desirable features in the future but they were not 133 implemented. 134 The rest of this section discusses the implemented subset of the 135 virtual-system design. 139 136 140 137 The virtual system supports multiple ``trees" of types. Each tree is … … 146 143 % A type's ancestors are its parent and its parent's ancestors. 147 144 % The root type has no ancestors. 148 % A type's de scendants are its children and its children's descendants.145 % A type's decedents are its children and its children's decedents. 149 146 150 147 Every virtual type also has a list of virtual members. Children inherit … … 153 150 of object-orientated programming, and can be of any type. 154 151 152 \PAB{I do not understand these sentences. Can you add an example? $\Rightarrow$ 155 153 \CFA still supports virtual methods as a special case of virtual members. 156 154 Function pointers that take a pointer to the virtual type are modified 157 155 with each level of inheritance so that refers to the new type. 158 156 This means an object can always be passed to a function in its virtual table 159 as if it were a method. 160 \todo{Clarify (with an example) virtual methods.} 157 as if it were a method.} 161 158 162 159 Each virtual type has a unique id. … … 164 161 into a virtual table type. Each virtual type has a pointer to a virtual table 165 162 as a hidden field. 166 \todo{Might need a diagram for virtual structure.} 163 164 \PAB{God forbid, maybe you need a UML diagram to relate these entities.} 167 165 168 166 Up until this point the virtual system is similar to ones found in … … 175 173 types can begin to satisfy a trait, stop satisfying a trait or satisfy the same 176 174 trait in a different way at any lexical location in the program. 177 In this sense, they are ``open" as they can change at any time. 178 This capability means it is impossible to pick a single set of functions179 that represent the type'simplementation across the program.175 In this sense, they are ``open" as they can change at any time. This capability means it 176 is impossible to pick a single set of functions that represent the type's 177 implementation across the program. 180 178 181 179 \CFA side-steps this issue by not having a single virtual table for each 182 180 type. A user can define virtual tables that are filled in at their 183 declaration and given a name. Anywhere that name is visible, even if it is181 declaration and given a name. Anywhere that name is visible, even if 184 182 defined locally inside a function (although that means it does not have a 185 183 static lifetime), it can be used. … … 188 186 through the object. 189 187 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 , which is the same as the \Cpp \code{C++}{dynamic_cast}.192 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}. 197 198 Note, the syntax and semantics matches a C-cast, rather than the function-like 198 199 \Cpp syntax for special casts. Both the type of @EXPRESSION@ and @TYPE@ must be … … 217 218 The trait is defined over two types, the exception type and the virtual table 218 219 type. Each exception type should have a single virtual table type. 219 There are no actual assertions in this trait because the trait system220 cannot express them yet(adding such assertions would be part of220 There are no actual assertions in this trait because currently the trait system 221 cannot express them (adding such assertions would be part of 221 222 completing the virtual system). The imaginary assertions would probably come 222 223 from a trait defined by the virtual system, and state that the exception type 223 is a virtual type, is a descend ant of @exception_t@ (the base exception type)224 is a virtual type, is a descendent of @exception_t@ (the base exception type) 224 225 and note its virtual table type. 225 226 … … 240 241 }; 241 242 \end{cfa} 242 Both traits ensure a pair of types are an exception type, its virtual table 243 type 243 Both traits ensure a pair of types are an exception type and its virtual table, 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, 272 \CFA provides two kinds of exception handling: termination and resumption. 271 As stated, \CFA provides two kinds of exception handling: termination and resumption. 273 272 These twin operations are the core of \CFA's exception handling mechanism. 274 This section will coverthe general patterns shared by the two operations and275 then go on to cover the details each individual operation.273 This section covers the general patterns shared by the two operations and 274 then go on to cover the details of each individual operation. 276 275 277 276 Both operations follow the same set of steps. 278 Both start with the user p reforming a raise on an exception.277 Both start with the user performing a raise on an exception. 279 278 Then the exception propagates up the stack. 280 279 If a handler is found the exception is caught and the handler is run. 281 After that control continues at a raise-dependent location.282 If the search fails a default handler is run and, if it returns, thencontrol283 continues after the raise. 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, control 282 continues after the raise. Note, the default handler may further change control flow rather than return. 284 283 285 284 This general description covers what the two kinds have in common. 286 Differences include how propagation is p reformed, where exception continues285 Differences include how propagation is performed, where exception continues 287 286 after an exception is caught and handled and which default handler is run. 288 287 289 288 \subsection{Termination} 290 289 \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 ifthe stack is unwound.315 the exception is not destroyed when 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 % 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, 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, 324 323 from callee to caller. 325 324 At each stack frame, a check is made for resumption handlers defined by the … … 335 334 \end{cfa} 336 335 When viewed on its own, a try statement simply executes the statements 337 in \snake{GUARDED_BLOCK} and when those are finished, 338 the try statement finishes. 336 in \snake{GUARDED_BLOCK} and when those are finished, the try statement finishes. 339 337 340 338 However, while the guarded statements are being executed, including any 341 invoked functions, all the handlers in these statements are included in the 342 search path. 343 Hence, if a termination exception is raised these handlers may be matched 344 against the exception and may handle it. 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. 345 342 346 343 Exception matching checks the handler in each catch clause in the order 347 344 they appear, top to bottom. If the representation of the raised exception type 348 345 is the same or a descendant of @EXCEPTION_TYPE@$_i$ then @NAME@$_i$ 349 (if provided) is 350 bound to a pointer to the exception and the statements in @HANDLER_BLOCK@$_i$ 351 are executed.If control reaches the end of the handler, the exception is346 (if provided) is bound to a pointer to the exception and the statements in 347 @HANDLER_BLOCK@$_i$ are executed. 348 If control reaches the end of the handler, the exception is 352 349 freed and control continues after the try statement. 353 350 354 If no termination handler is found during the search thenthe default handler355 (\defaultTerminationHandler) visible at the raise statement is run.356 Through \CFA's trait system the best match at the raise statement will beused.357 This function is run and is passed the copied exception. 358 If the default handler is run control continues after the raisestatement.351 If no termination handler is found during the search, the default handler 352 (\defaultTerminationHandler) visible at the raise statement is called. 353 Through \CFA's trait system, the best match at the raise sight is used. 354 This function is run and is passed the copied exception. If the default 355 handler returns, control continues after the throw statement. 359 356 360 357 There is a global @defaultTerminationHandler@ that is polymorphic over all 361 termination exception types. 362 Since it is so general a more specific handler can be 358 termination exception types. Since it is so general, a more specific handler can be 363 359 defined and is used for those types, effectively overriding the handler 364 360 for a particular exception type. … … 374 370 matched a closure is taken from up the stack and executed, 375 371 after which the raising function continues executing. 376 The common uses for resumption exceptions include 377 potentially repairable errors, where execution can continue in the same 378 function once the error is corrected, and 379 ignorable events, such as logging where nothing needs to happen and control 380 should always continue from the same place. 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.} 381 379 382 380 A resumption raise is started with the @throwResume@ statement: … … 384 382 throwResume EXPRESSION; 385 383 \end{cfa} 386 \todo{Decide on a final set of keywords and use them everywhere.}387 384 It works much the same way as the termination throw. 388 385 The expression must return a reference to a resumption exception, … … 390 387 @is_resumption_exception@ at the call site. 391 388 The assertions from this trait are available to 392 the exception system while handling the exception. 393 394 At run-time, no exception copy is made. 395 Resumption does not unwind the stack nor otherwise remove values from the 396 current scope, so there is no need to manage memory to keep things in scope. 397 398 The EHM then begins propagation. The search starts from the raise in the 399 resuming function and proceeds towards the base of the stack, 400 from callee to caller. 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. 401 397 At each stack frame, a check is made for resumption handlers defined by the 402 398 @catchResume@ clauses of a @try@ statement. … … 416 412 kind of raise. 417 413 When a try statement is executed, it simply executes the statements in the 418 @GUARDED_BLOCK@ and then finishes.414 @GUARDED_BLOCK@ and then returns. 419 415 420 416 However, while the guarded statements are being executed, including any 421 invoked functions, all the handlers in these statements are included in the 422 search path. 423 Hence, if a resumption exception is raised these handlers may be matched 424 against the exception and may handle it. 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. 425 420 426 421 Exception matching checks the handler in each catch clause in the order … … 432 427 the raise statement that raised the handled exception. 433 428 434 Like termination, if no resumption handler is found during the search, 435 the default handler (\defaultResumptionHandler) visible at the raise 436 statement is called. It will use the best match at the raise sight according 437 to \CFA's overloading rules. The default handler is438 passed the exception given to the raise. When the default handler finishes429 Like termination, if no resumption handler is found during the search, the default handler 430 (\defaultResumptionHandler) visible at the raise statement is called. 431 It uses the best match at the 432 raise sight according to \CFA's overloading rules. The default handler is 433 passed the exception given to the throw. When the default handler finishes 439 434 execution continues after the raise statement. 440 435 441 There is a global \defaultResumptionHandler{} is polymorphic over all442 resumption exception s and preforms a termination throw on the exception.443 The \defaultTerminationHandler{} can be overridden by providing a new444 function that is a better match.436 There is a global \defaultResumptionHandler{} that is polymorphic over all 437 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. 445 440 446 441 \subsubsection{Resumption Marking} 447 442 \label{s:ResumptionMarking} 443 448 444 A key difference between resumption and termination is that resumption does 449 445 not unwind the stack. A side effect that is that when a handler is matched 450 and run it's try block (the guarded statements) and every try statement451 searched before it are still on the stack. The re presence can lead to452 the recursiveresumption problem.446 and run, its try block (the guarded statements) and every try statement 447 searched before it are still on the stack. Their existence can lead to the recursive 448 resumption problem. 453 449 454 450 The recursive resumption problem is any situation where a resumption handler … … 463 459 \end{cfa} 464 460 When this code is executed, the guarded @throwResume@ starts a 465 search and match es the handler in the @catchResume@ clause. This466 call is placed on the stack above the try-block. The second raise then467 search es the same try block and putsanother instance of the468 same handler on the stack leading to infinite recursion.461 search and matchs the handler in the @catchResume@ clause. This 462 call is placed on the top of stack above the try-block. The second throw 463 searchs the same try block and puts call another instance of the 464 same handler on the stack leading to an infinite recursion. 469 465 470 466 While this situation is trivial and easy to avoid, much more complex cycles 471 467 can form with multiple handlers and different exception types. 472 468 473 To prevent all of these cases, a each try statement is ``marked" from the474 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, effecti vely478 skipping over itto the next try statement.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, effectify 474 skipping over them to the next try statement. 479 475 480 476 \begin{center} … … 482 478 \end{center} 483 479 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. 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. 497 491 498 492 \section{Conditional Catch} 493 499 494 Both termination and resumption handler clauses can be given an additional 500 495 condition to further control which exceptions they handle: … … 509 504 did not match. 510 505 511 The condition matching allows finer matching by checking506 The condition matching allows finer matching to check 512 507 more kinds of information than just the exception type. 513 508 \begin{cfa} … … 524 519 // Can't handle a failure relating to f2 here. 525 520 \end{cfa} 526 In this example the file that experienced the IO error is used to decide521 In this example, the file that experianced the IO error is used to decide 527 522 which handler should be run, if any at all. 528 523 … … 553 548 554 549 \subsection{Comparison with Reraising} 550 555 551 A more popular way to allow handlers to match in more detail is to reraise 556 552 the exception after it has been caught, if it could not be handled here. 557 On the surface these two features seem interchangeable. 558 559 If @throw;@ (no argument) starts a termination reraise, 560 which is the same as a raise but reuses the last caught exception, 561 then these two statements have the same behaviour: 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: 562 557 \begin{cfa} 563 558 try { … … 579 574 } 580 575 \end{cfa} 581 That is, they will have the same behaviour in isolation. 582 Two things can expose differences between these cases. 583 584 One is the existence of multiple handlers on a single try statement. 585 A reraise skips all later handlers on this try statement but a conditional 586 catch does not. 587 Hence, if an earlier handler contains a reraise later handlers are 588 implicitly skipped, with a conditional catch they are not. 589 Still, they are equivalently powerful, 590 both can be used two mimic the behaviour of the other, 591 as reraise can pack arbitrary code in the handler and conditional catches 592 can put arbitrary code in the predicate. 593 % I was struggling with a long explanation about some simple solutions, 594 % like repeating a condition on later handlers, and the general solution of 595 % merging everything together. I don't think it is useful though unless its 596 % for a proof. 597 % https://en.cppreference.com/w/cpp/language/throw 598 599 The question then becomes ``Which is a better default?" 600 We believe that not skipping possibly useful handlers is a better default. 601 If a handler can handle an exception it should and if the handler can not 602 handle the exception then it is probably safer to have that explicitly 603 described in the handler itself instead of implicitly described by its 604 ordering with other handlers. 605 % Or you could just alter the semantics of the throw statement. The handler 606 % index is in the exception so you could use it to know where to start 607 % searching from in the current try statement. 608 % No place for the `goto else;` metaphor. 609 610 The other issue is all of the discussion above assumes that the only 611 way to tell apart two raises is the exception being raised and the remaining 612 search path. 613 This is not true generally, the current state of the stack can matter in 614 a number of cases, even only for a stack trace after an program abort. 615 But \CFA has a much more significant need of the rest of the stack, the 616 default handlers for both termination and resumption. 617 618 % For resumption it turns out it is possible continue a raise after the 619 % exception has been caught, as if it hadn't been caught in the first place. 620 This becomes a problem combined with the stack unwinding used in termination 621 exception handling. 622 The stack is unwound before the handler is installed, and hence before any 623 reraises can run. So if a reraise happens the previous stack is gone, 624 the place on the stack where the default handler was supposed to run is gone, 625 if the default handler was a local function it may have been unwound too. 626 There is no reasonable way to restore that information, so the reraise has 627 to be considered as a new raise. 628 This is the strongest advantage conditional catches have over reraising, 629 they happen before stack unwinding and avoid this problem. 630 631 % The one possible disadvantage of conditional catch is that it runs user 632 % code during the exception search. While this is a new place that user code 633 % can be run destructors and finally clauses are already run during the stack 634 % unwinding. 635 % 636 % https://www.cplusplus.com/reference/exception/current_exception/ 637 % `exception_ptr current_exception() noexcept;` 638 % https://www.python.org/dev/peps/pep-0343/ 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. 639 604 640 605 \section{Finally Clauses} 641 606 \label{s:FinallyClauses} 607 642 608 Finally clauses are used to preform unconditional clean-up when leaving a 643 609 scope and are placed at the end of a try statement after any handler clauses: … … 652 618 The @FINALLY_BLOCK@ is executed when the try statement is removed from the 653 619 stack, including when the @GUARDED_BLOCK@ finishes, any termination handler 654 finishes or during an unwind.620 finishes, or during an unwind. 655 621 The only time the block is not executed is if the program is exited before 656 622 the stack is unwound. … … 668 634 669 635 Not all languages with unwinding have finally clauses. Notably \Cpp does 670 without it as descructors, and the RAII design pattern, serve a similar role. 671 Although destructors and finally clauses can be used in the same cases, 672 they have their own strengths, similar to top-level function and lambda 673 functions with closures. 674 Destructors take more work for their first use, but if there is clean-up code 675 that needs to be run every time a type is used they soon become much easier 676 to set-up. 677 On the other hand finally clauses capture the local context, so is easy to 678 use when the clean-up is not dependent on the type of a variable or requires 679 information from multiple variables. 680 % To Peter: I think these are the main points you were going for. 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. 681 642 682 643 \section{Cancellation} … … 691 652 raise, this exception is not used in matching only to pass information about 692 653 the cause of the cancellation. 693 (This also means matching cannot fail so there is no default handler.)654 (This restriction also means matching cannot fail so there is no default handler.) 694 655 695 656 After @cancel_stack@ is called the exception is copied into the EHM's memory 696 and the current stack is unwound. 697 The behaviour after that depends on the kind of stack being cancelled. 657 and the current stack is 658 unwound. 659 The result of a cancellation depends on the kind of stack that is being unwound. 698 660 699 661 \paragraph{Main Stack} … … 702 664 After the main stack is unwound there is a program-level abort. 703 665 704 There are two reasons for these semantics. 705 The first is that it had to do this abort. 666 There are two reasons for this semantics. The first is that it obviously had to do the abort 706 667 in a sequential program as there is nothing else to notify and the simplicity 707 668 of keeping the same behaviour in sequential and concurrent programs is good. 708 Also, even in concurrent programs there may not currently be any other stacks 709 and even if other stacks do exist, main has no way to know where they are. 669 \PAB{I do not understand this sentence. $\Rightarrow$ Also, even in concurrent programs, there is no stack that an innate connection 670 to, so it would have be explicitly managed.} 710 671 711 672 \paragraph{Thread Stack} … … 719 680 and an implicit join (from a destructor call). The explicit join takes the 720 681 default handler (@defaultResumptionHandler@) from its calling context while 721 the implicit join provides its own ;which does a program abort if the682 the implicit join provides its own, which does a program abort if the 722 683 @ThreadCancelled@ exception cannot be handled. 723 684 724 The communication and synchronization are done here because threads only have 725 two structural points (not dependent on user-code) where 726 communication /synchronization happens: start and join.685 \PAB{Communication can occur during the lifetime of a thread using shared variable and \lstinline{waitfor} statements. 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.} 727 688 Since a thread must be running to perform a cancellation (and cannot be 728 689 cancelled from another stack), the cancellation must be after start and 729 before the join, so join is use d.690 before the join, so join is use. 730 691 731 692 % TODO: Find somewhere to discuss unwind collisions. … … 734 695 a destructor and prevents cascading the error across multiple threads if 735 696 the user is not equipped to deal with it. 736 It is always possible to add an explicit join if that is the desired behaviour. 737 738 With explicit join and a default handler that triggers a cancellation, it is 739 possible to cascade an error across any number of threads, cleaning up each 740 in turn, until the error is handled or the main thread is reached. 697 Also you can always add an explicit join if that is the desired behaviour. 741 698 742 699 \paragraph{Coroutine Stack} … … 744 701 satisfies the @is_coroutine@ trait. 745 702 After a coroutine stack is unwound, control returns to the @resume@ function 746 that most recently resumed it. @resume@reports a747 @CoroutineCancelled@ exception, which contains areferences to the cancelled703 that most recently resumed it. The resume reports a 704 @CoroutineCancelled@ exception, which contains references to the cancelled 748 705 coroutine and the exception used to cancel it. 749 706 The @resume@ function also takes the \defaultResumptionHandler{} from the 750 caller's context and passes it to the internal report.707 caller's context and passes it to the internal cancellation. 751 708 752 709 A coroutine knows of two other coroutines, its starter and its last resumer. … … 754 711 (in terms of coroutine state) called resume on this coroutine, so the message 755 712 is passed to the latter. 756 757 With a default handler that triggers a cancellation, it is possible to758 cascade an error across any number of coroutines, cleaning up each in turn,759 until the error is handled or a thread stack is reached. -
doc/theses/andrew_beach_MMath/future.tex
r660665f r5a46e09 3 3 4 4 \section{Language Improvements} 5 \todo{Future/Language Improvements seems to have gotten mixed up. It is6 presented as ``waiting on language improvements" but really its more7 non-research based impovements.}8 5 \CFA is a developing programming language. As such, there are partially or 9 6 unimplemented features of the language (including several broken components) 10 7 that I had to workaround while building an exception handling system largely in 11 8 the \CFA language (some C components). The following are a few of these 12 issues, and once implemented/fixed, how th eywould affect the exception system.9 issues, and once implemented/fixed, how this would affect the exception system. 13 10 \begin{itemize} 14 11 \item 15 12 The implementation of termination is not portable because it includes 16 hand-crafted assembly statements. 17 The existing compilers cannot translate that for other platforms and those 18 sections must be ported by hand to 13 hand-crafted assembly statements. These sections must be ported by hand to 19 14 support more hardware architectures, such as the ARM processor. 20 15 \item … … 22 17 reference instead of a pointer. Since \CFA has a very general reference 23 18 capability, programmers will want to use it. Once fixed, this capability should 24 result in little or no change in the exception system but simplify usage.19 result in little or no change in the exception system. 25 20 \item 26 21 Termination handlers cannot use local control-flow transfers, \eg by @break@, … … 46 41 The virtual system should be completed. It was not supposed to be part of this 47 42 project, but was thrust upon it to do exception inheritance; hence, only 48 minimal work is done. A draft for a complete virtual system is available but43 minimal work was done. A draft for a complete virtual system is available but 49 44 it is not finalized. A future \CFA project is to complete that work and then 50 45 update the exception system that uses the current version. … … 72 67 bad software engineering. 73 68 74 Non-local/concurrent raise requires more 75 coordination between the concurrency system 69 Non-local/concurrent requires more coordination between the concurrency system 76 70 and the exception system. Many of the interesting design decisions centre 77 around masking , \ie controlling which exceptions may be thrown at a stack. It71 around masking (controlling which exceptions may be thrown at a stack). It 78 72 would likely require more of the virtual system and would also effect how 79 73 default handlers are set. … … 91 85 92 86 \section{Checked Exceptions} 93 Checked exceptions make exceptions part of a function's type by adding an87 Checked exceptions make exceptions part of a function's type by adding the 94 88 exception signature. An exception signature must declare all checked 95 exceptions that could prop agate from the function (either because they were89 exceptions that could propogate from the function (either because they were 96 90 raised inside the function or came from a sub-function). This improves safety 97 91 by making sure every checked exception is either handled or consciously … … 99 93 100 94 However checked exceptions were never seriously considered for this project 101 because they have significant trade-offs in usablity and code reuse in 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 102 99 exchange for the increased safety. 100 103 101 These trade-offs are most problematic when trying to pass exceptions through 104 102 higher-order functions from the functions the user passed into the 105 103 higher-order function. There are no well known solutions to this problem 106 that were s atisfactory for \CFA (which carries some of C's flexibility107 over safety design) so additional research is needed.104 that were statifactory for \CFA (which carries some of C's flexability 105 over safety design) so one would have to be researched and developed. 108 106 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 107 Follow-up work might add checked exceptions to \CFA, possibly using 108 polymorphic exception signatures, a form of tunneling\cite{Zhang19} or 112 109 checked and unchecked raises. 113 110 … … 153 150 For instance, resumption could be extended to cover this use by allowing local 154 151 control flow out of it. This approach would require an unwind as part of the 155 transition as there are stack frames that have to be removed between where 156 the resumption handler is installed and where it is defined. 157 This approach would not require, but might benefit from, a special statement 158 to leave the handler. 159 Currently, mimicking this behaviour in \CFA is possible by throwing a 160 termination inside a resumption handler. 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. 161 156 162 157 % Maybe talk about the escape; and escape CONTROL_STMT; statements or how -
doc/theses/andrew_beach_MMath/implement.tex
r660665f r5a46e09 2 2 \label{c:implement} 3 3 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 4 The implementation work for this thesis covers two components: the virtual 11 5 system and exceptions. Each component is discussed in detail. 12 6 … … 27 21 \todo{Talk about constructors for virtual types (after they are working).} 28 22 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 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 32 25 virtual table and the virtual members there. 33 26 34 27 \subsection{Type Id} 35 28 Every virtual type has a unique id. 36 Type ids can be compared for equality, 37 which checks if the types reperented are the same, 29 Type ids can be compared for equality (the types reperented are the same) 38 30 or used to access the type's type information. 39 31 The type information currently is only the parent's type id or, if the 40 type has no parent, the null pointer.32 type has no parent, zero. 41 33 42 34 The id's are implemented as pointers to the type's type information instance. 43 Derefe rencing the pointer gets the type information.44 The ancestors of a virtual type are found by traversing type ids through 45 the type info rmation.46 The informationpushes the issue of creating a unique value (for35 Derefencing 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 also pushes the issue of creating a unique value (for 47 39 the type id) to the problem of creating a unique instance (for type 48 information), which the linker can solve. 49 50 The advanced linker support is used here to avoid having to create 51 a new declaration to attach this data to. 52 With C/\CFA's header/implementation file divide for something to appear 53 exactly once it must come from a declaration that appears in exactly one 54 implementation file; the declarations in header files may exist only once 55 they can be included in many different translation units. 56 Therefore, structure's declaration will not work. 57 Neither will attaching the type information to the virtual table -- although 58 a vtable declarations are in implemention files they are not unique, see 59 \autoref{ss:VirtualTable}. 60 Instead the same type information is generated multiple times and then 61 the new attribute \snake{cfa_linkone} is used to removed duplicates. 62 63 Type information is constructed as follows: 64 \begin{enumerate} 65 \item 66 Use the type's name to generate a name for the type information structure. 67 This is saved so it may be reused. 68 \item 69 Generate a new structure definition to store the type 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 70 53 information. The layout is the same in each case, just the parent's type id, 71 but the types used change from instance to instance.72 The generated name is used for both this structure and, if relivant, the73 parent pointer.54 but the types are changed. 55 The structure's name is change, it is based off the virtual type's name, and 56 the type of the parent's type id. 74 57 If the virtual type is polymorphic then the type information structure is 75 58 polymorphic as well, with the same polymorphic arguments. 76 \item 77 A seperate name for instances is generated from the type's name. 78 \item 79 The definition is generated and initialised. 80 The parent id is set to the null pointer or to the address of the parent's 81 type information instance. Name resolution handles the rest. 82 \item 83 \CFA's name mangler does its regular name mangling encoding the type of 84 the declaration into the instance name. This gives a completely unique name 85 including different instances of the same polymorphic type. 86 \end{enumerate} 87 \todo{The list is making me realise, some of this isn't ordered.} 88 89 Writing that code manually, with helper macros for the early name mangling, 90 would look like this: 91 \begin{cfa} 92 struct INFO_TYPE(TYPE) { 93 INFO_TYPE(PARENT) const * parent; 59 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; 94 75 }; 95 76 96 77 __attribute__((cfa_linkonce)) 97 INFO_TYPE(TYPE) const INFO_NAME(TYPE)= {98 & INFO_NAME(PARENT),78 TYPE_ID_TYPE const TYPE_ID_NAME = { 79 &PARENT_ID_NAME, 99 80 }; 100 81 \end{cfa} 101 82 102 \subsubsection{\lstinline{cfa\_linkonce} Attribute} 103 % I just realised: This is an extension of the inline keyword. 104 % An extension of C's at least, it is very similar to C++'s. 83 \subsubsection{cfa\_linkonce Attribute} 105 84 Another feature added to \CFA is a new attribute: \texttt{cfa\_linkonce}. 106 This attribute is attached to an object or function definition 107 (any global declaration with a name and a type) 108 allowing it to be defined multiple times. 109 All matching definitions mush have the link-once attribute 110 and their implementations should be identical as well. 111 112 A single definition with the attribute can be included in a header 113 file as if it was a forward declaration, except no definition is required. 114 115 This technique is used for type-id instances. A link-once definition is 116 generated each time the structure is seen. This will result in multiple 117 copies but the link-once attribute ensures all but one are removed for a 118 unique instance. 119 120 Internally, @cfa_linkonce@ is replaced with 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 121 99 @section(".gnu.linkonce.NAME")@ where \texttt{NAME} is replaced by the 122 100 mangled name of the object. 123 Any other @section@ attributes are removed from the declaration.124 101 The prefix \texttt{.gnu.linkonce} in section names is recognized by the 125 linker. If two of these sections appear with the same name, including126 everything that comes after the special prefix, then only one is used 127 and the other isdiscarded.102 linker. If two of these sections with the same name, including everything 103 that comes after the special prefix, then only one will be used and the other 104 will be discarded. 128 105 129 106 \subsection{Virtual Table} 130 \label{ss:VirtualTable}131 107 Each virtual type has a virtual table type that stores its type id and 132 108 virtual members. … … 137 113 138 114 The layout always comes in three parts. 139 \todo{Add labels to the virtual table layout figure.}140 115 The first section is just the type id at the head of the table. It is always 141 there to ensure that it can be found even when the accessing code does not 142 know which virtual type it has. 116 there to ensure that 143 117 The second section are all the virtual members of the parent, in the same 144 118 order as they appear in the parent's virtual table. Note that the type may … … 159 133 prefix that has the same layout and types as its parent virtual table. 160 134 This, combined with the fixed offset to the virtual table pointer, means that 161 for any virtual type, it is always safe to access its virtual table and, 162 from there, it is safe to check the type id to identify the exact type of the 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 163 139 underlying object, access any of the virtual members and pass the object to 164 140 any of the method-like virtual members. 165 141 166 When a virtual table is declared ,the user decides where to declare it and its142 When a virtual table is declared the user decides where to declare it and its 167 143 name. The initialization of the virtual table is entirely automatic based on 168 144 the context of the declaration. 169 145 170 The type id is always fixed ; with each virtual table type having146 The type id is always fixed, each virtual table type will always have one 171 147 exactly one possible type id. 172 The virtual members are usually filled in by type resolution.173 The best match for a given name and type at the declaration site is used.174 There are two exceptions to that rule: the @size@ field , the type's size,175 is set using a @sizeof@ expression and the @align@ field,the176 type's alignment , is set usingan @alignof@ expression.148 The virtual members are usually filled in by resolution. The best match for 149 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 size 151 and is set to the result of a @sizeof@ expression, the @align@ field is the 152 type's alignment and similarly uses an @alignof@ expression. 177 153 178 154 \subsubsection{Concurrency Integration} 179 155 Coroutines and threads need instances of @CoroutineCancelled@ and 180 156 @ThreadCancelled@ respectively to use all of their functionality. When a new 181 data type is declared with @coroutine@ or @thread@ , aforward declaration for157 data type is declared with @coroutine@ or @thread@ the forward declaration for 182 158 the instance is created as well. The definition of the virtual table is created 183 159 at the definition of the main function. 184 185 This is showned through code re-writing in186 \autoref{f:ConcurrencyTypeTransformation} and187 \autoref{f:ConcurrencyMainTransformation}.188 In both cases the original declaration is not modified,189 only new ones are added.190 160 191 161 \begin{figure} … … 195 165 }; 196 166 \end{cfa} 197 198 \transformline[appends...]199 167 200 168 \begin{cfa} … … 207 175 extern CoroutineCancelled_vtable & _default_vtable; 208 176 \end{cfa} 209 \caption{Concurrency Type Transformation} 210 \label{f:ConcurrencyTypeTransformation} 211 \end{figure} 212 213 \begin{figure} 177 214 178 \begin{cfa} 215 179 void main(Example & this) { … … 217 181 } 218 182 \end{cfa} 219 220 \transformline[appends...]221 183 222 184 \begin{cfa} … … 229 191 &_default_vtable_object_declaration; 230 192 \end{cfa} 231 \caption{Concurrency Main Transformation}232 \label{f:Concurrency MainTransformation}193 \caption{Concurrency Transformations} 194 \label{f:ConcurrencyTransformations} 233 195 \end{figure} 196 \todo{Improve Concurrency Transformations figure.} 234 197 235 198 \subsection{Virtual Cast} … … 248 211 the cast target is passed in as @child@. 249 212 250 For generated C code wraps both arguments and the resultwith type casts.251 There is also an internal checkinside the compiler to make sure that the213 For C generation both arguments and the result are wrapped with type casts. 214 There is also an internal store inside the compiler to make sure that the 252 215 target type is a virtual type. 253 216 % It also checks for conflicting definitions. 254 217 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. 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. 258 220 The parent check is a simple linear search of child's ancestors using the 259 221 type information. … … 267 229 % resumption doesn't as well. 268 230 269 % Many modern languages work with an inter nal stack that function push and pop231 % Many modern languages work with an interal stack that function push and pop 270 232 % their local data to. Stack unwinding removes large sections of the stack, 271 233 % often across functions. … … 274 236 stack. On function entry and return, unwinding is handled directly by the 275 237 call/return code embedded in the function. 276 In many cases ,the position of the instruction pointer (relative to parameter238 In many cases the position of the instruction pointer (relative to parameter 277 239 and local declarations) is enough to know the current size of the stack 278 240 frame. 279 241 280 242 Usually, the stack-frame size is known statically based on parameter and 281 local variable declarations. Even with dynamic stack-size ,the information282 to determ inehow much of the stack has to be removed is still contained243 local variable declarations. Even with dynamic stack-size the information 244 to determain how much of the stack has to be removed is still contained 283 245 within the function. 284 246 Allocating/deallocating stack space is usually an $O(1)$ operation achieved by 285 247 bumping the hardware stack-pointer up or down as needed. 286 Constructing/destructing values within a stack frame has287 a similar complexity but can add additional work and take longer.248 Constructing/destructing values on the stack takes longer put in terms of 249 figuring out what needs to be done is of similar complexity. 288 250 289 251 Unwinding across multiple stack frames is more complex because that … … 299 261 reseting to a snap-shot of an arbitrary but existing function frame on the 300 262 stack. It is up to the programmer to ensure the snap-shot is valid when it is 301 reset and that all required clean-up from the unwound stacks is p erformed.302 This approach is fragile and requires extra work in the surrounding code.303 304 With respect to th e extra work inthe surounding code,263 reset and that all required clean-up from the unwound stacks is preformed. 264 This approach is fragile and forces a work onto the surounding code. 265 266 With respect to that work forced onto the surounding code, 305 267 many languages define clean-up actions that must be taken when certain 306 268 sections of the stack are removed. Such as when the storage for a variable 307 269 is removed from the stack or when a try statement with a finally clause is 308 270 (conceptually) popped from the stack. 309 None of these should be handled by the user ---that would contradict the310 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 and271 None of these should be handled by the user, that would contradict the 272 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 and 313 275 run these clean-up actions even when removing multiple functions unknown at 314 276 the beginning of the unwinding. … … 332 294 current stack frame, and what handlers should be checked. Theoretically, the 333 295 LSDA can contain any information but conventionally it is a table with entries 334 representing regions of afunction and what has to be done there during296 representing regions of the function and what has to be done there during 335 297 unwinding. These regions are bracketed by instruction addresses. If the 336 298 instruction pointer is within a region's start/end, then execution is currently … … 352 314 int avar __attribute__(( cleanup(clean_up) )); 353 315 \end{cfa} 354 The attribu te is used on a variable and specifies a function,316 The attribue is used on a variable and specifies a function, 355 317 in this case @clean_up@, run when the variable goes out of scope. 356 This feature is enough to mimic destructors, 357 but not try statements which can effect 318 This is enough to mimic destructors, but not try statements which can effect 358 319 the unwinding. 359 320 360 To get full unwinding support , all of these features must be handled directly361 in assembly and assembler directives; partiularly the cfi directives321 To get full unwinding support all of this has to be done directly with 322 assembly and assembler directives. Partiularly the cfi directives 362 323 \snake{.cfi_lsda} and \snake{.cfi_personality}. 363 324 … … 366 327 section covers some of the important parts of the interface. 367 328 368 A personality function can p erform different actions depending on how it is329 A personality function can preform different actions depending on how it is 369 330 called. 370 331 \begin{lstlisting} … … 403 364 404 365 The @exception_class@ argument is a copy of the 405 \code{C}{exception}'s @exception_class@ field ,406 which is a number that identifies the exception handling mechanism 407 th at created the exception.408 409 The \code{C}{exception} argument is a pointer to auser366 \code{C}{exception}'s @exception_class@ field. 367 This a number that identifies the exception handling mechanism that created 368 the 369 370 The \code{C}{exception} argument is a pointer to the user 410 371 provided storage object. It has two public fields: the @exception_class@, 411 372 which is described above, and the @exception_cleanup@ function. 412 The clean-up function is used by the EHM to clean-up the exception ,if it373 The clean-up function is used by the EHM to clean-up the exception if it 413 374 should need to be freed at an unusual time, it takes an argument that says 414 375 why it had to be cleaned up. … … 421 382 messages for special cases (some of which should never be used by the 422 383 personality function) and error codes. However, unless otherwise noted, the 423 personality function always returns@_URC_CONTINUE_UNWIND@.384 personality function should always return @_URC_CONTINUE_UNWIND@. 424 385 425 386 \subsection{Raise Exception} 426 Raising an exception is the central function of libunwind and it performs 387 Raising an exception is the central function of libunwind and it performs a 427 388 two-staged unwinding. 428 389 \begin{cfa} … … 511 472 % catches. Talk about GCC nested functions. 512 473 513 \CFA termination exceptions use libunwind heavily because they match 474 \CFA termination exceptions use libunwind heavily because they match \Cpp 514 475 \Cpp exceptions closely. The main complication for \CFA is that the 515 476 compiler generates C code, making it very difficult to generate the assembly to … … 524 485 525 486 \begin{figure} 526 \centering527 487 \input{exception-layout} 528 488 \caption{Exception Layout} 529 489 \label{f:ExceptionLayout} 530 490 \end{figure} 531 532 Exceptions are stored in variable-sized blocks 533 (see \autoref{f:ExceptionLayout}).491 \todo*{Convert the exception layout to an actual diagram.} 492 493 Exceptions are stored in variable-sized blocks (see \vref{f:ExceptionLayout}). 534 494 The first component is a fixed-sized data structure that contains the 535 495 information for libunwind and the exception system. The second component is an … … 538 498 @_Unwind_Exception@ to the entire node. 539 499 540 Multip le exceptions can exist at the same time because exceptions can be500 Multipe exceptions can exist at the same time because exceptions can be 541 501 raised inside handlers, destructors and finally blocks. 542 502 Figure~\vref{f:MultipleExceptions} shows a program that has multiple 543 503 exceptions active at one time. 544 504 Each time an exception is thrown and caught the stack unwinds and the finally 545 clause runs. This handler throwsanother exception (until @num_exceptions@ gets546 high enough) ,which must be allocated. The previous exceptions may not be505 clause runs. This will throw another exception (until @num_exceptions@ gets 506 high enough) which must be allocated. The previous exceptions may not be 547 507 freed because the handler/catch clause has not been run. 548 Therefore, the EHM must keep all unhandled exceptions alive 549 while it allocates exceptions for new throws. 508 So the EHM must keep them alive while it allocates exceptions for new throws. 550 509 551 510 \begin{figure} … … 600 559 \todo*{Work on multiple exceptions code sample.} 601 560 602 All exceptions are stored in nodes , which are then linked together in lists561 All exceptions are stored in nodes which are then linked together in lists, 603 562 one list per stack, with the 604 563 list head stored in the exception context. Within each linked list, the most … … 607 566 exception is being handled. The exception at the head of the list is currently 608 567 being handled, while other exceptions wait for the exceptions before them to be 609 handled andremoved.568 removed. 610 569 611 570 The virtual members in the exception's virtual table provide the size of the … … 614 573 exception into managed memory. After the exception is handled, the free 615 574 function is used to clean up the exception and then the entire node is 616 passed to free , returning the memoryback to the heap.575 passed to free so the memory can be given back to the heap. 617 576 618 577 \subsection{Try Statements and Catch Clauses} 619 578 The try statement with termination handlers is complex because it must 620 compensate for the C code-generation versus 621 assembly-code generated from \CFA. Libunwind 579 compensate for the lack of assembly-code generated from \CFA. Libunwind 622 580 requires an LSDA and personality function for control to unwind across a 623 581 function. The LSDA in particular is hard to mimic in generated C code. … … 634 592 embedded assembly. This assembly code is handcrafted using C @asm@ statements 635 593 and contains 636 enough information for asingle try statement the function repersents.594 enough information for the single try statement the function repersents. 637 595 638 596 The three functions passed to try terminate are: 639 597 \begin{description} 640 \item[try function:] This function is the try block, it is where all the code641 from inside the try block is placed. It takes no parameters and has no598 \item[try function:] This function is the try block, all the code inside the 599 try block is placed inside the try function. It takes no parameters and has no 642 600 return value. This function is called during regular execution to run the try 643 601 block. … … 651 609 handler that matches the exception. 652 610 653 \item[handler function:] This function handles the exception, and contains 654 all the code from the handlers in the try statement, joined with a switch 655 statement on the handler's id. 656 It takes a 611 \item[handler function:] This function handles the exception. It takes a 657 612 pointer to the exception and the handler's id and returns nothing. It is called 658 after the cleanup phase. 613 after the cleanup phase. It is constructed by stitching together the bodies of 614 each handler and dispatches to the selected handler. 659 615 \end{description} 660 616 All three functions are created with GCC nested functions. GCC nested functions 661 can be used to create closures, 662 in other words functions that can refer to the state of other 617 can be used to create closures, functions that can refer to the state of other 663 618 functions on the stack. This approach allows the functions to refer to all the 664 619 variables in scope for the function containing the @try@ statement. These … … 668 623 Using this pattern, \CFA implements destructors with the cleanup attribute. 669 624 670 \autoref{f:TerminationTransformation} shows the pattern used to transform671 a \CFA try statement with catch clauses into the approprate C functions.672 \todo{Explain the Termination Transformation figure.}673 674 625 \begin{figure} 675 626 \begin{cfa} … … 682 633 } 683 634 \end{cfa} 684 685 \transformline686 635 687 636 \begin{cfa} … … 734 683 % The stack-local data, the linked list of nodes. 735 684 736 Resumption issimpler to implement than termination685 Resumption simpler to implement than termination 737 686 because there is no stack unwinding. 738 687 Instead of storing the data in a special area using assembly, … … 743 692 The nodes are stored in order, with the more recent try statements closer 744 693 to the head of the list. 745 Instead of traversing the stack ,resumption handling traverses the list.746 At each node ,the EHM checks to see if the try statement the node repersents694 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 repersents 747 696 can handle the exception. If it can, then the exception is handled and 748 697 the operation finishes, otherwise the search continues to the next node. 749 698 If the search reaches the end of the list without finding a try statement 750 that can handle the exception ,the default handler is executed and the699 that can handle the exception the default handler is executed and the 751 700 operation finishes. 752 701 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.} 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. 769 713 770 714 \begin{figure} … … 778 722 } 779 723 \end{cfa} 780 781 \transformline782 724 783 725 \begin{cfa} … … 811 753 812 754 % Recursive Resumption Stuff: 813 \autoref{f:ResumptionMarking} shows search skipping 814 (see \vpageref{s:ResumptionMarking}), which ignores parts of 755 Search skipping (see \vpageref{s:ResumptionMarking}), which ignores parts of 815 756 the stack 816 757 already examined, is accomplished by updating the front of the list as the … … 818 759 is updated to the next node of the current node. After the search is complete, 819 760 successful or not, the head of the list is reset. 820 % No paragraph? 761 821 762 This mechanism means the current handler and every handler that has already 822 763 been checked are not on the list while a handler is run. If a resumption is 823 thrown during the handling of another resumption ,the active handlers and all764 thrown during the handling of another resumption the active handlers and all 824 765 the other handler checked up to this point are not checked again. 825 % No paragraph? 826 This structure also supports new handler sadded while the resumption is being766 767 This structure also supports new handler added while the resumption is being 827 768 handled. These are added to the front of the list, pointing back along the 828 stack -- - the first one points over all the checked handlers ---829 and the orderingis maintained.769 stack -- the first one points over all the checked handlers -- and the ordering 770 is maintained. 830 771 831 772 \begin{figure} … … 833 774 \caption{Resumption Marking} 834 775 \label{f:ResumptionMarking} 835 \todo*{ Label Resumption Marking to aid clarity.}776 \todo*{Convert Resumption Marking into a line figure.} 836 777 \end{figure} 837 778 838 779 \label{p:zero-cost} 839 Finally, the resumption implementation has a cost for entering/exiting a try 840 statement with @catchResume@ clauses, whereas a trystatement with @catch@780 Note, the resumption implementation has a cost for entering/exiting a @try@ 781 statement with @catchResume@ clauses, whereas a @try@ statement with @catch@ 841 782 clauses has zero-cost entry/exit. While resumption does not need the stack 842 783 unwinding and cleanup provided by libunwind, it could use the search phase to … … 869 810 870 811 The first step of cancellation is to find the cancelled stack and its type: 871 coroutine , thread or main thread.872 In \CFA, a thread (the construct the user works with) is a user-level thread 873 (point of execution) paired with a coroutine, the thread's main coroutine.874 The thread library also stores pointers to the main thread and the current 875 thread. 876 If the current thread's main and current coroutines are the same then the877 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 i f and only if the main and current threads are the same.812 coroutine or thread. Fortunately, the thread library stores the main thread 813 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 a the current thread's main and current coroutines are the same then the 818 current stack is a thread stack. Furthermore it is easy to compare the 819 current thread to the main thread to see if they are the same. And if this 820 is not a thread stack then it must be a coroutine stack. 880 821 881 822 However, if the threading library is not linked, the sequential execution is on 882 823 the main stack. Hence, the entire check is skipped because the weak-symbol 883 function is loaded. Therefore, main thread cancellation is unconditionally824 function is loaded. Therefore, a main thread cancellation is unconditionally 884 825 performed. 885 826 886 827 Regardless of how the stack is chosen, the stop function and parameter are 887 828 passed to the forced-unwind function. The general pattern of all three stop 888 functions is the same: continue unwinding until the end of stack and889 then preform the appropriatetransfer.829 functions is the same: they continue unwinding until the end of stack and 830 then preform their transfer. 890 831 891 832 For main stack cancellation, the transfer is just a program abort. … … 893 834 For coroutine cancellation, the exception is stored on the coroutine's stack, 894 835 and the coroutine context switches to its last resumer. The rest is handled on 895 the backside of the resume, which check sif the resumed coroutine is836 the backside of the resume, which check if the resumed coroutine is 896 837 cancelled. If cancelled, the exception is retrieved from the resumed coroutine, 897 838 and a @CoroutineCancelled@ exception is constructed and loaded with the -
doc/theses/andrew_beach_MMath/intro.tex
r660665f r5a46e09 1 1 \chapter{Introduction} 2 2 3 % The highest level overview of Cforall and EHMs. Get this done right away. 4 This thesis goes over the design and implementation of the exception handling 5 mechanism (EHM) of 6 \CFA (pronounced sea-for-all and may be written Cforall or CFA). 7 \CFA is a new programming language that extends C, that maintains 8 backwards-compatibility while introducing modern programming features. 9 Adding exception handling to \CFA gives it new ways to handle errors and 10 make other large control-flow jumps. 3 \PAB{Stay in the present tense. \newline 4 \url{https://plg.uwaterloo.ca/~pabuhr/technicalWriting.shtml}} 5 \newline 6 \PAB{Note, \lstinline{lstlisting} normally bolds keywords. None of the keywords in your thesis are bolded.} 11 7 12 % Now take a step back and explain what exceptions are generally. 13 Exception handling provides dynamic inter-function control flow. 8 % Talk about Cforall and exceptions generally. 9 %This thesis goes over the design and implementation of the exception handling 10 %mechanism (EHM) of 11 %\CFA (pernounced sea-for-all and may be written Cforall or CFA). 12 Exception handling provides alternative dynamic inter-function control flow. 14 13 There are two forms of exception handling covered in this thesis: 15 14 termination, which acts as a multi-level return, 16 15 and resumption, which is a dynamic function call. 17 Termination handling is much more common, 18 to the extent that it is often seen 19 This seperation is uncommon because termination exception handling is so 20 much more common that it is often assumed. 21 % WHY: Mention other forms of continuation and \cite{CommonLisp} here? 22 A language's EHM is the combination of language syntax and run-time 23 components that are used to construct, raise and handle exceptions, 24 including all control flow. 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}. 25 18 26 19 Termination exception handling allows control to return to any previous … … 31 24 \end{center} 32 25 33 Resumption exception handling seaches the stack for a handler and then calls34 it without adding or removing any other stack frames.26 Resumption exception handling calls a function, but asks the functions on the 27 stack what function that is. 35 28 \todo{Add a diagram showing control flow for resumption.} 36 29 … … 42 35 most of the cost only when the error actually occurs. 43 36 37 % Overview of exceptions in Cforall. 38 39 \PAB{You need section titles here. Don't take them out.} 40 44 41 \section{Thesis Overview} 45 This work describes the design and implementation of the \CFA EHM. 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. 46 47 The \CFA EHM implements all of the common exception features (or an 47 48 equivalent) found in most other EHMs and adds some features of its own. … … 76 77 harder to replicate in other programming languages. 77 78 79 \section{Background} 80 78 81 % Talk about other programming languages. 79 82 Some existing programming languages that include EHMs/exception handling … … 81 84 exceptions which unwind the stack as part of the 82 85 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} 83 92 84 93 The contributions of this work are: … … 93 102 \end{enumerate} 94 103 95 \todo{I can't figure out a good lead-in to the roadmap.} 96 The next section covers the existing state of exceptions. 97 The existing state of \CFA is also covered in \autoref{c:existing}. 98 The new features are introduced in \autoref{c:features}, 99 which explains their usage and design. 104 \todo{I can't figure out a good lead-in to the overview.} 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. 100 108 That is followed by the implementation of those features in 101 109 \autoref{c:implement}. 102 The performance results are examined in \autoref{c:performance}. 103 Possibilities to extend this project are discussed in \autoref{c:future}. 104 105 \section{Background} 106 \label{s:background} 107 108 Exception handling is not a new concept, 109 with papers on the subject dating back 70s. 110 111 Their were popularised by \Cpp, 112 which added them in its first major wave of non-object-orientated features 113 in 1990. 114 % https://en.cppreference.com/w/cpp/language/history 115 116 Java was the next popular language to use exceptions. It is also the most 117 popular language with checked exceptions. 118 Checked exceptions are part of the function interface they are raised from. 119 This includes functions they propogate through, until a handler for that 120 type of exception is found. 121 This makes exception information explicit, which can improve clarity and 122 safety, but can slow down programming. 123 Some of these, such as dealing with high-order methods or an overly specified 124 throws clause, are technical. However some of the issues are much more 125 human, in that writing/updating all the exception signatures can be enough 126 of a burden people will hack the system to avoid them. 127 Including the ``catch-and-ignore" pattern where a catch block is used without 128 anything to repair or recover from the exception. 129 130 %\subsection 131 Resumption exceptions have been much less popular. 132 Although resumption has a history as old as termination's, very few 133 programming languages have implement them. 134 % http://bitsavers.informatik.uni-stuttgart.de/pdf/xerox/parc/techReports/ 135 % CSL-79-3_Mesa_Language_Manual_Version_5.0.pdf 136 Mesa is one programming languages that did and experiance with that 137 languages is quoted as being one of the reasons resumptions were not 138 included in the \Cpp standard. 139 % https://en.wikipedia.org/wiki/Exception_handling 140 \todo{A comment about why we did include them when they are so unpopular 141 might be approprate.} 142 143 %\subsection 144 Functional languages, tend to use solutions like the return union, but some 145 exception-like constructs still appear. 146 147 For instance Haskell's built in error mechanism can make the result of any 148 expression, including function calls. Any expression that examines an 149 error value will in-turn produce an error. This continues until the main 150 function produces an error or until it is handled by one of the catch 151 functions. 152 153 %\subsection 154 More recently exceptions seem to be vanishing from newer programming 155 languages. 156 Rust and Go reduce this feature to panics. 157 Panicing is somewhere between a termination exception and a program abort. 158 Notably in Rust a panic can trigger either, a panic may unwind the stack or 159 simply kill the process. 160 % https://doc.rust-lang.org/std/panic/fn.catch_unwind.html 161 Go's panic is much more similar to a termination exception but there is 162 only a catch-all function with \code{Go}{recover()}. 163 So exceptions still are appearing, just in reduced forms. 164 165 %\subsection 166 Exception handling's most common use cases are in error handling. 167 Here are some other ways to handle errors and comparisons with exceptions. 168 \begin{itemize} 169 \item\emph{Error Codes}: 170 This pattern uses an enumeration (or just a set of fixed values) to indicate 171 that an error has occured and which error it was. 172 173 There are some issues if a function wants to return an error code and another 174 value. The main issue is that it can be easy to forget checking the error 175 code, which can lead to an error being quitely and implicitly ignored. 176 Some new languages have tools that raise warnings if the return value is 177 discarded to avoid this. 178 It also puts more code on the main execution path. 179 \item\emph{Special Return with Global Store}: 180 A function that encounters an error returns some value indicating that it 181 encountered a value but store which error occured in a fixed global location. 182 183 Perhaps the C standard @errno@ is the most famous example of this, 184 where some standard library functions will return some non-value (often a 185 NULL pointer) and set @errno@. 186 187 This avoids the multiple results issue encountered with straight error codes 188 but otherwise many of the same advantages and disadvantages. 189 It does however introduce one other major disadvantage: 190 Everything that uses that global location must agree on all possible errors. 191 \item\emph{Return Union}: 192 Replaces error codes with a tagged union. 193 Success is one tag and the errors are another. 194 It is also possible to make each possible error its own tag and carry its own 195 additional information, but the two branch format is easy to make generic 196 so that one type can be used everywhere in error handling code. 197 198 This pattern is very popular in functional or semi-functional language, 199 anything with primitive support for tagged unions (or algebraic data types). 200 % We need listing Rust/rust to format code snipits from it. 201 % Rust's \code{rust}{Result<T, E>} 202 203 The main disadvantage is again it puts code on the main execution path. 204 This is also the first technique that allows for more information about an 205 error, other than one of a fix-set of ids, to be sent. 206 They can be missed but some languages can force that they are checked. 207 It is also implicitly forced in any languages with checked union access. 208 \item\emph{Handler Functions}: 209 On error the function that produced the error calls another function to 210 handle it. 211 The handler function can be provided locally (passed in as an argument, 212 either directly as as a field of a structure/object) or globally (a global 213 variable). 214 215 C++ uses this as its fallback system if exception handling fails. 216 \snake{std::terminate_handler} and for a time \snake{std::unexpected_handler} 217 218 Handler functions work a lot like resumption exceptions. 219 The difference is they are more expencive to set up but cheaper to use, and 220 so are more suited to more fequent errors. 221 The exception being global handlers if they are rarely change as the time 222 in both cases strinks towards zero. 223 \end{itemize} 224 225 %\subsection 226 Because of their cost exceptions are rarely used for hot paths of execution. 227 There is an element of self-fulfilling prophocy here as implementation 228 techniques have been designed to make exceptions cheap to set-up at the cost 229 of making them expencive to use. 230 Still, use of exceptions for other tasks is more common in higher-level 231 scripting languages. 232 An iconic example is Python's StopIteration exception which is thrown by 233 an iterator to indicate that it is exausted. Combined with Python's heavy 234 use of the iterator based for-loop. 235 % https://docs.python.org/3/library/exceptions.html#StopIteration 110 % Future Work \autoref{c:future} -
doc/theses/andrew_beach_MMath/uw-ethesis.tex
r660665f r5a46e09 244 244 \input{features} 245 245 \input{implement} 246 \input{performance}247 246 \input{future} 248 247 -
doc/theses/mubeen_zulfiqar_MMath/.gitignore
r660665f r5a46e09 1 1 # Intermediate Results: 2 build/2 out/ 3 3 4 4 # Final Files: -
doc/theses/mubeen_zulfiqar_MMath/allocator.tex
r660665f r5a46e09 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? ----- 35 36 36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% uHeapLmmm Design 39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 \PAB{Often Performance is its own chapter. I added one for now.} 41 38 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 39 Performance evaluation using u-benchmark suite. 78 40 79 41 \noindent -
doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex
r660665f r5a46e09 34 34 \noindent 35 35 ==================== 36 37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Performance Matrices40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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 \item50 Memory Overhead51 \item52 Speed53 \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 explanation65 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 \item71 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 \item73 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 \item76 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 \item78 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 explanation81 \item82 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 explanation85 86 \item87 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 explanation95 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 explanation115 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 explanation123 124 *** FIX ME: Insert a figure of above scenrio 2 with explanation125 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 explanation131 132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Micro Benchmark Suite135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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 finalize146 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 description150 151 \subsubsection{Relevant Knobs}152 *** FIX ME: Insert Relevant Knobs153 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 description160 161 \paragraph{Relevant Knobs}162 *** FIX ME: Insert Relevant Knobs163 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 description167 168 \paragraph{Relevant Knobs}169 *** FIX ME: Insert Relevant Knobs170 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 description177 178 \paragraph{Relevant Knobs}179 *** FIX ME: Insert Relevant Knobs180 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 description184 185 \paragraph{Relevant Knobs}186 *** FIX ME: Insert Relevant Knobs187 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 description194 195 \paragraph{Relevant Knobs}196 *** FIX ME: Insert Relevant Knobs197 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 description201 202 \paragraph{Relevant Knobs}203 *** FIX ME: Insert Relevant Knobs204 205 \section{Results}206 *** FIX ME: add configuration details of memory allocators207 208 \subsection{Memory Benchmark}209 210 \subsubsection{Relevant Knobs}211 212 \subsection{Speed Benchmark}213 214 \subsubsection{Speed Time}215 216 \paragraph{Relevant Knobs}217 218 \subsubsection{Speed Workload}219 220 \paragraph{Relevant Knobs}221 222 \subsection{Cache Scratch}223 224 \subsubsection{Cache Scratch Time}225 226 \paragraph{Relevant Knobs}227 228 \subsubsection{Cache Scratch Layout}229 230 \paragraph{Relevant Knobs}231 232 \subsection{Cache Thrash}233 234 \subsubsection{Cache Thrash Time}235 236 \paragraph{Relevant Knobs}237 238 \subsubsection{Cache Thrash Layout}239 240 \paragraph{Relevant Knobs} -
doc/theses/mubeen_zulfiqar_MMath/uw-ethesis.tex
r660665f r5a46e09 165 165 % cfa macros used in the document 166 166 \input{common} 167 %\usepackageinput{common}168 167 \CFAStyle % CFA code-style for all languages 169 \lstset{ basicstyle=\linespread{0.9}\tt} % CFA typewriter font168 \lstset{language=CFA,basicstyle=\linespread{0.9}\tt} % CFA default language 170 169 \newcommand{\PAB}[1]{{\color{red}PAB: #1}} 171 170 -
libcfa/configure.ac
r660665f r5a46e09 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)], [])139 133 140 134 AH_TEMPLATE([CFA_HAVE_LINUX_IO_URING_H],[Defined if io_uring support is present when compiling libcfathread.]) -
libcfa/prelude/defines.hfa.in
r660665f r5a46e09 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_LIBRSEQ175 176 /* Defined if rseq support is present when compiling libcfathread. */177 #undef CFA_HAVE_LINUX_RSEQ_H178 179 173 /* Defined if openat2 support is present when compiling libcfathread. */ 180 174 #undef CFA_HAVE_OPENAT2 … … 211 205 #undef HAVE_LINUX_IO_URING_H 212 206 213 /* Define to 1 if you have the <linux/rseq.h> header file. */214 #undef HAVE_LINUX_RSEQ_H215 216 207 /* Define to 1 if you have the <memory.h> header file. */ 217 208 #undef HAVE_MEMORY_H -
libcfa/src/Makefile.am
r660665f r5a46e09 61 61 containers/queueLockFree.hfa \ 62 62 containers/stackLockFree.hfa \ 63 containers/vector2.hfa \64 63 vec/vec.hfa \ 65 64 vec/vec2.hfa \ … … 70 69 common.hfa \ 71 70 fstream.hfa \ 71 strstream.hfa \ 72 72 heap.hfa \ 73 73 iostream.hfa \ … … 78 78 rational.hfa \ 79 79 stdlib.hfa \ 80 strstream.hfa \81 80 time.hfa \ 82 81 bits/weakso_locks.hfa \ … … 84 83 containers/pair.hfa \ 85 84 containers/result.hfa \ 86 containers/vector.hfa \ 87 device/cpu.hfa 85 containers/vector.hfa 88 86 89 87 libsrc = ${inst_headers_src} ${inst_headers_src:.hfa=.cfa} \ -
libcfa/src/bits/signal.hfa
r660665f r5a46e09 20 20 21 21 #include <errno.h> 22 #define __USE_GNU 22 23 #include <signal.h> 24 #undef __USE_GNU 23 25 #include <stdlib.h> 24 26 #include <string.h> -
libcfa/src/concurrency/coroutine.cfa
r660665f r5a46e09 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE18 17 19 18 #include "coroutine.hfa" -
libcfa/src/concurrency/io.cfa
r660665f r5a46e09 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE18 17 19 18 #if defined(__CFA_DEBUG__) … … 24 23 25 24 #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
r660665f r5a46e09 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE 17 #define _GNU_SOURCE /* See feature_test_macros(7) */ 18 18 19 19 #if defined(__CFA_DEBUG__) -
libcfa/src/concurrency/kernel.cfa
r660665f r5a46e09 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE18 19 17 // #define __CFA_DEBUG_PRINT_RUNTIME_CORE__ 20 18 … … 280 278 281 279 // Spin a little on I/O, just in case 282 for(5) {280 for(5) { 283 281 __maybe_io_drain( this ); 284 282 readyThread = pop_fast( this->cltr ); … … 287 285 288 286 // no luck, try stealing a few times 289 for(5) {287 for(5) { 290 288 if( __maybe_io_drain( this ) ) { 291 289 readyThread = pop_fast( this->cltr ); … … 424 422 __cfactx_switch( &proc_cor->context, &thrd_dst->context ); 425 423 // when __cfactx_switch returns we are back in the processor coroutine 426 427 428 424 429 425 /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary ); … … 526 522 527 523 /* paranoid */ verify( ! __preemption_enabled() ); 528 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ) || thrd_src->corctx_flag, "ERROR : Returning $thread %p has been corrupted.\n StackPointer too small.\n", thrd_src );529 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit) || thrd_src->corctx_flag, "ERROR : Returning $thread %p has been corrupted.\n StackPointer too large.\n", thrd_src );524 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ), "ERROR : Returning $thread %p has been corrupted.\n StackPointer too small.\n", thrd_src ); 525 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit), "ERROR : Returning $thread %p has been corrupted.\n StackPointer too large.\n", thrd_src ); 530 526 } 531 527 -
libcfa/src/concurrency/kernel.hfa
r660665f r5a46e09 66 66 unsigned id; 67 67 unsigned target; 68 unsigned last;69 68 unsigned long long int cutoff; 70 69 } rdq; -
libcfa/src/concurrency/kernel/startup.cfa
r660665f r5a46e09 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE18 17 19 18 // C Includes 20 19 #include <errno.h> // errno 21 #include <signal.h>22 20 #include <string.h> // strerror 23 21 #include <unistd.h> // sysconf 24 25 22 extern "C" { 26 23 #include <limits.h> // PTHREAD_STACK_MIN 27 #include <unistd.h> // syscall28 24 #include <sys/eventfd.h> // eventfd 29 25 #include <sys/mman.h> // mprotect … … 140 136 }; 141 137 142 #if defined(CFA_HAVE_LINUX_LIBRSEQ)143 // No data needed144 #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 #else151 // No data needed152 #endif153 154 138 //----------------------------------------------------------------------------- 155 139 // Struct to steal stack … … 484 468 self_mon_p = &self_mon; 485 469 link.next = 0p; 486 link.ts = -1llu;470 link.ts = 0; 487 471 preferred = -1u; 488 472 last_proc = 0p; … … 513 497 this.rdq.id = -1u; 514 498 this.rdq.target = -1u; 515 this.rdq.last = -1u;516 499 this.rdq.cutoff = 0ull; 517 500 do_terminate = false; -
libcfa/src/concurrency/kernel_private.hfa
r660665f r5a46e09 16 16 #pragma once 17 17 18 #if !defined(__cforall_thread__)19 #error kernel_private.hfa should only be included in libcfathread source20 #endif21 22 18 #include "kernel.hfa" 23 19 #include "thread.hfa" … … 26 22 #include "stats.hfa" 27 23 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 #else34 #ifndef _GNU_SOURCE35 #error kernel_private requires gnu_source36 #endif37 #include <sched.h>38 #endif39 }40 41 24 //----------------------------------------------------------------------------- 42 25 // Scheduler 26 27 43 28 extern "C" { 44 29 void disable_interrupts() OPTIONAL_THREAD; … … 54 39 55 40 //----------------------------------------------------------------------------- 56 // Hardware57 58 #if defined(CFA_HAVE_LINUX_LIBRSEQ)59 // No data needed60 #elif defined(CFA_HAVE_LINUX_RSEQ_H)61 extern "Cforall" {62 extern __attribute__((aligned(128))) thread_local volatile struct rseq __cfaabi_rseq;63 }64 #else65 // No data needed66 #endif67 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 #else77 return sched_getcpu();78 #endif79 }80 81 //-----------------------------------------------------------------------------82 41 // Processor 83 42 void main(processorCtx_t *); … … 85 44 void * __create_pthread( pthread_t *, void * (*)(void *), void * ); 86 45 void __destroy_pthread( pthread_t pthread, void * stack, void ** retval ); 46 47 87 48 88 49 extern cluster * mainCluster; -
libcfa/src/concurrency/locks.cfa
r660665f r5a46e09 16 16 17 17 #define __cforall_thread__ 18 #define _GNU_SOURCE19 18 20 19 #include "locks.hfa" -
libcfa/src/concurrency/locks.hfa
r660665f r5a46e09 24 24 #include "containers/list.hfa" 25 25 26 #include "limits.hfa"27 26 #include "thread.hfa" 28 27 … … 88 87 bool tryP(BinaryBenaphore & this) { 89 88 ssize_t c = this.counter; 90 /* paranoid */ verify( c > MIN );91 89 return (c >= 1) && __atomic_compare_exchange_n(&this.counter, &c, c-1, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); 92 90 } … … 96 94 ssize_t c = 0; 97 95 for () { 98 /* paranoid */ verify( this.counter < MAX );99 96 if (__atomic_compare_exchange_n(&this.counter, &c, c+1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 100 97 if (c == 0) return true; … … 176 173 ThreadBenaphore sem; 177 174 }; 178 179 static inline void ?{}(fast_lock & this) { this.owner = 0p; }180 175 181 176 static inline bool $try_lock(fast_lock & this, $thread * thrd) { -
libcfa/src/concurrency/monitor.cfa
r660665f r5a46e09 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE18 17 19 18 #include "monitor.hfa" -
libcfa/src/concurrency/mutex.cfa
r660665f r5a46e09 17 17 18 18 #define __cforall_thread__ 19 #define _GNU_SOURCE20 19 21 20 #include "mutex.hfa" -
libcfa/src/concurrency/preemption.cfa
r660665f r5a46e09 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE18 19 17 // #define __CFA_DEBUG_PRINT_PREEMPTION__ 20 18 -
libcfa/src/concurrency/ready_queue.cfa
r660665f r5a46e09 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE18 19 17 // #define __CFA_DEBUG_PRINT_READY_QUEUE__ 20 18 … … 22 20 #define USE_RELAXED_FIFO 23 21 // #define USE_WORK_STEALING 24 // #define USE_CPU_WORK_STEALING25 22 26 23 #include "bits/defs.hfa" 27 #include "device/cpu.hfa"28 24 #include "kernel_private.hfa" 29 25 26 #define _GNU_SOURCE 30 27 #include "stdlib.hfa" 31 28 #include "math.hfa" 32 29 33 #include <errno.h>34 30 #include <unistd.h> 35 36 extern "C" {37 #include <sys/syscall.h> // __NR_xxx38 }39 31 40 32 #include "ready_subqueue.hfa" … … 54 46 #endif 55 47 56 #if defined(USE_CPU_WORK_STEALING) 57 #define READYQ_SHARD_FACTOR 2 58 #elif defined(USE_RELAXED_FIFO) 48 #if defined(USE_RELAXED_FIFO) 59 49 #define BIAS 4 60 50 #define READYQ_SHARD_FACTOR 4 … … 95 85 } 96 86 97 #if defined(CFA_HAVE_LINUX_LIBRSEQ)98 // No forward declaration needed99 #define __kernel_rseq_register rseq_register_current_thread100 #define __kernel_rseq_unregister rseq_unregister_current_thread101 #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_register106 #define __kernel_rseq_unregister __kernel_raw_rseq_unregister107 #else108 // No forward declaration needed109 // No initialization needed110 static inline void noop(void) {}111 112 #define __kernel_rseq_register noop113 #define __kernel_rseq_unregister noop114 #endif115 116 87 //======================================================================= 117 88 // Cluster wide reader-writer lock … … 136 107 // Lock-Free registering/unregistering of threads 137 108 unsigned register_proc_id( void ) with(*__scheduler_lock) { 138 __kernel_rseq_register();139 140 109 __cfadbg_print_safe(ready_queue, "Kernel : Registering proc %p for RW-Lock\n", proc); 141 110 bool * handle = (bool *)&kernelTLS().sched_lock; … … 192 161 193 162 __cfadbg_print_safe(ready_queue, "Kernel : Unregister proc %p\n", proc); 194 195 __kernel_rseq_unregister();196 163 } 197 164 … … 247 214 //======================================================================= 248 215 void ?{}(__ready_queue_t & this) with (this) { 249 #if defined(USE_CPU_WORK_STEALING) 250 lanes.count = cpu_info.hthrd_count * READYQ_SHARD_FACTOR; 251 lanes.data = alloc( lanes.count ); 252 lanes.tscs = alloc( lanes.count ); 253 254 for( idx; (size_t)lanes.count ) { 255 (lanes.data[idx]){}; 256 lanes.tscs[idx].tv = rdtscl(); 257 } 258 #else 259 lanes.data = 0p; 260 lanes.tscs = 0p; 261 lanes.count = 0; 262 #endif 216 lanes.data = 0p; 217 lanes.tscs = 0p; 218 lanes.count = 0; 263 219 } 264 220 265 221 void ^?{}(__ready_queue_t & this) with (this) { 266 #if !defined(USE_CPU_WORK_STEALING) 267 verify( SEQUENTIAL_SHARD == lanes.count ); 268 #endif 269 222 verify( SEQUENTIAL_SHARD == lanes.count ); 270 223 free(lanes.data); 271 224 free(lanes.tscs); … … 273 226 274 227 //----------------------------------------------------------------------- 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 retry300 } while( !__atomic_try_acquire( &lanes.data[i].lock ) );301 302 // Actually push it303 push(lanes.data[i], thrd);304 305 // Unlock and return306 __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 #endif312 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 cluster318 __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 target336 if(proc->rdq.target == -1u) {337 // if We don't have a338 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 0p395 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 #endif414 228 #if defined(USE_RELAXED_FIFO) 415 229 //----------------------------------------------------------------------- … … 705 519 if(is_empty(sl)) { 706 520 assert( sl.anchor.next == 0p ); 707 assert( sl.anchor.ts == -1llu);521 assert( sl.anchor.ts == 0 ); 708 522 assert( mock_head(sl) == sl.prev ); 709 523 } else { 710 524 assert( sl.anchor.next != 0p ); 711 assert( sl.anchor.ts != -1llu);525 assert( sl.anchor.ts != 0 ); 712 526 assert( mock_head(sl) != sl.prev ); 713 527 } … … 759 573 lanes.tscs = alloc(lanes.count, lanes.tscs`realloc); 760 574 for(i; lanes.count) { 761 unsigned long long tsc1 = ts(lanes.data[i]); 762 unsigned long long tsc2 = rdtscl(); 763 lanes.tscs[i].tv = min(tsc1, tsc2); 575 unsigned long long tsc = ts(lanes.data[i]); 576 lanes.tscs[i].tv = tsc != 0 ? tsc : rdtscl(); 764 577 } 765 578 #endif 766 579 } 767 580 768 #if defined(USE_CPU_WORK_STEALING) 769 // ready_queue size is fixed in this case 770 void ready_queue_grow(struct cluster * cltr) {} 771 void ready_queue_shrink(struct cluster * cltr) {} 772 #else 773 // Grow the ready queue 774 void ready_queue_grow(struct cluster * cltr) { 775 size_t ncount; 776 int target = cltr->procs.total; 777 778 /* paranoid */ verify( ready_mutate_islocked() ); 779 __cfadbg_print_safe(ready_queue, "Kernel : Growing ready queue\n"); 780 781 // Make sure that everything is consistent 782 /* paranoid */ check( cltr->ready_queue ); 783 784 // grow the ready queue 785 with( cltr->ready_queue ) { 786 // Find new count 787 // Make sure we always have atleast 1 list 788 if(target >= 2) { 789 ncount = target * READYQ_SHARD_FACTOR; 790 } else { 791 ncount = SEQUENTIAL_SHARD; 581 // Grow the ready queue 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 792 674 } 793 675 794 // Allocate new array (uses realloc and memcpies the data) 795 lanes.data = alloc( ncount, lanes.data`realloc ); 796 797 // Fix the moved data 798 for( idx; (size_t)lanes.count ) { 799 fix(lanes.data[idx]); 800 } 801 802 // Construct new data 803 for( idx; (size_t)lanes.count ~ ncount) { 804 (lanes.data[idx]){}; 805 } 806 807 // Update original 808 lanes.count = ncount; 809 } 810 811 fix_times(cltr); 812 813 reassign_cltr_id(cltr); 814 815 // Make sure that everything is consistent 816 /* paranoid */ check( cltr->ready_queue ); 817 818 __cfadbg_print_safe(ready_queue, "Kernel : Growing ready queue done\n"); 819 820 /* paranoid */ verify( ready_mutate_islocked() ); 821 } 822 823 // Shrink the ready queue 824 void ready_queue_shrink(struct cluster * cltr) { 825 /* paranoid */ verify( ready_mutate_islocked() ); 826 __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue\n"); 827 828 // Make sure that everything is consistent 829 /* paranoid */ check( cltr->ready_queue ); 830 831 int target = cltr->procs.total; 832 833 with( cltr->ready_queue ) { 834 // Remember old count 835 size_t ocount = lanes.count; 836 837 // Find new count 838 // Make sure we always have atleast 1 list 839 lanes.count = target >= 2 ? target * READYQ_SHARD_FACTOR: SEQUENTIAL_SHARD; 840 /* paranoid */ verify( ocount >= lanes.count ); 841 /* paranoid */ verify( lanes.count == target * READYQ_SHARD_FACTOR || target < 2 ); 842 843 // for printing count the number of displaced threads 844 #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_READY_QUEUE__) 845 __attribute__((unused)) size_t displaced = 0; 846 #endif 847 848 // redistribute old data 849 for( idx; (size_t)lanes.count ~ ocount) { 850 // Lock is not strictly needed but makes checking invariants much easier 851 __attribute__((unused)) bool locked = __atomic_try_acquire(&lanes.data[idx].lock); 852 verify(locked); 853 854 // As long as we can pop from this lane to push the threads somewhere else in the queue 855 while(!is_empty(lanes.data[idx])) { 856 struct $thread * thrd; 857 unsigned long long _; 858 [thrd, _] = pop(lanes.data[idx]); 859 860 push(cltr, thrd, true); 861 862 // for printing count the number of displaced threads 863 #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_READY_QUEUE__) 864 displaced++; 865 #endif 866 } 867 868 // Unlock the lane 869 __atomic_unlock(&lanes.data[idx].lock); 870 871 // TODO print the queue statistics here 872 873 ^(lanes.data[idx]){}; 874 } 875 876 __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue displaced %zu threads\n", displaced); 877 878 // Allocate new array (uses realloc and memcpies the data) 879 lanes.data = alloc( lanes.count, lanes.data`realloc ); 880 881 // Fix the moved data 882 for( idx; (size_t)lanes.count ) { 883 fix(lanes.data[idx]); 884 } 885 } 886 887 fix_times(cltr); 888 889 reassign_cltr_id(cltr); 890 891 // Make sure that everything is consistent 892 /* paranoid */ check( cltr->ready_queue ); 893 894 __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue done\n"); 895 /* paranoid */ verify( ready_mutate_islocked() ); 896 } 897 #endif 676 // Unlock the lane 677 __atomic_unlock(&lanes.data[idx].lock); 678 679 // TODO print the queue statistics here 680 681 ^(lanes.data[idx]){}; 682 } 683 684 __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue displaced %zu threads\n", displaced); 685 686 // Allocate new array (uses realloc and memcpies the data) 687 lanes.data = alloc( lanes.count, lanes.data`realloc ); 688 689 // Fix the moved data 690 for( idx; (size_t)lanes.count ) { 691 fix(lanes.data[idx]); 692 } 693 } 694 695 fix_times(cltr); 696 697 reassign_cltr_id(cltr); 698 699 // Make sure that everything is consistent 700 /* paranoid */ check( cltr->ready_queue ); 701 702 __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue done\n"); 703 /* paranoid */ verify( ready_mutate_islocked() ); 704 } 898 705 899 706 #if !defined(__CFA_NO_STATISTICS__) … … 903 710 } 904 711 #endif 905 906 907 #if defined(CFA_HAVE_LINUX_LIBRSEQ)908 // No definition needed909 #elif defined(CFA_HAVE_LINUX_RSEQ_H)910 911 #if defined( __x86_64 ) || defined( __i386 )912 #define RSEQ_SIG 0x53053053913 #elif defined( __ARM_ARCH )914 #ifdef __ARMEB__915 #define RSEQ_SIG 0xf3def5e7 /* udf #24035 ; 0x5de3 (ARMv6+) */916 #else917 #define RSEQ_SIG 0xe7f5def3 /* udf #24035 ; 0x5de3 */918 #endif919 #endif920 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 #else960 // No definition needed961 #endif -
libcfa/src/concurrency/ready_subqueue.hfa
r660665f r5a46e09 32 32 this.prev = mock_head(this); 33 33 this.anchor.next = 0p; 34 this.anchor.ts = -1llu;34 this.anchor.ts = 0; 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 == -1llu);46 /* paranoid */ verify( mock_head(this)->link.ts == 0 ); 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 == -1llu);57 /* paranoid */ verify( this.anchor.ts == 0 ); 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 == -1llu);66 /* paranoid */ verify( node->link.ts == 0 ); 67 67 /* paranoid */ verify( this.prev->link.next == 0p ); 68 /* paranoid */ verify( this.prev->link.ts == -1llu);68 /* paranoid */ verify( this.prev->link.ts == 0 ); 69 69 if( this.anchor.next == 0p ) { 70 70 /* paranoid */ verify( this.anchor.next == 0p ); 71 /* paranoid */ verify( this.anchor.ts == -1llu ); 72 /* paranoid */ verify( this.anchor.ts != 0 ); 71 /* paranoid */ verify( this.anchor.ts == 0 ); 73 72 /* paranoid */ verify( this.prev == mock_head( this ) ); 74 73 } else { 75 74 /* paranoid */ verify( this.anchor.next != 0p ); 76 /* paranoid */ verify( this.anchor.ts != -1llu );77 75 /* paranoid */ verify( this.anchor.ts != 0 ); 78 76 /* paranoid */ verify( this.prev != mock_head( this ) ); … … 94 92 /* paranoid */ verify( this.lock ); 95 93 /* paranoid */ verify( this.anchor.next != 0p ); 96 /* paranoid */ verify( this.anchor.ts != -1llu );97 94 /* paranoid */ verify( this.anchor.ts != 0 ); 98 95 … … 102 99 this.anchor.next = node->link.next; 103 100 this.anchor.ts = node->link.ts; 104 bool is_empty = this.anchor. next == 0p;101 bool is_empty = this.anchor.ts == 0; 105 102 node->link.next = 0p; 106 node->link.ts = -1llu;103 node->link.ts = 0; 107 104 #if !defined(__CFA_NO_STATISTICS__) 108 105 this.cnt--; … … 113 110 114 111 /* paranoid */ verify( node->link.next == 0p ); 115 /* paranoid */ verify( node->link.ts == -1llu ); 116 /* paranoid */ verify( node->link.ts != 0 ); 117 /* paranoid */ verify( this.anchor.ts != 0 ); 112 /* paranoid */ verify( node->link.ts == 0 ); 118 113 return [node, ts]; 119 114 } … … 121 116 // Check whether or not list is empty 122 117 static inline bool is_empty(__intrusive_lane_t & this) { 123 return this.anchor. next == 0p;118 return this.anchor.ts == 0; 124 119 } 125 120 … … 127 122 static inline unsigned long long ts(__intrusive_lane_t & this) { 128 123 // Cannot verify here since it may not be locked 129 /* paranoid */ verify(this.anchor.ts != 0);130 124 return this.anchor.ts; 131 125 } -
libcfa/src/concurrency/thread.cfa
r660665f r5a46e09 15 15 16 16 #define __cforall_thread__ 17 #define _GNU_SOURCE18 17 19 18 #include "thread.hfa" … … 40 39 curr_cluster = &cl; 41 40 link.next = 0p; 42 link.ts = -1llu;41 link.ts = 0; 43 42 preferred = -1u; 44 43 last_proc = 0p; -
libcfa/src/containers/array.hfa
r660665f r5a46e09 1 1 2 2 3 forall( __CFA_tysys_id_only_X & ) struct tag {}; 3 // a type whose size is n 4 #define Z(n) char[n] 5 6 // the inverse of Z(-) 7 #define z(N) sizeof(N) 8 9 forall( T & ) struct tag {}; 4 10 #define ttag(T) ((tag(T)){}) 5 #define ztag(n) ttag( n)11 #define ztag(n) ttag(Z(n)) 6 12 7 13 … … 12 18 forall( [N], S & | sized(S), Timmed &, Tbase & ) { 13 19 struct arpk { 14 S strides[ N];20 S strides[z(N)]; 15 21 }; 16 22 … … 50 56 51 57 static inline size_t ?`len( arpk(N, S, Timmed, Tbase) & a ) { 52 return N;58 return z(N); 53 59 } 54 60 55 61 // workaround #226 (and array relevance thereof demonstrated in mike102/otype-slow-ndims.cfa) 56 62 static inline void ?{}( arpk(N, S, Timmed, Tbase) & this ) { 57 void ?{}( S (&inner)[ N] ) {}63 void ?{}( S (&inner)[z(N)] ) {} 58 64 ?{}(this.strides); 59 65 } 60 66 static inline void ^?{}( arpk(N, S, Timmed, Tbase) & this ) { 61 void ^?{}( S (&inner)[ N] ) {}67 void ^?{}( S (&inner)[z(N)] ) {} 62 68 ^?{}(this.strides); 63 69 } … … 137 143 // Base 138 144 forall( [Nq], Sq & | sized(Sq), Tbase & ) 139 static inline tag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) { 140 tag(arpk(Nq, Sq, Tbase, Tbase)) ret; 141 return ret; 142 } 145 static inline tag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) {} 143 146 144 147 // Rec 145 148 forall( [Nq], Sq & | sized(Sq), [N], S & | sized(S), recq &, recr &, Tbase & | { tag(recr) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(recq) ); } ) 146 static inline tag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) { 147 tag(arpk(N, S, recr, Tbase)) ret; 148 return ret; 149 } 149 static inline tag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) {} 150 150 151 151 // Wrapper -
libcfa/src/exception.c
r660665f r5a46e09 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 working 32 #ifndef _URC_FATAL_PHASE1_ERROR 33 #define _URC_FATAL_PHASE1_ERROR 3 34 #endif // ! _URC_FATAL_PHASE1_ERROR 35 #ifndef _URC_FATAL_PHASE2_ERROR 36 #define _URC_FATAL_PHASE2_ERROR 2 37 #endif // ! _URC_FATAL_PHASE2_ERROR 38 #endif // __ARM_ARCH 39 29 40 #include "lsda.h" 30 41 … … 256 267 // the whole stack. 257 268 258 #if defined( __x86_64 ) || defined( __i386 )259 269 // We did not simply reach the end of the stack without finding a handler. This is an error. 260 270 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 #endif266 271 printf("UNWIND ERROR %d after raise exception\n", ret); 267 272 abort(); … … 296 301 } 297 302 298 #if defined( __x86_64 ) || defined( __i386 ) || defined( __ARM_ARCH )303 #if defined( __x86_64 ) || defined( __i386 ) 299 304 // This is our personality routine. For every stack frame annotated with 300 305 // ".cfi_personality 0x3,__gcfa_personality_v0" this function will be called twice when unwinding. … … 414 419 _Unwind_GetCFA(unwind_context) + 24; 415 420 # elif defined( __ARM_ARCH ) 416 _Unwind_GetCFA(unwind_context) + 40; 421 # warning FIX ME: check if anything needed for ARM 422 42; 417 423 # endif 418 424 int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos; … … 531 537 // HEADER 532 538 ".LFECFA1:\n" 533 #if defined( __x86_64 ) || defined( __i386 )534 539 " .globl __gcfa_personality_v0\n" 535 #else // defined( __ARM_ARCH )536 " .global __gcfa_personality_v0\n"537 #endif538 540 " .section .gcc_except_table,\"a\",@progbits\n" 539 541 // TABLE HEADER (important field is the BODY length at the end) … … 567 569 // No clue what this does specifically 568 570 " .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 )570 571 " .align 8\n" 571 #else // defined( __ARM_ARCH )572 " .align 3\n"573 #endif574 572 " .type CFA.ref.__gcfa_personality_v0, @object\n" 575 573 " .size CFA.ref.__gcfa_personality_v0, 8\n" … … 577 575 #if defined( __x86_64 ) 578 576 " .quad __gcfa_personality_v0\n" 579 #el if defined( __i386 )577 #else // then __i386 580 578 " .long __gcfa_personality_v0\n" 581 #else // defined( __ARM_ARCH )582 " .xword __gcfa_personality_v0\n"583 579 #endif 584 580 ); … … 587 583 // HEADER 588 584 ".LFECFA1:\n" 589 #if defined( __x86_64 ) || defined( __i386 )590 585 " .globl __gcfa_personality_v0\n" 591 #else // defined( __ARM_ARCH )592 " .global __gcfa_personality_v0\n"593 #endif594 586 " .section .gcc_except_table,\"a\",@progbits\n" 595 587 // TABLE HEADER (important field is the BODY length at the end) … … 620 612 #pragma GCC pop_options 621 613 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 } 622 629 #else 623 630 #error unsupported hardware architecture 624 #endif // __x86_64 || __i386 || __ARM_ARCH631 #endif // __x86_64 || __i386 -
libcfa/src/interpose.cfa
r660665f r5a46e09 95 95 96 96 extern "C" { 97 void __cfaabi_interpose_startup(void) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) )); 97 98 void __cfaabi_interpose_startup( void ) { 98 99 const char *version = 0p; -
libcfa/src/startup.cfa
r660665f r5a46e09 20 20 21 21 extern "C" { 22 void __cfaabi_appready_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_APPREADY ) ));23 void __cfaabi_appready_startup( void ) {22 void __cfaabi_appready_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_APPREADY ) )); 23 void __cfaabi_appready_startup( void ) { 24 24 tzset(); // initialize time global variables 25 25 setlocale( LC_NUMERIC, getenv("LANG") ); … … 28 28 heapAppStart(); 29 29 #endif // __CFA_DEBUG__ 30 } // __cfaabi_appready_startup30 } // __cfaabi_appready_startup 31 31 32 void __cfaabi_appready_shutdown( void ) __attribute__(( destructor( STARTUP_PRIORITY_APPREADY ) ));33 void __cfaabi_appready_shutdown( void ) {32 void __cfaabi_appready_shutdown( void ) __attribute__(( destructor( STARTUP_PRIORITY_APPREADY ) )); 33 void __cfaabi_appready_shutdown( void ) { 34 34 #ifdef __CFA_DEBUG__ 35 35 extern void heapAppStop(); 36 36 heapAppStop(); 37 37 #endif // __CFA_DEBUG__ 38 } // __cfaabi_appready_shutdown38 } // __cfaabi_appready_shutdown 39 39 40 void disable_interrupts() __attribute__(( weak )) {} 41 void enable_interrupts() __attribute__(( weak )) {} 42 43 44 extern void __cfaabi_interpose_startup( void ); 45 extern void __cfaabi_device_startup ( void ); 46 extern void __cfaabi_device_shutdown ( void ); 47 48 void __cfaabi_core_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) )); 49 void __cfaabi_core_startup( void ) { 50 __cfaabi_interpose_startup(); 51 __cfaabi_device_startup(); 52 } // __cfaabi_core_startup 53 54 void __cfaabi_core_shutdown( void ) __attribute__(( destructor( STARTUP_PRIORITY_CORE ) )); 55 void __cfaabi_core_shutdown( void ) { 56 __cfaabi_device_shutdown(); 57 } // __cfaabi_core_shutdown 40 void disable_interrupts() __attribute__(( weak )) {} 41 void enable_interrupts() __attribute__(( weak )) {} 58 42 } // extern "C" 59 43 -
src/AST/Convert.cpp
r660665f r5a46e09 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 error2420 // detection helps ensure that these occurrences have been compiled2421 // away, as expected. To move the DimensionExpr boundary downstream2422 // or move the new-AST translation boundary upstream, implement2423 // 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 2428 2417 virtual void visit( const AsmExpr * old ) override final { 2429 2418 this->node = visitBaseExpr( old, -
src/AST/Decl.cpp
r660665f r5a46e09 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 length value" };80 static const char * kindNames[] = { "sized data type", "sized data type", "sized object type", "sized function type", "sized tuple type", "sized array length type" }; 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
r660665f r5a46e09 175 175 class TypeDecl final : public NamedTypeDecl { 176 176 public: 177 enum Kind { Dtype, DStype, Otype, Ftype, Ttype, Dimension, NUMBER_OF_KINDS };177 enum Kind { Dtype, DStype, Otype, Ftype, Ttype, ALtype, NUMBER_OF_KINDS }; 178 178 179 179 Kind kind; -
src/AST/Pass.impl.hpp
r660665f r5a46e09 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 ); 526 maybe_accept( node, &StructDecl::attributes ); 524 maybe_accept( node, &StructDecl::params ); 525 maybe_accept( node, &StructDecl::members ); 527 526 }) 528 527 … … 544 543 VISIT({ 545 544 guard_symtab guard { * this }; 546 maybe_accept( node, &UnionDecl::params ); 547 maybe_accept( node, &UnionDecl::members ); 548 maybe_accept( node, &UnionDecl::attributes ); 545 maybe_accept( node, &UnionDecl::params ); 546 maybe_accept( node, &UnionDecl::members ); 549 547 }) 550 548 … … 564 562 VISIT( 565 563 // unlike structs, traits, and unions, enums inject their members into the global scope 566 maybe_accept( node, &EnumDecl::params ); 567 maybe_accept( node, &EnumDecl::members ); 568 maybe_accept( node, &EnumDecl::attributes ); 564 maybe_accept( node, &EnumDecl::params ); 565 maybe_accept( node, &EnumDecl::members ); 569 566 ) 570 567 … … 580 577 VISIT({ 581 578 guard_symtab guard { *this }; 582 maybe_accept( node, &TraitDecl::params ); 583 maybe_accept( node, &TraitDecl::members ); 584 maybe_accept( node, &TraitDecl::attributes ); 579 maybe_accept( node, &TraitDecl::params ); 580 maybe_accept( node, &TraitDecl::members ); 585 581 }) 586 582 -
src/CodeGen/CodeGenerator.cc
r660665f r5a46e09 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();596 591 } 597 592 -
src/CodeGen/CodeGenerator.h
r660665f r5a46e09 92 92 void postvisit( TupleIndexExpr * tupleExpr ); 93 93 void postvisit( TypeExpr *typeExpr ); 94 void postvisit( DimensionExpr *dimensionExpr );95 94 void postvisit( AsmExpr * ); 96 95 void postvisit( StmtExpr * ); -
src/Common/PassVisitor.h
r660665f r5a46e09 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;171 169 virtual void visit( AsmExpr * asmExpr ) override final; 172 170 virtual void visit( const AsmExpr * asmExpr ) override final; … … 311 309 virtual Expression * mutate( CommaExpr * commaExpr ) override final; 312 310 virtual Expression * mutate( TypeExpr * typeExpr ) override final; 313 virtual Expression * mutate( DimensionExpr * dimensionExpr ) override final;314 311 virtual Expression * mutate( AsmExpr * asmExpr ) override final; 315 312 virtual Expression * mutate( ImplicitCopyCtorExpr * impCpCtorExpr ) override final; … … 545 542 class WithIndexer { 546 543 protected: 547 WithIndexer( bool trackIdentifiers = true ) : indexer(trackIdentifiers) {}544 WithIndexer() {} 548 545 ~WithIndexer() {} 549 546 -
src/Common/PassVisitor.impl.h
r660665f r5a46e09 636 636 maybeAccept_impl( node->parameters, *this ); 637 637 maybeAccept_impl( node->members , *this ); 638 maybeAccept_impl( node->attributes, *this );639 638 } 640 639 … … 657 656 maybeAccept_impl( node->parameters, *this ); 658 657 maybeAccept_impl( node->members , *this ); 659 maybeAccept_impl( node->attributes, *this );660 658 } 661 659 … … 678 676 maybeMutate_impl( node->parameters, *this ); 679 677 maybeMutate_impl( node->members , *this ); 680 maybeMutate_impl( node->attributes, *this );681 678 } 682 679 … … 700 697 maybeAccept_impl( node->parameters, *this ); 701 698 maybeAccept_impl( node->members , *this ); 702 maybeAccept_impl( node->attributes, *this );703 699 } 704 700 … … 718 714 maybeAccept_impl( node->parameters, *this ); 719 715 maybeAccept_impl( node->members , *this ); 720 maybeAccept_impl( node->attributes, *this );721 716 } 722 717 … … 737 732 maybeMutate_impl( node->parameters, *this ); 738 733 maybeMutate_impl( node->members , *this ); 739 maybeMutate_impl( node->attributes, *this );740 734 } 741 735 … … 756 750 maybeAccept_impl( node->parameters, *this ); 757 751 maybeAccept_impl( node->members , *this ); 758 maybeAccept_impl( node->attributes, *this );759 752 760 753 VISIT_END( node ); … … 770 763 maybeAccept_impl( node->parameters, *this ); 771 764 maybeAccept_impl( node->members , *this ); 772 maybeAccept_impl( node->attributes, *this );773 765 774 766 VISIT_END( node ); … … 784 776 maybeMutate_impl( node->parameters, *this ); 785 777 maybeMutate_impl( node->members , *this ); 786 maybeMutate_impl( node->attributes, *this );787 778 788 779 MUTATE_END( Declaration, node ); … … 799 790 maybeAccept_impl( node->parameters, *this ); 800 791 maybeAccept_impl( node->members , *this ); 801 maybeAccept_impl( node->attributes, *this );802 792 } 803 793 … … 815 805 maybeAccept_impl( node->parameters, *this ); 816 806 maybeAccept_impl( node->members , *this ); 817 maybeAccept_impl( node->attributes, *this );818 807 } 819 808 … … 831 820 maybeMutate_impl( node->parameters, *this ); 832 821 maybeMutate_impl( node->members , *this ); 833 maybeMutate_impl( node->attributes, *this );834 822 } 835 823 … … 2519 2507 2520 2508 //-------------------------------------------------------------------------- 2521 // DimensionExpr2522 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 //--------------------------------------------------------------------------2551 2509 // AsmExpr 2552 2510 template< typename pass_type > … … 3187 3145 3188 3146 maybeAccept_impl( node->forall, *this ); 3189 maybeAccept_impl( node->dimension, *this );3147 // xxx - should PointerType visit/mutate dimension? 3190 3148 maybeAccept_impl( node->base, *this ); 3191 3149 … … 3198 3156 3199 3157 maybeAccept_impl( node->forall, *this ); 3200 maybeAccept_impl( node->dimension, *this );3158 // xxx - should PointerType visit/mutate dimension? 3201 3159 maybeAccept_impl( node->base, *this ); 3202 3160 … … 3209 3167 3210 3168 maybeMutate_impl( node->forall, *this ); 3211 maybeMutate_impl( node->dimension, *this );3169 // xxx - should PointerType visit/mutate dimension? 3212 3170 maybeMutate_impl( node->base, *this ); 3213 3171 … … 3898 3856 3899 3857 //-------------------------------------------------------------------------- 3900 // Constant3858 // Attribute 3901 3859 template< typename pass_type > 3902 3860 void PassVisitor< pass_type >::visit( Constant * node ) { -
src/InitTweak/InitTweak.cc
r660665f r5a46e09 10 10 // Created On : Fri May 13 11:26:36 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 16 20:57:22 202113 // Update Count : 1812 // Last Modified On : Fri Dec 13 23:15:52 2019 13 // Update Count : 8 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 #if defined( __x86_64 ) || defined( __i386 ) // assembler comment to prevent assembler warning message 1221 "#" 1222 #else // defined( __ARM_ARCH ) 1223 "//" 1224 #endif 1225 ))})); 1219 new ConstantExpr( Constant::from_string(".data#") ), 1220 })); 1226 1221 } 1227 1222 1228 1223 void addDataSectionAttribute( ast::ObjectDecl * objDecl ) { 1229 1224 objDecl->attributes.push_back(new ast::Attribute("section", { 1230 ast::ConstantExpr::from_string(objDecl->location, ".data" 1231 #if defined( __x86_64 ) || defined( __i386 ) // assembler comment to prevent assembler warning message 1232 "#" 1233 #else // defined( __ARM_ARCH ) 1234 "//" 1235 #endif 1236 )})); 1225 ast::ConstantExpr::from_string(objDecl->location, ".data#"), 1226 })); 1237 1227 } 1238 1228 -
src/Parser/DeclarationNode.cc
r660665f r5a46e09 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 type, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::Dimension};1078 static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::DStype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::Dtype }; 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:: DStype, variable.initializer ? variable.initializer->buildType() : nullptr );1081 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype || variable.tyClass == TypeDecl::ALtype, variable.initializer ? variable.initializer->buildType() : nullptr ); 1082 1082 buildList( variable.assertions, ret->get_assertions() ); 1083 1083 return ret; -
src/Parser/ExpressionNode.cc
r660665f r5a46e09 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_varref516 511 // TODO: get rid of this and OperKinds and reuse code from OperatorTable 517 512 static const char * OperName[] = { // must harmonize with OperKinds -
src/Parser/ParseNode.h
r660665f r5a46e09 183 183 184 184 NameExpr * build_varref( const std::string * name ); 185 DimensionExpr * build_dimensionref( const std::string * name );186 185 187 186 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); -
src/Parser/TypedefTable.cc
r660665f r5a46e09 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 19 08:30:14202113 // Update Count : 26 212 // Last Modified On : Mon Mar 15 20:56:47 2021 13 // Update Count : 260 14 14 // 15 15 … … 31 31 switch ( kind ) { 32 32 case IDENTIFIER: return "identifier"; 33 case TYPEDIMname: return "typedim";34 33 case TYPEDEFname: return "typedef"; 35 34 case TYPEGENname: return "typegen"; -
src/Parser/lex.ll
r660665f r5a46e09 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Sun Jun 20 18:41:09202113 * Update Count : 75 912 * Last Modified On : Thu Apr 1 13:22:31 2021 13 * Update Count : 754 14 14 */ 15 15 … … 117 117 hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt} 118 118 119 // GCC: floating D (double), imaginary iI, and decimal floating DF, DD, DL119 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 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 decimal_floating_suffix [dD][fFdDlL] 125 floating_suffix_opt ("_"?({floating_suffix}|{decimal_floating_suffix}))? 124 floating_suffix_opt ("_"?({floating_suffix}|"DL"))? 126 125 decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal}) 127 126 floating_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt} … … 235 234 continue { KEYWORD_RETURN(CONTINUE); } 236 235 coroutine { KEYWORD_RETURN(COROUTINE); } // CFA 237 _Decimal32 { KEYWORD_RETURN(DECIMAL32); } // GCC238 _Decimal64 { KEYWORD_RETURN(DECIMAL64); } // GCC239 _Decimal128 { KEYWORD_RETURN(DECIMAL128); } // GCC240 236 default { KEYWORD_RETURN(DEFAULT); } 241 237 disable { KEYWORD_RETURN(DISABLE); } // CFA -
src/Parser/parser.yy
r660665f r5a46e09 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 29 09:12:47202113 // Update Count : 502712 // Last Modified On : Mon Apr 26 18:41:54 2021 13 // Update Count : 4990 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 // designation with '=' (use ':' instead) 29 // 30 // This incompatibility is discussed in detail before the "designation" grammar rule. Most of the syntactic extensions 31 // from ANSI90 to ANSI11 C are marked with the comment "C99/C11". 32 33 // This grammar also has two levels of extensions. The first extensions cover most of the GCC C extensions All of the 34 // syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall (CFA), which 35 // fixes several of C's outstanding problems and extends C with many modern language concepts. All of the syntactic 36 // extensions for CFA C are marked with the comment "CFA". 28 // 1. designation with '=' (use ':' instead) 29 // 30 // Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This grammar also has 31 // two levels of extensions. The first extensions cover most of the GCC C extensions, except for: 32 // 33 // 1. designation with and without '=' (use ':' instead) 34 35 // 36 // All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall 37 // (CFA), which fixes several of C's outstanding problems and extends C with many modern language concepts. All of the 38 // syntactic extensions for CFA C are marked with the comment "CFA". As noted above, there is one unreconcileable 39 // parsing problem between C99 and CFA with respect to designators; this is discussed in detail before the "designation" 40 // grammar rule. 37 41 38 42 %{ … … 265 269 %token INT128 UINT128 uuFLOAT80 uuFLOAT128 // GCC 266 270 %token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC 267 %token DECIMAL32 DECIMAL64 DECIMAL128 // GCC268 271 %token ZERO_T ONE_T // CFA 269 272 %token SIZEOF TYPEOF VALIST AUTO_TYPE // GCC … … 284 287 285 288 // names and constants: lexer differentiates between identifier and typedef names 286 %token<tok> IDENTIFIER QUOTED_IDENTIFIER TYPED IMname TYPEDEFname TYPEGENname289 %token<tok> IDENTIFIER QUOTED_IDENTIFIER TYPEDEFname TYPEGENname 287 290 %token<tok> TIMEOUT WOR CATCH RECOVER CATCHRESUME FIXUP FINALLY // CFA 288 291 %token<tok> INTEGERconstant CHARACTERconstant STRINGliteral … … 583 586 | quasi_keyword 584 587 { $$ = new ExpressionNode( build_varref( $1 ) ); } 585 | TYPEDIMname // CFA, generic length argument586 // { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( DeclarationNode::newFromTypedef( $1 ) ) ) ); }587 // { $$ = new ExpressionNode( build_varref( $1 ) ); }588 { $$ = new ExpressionNode( build_dimensionref( $1 ) ); }589 588 | tuple 590 589 | '(' comma_expression ')' … … 631 630 postfix_expression: 632 631 primary_expression 633 | postfix_expression '[' assignment_expression ',' tuple_expression_list ']' 634 // Historic, transitional: Disallow commas in subscripts. 635 // Switching to this behaviour may help check if a C compatibilty case uses comma-exprs in subscripts. 636 // { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; } 637 // Current: Commas in subscripts make tuples. 638 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $5 ) ) )) ) ); } 632 | postfix_expression '[' assignment_expression ',' comma_expression ']' 633 // { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_binary_val( OperKinds::Index, $3, $5 ) ) ) ); } 634 { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; } 639 635 | postfix_expression '[' assignment_expression ']' 640 636 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a … … 1891 1887 | uFLOAT128 1892 1888 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat128 ); } 1893 | DECIMAL321894 { SemanticError( yylloc, "_Decimal32 is currently unimplemented." ); $$ = nullptr; }1895 | DECIMAL641896 { SemanticError( yylloc, "_Decimal64 is currently unimplemented." ); $$ = nullptr; }1897 | DECIMAL1281898 { SemanticError( yylloc, "_Decimal128 is currently unimplemented." ); $$ = nullptr; }1899 1889 | COMPLEX // C99 1900 1890 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); } … … 1919 1909 // empty 1920 1910 { $$ = nullptr; } 1921 | vtable 1911 | vtable; 1922 1912 ; 1923 1913 … … 2545 2535 | '[' identifier_or_type_name ']' 2546 2536 { 2547 typedefTable.addToScope( *$2, TYPED IMname, "9" );2548 $$ = DeclarationNode::newTypeParam( TypeDecl:: Dimension, $2 );2537 typedefTable.addToScope( *$2, TYPEDEFname, "9" ); 2538 $$ = DeclarationNode::newTypeParam( TypeDecl::ALtype, $2 ); 2549 2539 } 2550 2540 // | type_specifier identifier_parameter_declarator … … 2560 2550 | '*' 2561 2551 { $$ = TypeDecl::DStype; } // dtype + sized 2562 // | '(' '*' ')'2563 // { $$ = TypeDecl::Ftype; }2564 2552 | ELLIPSIS 2565 2553 { $$ = TypeDecl::Ttype; } … … 2602 2590 { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); } 2603 2591 | assignment_expression 2592 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; } 2604 2593 | type_list ',' type 2605 2594 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); } 2606 2595 | type_list ',' assignment_expression 2607 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2596 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } 2597 // { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2608 2598 ; 2609 2599 -
src/SymTab/Indexer.cc
r660665f r5a46e09 74 74 } 75 75 76 Indexer::Indexer( bool trackIdentifiers)76 Indexer::Indexer() 77 77 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 78 prevScope(), scope( 0 ), repScope( 0 ) , trackIdentifiers( trackIdentifiers ){ ++* stats().count; }78 prevScope(), scope( 0 ), repScope( 0 ) { ++* 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 114 112 ++* stats().lookup_calls; 115 113 if ( ! idTable ) return; … … 436 434 const Declaration * deleteStmt ) { 437 435 ++* stats().add_calls; 438 if ( ! trackIdentifiers ) return;439 436 const std::string &name = decl->name; 440 437 if ( name == "" ) return; -
src/SymTab/Indexer.h
r660665f r5a46e09 31 31 class Indexer : public std::enable_shared_from_this<SymTab::Indexer> { 32 32 public: 33 explicit Indexer( bool trackIdentifiers = true);33 explicit Indexer(); 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;184 182 }; 185 183 } // namespace SymTab -
src/SymTab/Validate.cc
r660665f r5a46e09 105 105 106 106 struct FixQualifiedTypes final : public WithIndexer { 107 FixQualifiedTypes() : WithIndexer(false) {}108 107 Type * postmutate( QualifiedType * ); 109 108 }; … … 175 174 }; 176 175 177 /// Does early resolution on the expressions that give enumeration constants their values178 struct ResolveEnumInitializers final : public WithIndexer, public WithGuards, public WithVisitorRef<ResolveEnumInitializers>, public WithShortCircuiting {179 ResolveEnumInitializers( const Indexer * indexer );180 void postvisit( EnumDecl * enumDecl );181 182 private:183 const Indexer * local_indexer;184 185 };186 187 176 /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID. 188 177 struct ForallPointerDecay_old final { … … 271 260 void previsit( StructInstType * inst ); 272 261 void previsit( UnionInstType * inst ); 273 };274 275 /// desugar declarations and uses of dimension paramaters like [N],276 /// from type-system managed values, to tunnneling via ordinary types,277 /// as char[-] in and sizeof(-) out278 struct TranslateDimensionGenericParameters : public WithIndexer, public WithGuards {279 static void translateDimensions( std::list< Declaration * > &translationUnit );280 TranslateDimensionGenericParameters();281 282 bool nextVisitedNodeIsChildOfSUIT = false; // SUIT = Struct or Union -Inst Type283 bool visitingChildOfSUIT = false;284 void changeState_ChildOfSUIT( bool newVal );285 void premutate( StructInstType * sit );286 void premutate( UnionInstType * uit );287 void premutate( BaseSyntaxNode * node );288 289 TypeDecl * postmutate( TypeDecl * td );290 Expression * postmutate( DimensionExpr * de );291 Expression * postmutate( Expression * e );292 262 }; 293 263 … … 337 307 PassVisitor<EnumAndPointerDecay_old> epc; 338 308 PassVisitor<LinkReferenceToTypes_old> lrt( nullptr ); 339 PassVisitor<ResolveEnumInitializers> rei( nullptr );340 309 PassVisitor<ForallPointerDecay_old> fpd; 341 310 PassVisitor<CompoundLiteral> compoundliteral; … … 357 326 Stats::Heap::newPass("validate-B"); 358 327 Stats::Time::BlockGuard guard("validate-B"); 359 acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions 360 mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes_old, because aggregate members are accessed 361 HoistStruct::hoistStruct( translationUnit ); 362 EliminateTypedef::eliminateTypedef( translationUnit ); 328 Stats::Time::TimeBlock("Link Reference To Types", [&]() { 329 acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions 330 }); 331 Stats::Time::TimeBlock("Fix Qualified Types", [&]() { 332 mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes_old, because aggregate members are accessed 333 }); 334 Stats::Time::TimeBlock("Hoist Structs", [&]() { 335 HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order 336 }); 337 Stats::Time::TimeBlock("Eliminate Typedefs", [&]() { 338 EliminateTypedef::eliminateTypedef( translationUnit ); // 339 }); 363 340 } 364 341 { 365 342 Stats::Heap::newPass("validate-C"); 366 343 Stats::Time::BlockGuard guard("validate-C"); 367 Stats::Time::TimeBlock("Validate Generic Parameters", [&]() { 368 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes_old; observed failing when attempted before eliminateTypedef 369 }); 370 Stats::Time::TimeBlock("Translate Dimensions", [&]() { 371 TranslateDimensionGenericParameters::translateDimensions( translationUnit ); 372 }); 373 Stats::Time::TimeBlock("Resolve Enum Initializers", [&]() { 374 acceptAll( translationUnit, rei ); // must happen after translateDimensions because rei needs identifier lookup, which needs name mangling 375 }); 376 Stats::Time::TimeBlock("Check Function Returns", [&]() { 377 ReturnChecker::checkFunctionReturns( translationUnit ); 378 }); 379 Stats::Time::TimeBlock("Fix Return Statements", [&]() { 380 InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen 381 }); 344 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes_old 345 ReturnChecker::checkFunctionReturns( translationUnit ); 346 InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen 382 347 } 383 348 { … … 679 644 } 680 645 681 LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer * other_indexer ) : WithIndexer( false ){646 LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer * other_indexer ) { 682 647 if ( other_indexer ) { 683 648 local_indexer = other_indexer; … … 699 664 } 700 665 666 void checkGenericParameters( ReferenceToType * inst ) { 667 for ( Expression * param : inst->parameters ) { 668 if ( ! dynamic_cast< TypeExpr * >( param ) ) { 669 SemanticError( inst, "Expression parameters for generic types are currently unsupported: " ); 670 } 671 } 672 } 673 701 674 void LinkReferenceToTypes_old::postvisit( StructInstType * structInst ) { 702 675 const StructDecl * st = local_indexer->lookupStruct( structInst->name ); … … 709 682 forwardStructs[ structInst->name ].push_back( structInst ); 710 683 } // if 684 checkGenericParameters( structInst ); 711 685 } 712 686 … … 721 695 forwardUnions[ unionInst->name ].push_back( unionInst ); 722 696 } // if 697 checkGenericParameters( unionInst ); 723 698 } 724 699 … … 832 807 forwardEnums.erase( fwds ); 833 808 } // if 809 810 for ( Declaration * member : enumDecl->members ) { 811 ObjectDecl * field = strict_dynamic_cast<ObjectDecl *>( member ); 812 if ( field->init ) { 813 // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information. 814 SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init ); 815 ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer ); 816 } 817 } 834 818 } // if 835 819 } … … 894 878 typeInst->set_isFtype( typeDecl->kind == TypeDecl::Ftype ); 895 879 } // if 896 } // if897 }898 899 ResolveEnumInitializers::ResolveEnumInitializers( const Indexer * other_indexer ) : WithIndexer( true ) {900 if ( other_indexer ) {901 local_indexer = other_indexer;902 } else {903 local_indexer = &indexer;904 } // if905 }906 907 void ResolveEnumInitializers::postvisit( EnumDecl * enumDecl ) {908 if ( enumDecl->body ) {909 for ( Declaration * member : enumDecl->members ) {910 ObjectDecl * field = strict_dynamic_cast<ObjectDecl *>( member );911 if ( field->init ) {912 // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information.913 SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init );914 ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );915 }916 }917 880 } // if 918 881 } … … 1189 1152 GuardScope( typedeclNames ); 1190 1153 mutateAll( aggr->parameters, * visitor ); 1191 mutateAll( aggr->attributes, * visitor );1192 1154 1193 1155 // unroll mutateAll for aggr->members so that implicit typedefs for nested types are added to the aggregate body. … … 1258 1220 } 1259 1221 } 1260 }1261 1262 // Test for special name on a generic parameter. Special treatment for the1263 // special name is a bootstrapping hack. In most cases, the worlds of T's1264 // and of N's don't overlap (normal treamtemt). The foundations in1265 // array.hfa use tagging for both types and dimensions. Tagging treats1266 // its subject parameter even more opaquely than T&, which assumes it is1267 // possible to have a pointer/reference to such an object. Tagging only1268 // seeks to identify the type-system resident at compile time. Both N's1269 // and T's can make tags. The tag definition uses the special name, which1270 // is treated as "an N or a T." This feature is not inteded to be used1271 // outside of the definition and immediate uses of a tag.1272 static inline bool isReservedTysysIdOnlyName( const std::string & name ) {1273 // name's prefix was __CFA_tysys_id_only, before it got wrapped in __..._generic1274 int foundAt = name.find("__CFA_tysys_id_only");1275 if (foundAt == 0) return true;1276 if (foundAt == 2 && name[0] == '_' && name[1] == '_') return true;1277 return false;1278 1222 } 1279 1223 … … 1294 1238 TypeSubstitution sub; 1295 1239 auto paramIter = params->begin(); 1296 auto argIter = args.begin(); 1297 for ( ; paramIter != params->end(); ++paramIter, ++argIter ) { 1298 if ( argIter != args.end() ) { 1299 TypeExpr * expr = dynamic_cast< TypeExpr * >( * argIter ); 1300 if ( expr ) { 1301 sub.add( (* paramIter)->get_name(), expr->get_type()->clone() ); 1302 } 1303 } else { 1240 for ( size_t i = 0; paramIter != params->end(); ++paramIter, ++i ) { 1241 if ( i < args.size() ) { 1242 TypeExpr * expr = strict_dynamic_cast< TypeExpr * >( * std::next( args.begin(), i ) ); 1243 sub.add( (* paramIter)->get_name(), expr->get_type()->clone() ); 1244 } else if ( i == args.size() ) { 1304 1245 Type * defaultType = (* paramIter)->get_init(); 1305 1246 if ( defaultType ) { 1306 1247 args.push_back( new TypeExpr( defaultType->clone() ) ); 1307 1248 sub.add( (* paramIter)->get_name(), defaultType->clone() ); 1308 argIter = std::prev(args.end());1309 } else {1310 SemanticError( inst, "Too few type arguments in generic type " );1311 1249 } 1312 1250 } 1313 assert( argIter != args.end() );1314 bool typeParamDeclared = (*paramIter)->kind != TypeDecl::Kind::Dimension;1315 bool typeArgGiven;1316 if ( isReservedTysysIdOnlyName( (*paramIter)->name ) ) {1317 // coerce a match when declaration is reserved name, which means "either"1318 typeArgGiven = typeParamDeclared;1319 } else {1320 typeArgGiven = dynamic_cast< TypeExpr * >( * argIter );1321 }1322 if ( ! typeParamDeclared && typeArgGiven ) SemanticError( inst, "Type argument given for value parameter: " );1323 if ( typeParamDeclared && ! typeArgGiven ) SemanticError( inst, "Expression argument given for type parameter: " );1324 1251 } 1325 1252 1326 1253 sub.apply( inst ); 1254 if ( args.size() < params->size() ) SemanticError( inst, "Too few type arguments in generic type " ); 1327 1255 if ( args.size() > params->size() ) SemanticError( inst, "Too many type arguments in generic type " ); 1328 1256 } … … 1335 1263 void ValidateGenericParameters::previsit( UnionInstType * inst ) { 1336 1264 validateGeneric( inst ); 1337 }1338 1339 void TranslateDimensionGenericParameters::translateDimensions( std::list< Declaration * > &translationUnit ) {1340 PassVisitor<TranslateDimensionGenericParameters> translator;1341 mutateAll( translationUnit, translator );1342 }1343 1344 TranslateDimensionGenericParameters::TranslateDimensionGenericParameters() : WithIndexer( false ) {}1345 1346 // Declaration of type variable: forall( [N] ) -> forall( N & | sized( N ) )1347 TypeDecl * TranslateDimensionGenericParameters::postmutate( TypeDecl * td ) {1348 if ( td->kind == TypeDecl::Dimension ) {1349 td->kind = TypeDecl::Dtype;1350 if ( ! isReservedTysysIdOnlyName( td->name ) ) {1351 td->sized = true;1352 }1353 }1354 return td;1355 }1356 1357 // Situational awareness:1358 // array( float, [[currentExpr]] ) has visitingChildOfSUIT == true1359 // array( float, [[currentExpr]] - 1 ) has visitingChildOfSUIT == false1360 // size_t x = [[currentExpr]] has visitingChildOfSUIT == false1361 void TranslateDimensionGenericParameters::changeState_ChildOfSUIT( bool newVal ) {1362 GuardValue( nextVisitedNodeIsChildOfSUIT );1363 GuardValue( visitingChildOfSUIT );1364 visitingChildOfSUIT = nextVisitedNodeIsChildOfSUIT;1365 nextVisitedNodeIsChildOfSUIT = newVal;1366 }1367 void TranslateDimensionGenericParameters::premutate( StructInstType * sit ) {1368 (void) sit;1369 changeState_ChildOfSUIT(true);1370 }1371 void TranslateDimensionGenericParameters::premutate( UnionInstType * uit ) {1372 (void) uit;1373 changeState_ChildOfSUIT(true);1374 }1375 void TranslateDimensionGenericParameters::premutate( BaseSyntaxNode * node ) {1376 (void) node;1377 changeState_ChildOfSUIT(false);1378 }1379 1380 // Passing values as dimension arguments: array( float, 7 ) -> array( float, char[ 7 ] )1381 // Consuming dimension parameters: size_t x = N - 1 ; -> size_t x = sizeof(N) - 1 ;1382 // Intertwined reality: array( float, N ) -> array( float, N )1383 // array( float, N - 1 ) -> array( float, char[ sizeof(N) - 1 ] )1384 // Intertwined case 1 is not just an optimization.1385 // Avoiding char[sizeof(-)] is necessary to enable the call of f to bind the value of N, in:1386 // forall([N]) void f( array(float, N) & );1387 // array(float, 7) a;1388 // f(a);1389 1390 Expression * TranslateDimensionGenericParameters::postmutate( DimensionExpr * de ) {1391 // Expression de is an occurrence of N in LHS of above examples.1392 // Look up the name that de references.1393 // If we are in a struct body, then this reference can be to an entry of the stuct's forall list.1394 // Whether or not we are in a struct body, this reference can be to an entry of a containing function's forall list.1395 // If we are in a struct body, then the stuct's forall declarations are innermost (functions don't occur in structs).1396 // Thus, a potential struct's declaration is highest priority.1397 // A struct's forall declarations are already renamed with _generic_ suffix. Try that name variant first.1398 1399 std::string useName = "__" + de->name + "_generic_";1400 TypeDecl * namedParamDecl = const_cast<TypeDecl *>( strict_dynamic_cast<const TypeDecl *, nullptr >( indexer.lookupType( useName ) ) );1401 1402 if ( ! namedParamDecl ) {1403 useName = de->name;1404 namedParamDecl = const_cast<TypeDecl *>( strict_dynamic_cast<const TypeDecl *, nullptr >( indexer.lookupType( useName ) ) );1405 }1406 1407 // Expect to find it always. A misspelled name would have been parsed as an identifier.1408 assert( namedParamDecl && "Type-system-managed value name not found in symbol table" );1409 1410 delete de;1411 1412 TypeInstType * refToDecl = new TypeInstType( 0, useName, namedParamDecl );1413 1414 if ( visitingChildOfSUIT ) {1415 // As in postmutate( Expression * ), topmost expression needs a TypeExpr wrapper1416 // But avoid ArrayType-Sizeof1417 return new TypeExpr( refToDecl );1418 } else {1419 // the N occurrence is being used directly as a runtime value,1420 // if we are in a type instantiation, then the N is within a bigger value computation1421 return new SizeofExpr( refToDecl );1422 }1423 }1424 1425 Expression * TranslateDimensionGenericParameters::postmutate( Expression * e ) {1426 if ( visitingChildOfSUIT ) {1427 // e is an expression used as an argument to instantiate a type1428 if (! dynamic_cast< TypeExpr * >( e ) ) {1429 // e is a value expression1430 // but not a DimensionExpr, which has a distinct postmutate1431 Type * typeExprContent = new ArrayType( 0, new BasicType( 0, BasicType::Char ), e, true, false );1432 TypeExpr * result = new TypeExpr( typeExprContent );1433 return result;1434 }1435 }1436 return e;1437 1265 } 1438 1266 -
src/SynTree/Declaration.h
r660665f r5a46e09 201 201 typedef NamedTypeDecl Parent; 202 202 public: 203 enum Kind { Dtype, DStype, Otype, Ftype, Ttype, Dimension, NUMBER_OF_KINDS };203 enum Kind { Dtype, DStype, Otype, Ftype, Ttype, ALtype, NUMBER_OF_KINDS }; 204 204 205 205 Kind kind; -
src/SynTree/Expression.h
r660665f r5a46e09 587 587 }; 588 588 589 /// DimensionExpr represents a type-system provided value used in an expression ( forrall([N]) ... N + 1 )590 class DimensionExpr : public Expression {591 public:592 std::string name;593 594 DimensionExpr( std::string name );595 DimensionExpr( const DimensionExpr & other );596 virtual ~DimensionExpr();597 598 const std::string & get_name() const { return name; }599 void set_name( std::string newValue ) { name = newValue; }600 601 virtual DimensionExpr * clone() const override { return new DimensionExpr( * this ); }602 virtual void accept( Visitor & v ) override { v.visit( this ); }603 virtual void accept( Visitor & v ) const override { v.visit( this ); }604 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }605 virtual void print( std::ostream & os, Indenter indent = {} ) const override;606 };607 608 589 /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result) 609 590 class AsmExpr : public Expression { -
src/SynTree/Mutator.h
r660665f r5a46e09 80 80 virtual Expression * mutate( CommaExpr * commaExpr ) = 0; 81 81 virtual Expression * mutate( TypeExpr * typeExpr ) = 0; 82 virtual Expression * mutate( DimensionExpr * dimensionExpr ) = 0;83 82 virtual Expression * mutate( AsmExpr * asmExpr ) = 0; 84 83 virtual Expression * mutate( ImplicitCopyCtorExpr * impCpCtorExpr ) = 0; -
src/SynTree/SynTree.h
r660665f r5a46e09 85 85 class CommaExpr; 86 86 class TypeExpr; 87 class DimensionExpr;88 87 class AsmExpr; 89 88 class ImplicitCopyCtorExpr; -
src/SynTree/TypeDecl.cc
r660665f r5a46e09 33 33 34 34 const char * TypeDecl::typeString() const { 35 static const char * kindNames[] = { "sized data type", "sized data type", "sized object type", "sized function type", "sized tuple type", "sized length value" };35 static const char * kindNames[] = { "sized data type", "sized data type", "sized object type", "sized function type", "sized tuple type", "sized array length type" }; 36 36 static_assert( sizeof(kindNames) / sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." ); 37 37 assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." ); -
src/SynTree/TypeExpr.cc
r660665f r5a46e09 35 35 } 36 36 37 DimensionExpr::DimensionExpr( std::string name ) : Expression(), name(name) {38 assertf(name != "0", "Zero is not a valid name");39 assertf(name != "1", "One is not a valid name");40 }41 42 DimensionExpr::DimensionExpr( const DimensionExpr & other ) : Expression( other ), name( other.name ) {43 }44 45 DimensionExpr::~DimensionExpr() {}46 47 void DimensionExpr::print( std::ostream & os, Indenter indent ) const {48 os << "Type-Sys Value: " << get_name();49 Expression::print( os, indent );50 }51 37 // Local Variables: // 52 38 // tab-width: 4 // -
src/SynTree/Visitor.h
r660665f r5a46e09 135 135 virtual void visit( TypeExpr * node ) { visit( const_cast<const TypeExpr *>(node) ); } 136 136 virtual void visit( const TypeExpr * typeExpr ) = 0; 137 virtual void visit( DimensionExpr * node ) { visit( const_cast<const DimensionExpr *>(node) ); }138 virtual void visit( const DimensionExpr * typeExpr ) = 0;139 137 virtual void visit( AsmExpr * node ) { visit( const_cast<const AsmExpr *>(node) ); } 140 138 virtual void visit( const AsmExpr * asmExpr ) = 0; -
tests/.expect/forall.txt
r660665f r5a46e09 1 forall.cfa:2 42:25: warning: Compiled1 forall.cfa:216:25: warning: Compiled -
tests/.expect/typedefRedef-ERR1.txt
r660665f r5a46e09 1 typedefRedef.cfa: 75:25: warning: Compiled1 typedefRedef.cfa:69:25: warning: Compiled 2 2 typedefRedef.cfa:4:1 error: Cannot redefine typedef: Foo 3 typedefRedef.cfa: 65:1 error: Cannot redefine typedef: ARR3 typedefRedef.cfa:59:1 error: Cannot redefine typedef: ARR -
tests/.expect/typedefRedef.txt
r660665f r5a46e09 1 typedefRedef.cfa: 75:25: warning: Compiled1 typedefRedef.cfa:69:25: warning: Compiled -
tests/array-container/array-basic.cfa
r660665f r5a46e09 61 61 forall( [Nw], [Nx], [Ny], [Nz] ) 62 62 void fillHelloData( array( float, Nw, Nx, Ny, Nz ) & wxyz ) { 63 for (w; Nw)64 for (x; Nx)65 for (y; Ny)66 for (z; Nz)63 for (w; z(Nw)) 64 for (x; z(Nx)) 65 for (y; z(Ny)) 66 for (z; z(Nz)) 67 67 wxyz[w][x][y][z] = getMagicNumber(w, x, y, z); 68 68 } 69 69 70 forall( [ N]70 forall( [Zn] 71 71 , S & | sized(S) 72 72 ) 73 float total1d_low( arpk( N, S, float, float ) & a ) {73 float total1d_low( arpk(Zn, S, float, float ) & a ) { 74 74 float total = 0.0f; 75 for (i; N)75 for (i; z(Zn)) 76 76 total += a[i]; 77 77 return total; … … 98 98 99 99 expect = 0; 100 for (i; Nw)100 for (i; z(Nw)) 101 101 expect += getMagicNumber( i, slice_ix, slice_ix, slice_ix ); 102 102 printf("expect Ws = %f\n", expect); … … 105 105 printf("result Ws [][][][] lo = %f\n", result); 106 106 107 result = total1d_low( wxyz[ all, slice_ix, slice_ix, slice_ix] );107 result = total1d_low( wxyz[[all, slice_ix, slice_ix, slice_ix]] ); 108 108 printf("result Ws [,,,] lo = %f\n", result); 109 109 … … 111 111 printf("result Ws [][][][] hi = %f\n", result); 112 112 113 result = total1d_hi( wxyz[ all, slice_ix, slice_ix, slice_ix] );113 result = total1d_hi( wxyz[[all, slice_ix, slice_ix, slice_ix]] ); 114 114 printf("result Ws [,,,] hi = %f\n", result); 115 115 … … 117 117 118 118 expect = 0; 119 for (i; Nx)119 for (i; z(Nx)) 120 120 expect += getMagicNumber( slice_ix, i, slice_ix, slice_ix ); 121 121 printf("expect Xs = %f\n", expect); … … 124 124 printf("result Xs [][][][] lo = %f\n", result); 125 125 126 result = total1d_low( wxyz[ slice_ix, all, slice_ix, slice_ix] );126 result = total1d_low( wxyz[[slice_ix, all, slice_ix, slice_ix]] ); 127 127 printf("result Xs [,,,] lo = %f\n", result); 128 128 … … 130 130 printf("result Xs [][][][] hi = %f\n", result); 131 131 132 result = total1d_hi( wxyz[ slice_ix, all, slice_ix, slice_ix] );132 result = total1d_hi( wxyz[[slice_ix, all, slice_ix, slice_ix]] ); 133 133 printf("result Xs [,,,] hi = %f\n", result); 134 134 -
tests/array-container/array-md-sbscr-cases.cfa
r660665f r5a46e09 20 20 forall( [Nw], [Nx], [Ny], [Nz] ) 21 21 void fillHelloData( array( float, Nw, Nx, Ny, Nz ) & wxyz ) { 22 for (w; Nw)23 for (x; Nx)24 for (y; Ny)25 for (z; Nz)22 for (w; z(Nw)) 23 for (x; z(Nx)) 24 for (y; z(Ny)) 25 for (z; z(Nz)) 26 26 wxyz[w][x][y][z] = getMagicNumber(w, x, y, z); 27 27 } … … 53 53 // order wxyz, natural split (4-0 or 0-4, no intermediate to declare) 54 54 55 assert(( wxyz[ iw, ix, iy, iz] == valExpected ));55 assert(( wxyz[[iw, ix, iy, iz]] == valExpected )); 56 56 57 57 // order wxyz, unnatural split 1-3 (three ways declared) 58 58 59 59 typeof( wxyz[iw] ) xyz1 = wxyz[iw]; 60 assert(( xyz1[ ix, iy, iz] == valExpected ));60 assert(( xyz1[[ix, iy, iz]] == valExpected )); 61 61 62 62 typeof( wxyz[iw] ) xyz2; 63 63 &xyz2 = &wxyz[iw]; 64 assert(( xyz2[ ix, iy, iz] == valExpected ));65 66 assert(( wxyz[iw][ ix, iy, iz] == valExpected ));64 assert(( xyz2[[ix, iy, iz]] == valExpected )); 65 66 assert(( wxyz[iw][[ix, iy, iz]] == valExpected )); 67 67 68 68 // order wxyz, unnatural split 2-2 (three ways declared) 69 69 70 typeof( wxyz[ iw, ix] ) yz1 = wxyz[iw,ix];71 assert(( yz1[ iy, iz] == valExpected ));72 73 typeof( wxyz[ iw, ix] ) yz2;74 &yz2 = &wxyz[ iw, ix];75 assert(( yz2[ iy, iz] == valExpected ));76 77 assert(( wxyz[ iw, ix][iy, iz] == valExpected ));70 typeof( wxyz[[iw, ix]] ) yz1 = wxyz[[iw,ix]]; 71 assert(( yz1[[iy, iz]] == valExpected )); 72 73 typeof( wxyz[[iw, ix]] ) yz2; 74 &yz2 = &wxyz[[iw, ix]]; 75 assert(( yz2[[iy, iz]] == valExpected )); 76 77 assert(( wxyz[[iw, ix]][[iy, iz]] == valExpected )); 78 78 79 79 // order wxyz, unnatural split 3-1 (three ways declared) 80 80 81 typeof( wxyz[ iw, ix, iy] ) z1 = wxyz[iw, ix, iy];81 typeof( wxyz[[iw, ix, iy]] ) z1 = wxyz[[iw, ix, iy]]; 82 82 assert(( z1[iz] == valExpected )); 83 83 84 typeof( wxyz[ iw, ix, iy] ) z2;85 &z2 = &wxyz[ iw, ix, iy];84 typeof( wxyz[[iw, ix, iy]] ) z2; 85 &z2 = &wxyz[[iw, ix, iy]]; 86 86 assert(( z2[iz] == valExpected )); 87 87 88 assert(( wxyz[ iw, ix, iy][iz] == valExpected ));88 assert(( wxyz[[iw, ix, iy]][iz] == valExpected )); 89 89 } 90 90 … … 104 104 // order wxyz (no intermediates to declare) 105 105 106 assert(( wxyz[ iw , ix , iy , iz] == valExpected ));107 assert(( wxyz[ iw-1, ix , iy , iz] != valExpected ));106 assert(( wxyz[[iw , ix , iy , iz ]] == valExpected )); 107 assert(( wxyz[[iw-1, ix , iy , iz ]] != valExpected )); 108 108 109 109 // order xyzw: *xyz, w 110 110 111 assert(( wxyz[ all , ix , iy , iz][iw ] == valExpected ));112 assert(( wxyz[ all , ix-1, iy , iz][iw ] != valExpected ));113 assert(( wxyz[ all , ix , iy , iz][iw-1] != valExpected ));111 assert(( wxyz[[all , ix , iy , iz ]][iw ] == valExpected )); 112 assert(( wxyz[[all , ix-1, iy , iz ]][iw ] != valExpected )); 113 assert(( wxyz[[all , ix , iy , iz ]][iw-1] != valExpected )); 114 114 115 115 // order wyzx: w*yz, x 116 116 117 assert(( wxyz[ iw , all , iy , iz][ix ] == valExpected ));118 assert(( wxyz[ iw , all , iy-1, iz][ix ] != valExpected ));119 assert(( wxyz[ iw , all , iy , iz][ix-1] != valExpected ));117 assert(( wxyz[[iw , all , iy , iz ]][ix ] == valExpected )); 118 assert(( wxyz[[iw , all , iy-1, iz ]][ix ] != valExpected )); 119 assert(( wxyz[[iw , all , iy , iz ]][ix-1] != valExpected )); 120 120 121 121 // order wxzy: wx*z, y 122 122 #if 0 123 123 // not working on 32-bit 124 assert(( wxyz[ iw , ix , all , iz][iy ] == valExpected ));125 assert(( wxyz[ iw , ix , all , iz-1][iy ] != valExpected ));126 assert(( wxyz[ iw , ix , all , iz][iy-1] != valExpected ));124 assert(( wxyz[[iw , ix , all , iz ]][iy ] == valExpected )); 125 assert(( wxyz[[iw , ix , all , iz-1]][iy ] != valExpected )); 126 assert(( wxyz[[iw , ix , all , iz ]][iy-1] != valExpected )); 127 127 #endif 128 128 } … … 131 131 // The comments specify a covering set of orders, each in its most natural split. 132 132 // Covering means that each edge on the lattice of dimesnions-provided is used. 133 // Natural split means the arity of every -[ -,...] tuple equals the dimensionality of its "this" operand, then that the fewest "all" subscripts are given.133 // Natural split means the arity of every -[[-,...]] tuple equals the dimensionality of its "this" operand, then that the fewest "all" subscripts are given. 134 134 // The commented-out test code shows cases that don't work. We wish all the comment-coverd cases worked. 135 135 forall( [Nw], [Nx], [Ny], [Nz] ) … … 147 147 // order wxyz (no intermediates to declare) 148 148 149 assert(( wxyz[ iw, ix, iy, iz] == valExpected ));149 assert(( wxyz[[iw, ix, iy, iz]] == valExpected )); 150 150 151 151 { … … 153 153 assert( wxyz[iw][all][iy][all] [ix][iz] == valExpected ); 154 154 155 typeof( wxyz[ iw, all, iy, all] ) xz1 = wxyz[iw, all, iy, all];156 assert(( xz1[ ix, iz] == valExpected ));157 158 typeof( wxyz[ iw, all, iy, all] ) xz2;159 &xz2 = &wxyz[ iw, all, iy, all];160 assert(( xz2[ ix, iz] == valExpected ));161 162 assert(( wxyz[ iw , all, iy , all][ix , iz] == valExpected ));163 assert(( wxyz[ iw-1, all, iy , all][ix , iz] != valExpected ));164 assert(( wxyz[ iw , all, iy-1, all][ix , iz] != valExpected ));165 assert(( wxyz[ iw , all, iy , all][ix-1, iz] != valExpected ));166 assert(( wxyz[ iw , all, iy , all][ix , iz-1] != valExpected ));155 typeof( wxyz[[iw, all, iy, all]] ) xz1 = wxyz[[iw, all, iy, all]]; 156 assert(( xz1[[ix, iz]] == valExpected )); 157 158 typeof( wxyz[[iw, all, iy, all]] ) xz2; 159 &xz2 = &wxyz[[iw, all, iy, all]]; 160 assert(( xz2[[ix, iz]] == valExpected )); 161 162 assert(( wxyz[[iw , all, iy , all]][[ix , iz ]] == valExpected )); 163 assert(( wxyz[[iw-1, all, iy , all]][[ix , iz ]] != valExpected )); 164 assert(( wxyz[[iw , all, iy-1, all]][[ix , iz ]] != valExpected )); 165 assert(( wxyz[[iw , all, iy , all]][[ix-1, iz ]] != valExpected )); 166 assert(( wxyz[[iw , all, iy , all]][[ix , iz-1]] != valExpected )); 167 167 } 168 168 { … … 170 170 assert( wxyz[iw][all][all][iz] [ix][iy] == valExpected ); 171 171 172 // typeof( wxyz[ iw, all, all, iz] ) xy1 = wxyz[iw, all, all, iz];173 // assert(( xy1[ ix, iy] == valExpected ));174 175 // typeof( wxyz[ iw, all, all, iz] ) xy2;176 // &xy2 = &wxyz[ iw, all, all, iz];177 // assert(( xy2[ ix, iy] == valExpected ));178 179 // assert(( wxyz[ iw , all, all, iz ][ix , iy] == valExpected ));180 // assert(( wxyz[ iw-1, all, all, iz ][ix , iy] != valExpected ));181 // assert(( wxyz[ iw , all, all, iz-1][ix , iy] != valExpected ));182 // assert(( wxyz[ iw , all, all, iz ][ix-1, iy] != valExpected ));183 // assert(( wxyz[ iw , all, all, iz ][ix , iy-1] != valExpected ));172 // typeof( wxyz[[iw, all, all, iz]] ) xy1 = wxyz[[iw, all, all, iz]]; 173 // assert(( xy1[[ix, iy]] == valExpected )); 174 175 // typeof( wxyz[[iw, all, all, iz]] ) xy2; 176 // &xy2 = &wxyz[[iw, all, all, iz]]; 177 // assert(( xy2[[ix, iy]] == valExpected )); 178 179 // assert(( wxyz[[iw , all, all, iz ]][[ix , iy ]] == valExpected )); 180 // assert(( wxyz[[iw-1, all, all, iz ]][[ix , iy ]] != valExpected )); 181 // assert(( wxyz[[iw , all, all, iz-1]][[ix , iy ]] != valExpected )); 182 // assert(( wxyz[[iw , all, all, iz ]][[ix-1, iy ]] != valExpected )); 183 // assert(( wxyz[[iw , all, all, iz ]][[ix , iy-1]] != valExpected )); 184 184 } 185 185 { … … 187 187 assert( wxyz[all][ix][iy][all] [iw][iz] == valExpected ); 188 188 189 typeof( wxyz[ all, ix, iy, all] ) wz1 = wxyz[all, ix, iy, all];190 assert(( wz1[ iw, iz] == valExpected ));191 192 assert(( wxyz[ all , ix, iy , all][iw , iz] == valExpected ));189 typeof( wxyz[[all, ix, iy, all]] ) wz1 = wxyz[[all, ix, iy, all]]; 190 assert(( wz1[[iw, iz]] == valExpected )); 191 192 assert(( wxyz[[all , ix, iy , all]][[iw , iz ]] == valExpected )); 193 193 } 194 194 { … … 196 196 assert( wxyz[all][ix][all][iz] [iw][iy] == valExpected ); 197 197 198 // assert(( wxyz[ all , ix , all , iz ][iw , iy] == valExpected ));198 // assert(( wxyz[[all , ix , all , iz ]][[iw , iy ]] == valExpected )); 199 199 } 200 200 { … … 202 202 assert( wxyz[all][all][iy][iz] [iw][ix] == valExpected ); 203 203 204 // assert(( wxyz[ all , all , iy , iz ][iw , ix] == valExpected ));204 // assert(( wxyz[[all , all , iy , iz ]][[iw , ix ]] == valExpected )); 205 205 } 206 206 { … … 208 208 assert( wxyz[all][ix][all][all] [iw][all][iz] [iy] == valExpected ); 209 209 210 typeof( wxyz[all][ix][all][all] ) wyz_workaround = wxyz[ all , ix , all , all];211 typeof( wyz_workaround[iw][all][iz] ) y_workaround = wyz_workaround[ iw , all , iz];210 typeof( wxyz[all][ix][all][all] ) wyz_workaround = wxyz[[all , ix , all , all ]]; 211 typeof( wyz_workaround[iw][all][iz] ) y_workaround = wyz_workaround[[iw , all , iz ]]; 212 212 assert( y_workaround[iy] == valExpected ); 213 213 214 // assert(( wxyz[ all , ix , all , all ][iw , all , iz][iy ] == valExpected ));214 // assert(( wxyz[[all , ix , all , all ]][[iw , all , iz ]][iy ] == valExpected )); 215 215 } 216 216 { … … 239 239 valExpected = getMagicNumber(2, 3, 4, 5); 240 240 assert(( wxyz [2] [3] [4] [5] == valExpected )); 241 assert(( wxyz[ 2, 3][4] [5] == valExpected ));242 assert(( wxyz [2][ 3, 4][5] == valExpected ));243 assert(( wxyz [2] [3][ 4, 5] == valExpected ));244 assert(( wxyz[ 2, 3, 4][5] == valExpected ));245 assert(( wxyz [2][ 3, 4, 5] == valExpected ));246 assert(( wxyz[ 2, 3, 4, 5] == valExpected ));247 248 for ( i; Nw) {249 assert(( wxyz[ i, 3, 4, 5] == getMagicNumber(i, 3, 4, 5) ));250 } 251 252 for ( i; Nx) {253 assert(( wxyz[ 2, i, 4, 5] == getMagicNumber(2, i, 4, 5) ));254 } 255 256 for ( i; Ny) {257 assert(( wxyz[ 2, 3, i, 5] == getMagicNumber(2, 3, i, 5) ));258 } 259 260 for ( i; Nz) {261 assert(( wxyz[ 2, 3, 4, i] == getMagicNumber(2, 3, 4, i) ));262 } 263 264 for ( i; Nw) {265 assert(( wxyz[ i, all, 4, 5][3] == getMagicNumber(i, 3, 4, 5) ));266 } 267 268 for ( i; Nw) {269 assert(( wxyz[ all, 3, 4, 5][i] == getMagicNumber(i, 3, 4, 5) ));241 assert(( wxyz[[2, 3]][4] [5] == valExpected )); 242 assert(( wxyz [2][[3, 4]][5] == valExpected )); 243 assert(( wxyz [2] [3][[4, 5]] == valExpected )); 244 assert(( wxyz[[2, 3, 4]][5] == valExpected )); 245 assert(( wxyz [2][[3, 4, 5]] == valExpected )); 246 assert(( wxyz[[2, 3, 4, 5]] == valExpected )); 247 248 for ( i; z(Nw) ) { 249 assert(( wxyz[[ i, 3, 4, 5 ]] == getMagicNumber(i, 3, 4, 5) )); 250 } 251 252 for ( i; z(Nx) ) { 253 assert(( wxyz[[ 2, i, 4, 5 ]] == getMagicNumber(2, i, 4, 5) )); 254 } 255 256 for ( i; z(Ny) ) { 257 assert(( wxyz[[ 2, 3, i, 5 ]] == getMagicNumber(2, 3, i, 5) )); 258 } 259 260 for ( i; z(Nz) ) { 261 assert(( wxyz[[ 2, 3, 4, i ]] == getMagicNumber(2, 3, 4, i) )); 262 } 263 264 for ( i; z(Nw) ) { 265 assert(( wxyz[[ i, all, 4, 5 ]][3] == getMagicNumber(i, 3, 4, 5) )); 266 } 267 268 for ( i; z(Nw) ) { 269 assert(( wxyz[[ all, 3, 4, 5 ]][i] == getMagicNumber(i, 3, 4, 5) )); 270 270 } 271 271 } -
tests/concurrent/signal/disjoint.cfa
r660665f r5a46e09 77 77 wait( cond ); 78 78 if( d.state != SIGNAL ) { 79 abort | "ERROR barging!";79 sout | "ERROR barging!"; 80 80 } 81 81 … … 113 113 bool running = TEST(globals.data.counter < N) && globals.data.counter > 0; 114 114 if( globals.data.state != SIGNAL && running ) { 115 abort | "ERROR Eager signal" | globals.data.state;115 sout | "ERROR Eager signal" | globals.data.state; 116 116 } 117 117 } -
tests/coroutine/fibonacci.cfa
r660665f r5a46e09 31 31 } 32 32 33 int next( Fibonacci & fib ) with( fib ) { 34 resume( fib ); // restart last suspend 35 return fn; 36 } 37 33 38 int main() { 34 39 Fibonacci f1, f2; 35 40 for ( 10 ) { // print N Fibonacci values 36 sout | resume( f1 ).fn | resume( f2 ).fn;41 sout | next( f1 ) | next( f2 ); 37 42 } // for 38 43 } -
tests/forall.cfa
r660665f r5a46e09 199 199 } 200 200 201 forall( T ) void check_otype() {202 T & tr = *0p;203 T * tp = 0p;204 205 &tr += 1;206 tp += 1;207 T & tx = tp[1];208 209 T t;210 T t2 = t;211 }212 213 forall( T * ) void check_dstype() {214 T & tr = *0p;215 T * tp = 0p;216 217 &tr += 1;218 tp += 1;219 T & tx = tp[1];220 }221 222 forall( T & ) void check_dtype() {223 T & tr = *0p;224 T * tp = 0p;225 }226 227 201 //otype T1 | { void xxx( T1 ); }; 228 202 -
tests/generator/fibonacci.cfa
r660665f r5a46e09 8 8 // 9 9 // Author : Thierry Delisle 10 // Created On : Mon Mar 1 16:54:23 202011 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Jun 10 21:54:14 202113 // Update Count : 310 // Created On : Mon Mar 1 16:54:23 2020 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 14 14 // 15 16 #include <fstream.hfa>17 15 18 16 generator Fib { … … 20 18 }; 21 19 22 void main(Fib & fib) with (fib) {20 void main(Fib & b) with (b) { 23 21 [fn1, fn] = [1, 0]; 24 22 for () { … … 31 29 Fib f1, f2; 32 30 for ( 10 ) { 33 resume( f1 ); resume( f2 );34 sout | f1.fn | f2.fn;35 // sout | resume( f1 ).fn | resume( f2 ).fn; // compiler bug31 resume( f1 ); 32 resume( f2 ); 33 printf("%d %d\n", f1.fn, f2.fn); 36 34 } 35 37 36 } 38 37 -
tests/generator/fmtLines.cfa
r660665f r5a46e09 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu Mar 5 16:09:08 2020 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Jun 10 21:56:22 202113 // Update Count : 211 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 14 14 // 15 15 -
tests/generator/suspend_then.cfa
r660665f r5a46e09 9 9 // Author : Peter A. Buhr 10 10 // Created On : Mon Apr 29 12:01:35 2019 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Jun 10 21:55:51 202113 // Update Count : 111 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 14 14 // 15 15 -
tests/literals.cfa
r660665f r5a46e09 10 10 // Created On : Sat Sep 9 16:34:38 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 19 15:47:49 202113 // Update Count : 2 3712 // Last Modified On : Sat Aug 29 10:57:56 2020 13 // Update Count : 226 14 14 // 15 15 … … 63 63 -0X0123456789ABCDEF; -0X0123456789ABCDEFu; -0X0123456789ABCDEFl; -0X0123456789ABCDEFll; -0X0123456789ABCDEFul; -0X0123456789ABCDEFlu; -0X0123456789ABCDEFull; -0X0123456789ABCDEFllu; 64 64 65 // floating literals66 67 0123456789.; 0123456789.f; 0123456789.d; 0123456789.l; 0123456789.F; 0123456789.D; 0123456789.L;68 +0123456789.; +0123456789.f; +0123456789.d; +0123456789.l; +0123456789.F; +0123456789.D; +0123456789.L;69 -0123456789.; -0123456789.f; -0123456789.d; -0123456789.l; -0123456789.F; -0123456789.D; -0123456789.L;70 71 0123456789.e09; 0123456789.e09f; 0123456789.e09d; 0123456789.e09l; 0123456789.e09F; 0123456789.e09D; 0123456789.e09L;72 +0123456789.e09; +0123456789.e09f; +0123456789.e09d; +0123456789.e09l; +0123456789.e09F; +0123456789.e09D; +0123456789.e09L;73 -0123456789.e09; -0123456789.e09f; -0123456789.e09d; -0123456789.e09l; -0123456789.e09F; -0123456789.e09D; -0123456789.e09L;74 75 0123456789.e+09; 0123456789.e+09f; 0123456789.e+09d; 0123456789.e+09l; 0123456789.e+09F; 0123456789.e+09D; 0123456789.e+09L;76 +0123456789.e+09; +0123456789.e+09f; +0123456789.e+09d; +0123456789.e+09l; +0123456789.e+09F; +0123456789.e+09D; +0123456789.e+09L;77 -0123456789.e+09; -0123456789.e+09f; -0123456789.e+09d; -0123456789.e+09l; -0123456789.e+09F; -0123456789.e+09D; -0123456789.e+09L;78 79 0123456789.e-09; 0123456789.e-09f; 0123456789.e-09d; 0123456789.e-09l; 0123456789.e-09F; 0123456789.e-09D; 0123456789.e-09L;80 +0123456789.e-09; +0123456789.e-09f; +0123456789.e-09d; +0123456789.e-09l; +0123456789.e-09F; +0123456789.e-09D; +0123456789.e-09L;81 -0123456789.e-09; -0123456789.e-09f; -0123456789.e-09d; -0123456789.e-09l; -0123456789.e-09F; -0123456789.e-09D; -0123456789.e-09L;82 83 .0123456789; .0123456789f; .0123456789d; .0123456789l; .0123456789F; .0123456789D; .0123456789L;84 +.0123456789; +.0123456789f; +.0123456789d; +.0123456789l; +.0123456789F; +.0123456789D; +.0123456789L;85 -.0123456789; -.0123456789f; -.0123456789d; -.0123456789l; -.0123456789F; -.0123456789D; -.0123456789L;86 87 .0123456789e09; .0123456789e09f; .0123456789e09d; .0123456789e09l; .0123456789e09F; .0123456789e09D; .0123456789e09L;88 +.0123456789e09; +.0123456789e09f; +.0123456789e09d; +.0123456789e09l; +.0123456789e09F; +.0123456789e09D; +.0123456789e09L;89 -.0123456789e09; -.0123456789e09f; -.0123456789e09d; -.0123456789e09l; -.0123456789e09F; -.0123456789e09D; -.0123456789e09L;90 91 .0123456789E+09; .0123456789E+09f; .0123456789E+09d; .0123456789E+09l; .0123456789E+09F; .0123456789E+09D; .0123456789E+09L;92 +.0123456789E+09; +.0123456789E+09f; +.0123456789E+09d; +.0123456789E+09l; +.0123456789E+09F; +.0123456789E+09D; +.0123456789E+09L;93 -.0123456789E+09; -.0123456789E+09f; -.0123456789E+09d; -.0123456789E+09l; -.0123456789E+09F; -.0123456789E+09D; -.0123456789E+09L;94 95 .0123456789E-09; .0123456789E-09f; .0123456789E-09d; .0123456789E-09l; .0123456789E-09F; .0123456789E-09D; .0123456789E-09L;96 -.0123456789E-09; -.0123456789E-09f; -.0123456789E-09d; -.0123456789E-09l; -.0123456789E-09F; -.0123456789E-09D; -.0123456789E-09L;97 -.0123456789E-09; -.0123456789E-09f; -.0123456789E-09d; -.0123456789E-09l; -.0123456789E-09F; -.0123456789E-09D; -.0123456789E-09L;98 99 0123456789.0123456789; 0123456789.0123456789f; 0123456789.0123456789d; 0123456789.0123456789l; 0123456789.0123456789F; 0123456789.0123456789D; 0123456789.0123456789L;100 +0123456789.0123456789; +0123456789.0123456789f; +0123456789.0123456789d; +0123456789.0123456789l; +0123456789.0123456789F; +0123456789.0123456789D; +0123456789.0123456789L;101 -0123456789.0123456789; -0123456789.0123456789f; -0123456789.0123456789d; -0123456789.0123456789l; -0123456789.0123456789F; -0123456789.0123456789D; -0123456789.0123456789L;102 103 0123456789.0123456789E09; 0123456789.0123456789E09f; 0123456789.0123456789E09d; 0123456789.0123456789E09l; 0123456789.0123456789E09F; 0123456789.0123456789E09D; 0123456789.0123456789E09L;104 +0123456789.0123456789E09; +0123456789.0123456789E09f; +0123456789.0123456789E09d; +0123456789.0123456789E09l; +0123456789.0123456789E09F; +0123456789.0123456789E09D; +0123456789.0123456789E09L;105 -0123456789.0123456789E09; -0123456789.0123456789E09f; -0123456789.0123456789E09d; -0123456789.0123456789E09l; -0123456789.0123456789E09F; -0123456789.0123456789E09D; -0123456789.0123456789E09L;106 107 0123456789.0123456789E+09; 0123456789.0123456789E+09f; 0123456789.0123456789E+09d; 0123456789.0123456789E+09l; 0123456789.0123456789E+09F; 0123456789.0123456789E+09D; 0123456789.0123456789E+09L;108 +0123456789.0123456789E+09; +0123456789.0123456789E+09f; +0123456789.0123456789E+09d; +0123456789.0123456789E+09l; +0123456789.0123456789E+09F; +0123456789.0123456789E+09D; +0123456789.0123456789E+09L;109 -0123456789.0123456789E+09; -0123456789.0123456789E+09f; -0123456789.0123456789E+09d; -0123456789.0123456789E+09l; -0123456789.0123456789E+09F; -0123456789.0123456789E+09D; -0123456789.0123456789E+09L;110 111 0123456789.0123456789E-09; 0123456789.0123456789E-09f; 0123456789.0123456789E-09d; 0123456789.0123456789E-09l; 0123456789.0123456789E-09F; 0123456789.0123456789E-09D; 0123456789.0123456789E-09L;112 +0123456789.0123456789E-09; +0123456789.0123456789E-09f; +0123456789.0123456789E-09d; +0123456789.0123456789E-09l; +0123456789.0123456789E-09F; +0123456789.0123456789E-09D; +0123456789.0123456789E-09L;113 -0123456789.0123456789E-09; -0123456789.0123456789E-09f; -0123456789.0123456789E-09d; -0123456789.0123456789E-09l; -0123456789.0123456789E-09F; -0123456789.0123456789E-09D; -0123456789.0123456789E-09L;114 115 65 // decimal floating literals 116 66 117 #if ! defined( __aarch64__ ) // unsupported on ARM after gcc-9 118 0123456789.df; 0123456789.dd; 0123456789.dl; 0123456789.DF; 0123456789.DD; 0123456789.DL; 119 +0123456789.df; +0123456789.dd; +0123456789.dl; +0123456789.DF; +0123456789.DD; +0123456789.DL; 120 -0123456789.df; -0123456789.dd; -0123456789.dl; -0123456789.DF; -0123456789.DD; -0123456789.DL; 121 122 0123456789.e09df; 0123456789.e09dd; 0123456789.e09dl; 0123456789.e09DF; 0123456789.e09DD; 0123456789.e09DL; 123 +0123456789.e09df; +0123456789.e09dd; +0123456789.e09dl; +0123456789.e09DF; +0123456789.e09DD; +0123456789.e09DL; 124 -0123456789.e09df; -0123456789.e09dd; -0123456789.e09dl; -0123456789.e09DF; -0123456789.e09DD; -0123456789.e09DL; 125 126 0123456789.e+09df; 0123456789.e+09dd; 0123456789.e+09dl; 0123456789.e+09DF; 0123456789.e+09DD; 0123456789.e+09DL; 127 +0123456789.e+09df; +0123456789.e+09dd; +0123456789.e+09dl; +0123456789.e+09DF; +0123456789.e+09DD; +0123456789.e+09DL; 128 -0123456789.e+09df; -0123456789.e+09dd; -0123456789.e+09dl; -0123456789.e+09DF; -0123456789.e+09DD; -0123456789.e+09DL; 129 130 0123456789.e-09df; 0123456789.e-09dd; 0123456789.e-09dl; 0123456789.e-09DF; 0123456789.e-09DD; 0123456789.e-09DL; 131 +0123456789.e-09df; +0123456789.e-09dd; +0123456789.e-09dl; +0123456789.e-09DF; +0123456789.e-09DD; +0123456789.e-09DL; 132 -0123456789.e-09df; -0123456789.e-09dd; -0123456789.e-09dl; -0123456789.e-09DF; -0123456789.e-09DD; -0123456789.e-09DL; 133 134 .0123456789df; .0123456789dd; .0123456789dl; .0123456789DF; .0123456789DD; .0123456789DL; 135 +.0123456789df; +.0123456789dd; +.0123456789dl; +.0123456789DF; +.0123456789DD; +.0123456789DL; 136 -.0123456789df; -.0123456789dd; -.0123456789dl; -.0123456789DF; -.0123456789DD; -.0123456789DL; 137 138 .0123456789e09df; .0123456789e09dd; .0123456789e09dl; .0123456789e09DF; .0123456789e09DD; .0123456789e09DL; 139 +.0123456789e09df; +.0123456789e09dd; +.0123456789e09dl; +.0123456789e09DF; +.0123456789e09DD; +.0123456789e09DL; 140 -.0123456789e09df; -.0123456789e09dd; -.0123456789e09dl; -.0123456789e09DF; -.0123456789e09DD; -.0123456789e09DL; 141 142 .0123456789E+09df; .0123456789E+09dd; .0123456789E+09dl; .0123456789E+09DF; .0123456789E+09DD; .0123456789E+09DL; 143 +.0123456789E+09df; +.0123456789E+09dd; +.0123456789E+09dl; +.0123456789E+09DF; +.0123456789E+09DD; +.0123456789E+09DL; 144 -.0123456789E+09df; -.0123456789E+09dd; -.0123456789E+09dl; -.0123456789E+09DF; -.0123456789E+09DD; -.0123456789E+09DL; 145 146 .0123456789E-09df; .0123456789E-09dd; .0123456789E-09dl; .0123456789E-09DF; .0123456789E-09DD; .0123456789E-09DL; 147 -.0123456789E-09df; -.0123456789E-09dd; -.0123456789E-09dl; -.0123456789E-09DF; -.0123456789E-09DD; -.0123456789E-09DL; 148 -.0123456789E-09df; -.0123456789E-09dd; -.0123456789E-09dl; -.0123456789E-09DF; -.0123456789E-09DD; -.0123456789E-09DL; 149 150 0123456789.0123456789df; 0123456789.0123456789dd; 0123456789.0123456789dl; 0123456789.0123456789DF; 0123456789.0123456789DD; 0123456789.0123456789DL; 151 +0123456789.0123456789df; +0123456789.0123456789dd; +0123456789.0123456789dl; +0123456789.0123456789DF; +0123456789.0123456789DD; +0123456789.0123456789DL; 152 -0123456789.0123456789df; -0123456789.0123456789dd; -0123456789.0123456789dl; -0123456789.0123456789DF; -0123456789.0123456789DD; -0123456789.0123456789DL; 153 154 0123456789.0123456789E09df; 0123456789.0123456789E09dd; 0123456789.0123456789E09dl; 0123456789.0123456789E09DF; 0123456789.0123456789E09DD; 0123456789.0123456789E09DL; 155 +0123456789.0123456789E09df; +0123456789.0123456789E09dd; +0123456789.0123456789E09dl; +0123456789.0123456789E09DF; +0123456789.0123456789E09DD; +0123456789.0123456789E09DL; 156 -0123456789.0123456789E09df; -0123456789.0123456789E09dd; -0123456789.0123456789E09dl; -0123456789.0123456789E09DF; -0123456789.0123456789E09DD; -0123456789.0123456789E09DL; 157 158 0123456789.0123456789E+09df; 0123456789.0123456789E+09dd; 0123456789.0123456789E+09dl; 0123456789.0123456789E+09DF; 0123456789.0123456789E+09DD; 0123456789.0123456789E+09DL; 159 +0123456789.0123456789E+09df; +0123456789.0123456789E+09dd; +0123456789.0123456789E+09dl; +0123456789.0123456789E+09DF; +0123456789.0123456789E+09DD; +0123456789.0123456789E+09DL; 160 -0123456789.0123456789E+09df; -0123456789.0123456789E+09dd; -0123456789.0123456789E+09dl; -0123456789.0123456789E+09DF; -0123456789.0123456789E+09DD; -0123456789.0123456789E+09DL; 161 162 0123456789.0123456789E-09df; 0123456789.0123456789E-09dd; 0123456789.0123456789E-09dl; 0123456789.0123456789E-09DF; 0123456789.0123456789E-09DD; 0123456789.0123456789E-09DL; 163 +0123456789.0123456789E-09df; +0123456789.0123456789E-09dd; +0123456789.0123456789E-09dl; +0123456789.0123456789E-09DF; +0123456789.0123456789E-09DD; +0123456789.0123456789E-09DL; 164 -0123456789.0123456789E-09df; -0123456789.0123456789E-09dd; -0123456789.0123456789E-09dl; -0123456789.0123456789E-09DF; -0123456789.0123456789E-09DD; -0123456789.0123456789E-09DL; 165 #endif // ! __aarch64__ 67 0123456789.; 0123456789.f; 0123456789.l; 0123456789.F; 0123456789.L; 0123456789.DL; 68 +0123456789.; +0123456789.f; +0123456789.l; +0123456789.F; +0123456789.L; +0123456789.DL; 69 -0123456789.; -0123456789.f; -0123456789.l; -0123456789.F; -0123456789.L; -0123456789.DL; 70 71 0123456789.e09; 0123456789.e09f; 0123456789.e09l; 0123456789.e09F; 0123456789.e09L; 0123456789.e09DL; 72 +0123456789.e09; +0123456789.e09f; +0123456789.e09l; +0123456789.e09F; +0123456789.e09L; +0123456789.e09DL; 73 -0123456789.e09; -0123456789.e09f; -0123456789.e09l; -0123456789.e09F; -0123456789.e09L; -0123456789.e09DL; 74 75 0123456789.e+09; 0123456789.e+09f; 0123456789.e+09l; 0123456789.e+09F; 0123456789.e+09L; 0123456789.e+09DL; 76 +0123456789.e+09; +0123456789.e+09f; +0123456789.e+09l; +0123456789.e+09F; +0123456789.e+09L; +0123456789.e+09DL; 77 -0123456789.e+09; -0123456789.e+09f; -0123456789.e+09l; -0123456789.e+09F; -0123456789.e+09L; -0123456789.e+09DL; 78 79 0123456789.e-09; 0123456789.e-09f; 0123456789.e-09l; 0123456789.e-09F; 0123456789.e-09L; 0123456789.e-09DL; 80 +0123456789.e-09; +0123456789.e-09f; +0123456789.e-09l; +0123456789.e-09F; +0123456789.e-09L; +0123456789.e-09DL; 81 -0123456789.e-09; -0123456789.e-09f; -0123456789.e-09l; -0123456789.e-09F; -0123456789.e-09L; -0123456789.e-09DL; 82 83 .0123456789; .0123456789f; .0123456789l; .0123456789F; .0123456789L; .0123456789DL; 84 +.0123456789; +.0123456789f; +.0123456789l; +.0123456789F; +.0123456789L; +.0123456789DL; 85 -.0123456789; -.0123456789f; -.0123456789l; -.0123456789F; -.0123456789L; -.0123456789DL; 86 87 .0123456789e09; .0123456789e09f; .0123456789e09l; .0123456789e09F; .0123456789e09L; .0123456789e09DL; 88 +.0123456789e09; +.0123456789e09f; +.0123456789e09l; +.0123456789e09F; +.0123456789e09L; +.0123456789e09DL; 89 -.0123456789e09; -.0123456789e09f; -.0123456789e09l; -.0123456789e09F; -.0123456789e09L; -.0123456789e09DL; 90 91 .0123456789E+09; .0123456789E+09f; .0123456789E+09l; .0123456789E+09F; .0123456789E+09L; .0123456789E+09DL; 92 +.0123456789E+09; +.0123456789E+09f; +.0123456789E+09l; +.0123456789E+09F; +.0123456789E+09L; +.0123456789E+09DL; 93 -.0123456789E+09; -.0123456789E+09f; -.0123456789E+09l; -.0123456789E+09F; -.0123456789E+09L; -.0123456789E+09DL; 94 95 .0123456789E-09; .0123456789E-09f; .0123456789E-09l; .0123456789E-09F; .0123456789E-09L; .0123456789E-09DL; 96 -.0123456789E-09; -.0123456789E-09f; -.0123456789E-09l; -.0123456789E-09F; -.0123456789E-09L; -.0123456789E-09DL; 97 -.0123456789E-09; -.0123456789E-09f; -.0123456789E-09l; -.0123456789E-09F; -.0123456789E-09L; -.0123456789E-09DL; 98 99 0123456789.0123456789; 0123456789.0123456789f; 0123456789.0123456789l; 0123456789.0123456789F; 0123456789.0123456789L; 0123456789.0123456789DL; 100 +0123456789.0123456789; +0123456789.0123456789f; +0123456789.0123456789l; +0123456789.0123456789F; +0123456789.0123456789L; +0123456789.0123456789DL; 101 -0123456789.0123456789; -0123456789.0123456789f; -0123456789.0123456789l; -0123456789.0123456789F; -0123456789.0123456789L; -0123456789.0123456789DL; 102 103 0123456789.0123456789E09; 0123456789.0123456789E09f; 0123456789.0123456789E09l; 0123456789.0123456789E09F; 0123456789.0123456789E09L; 0123456789.0123456789E09DL; 104 +0123456789.0123456789E09; +0123456789.0123456789E09f; +0123456789.0123456789E09l; +0123456789.0123456789E09F; +0123456789.0123456789E09L; +0123456789.0123456789E09DL; 105 -0123456789.0123456789E09; -0123456789.0123456789E09f; -0123456789.0123456789E09l; -0123456789.0123456789E09F; -0123456789.0123456789E09L; -0123456789.0123456789E09DL; 106 107 0123456789.0123456789E+09; 0123456789.0123456789E+09f; 0123456789.0123456789E+09l; 0123456789.0123456789E+09F; 0123456789.0123456789E+09L; 0123456789.0123456789E+09DL; 108 +0123456789.0123456789E+09; +0123456789.0123456789E+09f; +0123456789.0123456789E+09l; +0123456789.0123456789E+09F; +0123456789.0123456789E+09L; +0123456789.0123456789E+09DL; 109 -0123456789.0123456789E+09; -0123456789.0123456789E+09f; -0123456789.0123456789E+09l; -0123456789.0123456789E+09F; -0123456789.0123456789E+09L; -0123456789.0123456789E+09DL; 110 111 0123456789.0123456789E-09; 0123456789.0123456789E-09f; 0123456789.0123456789E-09l; 0123456789.0123456789E-09F; 0123456789.0123456789E-09L; 0123456789.0123456789E-09DL; 112 +0123456789.0123456789E-09; +0123456789.0123456789E-09f; +0123456789.0123456789E-09l; +0123456789.0123456789E-09F; +0123456789.0123456789E-09L; +0123456789.0123456789E-09DL; 113 -0123456789.0123456789E-09; -0123456789.0123456789E-09f; -0123456789.0123456789E-09l; -0123456789.0123456789E-09F; -0123456789.0123456789E-09L; -0123456789.0123456789E-09DL; 166 114 167 115 // hexadecimal floating literals, must have exponent -
tests/math.cfa
r660665f r5a46e09 10 10 // Created On : Fri Apr 22 14:59:21 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jun 18 17:02:44202113 // Update Count : 12 412 // Last Modified On : Tue Apr 13 21:04:48 2021 13 // Update Count : 123 14 14 // 15 15 … … 40 40 41 41 sout | "exp:" | exp( 1.0F ) | exp( 1.0D ) | exp( 1.0L ) | nonl; 42 sout | exp( 1.0F+1.0FI ) | exp( 1.0D+1.0DI ) | exp( 1.0 L+1.0LI );42 sout | exp( 1.0F+1.0FI ) | exp( 1.0D+1.0DI ) | exp( 1.0DL+1.0LI ); 43 43 sout | "exp2:" | exp2( 1.0F ) | exp2( 1.0D ) | exp2( 1.0L ); 44 44 sout | "expm1:" | expm1( 1.0F ) | expm1( 1.0D ) | expm1( 1.0L ); 45 45 sout | "pow:" | pow( 1.0F, 1.0F ) | pow( 1.0D, 1.0D ) | pow( 1.0L, 1.0L ) | nonl; 46 sout | pow( 1.0F+1.0FI, 1.0F+1.0FI ) | pow( 1.0D+1.0DI, 1.0D+1.0DI ) | pow( 1.5 L+1.5LI, 1.5L+1.5LI );46 sout | pow( 1.0F+1.0FI, 1.0F+1.0FI ) | pow( 1.0D+1.0DI, 1.0D+1.0DI ) | pow( 1.5DL+1.5LI, 1.5DL+1.5LI ); 47 47 48 48 int b = 4; … … 68 68 69 69 sout | "log:" | log( 1.0F ) | log( 1.0D ) | log( 1.0L ) | nonl; 70 sout | log( 1.0F+1.0FI ) | log( 1.0D+1.0DI ) | log( 1.0 L+1.0LI );70 sout | log( 1.0F+1.0FI ) | log( 1.0D+1.0DI ) | log( 1.0DL+1.0LI ); 71 71 sout | "log2:" | log2( 1024 ) | log2( 2 \ 17u ) | log2( 2 \ 23u ); 72 72 sout | "log2:" | log2( 1024l ) | log2( 2l \ 17u ) | log2( 2l \ 23u ); … … 82 82 83 83 sout | "sqrt:" | sqrt( 1.0F ) | sqrt( 1.0D ) | sqrt( 1.0L ) | nonl; 84 sout | sqrt( 1.0F+1.0FI ) | sqrt( 1.0D+1.0DI ) | sqrt( 1.0 L+1.0LI );84 sout | sqrt( 1.0F+1.0FI ) | sqrt( 1.0D+1.0DI ) | sqrt( 1.0DL+1.0LI ); 85 85 sout | "cbrt:" | cbrt( 27.0F ) | cbrt( 27.0D ) | cbrt( 27.0L ); 86 86 sout | "hypot:" | hypot( 1.0F, -1.0F ) | hypot( 1.0D, -1.0D ) | hypot( 1.0L, -1.0L ); … … 89 89 90 90 sout | "sin:" | sin( 1.0F ) | sin( 1.0D ) | sin( 1.0L ) | nonl; 91 sout | sin( 1.0F+1.0FI ) | sin( 1.0D+1.0DI ) | sin( 1.0 L+1.0LI );91 sout | sin( 1.0F+1.0FI ) | sin( 1.0D+1.0DI ) | sin( 1.0DL+1.0LI ); 92 92 sout | "cos:" | cos( 1.0F ) | cos( 1.0D ) | cos( 1.0L ) | nonl; 93 sout | cos( 1.0F+1.0FI ) | cos( 1.0D+1.0DI ) | cos( 1.0 L+1.0LI );93 sout | cos( 1.0F+1.0FI ) | cos( 1.0D+1.0DI ) | cos( 1.0DL+1.0LI ); 94 94 sout | "tan:" | tan( 1.0F ) | tan( 1.0D ) | tan( 1.0L ) | nonl; 95 sout | tan( 1.0F+1.0FI ) | tan( 1.0D+1.0DI ) | tan( 1.0 L+1.0LI );95 sout | tan( 1.0F+1.0FI ) | tan( 1.0D+1.0DI ) | tan( 1.0DL+1.0LI ); 96 96 sout | "asin:" | asin( 1.0F ) | asin( 1.0D ) | asin( 1.0L ) | nonl; 97 sout | asin( 1.0F+1.0FI ) | asin( 1.0D+1.0DI ) | asin( 1.0 L+1.0LI );97 sout | asin( 1.0F+1.0FI ) | asin( 1.0D+1.0DI ) | asin( 1.0DL+1.0LI ); 98 98 sout | "acos:" | acos( 1.0F ) | acos( 1.0D ) | acos( 1.0L ) | nonl; 99 sout | acos( 1.0F+1.0FI ) | acos( 1.0D+1.0DI ) | acos( 1.0 L+1.0LI );99 sout | acos( 1.0F+1.0FI ) | acos( 1.0D+1.0DI ) | acos( 1.0DL+1.0LI ); 100 100 sout | "atan:" | atan( 1.0F ) | atan( 1.0D ) | atan( 1.0L ) | nonl; 101 sout | atan( 1.0F+1.0FI ) | atan( 1.0D+1.0DI ) | atan( 1.0 L+1.0LI );101 sout | atan( 1.0F+1.0FI ) | atan( 1.0D+1.0DI ) | atan( 1.0DL+1.0LI ); 102 102 sout | "atan2:" | atan2( 1.0F, 1.0F ) | atan2( 1.0D, 1.0D ) | atan2( 1.0L, 1.0L ) | nonl; 103 103 sout | "atan:" | atan( 1.0F, 1.0F ) | atan( 1.0D, 1.0D ) | atan( 1.0L, 1.0L ); … … 106 106 107 107 sout | "sinh:" | sinh( 1.0F ) | sinh( 1.0D ) | sinh( 1.0L ) | nonl; 108 sout | sinh( 1.0F+1.0FI ) | sinh( 1.0D+1.0DI ) | sinh( 1.0 L+1.0LI );108 sout | sinh( 1.0F+1.0FI ) | sinh( 1.0D+1.0DI ) | sinh( 1.0DL+1.0LI ); 109 109 sout | "cosh:" | cosh( 1.0F ) | cosh( 1.0D ) | cosh( 1.0L ) | nonl; 110 sout | cosh( 1.0F+1.0FI ) | cosh( 1.0D+1.0DI ) | cosh( 1.0 L+1.0LI );110 sout | cosh( 1.0F+1.0FI ) | cosh( 1.0D+1.0DI ) | cosh( 1.0DL+1.0LI ); 111 111 sout | "tanh:" | tanh( 1.0F ) | tanh( 1.0D ) | tanh( 1.0L ) | nonl; 112 sout | tanh( 1.0F+1.0FI ) | tanh( 1.0D+1.0DI ) | tanh( 1.0 L+1.0LI );112 sout | tanh( 1.0F+1.0FI ) | tanh( 1.0D+1.0DI ) | tanh( 1.0DL+1.0LI ); 113 113 sout | "acosh:" | acosh( 1.0F ) | acosh( 1.0D ) | acosh( 1.0L ) | nonl; 114 sout | acosh( 1.0F+1.0FI ) | acosh( 1.0D+1.0DI ) | acosh( 1.0 L+1.0LI );114 sout | acosh( 1.0F+1.0FI ) | acosh( 1.0D+1.0DI ) | acosh( 1.0DL+1.0LI ); 115 115 sout | "asinh:" | asinh( 1.0F ) | asinh( 1.0D ) | asinh( 1.0L ) | nonl; 116 sout | asinh( 1.0F+1.0FI ) | asinh( 1.0D+1.0DI ) | asinh( 1.0 L+1.0LI );116 sout | asinh( 1.0F+1.0FI ) | asinh( 1.0D+1.0DI ) | asinh( 1.0DL+1.0LI ); 117 117 sout | "atanh:" | atanh( 1.0F ) | atanh( 1.0D ) | atanh( 1.0L ) | nonl; 118 sout | atanh( 1.0F+1.0FI ) | atanh( 1.0D+1.0DI ) | atanh( 1.0 L+1.0LI );118 sout | atanh( 1.0F+1.0FI ) | atanh( 1.0D+1.0DI ) | atanh( 1.0DL+1.0LI ); 119 119 120 120 //---------------------- Error / Gamma ---------------------- -
tests/pybin/tools.py
r660665f r5a46e09 376 376 return 1, "ERR No core dump" 377 377 378 try: 379 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE) 380 except: 381 return 1, "ERR Could not read core with gdb" 378 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE) 382 379 383 380 def core_archive(dst, name, exe): -
tests/test.py
r660665f r5a46e09 13 13 14 14 import os 15 import psutil 15 16 import signal 16 17 -
tests/typedefRedef.cfa
r660665f r5a46e09 45 45 typedef int X2; 46 46 47 X2 value __attribute__((aligned(4 * sizeof(X2))));48 49 __attribute__((aligned(4 * sizeof(X2)))) struct rseq_cs {50 int foo;51 };52 53 47 // xxx - this doesn't work yet due to parsing problems with generic types 54 48 // #ifdef __CFA__ -
tests/unified_locking/fast.cfa
r660665f r5a46e09 22 22 uint32_t cs() { 23 23 $thread * me = active_thread(); 24 uint32_t value ;24 uint32_t value = (uint32_t)me; 25 25 lock(mo.l); 26 26 { … … 28 28 mo.id = me; 29 29 yield(random(5)); 30 value = ((uint32_t)random()) ^ ((uint32_t)me);31 30 if(mo.id != me) sout | "Intruder!"; 32 31 mo.sum = tsum + value;
Note:
See TracChangeset
for help on using the changeset viewer.