From dc7d47597b285c66e4887daa5cf31b3886eb433f Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 26 Apr 2026 23:05:12 +0300 Subject: [PATCH] checker: make unused private fn/const warning a notice --- doc/docs.md | 4 ++-- vlib/sync/waitgroup_test.v | 2 +- vlib/v/checker/tests/auto_ref_voidptr.out | 22 +++++++++---------- .../function_stored_in_global.run.out | 2 +- .../tests/incorrect_smartcast2_err.out | 4 ++-- .../modules/unused_private_declarations.out | 7 +++--- .../checker/tests/return_working_comp_if.out | 2 +- .../tests/return_working_comp_if_nested.out | 2 +- .../checker/tests/return_working_if_match.out | 2 +- .../checker/tests/return_working_match_if.out | 2 +- .../v/checker/tests/return_working_nested.out | 2 +- .../v/checker/tests/return_working_simple.out | 2 +- .../v/checker/tests/return_working_two_if.out | 2 +- .../v/checker/tests/return_working_unsafe.out | 2 +- .../tests/unused_private_declarations.out | 4 ++-- .../tests/use_deprecated_function_warning.out | 16 +++++++------- vlib/v/checker/tests/var_duplicate_const.out | 2 +- vlib/v/checker/unused_declarations.v | 4 ++-- vlib/v/util/util.v | 7 ++++-- 19 files changed, 47 insertions(+), 43 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index 47e46a4a6..fe882dc49 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -517,8 +517,8 @@ In development mode the compiler will warn you that you haven't used the variabl (you'll get an "unused variable" warning). In production mode (enabled by passing the `-prod` flag to v – `v -prod foo.v`) it will not compile at all (like in Go). -The same warning or error also applies to private top-level functions and constants -in the `main` module when they are never referenced. +The compiler also emits an informational notice for private top-level functions +and constants in the `main` module when they are never referenced. ```v fn main() { a := 10 diff --git a/vlib/sync/waitgroup_test.v b/vlib/sync/waitgroup_test.v index 77b1751a3..d02df8da4 100644 --- a/vlib/sync/waitgroup_test.v +++ b/vlib/sync/waitgroup_test.v @@ -36,7 +36,7 @@ fn test_waitgroup_reuse() { fn test_waitgroup_no_use() { mut done := false spawn fn (done voidptr) { - time.sleep(1 * time.second) + time.sleep(10 * time.second) if unsafe { *(&bool(done)) } == false { panic('test_waitgroup_no_use did not complete in time') } diff --git a/vlib/v/checker/tests/auto_ref_voidptr.out b/vlib/v/checker/tests/auto_ref_voidptr.out index 9de83c91f..fc844bdb7 100644 --- a/vlib/v/checker/tests/auto_ref_voidptr.out +++ b/vlib/v/checker/tests/auto_ref_voidptr.out @@ -1,19 +1,26 @@ vlib/v/checker/tests/auto_ref_voidptr.vv:1:8: notice: unused parameter: `x` 1 | fn foo(x int, p voidptr) {} | ^ - 2 | + 2 | 3 | fn foo2(p &Aa) {} vlib/v/checker/tests/auto_ref_voidptr.vv:1:15: notice: unused parameter: `p` 1 | fn foo(x int, p voidptr) {} | ^ - 2 | + 2 | 3 | fn foo2(p &Aa) {} vlib/v/checker/tests/auto_ref_voidptr.vv:3:9: notice: unused parameter: `p` 1 | fn foo(x int, p voidptr) {} - 2 | + 2 | 3 | fn foo2(p &Aa) {} | ^ - 4 | + 4 | + 5 | struct Aa {} +vlib/v/checker/tests/auto_ref_voidptr.vv:3:4: notice: unused function: `foo2` + 1 | fn foo(x int, p voidptr) {} + 2 | + 3 | fn foo2(p &Aa) {} + | ~~~~ + 4 | 5 | struct Aa {} vlib/v/checker/tests/auto_ref_voidptr.vv:9:9: warning: automatic Aa referencing/dereferencing into voidptr is deprecated and will be removed soon; use `foo(&x)` instead of `foo(x)` 7 | fn main() { @@ -22,10 +29,3 @@ vlib/v/checker/tests/auto_ref_voidptr.vv:9:9: warning: automatic Aa referencing/ | ^ 10 | // foo2(a) 11 | } -vlib/v/checker/tests/auto_ref_voidptr.vv:3:4: warning: unused function: `foo2` - 1 | fn foo(x int, p voidptr) {} - 2 | - 3 | fn foo2(p &Aa) {} - | ~~~~ - 4 | - 5 | struct Aa {} diff --git a/vlib/v/checker/tests/globals_run/function_stored_in_global.run.out b/vlib/v/checker/tests/globals_run/function_stored_in_global.run.out index 9ab274619..bde555d20 100644 --- a/vlib/v/checker/tests/globals_run/function_stored_in_global.run.out +++ b/vlib/v/checker/tests/globals_run/function_stored_in_global.run.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/globals_run/function_stored_in_global.vv:4:4: warning: unused function: `current` +vlib/v/checker/tests/globals_run/function_stored_in_global.vv:4:4: notice: unused function: `current` 2 | cpu_get_id fn () u64 3 | ) 4 | fn current() u64 { diff --git a/vlib/v/checker/tests/incorrect_smartcast2_err.out b/vlib/v/checker/tests/incorrect_smartcast2_err.out index 7344e2e5b..11ec0a5c8 100644 --- a/vlib/v/checker/tests/incorrect_smartcast2_err.out +++ b/vlib/v/checker/tests/incorrect_smartcast2_err.out @@ -1,11 +1,11 @@ -vlib/v/checker/tests/incorrect_smartcast2_err.vv:11:4: warning: unused function: `works` +vlib/v/checker/tests/incorrect_smartcast2_err.vv:11:4: notice: unused function: `works` 9 | type Either[T, E] = Left[E] | Right[T] 10 | 11 | fn works(v []Either[int, int]) { | ~~~~~ 12 | first := v[0] 13 | match first { -vlib/v/checker/tests/incorrect_smartcast2_err.vv:21:4: warning: unused function: `doesntwork` +vlib/v/checker/tests/incorrect_smartcast2_err.vv:21:4: notice: unused function: `doesntwork` 19 | } 20 | 21 | fn doesntwork(v []Either[int, int]) { diff --git a/vlib/v/checker/tests/modules/unused_private_declarations.out b/vlib/v/checker/tests/modules/unused_private_declarations.out index 62735a83b..3f0e689a8 100644 --- a/vlib/v/checker/tests/modules/unused_private_declarations.out +++ b/vlib/v/checker/tests/modules/unused_private_declarations.out @@ -1,14 +1,15 @@ -vlib/v/checker/tests/modules/unused_private_declarations/main.v:4:7: error: unused constant: `unused_const` +vlib/v/checker/tests/modules/unused_private_declarations/main.v:4:7: notice: unused constant: `unused_const` 2 | const used_by_pub_const = 3 3 | const const_used_by_unused_fn = 2 4 | const unused_const = 4 | ~~~~~~~~~~~~~~~~ 5 | 6 | fn used_fn() int { -vlib/v/checker/tests/modules/unused_private_declarations/main.v:14:4: error: unused function: `unused_fn` +vlib/v/checker/tests/modules/unused_private_declarations/main.v:14:4: notice: unused function: `unused_fn` 12 | } - 13 | + 13 | 14 | fn unused_fn() int { | ~~~~~~~~~ 15 | return const_used_by_unused_fn 16 | } +1 diff --git a/vlib/v/checker/tests/return_working_comp_if.out b/vlib/v/checker/tests/return_working_comp_if.out index 99085f521..eaf66a6aa 100644 --- a/vlib/v/checker/tests/return_working_comp_if.out +++ b/vlib/v/checker/tests/return_working_comp_if.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/return_working_comp_if.vv:3:4: warning: unused function: `foo` +vlib/v/checker/tests/return_working_comp_if.vv:3:4: notice: unused function: `foo` 1 | fn main() {} 2 | 3 | fn foo() string { diff --git a/vlib/v/checker/tests/return_working_comp_if_nested.out b/vlib/v/checker/tests/return_working_comp_if_nested.out index 442f64705..a55d55b54 100644 --- a/vlib/v/checker/tests/return_working_comp_if_nested.out +++ b/vlib/v/checker/tests/return_working_comp_if_nested.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/return_working_comp_if_nested.vv:3:4: warning: unused function: `foo` +vlib/v/checker/tests/return_working_comp_if_nested.vv:3:4: notice: unused function: `foo` 1 | fn main() {} 2 | 3 | fn foo() string { diff --git a/vlib/v/checker/tests/return_working_if_match.out b/vlib/v/checker/tests/return_working_if_match.out index 5e9ef1cc0..8952f3d47 100644 --- a/vlib/v/checker/tests/return_working_if_match.out +++ b/vlib/v/checker/tests/return_working_if_match.out @@ -19,7 +19,7 @@ vlib/v/checker/tests/return_working_if_match.vv:7:4: notice: match is always fal | ^ 8 | else { return '' } 9 | } -vlib/v/checker/tests/return_working_if_match.vv:3:4: warning: unused function: `foo` +vlib/v/checker/tests/return_working_if_match.vv:3:4: notice: unused function: `foo` 1 | fn main() {} 2 | 3 | fn foo() string { diff --git a/vlib/v/checker/tests/return_working_match_if.out b/vlib/v/checker/tests/return_working_match_if.out index ddff899ea..cdfca4343 100644 --- a/vlib/v/checker/tests/return_working_match_if.out +++ b/vlib/v/checker/tests/return_working_match_if.out @@ -19,7 +19,7 @@ vlib/v/checker/tests/return_working_match_if.vv:9:7: notice: condition is always | ~~~~ 10 | return '' 11 | } else { -vlib/v/checker/tests/return_working_match_if.vv:3:4: warning: unused function: `foo` +vlib/v/checker/tests/return_working_match_if.vv:3:4: notice: unused function: `foo` 1 | fn main() {} 2 | 3 | fn foo() string { diff --git a/vlib/v/checker/tests/return_working_nested.out b/vlib/v/checker/tests/return_working_nested.out index 93e4ad9d8..f7f86f639 100644 --- a/vlib/v/checker/tests/return_working_nested.out +++ b/vlib/v/checker/tests/return_working_nested.out @@ -12,7 +12,7 @@ vlib/v/checker/tests/return_working_nested.vv:7:6: notice: condition is always t | ~~~~ 8 | return '' 9 | } -vlib/v/checker/tests/return_working_nested.vv:3:4: warning: unused function: `foo` +vlib/v/checker/tests/return_working_nested.vv:3:4: notice: unused function: `foo` 1 | fn main() {} 2 | 3 | fn foo() string { diff --git a/vlib/v/checker/tests/return_working_simple.out b/vlib/v/checker/tests/return_working_simple.out index 785b9fc16..aa788fd10 100644 --- a/vlib/v/checker/tests/return_working_simple.out +++ b/vlib/v/checker/tests/return_working_simple.out @@ -5,7 +5,7 @@ vlib/v/checker/tests/return_working_simple.vv:4:5: notice: condition is always t | ~~~~ 5 | return '' 6 | } else { -vlib/v/checker/tests/return_working_simple.vv:3:4: warning: unused function: `foo` +vlib/v/checker/tests/return_working_simple.vv:3:4: notice: unused function: `foo` 1 | fn main() {} 2 | 3 | fn foo() string { diff --git a/vlib/v/checker/tests/return_working_two_if.out b/vlib/v/checker/tests/return_working_two_if.out index fe159a8f0..5ea8002d3 100644 --- a/vlib/v/checker/tests/return_working_two_if.out +++ b/vlib/v/checker/tests/return_working_two_if.out @@ -19,7 +19,7 @@ vlib/v/checker/tests/return_working_two_if.vv:9:6: notice: condition is always t | ~~~~ 10 | return '' 11 | } else { -vlib/v/checker/tests/return_working_two_if.vv:3:4: warning: unused function: `foo` +vlib/v/checker/tests/return_working_two_if.vv:3:4: notice: unused function: `foo` 1 | fn main() {} 2 | 3 | fn foo() string { diff --git a/vlib/v/checker/tests/return_working_unsafe.out b/vlib/v/checker/tests/return_working_unsafe.out index 401ed6134..c5a0b2b3c 100644 --- a/vlib/v/checker/tests/return_working_unsafe.out +++ b/vlib/v/checker/tests/return_working_unsafe.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/return_working_unsafe.vv:3:4: warning: unused function: `foo` +vlib/v/checker/tests/return_working_unsafe.vv:3:4: notice: unused function: `foo` 1 | fn main() {} 2 | 3 | fn foo() string { diff --git a/vlib/v/checker/tests/unused_private_declarations.out b/vlib/v/checker/tests/unused_private_declarations.out index 708395d8d..f5044a962 100644 --- a/vlib/v/checker/tests/unused_private_declarations.out +++ b/vlib/v/checker/tests/unused_private_declarations.out @@ -1,11 +1,11 @@ -vlib/v/checker/tests/unused_private_declarations.vv:4:7: warning: unused constant: `unused_const` +vlib/v/checker/tests/unused_private_declarations.vv:4:7: notice: unused constant: `unused_const` 2 | const used_by_pub_const = 3 3 | const const_used_by_unused_fn = 2 4 | const unused_const = 4 | ~~~~~~~~~~~~~~~~ 5 | 6 | fn used_fn() int { -vlib/v/checker/tests/unused_private_declarations.vv:14:4: warning: unused function: `unused_fn` +vlib/v/checker/tests/unused_private_declarations.vv:14:4: notice: unused function: `unused_fn` 12 | } 13 | 14 | fn unused_fn() int { diff --git a/vlib/v/checker/tests/use_deprecated_function_warning.out b/vlib/v/checker/tests/use_deprecated_function_warning.out index 35bbc3ac9..1882d2997 100644 --- a/vlib/v/checker/tests/use_deprecated_function_warning.out +++ b/vlib/v/checker/tests/use_deprecated_function_warning.out @@ -1,5 +1,12 @@ +vlib/v/checker/tests/use_deprecated_function_warning.vv:21:4: notice: unused function: `method` + 19 | fn (s S1) m() {} + 20 | + 21 | fn method() { + | ~~~~~~ + 22 | s := S1{} + 23 | s.m() vlib/v/checker/tests/use_deprecated_function_warning.vv:12:2: warning: function `xyz` has been deprecated - 10 | + 10 | 11 | fn main() { 12 | xyz() | ~~~~~ @@ -18,10 +25,3 @@ vlib/v/checker/tests/use_deprecated_function_warning.vv:23:4: warning: method `S 23 | s.m() | ~~~ 24 | } -vlib/v/checker/tests/use_deprecated_function_warning.vv:21:4: warning: unused function: `method` - 19 | fn (s S1) m() {} - 20 | - 21 | fn method() { - | ~~~~~~ - 22 | s := S1{} - 23 | s.m() diff --git a/vlib/v/checker/tests/var_duplicate_const.out b/vlib/v/checker/tests/var_duplicate_const.out index b1e152e30..831a9310b 100644 --- a/vlib/v/checker/tests/var_duplicate_const.out +++ b/vlib/v/checker/tests/var_duplicate_const.out @@ -12,7 +12,7 @@ vlib/v/checker/tests/var_duplicate_const.vv:4:5: warning: unused variable: `size | ~~~~ 5 | println(main.size) 6 | } -vlib/v/checker/tests/var_duplicate_const.vv:1:7: warning: unused constant: `size` +vlib/v/checker/tests/var_duplicate_const.vv:1:7: notice: unused constant: `size` 1 | const size = 22 | ~~~~~~~~~ 2 | diff --git a/vlib/v/checker/unused_declarations.v b/vlib/v/checker/unused_declarations.v index 1dcaaae19..a6289c280 100644 --- a/vlib/v/checker/unused_declarations.v +++ b/vlib/v/checker/unused_declarations.v @@ -71,14 +71,14 @@ fn (mut c Checker) check_unused_declarations_in_stmts(stmts []ast.Stmt) { ast.ConstDecl { for field in stmt.fields { if c.should_warn_about_unused_const(field) { - c.warn('unused constant: `${stripped_name(field.name)}`', field.pos) + c.note('unused constant: `${stripped_name(field.name)}`', field.pos) } } } ast.FnDecl { if c.should_warn_about_unused_fn(stmt) { name := if stmt.short_name != '' { stmt.short_name } else { stmt.get_name() } - c.warn('unused function: `${name}`', stmt.name_pos) + c.note('unused function: `${name}`', stmt.name_pos) } } ast.ExprStmt { diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 5705796ed..e91c26947 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -265,8 +265,11 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) { tlog('lockfile released') } else { tlog('another process got the lock') - // wait till the other V tool recompilation process finished: - if l.wait_acquire(10 * time.second) { + // wait till the other V tool recompilation process finished; + // the timeout is intentionally generous, since on slow CI VMs + // (e.g. FreeBSD QEMU), recompiling a tool can take >10s, and + // falling through with a missing tool_exe leads to ENOENT on exec: + if l.wait_acquire(60 * time.second) { tlog('the other process finished') l.release() } else { -- 2.39.5