vfmt: format all of cmd/ and add it to `v test-cleancode` (#9418)

pull/9457/head weekly.2021.12.2
Lukas Neubert 2021-03-24 22:37:10 +01:00 committed by GitHub
parent 837cada30c
commit 7664964c56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 68 additions and 43 deletions

View File

@ -30,7 +30,8 @@ fn main() {
checksum = 0
for len in str_lens {
end_pos := start_pos + len
checksum ^= wyhash.wyhash_c(unsafe { byteptr(bytepile.data) + start_pos }, u64(len), 1)
checksum ^= wyhash.wyhash_c(unsafe { byteptr(bytepile.data) + start_pos }, u64(len),
1)
start_pos = end_pos
}
bhashing_1.measure('wyhash.wyhash_c | checksum: ${checksum:22}')

View File

@ -59,8 +59,8 @@ fn report_undocumented_functions_in_file(opt Options, file string) {
lines := contents.split('\n')
mut info := []UndocumentedFN{}
for i, line in lines {
if line.starts_with('pub fn') ||
(line.starts_with('fn ') && !(line.starts_with('fn C.') || line.starts_with('fn main'))) {
if line.starts_with('pub fn') || (line.starts_with('fn ') && !(line.starts_with('fn C.')
|| line.starts_with('fn main'))) {
// println('Match: $line')
if i > 0 && lines.len > 0 {
mut line_above := lines[i - 1]
@ -89,7 +89,11 @@ fn report_undocumented_functions_in_file(opt Options, file string) {
}
if info.len > 0 {
for undocumented_fn in info {
tags_str := if opt.collect_tags && undocumented_fn.tags.len > 0 { '$undocumented_fn.tags' } else { '' }
tags_str := if opt.collect_tags && undocumented_fn.tags.len > 0 {
'$undocumented_fn.tags'
} else {
''
}
if opt.deprecated {
println('$file:$undocumented_fn.line:0:$undocumented_fn.signature $tags_str')
} else {

View File

@ -404,7 +404,9 @@ pub fn building_any_v_binaries_failed() bool {
os.chdir(parent_dir)
mut failed := false
v_build_commands := ['$vexe -o v_g -g cmd/v', '$vexe -o v_prod_g -prod -g cmd/v',
'$vexe -o v_cg -cg cmd/v', '$vexe -o v_prod_cg -prod -cg cmd/v', '$vexe -o v_prod -prod cmd/v']
'$vexe -o v_cg -cg cmd/v', '$vexe -o v_prod_cg -prod -cg cmd/v',
'$vexe -o v_prod -prod cmd/v',
]
mut bmark := benchmark.new_benchmark()
for cmd in v_build_commands {
bmark.step()

View File

@ -154,8 +154,8 @@ pub mut:
pub fn add_common_tool_options(mut context VGitOptions, mut fp flag.FlagParser) []string {
tdir := os.temp_dir()
context.workdir = os.real_path(fp.string('workdir', `w`, tdir, 'A writable base folder. Default: $tdir'))
context.v_repo_url = fp.string('vrepo', 0, remote_v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.')
context.vc_repo_url = fp.string('vcrepo', 0, remote_vc_repo_url, 'The url of the vc repository. You can clone it
context.v_repo_url = fp.string('vrepo', 0, vgit.remote_v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.')
context.vc_repo_url = fp.string('vcrepo', 0, vgit.remote_vc_repo_url, 'The url of the vc repository. You can clone it
${flag.space}beforehand, and then just give the local folder
${flag.space}path here. That will eliminate the network ops
${flag.space}done by this tool, which is useful, if you want

View File

@ -12,4 +12,3 @@ pub fn show_topic(topic string) {
}
println(content)
}

View File

@ -6,7 +6,7 @@ import vgit
const (
tool_version = '0.0.5'
tool_description = " Compares V executable size and performance,
| between 2 commits from V\'s local git history.
| between 2 commits from V's local git history.
| When only one commit is given, it is compared to master.
| ".strip_margin()
)
@ -50,14 +50,23 @@ fn (c Context) compare_versions() {
// The first is the baseline, against which all the others will be compared.
// It is the fastest, since hello_world.v has only a single println in it,
mut perf_files := []string{}
perf_files <<
c.compare_v_performance('source_hello', ['vprod @DEBUG@ -o source.c examples/hello_world.v', 'vprod -o source.c examples/hello_world.v', 'v @DEBUG@ -o source.c examples/hello_world.v', 'v -o source.c examples/hello_world.v'])
perf_files <<
c.compare_v_performance('source_v', ['vprod @DEBUG@ -o source.c @COMPILER@', 'vprod -o source.c @COMPILER@', 'v @DEBUG@ -o source.c @COMPILER@', 'v -o source.c @COMPILER@'])
perf_files <<
c.compare_v_performance('binary_hello', ['vprod -o hello examples/hello_world.v', 'v -o hello examples/hello_world.v'])
perf_files <<
c.compare_v_performance('binary_v', ['vprod -o binary @COMPILER@', 'v -o binary @COMPILER@'])
perf_files << c.compare_v_performance('source_hello', [
'vprod @DEBUG@ -o source.c examples/hello_world.v',
'vprod -o source.c examples/hello_world.v',
'v @DEBUG@ -o source.c examples/hello_world.v',
'v -o source.c examples/hello_world.v',
])
perf_files << c.compare_v_performance('source_v', ['vprod @DEBUG@ -o source.c @COMPILER@',
'vprod -o source.c @COMPILER@', 'v @DEBUG@ -o source.c @COMPILER@',
'v -o source.c @COMPILER@',
])
perf_files << c.compare_v_performance('binary_hello', [
'vprod -o hello examples/hello_world.v',
'v -o hello examples/hello_world.v',
])
perf_files << c.compare_v_performance('binary_v', ['vprod -o binary @COMPILER@',
'v -o binary @COMPILER@',
])
println('All performance files:')
for f in perf_files {
println(' $f')
@ -97,7 +106,9 @@ fn (c &Context) prepare_v(cdir string, commit string) {
scripting.run('upx -qqq --lzma vprod_stripped_upxed')
scripting.show_sizes_of_files(['$cdir/cv', '$cdir/cv_stripped', '$cdir/cv_stripped_upxed'])
scripting.show_sizes_of_files(['$cdir/v', '$cdir/v_stripped', '$cdir/v_stripped_upxed'])
scripting.show_sizes_of_files(['$cdir/vprod', '$cdir/vprod_stripped', '$cdir/vprod_stripped_upxed'])
scripting.show_sizes_of_files(['$cdir/vprod', '$cdir/vprod_stripped',
'$cdir/vprod_stripped_upxed',
])
vversion := scripting.run('$cdir/v -version')
vcommit := scripting.run('git rev-parse --short --verify HEAD')
println('V version is: $vversion , local source commit: $vcommit')
@ -110,7 +121,8 @@ fn (c &Context) prepare_v(cdir string, commit string) {
scripting.run('wc cmd/v/*.v vlib/compiler/*.v | tail -n -1'))
}
} else if vgit_context.vvlocation == 'v.v' {
println('Source lines of the compiler: ' + scripting.run('wc v.v vlib/compiler/*.v | tail -n -1'))
println('Source lines of the compiler: ' +
scripting.run('wc v.v vlib/compiler/*.v | tail -n -1'))
} else {
println('Source lines of the compiler: ' + scripting.run('wc compiler/*.v | tail -n -1'))
}
@ -140,17 +152,26 @@ fn (c Context) compare_v_performance(label string, commands []string) string {
println(cmd)
}
for cmd in commands {
hyperfine_commands_arguments <<
" \'cd ${c.b:-34s} ; ./$cmd \' ".replace_each(['@COMPILER@', source_location_b, '@DEBUG@', debug_option_b])
hyperfine_commands_arguments << " \'cd ${c.b:-34s} ; ./$cmd \' ".replace_each([
'@COMPILER@',
source_location_b,
'@DEBUG@',
debug_option_b,
])
}
for cmd in commands {
hyperfine_commands_arguments <<
" \'cd ${c.a:-34s} ; ./$cmd \' ".replace_each(['@COMPILER@', source_location_a, '@DEBUG@', debug_option_a])
hyperfine_commands_arguments << " \'cd ${c.a:-34s} ; ./$cmd \' ".replace_each([
'@COMPILER@',
source_location_a,
'@DEBUG@',
debug_option_a,
])
}
// /////////////////////////////////////////////////////////////////////////////
cmd_stats_file := os.real_path([c.vgo.workdir, 'v_performance_stats_${label}.json'].join(os.path_separator))
comparison_cmd := 'hyperfine $c.hyperfineopts ' + '--export-json $cmd_stats_file ' + '--time-unit millisecond ' +
'--style full --warmup $c.warmups ' + hyperfine_commands_arguments.join(' ')
comparison_cmd := 'hyperfine $c.hyperfineopts ' + '--export-json $cmd_stats_file ' +
'--time-unit millisecond ' + '--style full --warmup $c.warmups ' +
hyperfine_commands_arguments.join(' ')
// /////////////////////////////////////////////////////////////////////////////
if c.vgo.verbose {
println(comparison_cmd)

View File

@ -23,9 +23,7 @@ const (
'vlib/gg/m4/matrix.v' /* has hand crafted meaningful formatting of matrices */,
]
vfmt_verify_list = [
'cmd/v/v.v',
'cmd/tools/vdoc/',
'cmd/tools/vvet/',
'cmd/',
'vlib/arrays/',
'vlib/benchmark/',
'vlib/bitfield/',

View File

@ -7,19 +7,19 @@ import v.util
const (
known_failing_exceptions = [
'vlib/crypto/aes/const.v',
/* multiple narrow columns of []string turned to 1 long single column, otherwise works */
// multiple narrow columns of []string turned to 1 long single column, otherwise works
'vlib/v/gen/js/tests/life.v',
/* error: unexpected `,`, expecting ), on JS.setInterval(fn () { show(game) game = step(game) }, 500) */
// error: unexpected `,`, expecting ), on JS.setInterval(fn () { show(game) game = step(game) }, 500)
'vlib/builtin/js/builtin.v',
/* JS.console.error(s) => JS.error(s), JS.process.exit(c) => JS.exit(c) */
// JS.console.error(s) => JS.error(s), JS.process.exit(c) => JS.exit(c)
'vlib/builtin/js/jsfns_node.js.v',
'vlib/builtin/js/jsfns.js.v',
'vlib/builtin/js/jsfns_browser.js.v',
/* error: expr(): bad token `asm`, on `asm {}` */
// error: expr(): bad token `asm`, on `asm {}`
'vlib/builtin/bare/linuxsys_bare.v',
/* total chaos (duplicated code several times) in array_eq_test.v */
// total chaos (duplicated code several times) in array_eq_test.v
'vlib/builtin/array_eq_test.v',
/* the fn args are removed, then `cb fn (picohttpparser.Request, mut picohttpparser.Response)` can not be reparsed */
// the fn args are removed, then `cb fn (picohttpparser.Request, mut picohttpparser.Response)` can not be reparsed
'vlib/picoev/picoev.v',
]
)

View File

@ -19,7 +19,7 @@ pub fn print_and_exit(topic string) {
exit(1)
}
// `init` has the same help topic as `new`
name := if topic == "init" { "new" } else { topic }
name := if topic == 'init' { 'new' } else { topic }
target_topic := os.join_path(vroot, 'cmd', 'v', 'help', '${name}.txt')
content := os.read_file(target_topic) or {
eprintln(help.unknown_topic)