vfmt: change all '$expr' to '${expr}' (#16428)

This commit is contained in:
yuyi 2022-11-15 21:53:13 +08:00 committed by GitHub
parent 56239b4a23
commit 017ace6ea7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
859 changed files with 7156 additions and 7135 deletions

View file

@ -18,7 +18,7 @@ const fast_dir = os.dir(@FILE)
const vdir = os.dir(os.dir(os.dir(fast_dir)))
fn elog(msg string) {
eprintln('$time.now().format_ss_micro() $msg')
eprintln('${time.now().format_ss_micro()} ${msg}')
}
fn main() {
@ -35,10 +35,10 @@ fn main() {
if os.args.contains('-clang') {
ccompiler_path = 'clang'
}
elog('fast_dir: $fast_dir | vdir: $vdir | compiler: $ccompiler_path')
elog('fast_dir: ${fast_dir} | vdir: ${vdir} | compiler: ${ccompiler_path}')
os.chdir(fast_dir)!
if !os.exists('$vdir/v') && !os.is_dir('$vdir/vlib') {
if !os.exists('${vdir}/v') && !os.is_dir('${vdir}/vlib') {
elog('fast.html generator needs to be located in `v/cmd/tools/fast`')
exit(1)
}
@ -48,9 +48,9 @@ fn main() {
if !os.args.contains('-noupdate') {
elog('Fetching updates...')
ret := os.system('$vdir/v up')
ret := os.system('${vdir}/v up')
if ret != 0 {
elog('failed to update V, exit_code: $ret')
elog('failed to update V, exit_code: ${ret}')
return
}
}
@ -59,8 +59,8 @@ fn main() {
commit := exec('git rev-parse HEAD')[..8]
if os.exists('website/index.html') {
uploaded_index := os.read_file('website/index.html')!
if uploaded_index.contains('>$commit<') {
elog('NOTE: commit $commit had been benchmarked already.')
if uploaded_index.contains('>${commit}<') {
elog('NOTE: commit ${commit} had been benchmarked already.')
if !os.args.contains('-force') {
elog('nothing more to do')
return
@ -69,16 +69,16 @@ fn main() {
}
os.chdir(vdir)!
message := exec('git log --pretty=format:"%s" -n1 $commit')
commit_date := exec('git log -n1 --pretty="format:%at" $commit')
message := exec('git log --pretty=format:"%s" -n1 ${commit}')
commit_date := exec('git log -n1 --pretty="format:%at" ${commit}')
date := time.unix(commit_date.i64())
elog('Benchmarking commit $commit , with commit message: "$message", commit_date: $commit_date, date: $date')
elog('Benchmarking commit ${commit} , with commit message: "${message}", commit_date: ${commit_date}, date: ${date}')
// build an optimized V
if os.args.contains('-do-not-rebuild-vprod') {
if !os.exists('vprod') {
elog('Exiting, since if you use `-do-not-rebuild-vprod`, you should already have a `$vdir/vprod` executable, but it is missing!')
elog('Exiting, since if you use `-do-not-rebuild-vprod`, you should already have a `${vdir}/vprod` executable, but it is missing!')
return
}
} else {
@ -93,15 +93,15 @@ fn main() {
if !os.args.contains('-do-not-rebuild-caches') {
elog('clearing caches...')
// cache vlib modules
exec('$vdir/v wipe-cache')
exec('$vdir/v -o vwarm_caches -cc $ccompiler_path cmd/v')
exec('${vdir}/v wipe-cache')
exec('${vdir}/v -o vwarm_caches -cc ${ccompiler_path} cmd/v')
}
// measure
diff1 := measure('$vdir/vprod $voptions -o v.c cmd/v', 'v.c')
diff2 := measure('$vdir/vprod $voptions -cc $ccompiler_path -o v2 cmd/v', 'v2')
diff1 := measure('${vdir}/vprod ${voptions} -o v.c cmd/v', 'v.c')
diff2 := measure('${vdir}/vprod ${voptions} -cc ${ccompiler_path} -o v2 cmd/v', 'v2')
diff3 := 0 // measure('$vdir/vprod -native $vdir/cmd/tools/1mil.v', 'native 1mil')
diff4 := measure('$vdir/vprod $voptions -cc $ccompiler_path examples/hello_world.v',
diff4 := measure('${vdir}/vprod ${voptions} -cc ${ccompiler_path} examples/hello_world.v',
'hello.v')
vc_size := os.file_size('v.c') / 1000
scan, parse, check, cgen, vlines := measure_steps_minimal(vdir)!
@ -113,19 +113,19 @@ fn main() {
table := os.read_file('table.html')!
new_table :=
' <tr>
<td>$date.format()</td>
<td><a target=_blank href="https://github.com/vlang/v/commit/$commit">$commit</a></td>
<td>$html_message</td>
<td>${date.format()}</td>
<td><a target=_blank href="https://github.com/vlang/v/commit/${commit}">${commit}</a></td>
<td>${html_message}</td>
<td>${diff1}ms</td>
<td>${diff2}ms</td>
<td>${diff3}ms</td>
<td>${diff4}ms</td>
<td>$vc_size KB</td>
<td>${vc_size} KB</td>
<td>${parse}ms</td>
<td>${check}ms</td>
<td>${cgen}ms</td>
<td>${scan}ms</td>
<td>$vlines</td>
<td>${vlines}</td>
<td>${int(f64(vlines) / f64(diff1) * 1000.0)}</td>
</tr>\n' +
table.trim_space() + '\n'
@ -159,7 +159,7 @@ fn exec(s string) string {
// measure returns milliseconds
fn measure(cmd string, description string) int {
elog(' Measuring $description, warmups: $warmup_samples, samples: $max_samples, discard: $discard_highest_samples, with cmd: `$cmd`')
elog(' Measuring ${description}, warmups: ${warmup_samples}, samples: ${max_samples}, discard: ${discard_highest_samples}, with cmd: `${cmd}`')
for _ in 0 .. warmup_samples {
exec(cmd)
}
@ -170,23 +170,23 @@ fn measure(cmd string, description string) int {
exec(cmd)
sample := int(sw.elapsed().milliseconds())
runs << sample
println('$sample ms')
println('${sample} ms')
flush_stdout()
}
runs.sort()
elog(' runs before discarding: $runs, avg: ${f64(arrays.sum(runs) or { 0 }) / runs.len:5.2f}')
elog(' runs before discarding: ${runs}, avg: ${f64(arrays.sum(runs) or { 0 }) / runs.len:5.2f}')
// Discard the highest times, since on AWS, they are caused by random load spikes,
// that are unpredictable, add noise and skew the statistics, without adding useful
// insights:
for _ in 0 .. discard_highest_samples {
runs.pop()
}
elog(' runs after discarding: $runs, avg: ${f64(arrays.sum(runs) or { 0 }) / runs.len:5.2f}')
elog(' runs after discarding: ${runs}, avg: ${f64(arrays.sum(runs) or { 0 }) / runs.len:5.2f}')
return int(f64(arrays.sum(runs) or { 0 }) / runs.len)
}
fn measure_steps_minimal(vdir string) !(int, int, int, int, int) {
elog('measure_steps_minimal $vdir, samples: $max_samples')
elog('measure_steps_minimal ${vdir}, samples: ${max_samples}')
mut scans, mut parses, mut checks, mut cgens, mut vliness := []int{}, []int{}, []int{}, []int{}, []int{}
for i in 0 .. max_samples {
scan, parse, check, cgen, vlines := measure_steps_one_sample(vdir)
@ -195,15 +195,15 @@ fn measure_steps_minimal(vdir string) !(int, int, int, int, int) {
checks << check
cgens << cgen
vliness << vlines
elog(' [${i:2}/${max_samples:2}] scan: $scan ms, min parse: $parse ms, min check: $check ms, min cgen: $cgen ms, min vlines: $vlines ms')
elog(' [${i:2}/${max_samples:2}] scan: ${scan} ms, min parse: ${parse} ms, min check: ${check} ms, min cgen: ${cgen} ms, min vlines: ${vlines} ms')
}
scan, parse, check, cgen, vlines := arrays.min(scans)!, arrays.min(parses)!, arrays.min(checks)!, arrays.min(cgens)!, arrays.min(vliness)!
elog('measure_steps_minimal => min scan: $scan ms, min parse: $parse ms, min check: $check ms, min cgen: $cgen ms, min vlines: $vlines ms')
elog('measure_steps_minimal => min scan: ${scan} ms, min parse: ${parse} ms, min check: ${check} ms, min cgen: ${cgen} ms, min vlines: ${vlines} ms')
return scan, parse, check, cgen, vlines
}
fn measure_steps_one_sample(vdir string) (int, int, int, int, int) {
resp := os.execute_or_exit('$vdir/vprod $voptions -o v.c cmd/v')
resp := os.execute_or_exit('${vdir}/vprod ${voptions} -o v.c cmd/v')
mut scan, mut parse, mut check, mut cgen, mut vlines := 0, 0, 0, 0, 0
lines := resp.output.split_into_lines()