cgen,markused: skip struct none { in cgen, if none is not used by V code reachable from fn main() { (#24824)

This commit is contained in:
Delyan Angelov 2025-07-01 14:13:03 +03:00 committed by GitHub
parent d05dc1f519
commit 2c063ea191
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 1 deletions

View File

@ -40,6 +40,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_none int // how many times `none` was used, filled in by markused
external_types bool // true, when external type is used
// json bool // json is imported
debugger bool // debugger is used

View File

@ -6635,7 +6635,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) {
if sym.name.starts_with('C.') {
continue
}
if sym.kind == .none {
if sym.kind == .none && (!g.pref.skip_unused || g.table.used_features.used_none > 0) {
g.type_definitions.writeln('struct none {')
g.type_definitions.writeln('\tEMPTY_STRUCT_DECLARATION;')
g.type_definitions.writeln('};')

View File

@ -540,6 +540,10 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
}
}
table.used_features.used_none = walker.used_none
if walker.used_none == 0 {
walker.used_fns.delete('${int(ast.none_type)}.str')
}
table.used_features.used_fns = walker.used_fns.move()
table.used_features.used_consts = walker.used_consts.move()
table.used_features.used_globals = walker.used_globals.move()