Skip to content

Commit

Permalink
markused: fix eprintln(err) on imported module on short program (re…
Browse files Browse the repository at this point in the history
…lated: #23498) (#23499)
  • Loading branch information
felipensp authored Jan 17, 2025
1 parent 3b0cfbf commit c98295b
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub mut:
used_veb_types []Type // veb context types, filled in by checker
used_maps int // how many times maps were used, filled in by markused
used_arrays int // how many times arrays were used, filled in by markused
used_modules map[string]bool // filled in checker
external_types bool // true, when external type is used
// json bool // json is imported
debugger bool // debugger is used
comptime_calls map[string]bool // resolved name to call on comptime
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -4004,7 +4004,7 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
node.pos)
}
if c.pref.skip_unused && !c.is_builtin_mod && node.language == .v && node.name.contains('.') {
c.table.used_features.used_modules[node.name.all_before('.')] = true
c.table.used_features.external_types = true
}
if mut obj := node.scope.find(node.name) {
match mut obj {
Expand Down
11 changes: 5 additions & 6 deletions vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -761,15 +761,14 @@ fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
}
}
c.expected_or_type = old_expected_or_type
if c.pref.skip_unused && !c.is_builtin_mod && c.mod == 'main' {
if c.pref.skip_unused && !c.is_builtin_mod && c.mod == 'main'
&& !c.table.used_features.external_types {
if node.is_method {
type_str := c.table.type_to_str(node.left_type)
if c.table.sym(node.left_type).is_builtin()
&& type_str !in c.table.used_features.used_modules {
c.table.used_features.used_modules[type_str] = true
if c.table.sym(node.left_type).is_builtin() {
c.table.used_features.external_types = true
}
} else if node.name.contains('.') {
c.table.used_features.used_modules[node.name.all_before('.')] = true
c.table.used_features.external_types = true
}
}

Expand Down
4 changes: 4 additions & 0 deletions vlib/v/checker/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
node.typ = c.expected_type
}
}
if c.pref.skip_unused && !c.is_builtin_mod && !c.table.used_features.external_types {
type_str := c.table.type_to_str(node.typ)
c.table.used_features.external_types = type_str.contains('.') && type_str.len > 1
}
struct_sym := c.table.sym(node.typ)
mut old_inside_generic_struct_init := false
mut old_cur_struct_generic_types := []ast.Type{}
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -6169,7 +6169,7 @@ fn (mut g Gen) write_init_function() {
g.write('\tas_cast_type_indexes = ')
g.writeln(g.as_cast_name_table())
}
if !g.pref.is_shared && (!g.pref.skip_unused || g.table.used_features.used_modules.len > 0) {
if !g.pref.is_shared && (!g.pref.skip_unused || g.table.used_features.external_types) {
// shared object does not need this
g.writeln('\tbuiltin_init();')
}
Expand Down
6 changes: 3 additions & 3 deletions vlib/v/markused/markused.v
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
core_fns << ref_array_idx_str + '.push'
core_fns << ref_array_idx_str + '.pop'
}
if table.used_features.used_modules.len > 0 {
if table.used_features.external_types {
include_panic_deps = true
}
if pref_.autofree {
Expand Down Expand Up @@ -289,7 +289,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
if table.used_features.auto_str || table.used_features.dump
|| table.used_features.print_types[mfn.receiver.typ.idx()]
|| table.used_features.asserts || table.used_features.debugger
|| table.used_features.used_modules.len > 0 {
|| table.used_features.external_types {
all_fn_root_names << k
}
continue
Expand All @@ -298,7 +298,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
all_fn_root_names << k
continue
}
if (pref_.autofree || table.used_features.used_modules.len > 0) && k.ends_with('.free') {
if (pref_.autofree || table.used_features.external_types) && k.ends_with('.free') {
all_fn_root_names << k
continue
}
Expand Down
1 change: 1 addition & 0 deletions vlib/v/tests/skip_unused/ierror_str.run.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No such file or directory; code: 2
1 change: 1 addition & 0 deletions vlib/v/tests/skip_unused/ierror_str.skip_unused.run.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No such file or directory; code: 2
6 changes: 6 additions & 0 deletions vlib/v/tests/skip_unused/ierror_str.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os

fn main() {
mut proc := os.Process{}
proc.run()
}

0 comments on commit c98295b

Please sign in to comment.