Skip to content

Commit bc4a240

Browse files
committed
cgen: support -d trace_cgen_fn_decl and -d trace_cgen_gen_fn_decl too
1 parent bf7f43f commit bc4a240

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ mut:
284284
curr_comptime_node &ast.Expr = unsafe { nil } // current `$if` expr
285285
is_builtin_overflow_mod bool
286286
do_int_overflow_checks bool // outside a `@[ignore_overflow] fn abc() {}` or a function in `builtin.overflow`
287+
//
288+
tid int // the thread id of the file processor in the thread pool (log it to debug issues in parallel cgen)
289+
fid int // the index of ast.File that is currently processed (log it to debug issues in parallel cgen)
287290
}
288291

289292
@[heap]
@@ -491,7 +494,9 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
491494
}
492495
} else {
493496
util.timing_start('cgen serial processing')
494-
for file in files {
497+
for fid, file in files {
498+
global_g.tid = 0
499+
global_g.fid = fid
495500
global_g.file = file
496501
global_g.gen_file()
497502
global_g.cleanups[file.mod.name].drain_builder(mut global_g.cleanup, 100)
@@ -815,6 +820,8 @@ fn cgen_process_one_file_cb(mut p pool.PoolProcessor, idx int, wid int) &Gen {
815820
}
816821
mut global_g := unsafe { &Gen(p.get_shared_context()) }
817822
mut g := &Gen{
823+
fid: idx
824+
tid: wid
818825
file: file
819826
out: strings.new_builder(512000)
820827
cheaders: strings.new_builder(15000)
@@ -925,7 +932,7 @@ pub fn (mut g Gen) free_builders() {
925932

926933
pub fn (mut g Gen) gen_file() {
927934
$if trace_cgen ? {
928-
eprintln('> ${@FILE}:${@LINE} | g.file.path: ${g.file.path}')
935+
eprintln('> ${@FILE}:${@LINE} | g.file.path: ${g.file.path} | g.tid: ${g.tid:3} | g.fid: ${g.fid:3}')
929936
}
930937
g.timers.start('cgen_file ${g.file.path}')
931938
g.unique_file_path_hash = fnv1a.sum64_string(g.file.path)

vlib/v/gen/c/fn.v

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ fn (mut g Gen) is_used_by_main(node ast.FnDecl) bool {
5050
}
5151

5252
fn (mut g Gen) fn_decl(node ast.FnDecl) {
53+
$if trace_cgen_fn_decl ? {
54+
eprintln('> g.tid: ${g.tid:3} | g.fid: ${g.fid:3} | g.file.path: ${g.file.path} | fn_decl: ${node.name}')
55+
}
5356
if node.should_be_skipped {
5457
return
5558
}
@@ -167,6 +170,9 @@ fn (mut g Gen) fn_decl(node ast.FnDecl) {
167170
}
168171

169172
fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
173+
$if trace_cgen_gen_fn_decl ? {
174+
eprintln('> g.tid: ${g.tid:3} | g.fid: ${g.fid:3} | g.file.path: ${g.file.path} | gen_fn_decl: ${node.name} | skip: ${skip}')
175+
}
170176
// TODO: For some reason, build fails with autofree with this line
171177
// as it's only informative, comment it for now
172178
// g.gen_attrs(it.attrs)

0 commit comments

Comments
 (0)