@@ -8,7 +8,7 @@ import v.pref
88
99// mark_used walks the AST, starting at main() and marks all used fns transitively
1010pub fn mark_used (mut table ast.Table, mut pref_ pref.Preferences, ast_files []& ast.File) {
11- mut all_fns , all_consts , all_globals := all_fn_const_and_global (ast_files)
11+ mut all_fns , all_consts , all_globals , all_fields := all_global_decl (ast_files)
1212 util.timing_start ('MARKUSED' )
1313 defer {
1414 util.timing_measure ('MARKUSED' )
@@ -464,11 +464,13 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
464464 all_fns: all_fns
465465 all_consts: all_consts
466466 all_globals: all_globals
467+ all_fields: all_fields
467468 pref: pref_
468469 )
469470 walker.mark_markused_consts () // tagged with `@[markused]`
470471 walker.mark_markused_globals () // tagged with `@[markused]`
471472 walker.mark_markused_fns () // tagged with `@[markused]`, `@[export]` and veb actions
473+ walker.mark_struct_field_default_expr ()
472474
473475 for k, _ in table.used_features.comptime_calls {
474476 walker.fn_by_name (k)
@@ -553,14 +555,15 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
553555 }
554556}
555557
556- fn all_fn_const_and_global (ast_files []& ast.File) (map [string ]ast.FnDecl, map [string ]ast.ConstField, map [string ]ast.GlobalField) {
558+ fn all_global_decl (ast_files []& ast.File) (map [string ]ast.FnDecl, map [string ]ast.ConstField, map [string ]ast.GlobalField, map [ string ]ast.StructField ) {
557559 util.timing_start (@METHOD)
558560 defer {
559561 util.timing_measure (@METHOD)
560562 }
561563 mut all_fns := map [string ]ast.FnDecl{}
562564 mut all_consts := map [string ]ast.ConstField{}
563565 mut all_globals := map [string ]ast.GlobalField{}
566+ mut all_fields := map [string ]ast.StructField{}
564567 for i in 0 .. ast_files.len {
565568 for node in ast_files[i].stmts {
566569 match node {
@@ -582,11 +585,17 @@ fn all_fn_const_and_global(ast_files []&ast.File) (map[string]ast.FnDecl, map[st
582585 all_globals[gkey] = gfield
583586 }
584587 }
588+ ast.StructDecl {
589+ for sfield in node.fields {
590+ sfkey := sfield.sfkey ()
591+ all_fields[sfkey] = sfield
592+ }
593+ }
585594 else {}
586595 }
587596 }
588597 }
589- return all_fns, all_consts, all_globals
598+ return all_fns, all_consts, all_globals, all_fields
590599}
591600
592601fn mark_all_methods_used (mut table ast.Table, mut all_fn_root_names []string , typ ast.Type) {
0 commit comments