From 82a947bffa6fc5629db32de61497d573535d3a3d Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 14 Dec 2024 05:47:42 -0300 Subject: [PATCH] markused: fix codegen for a .v program, that does just `import json as _` (#23155) --- vlib/v/markused/markused.v | 12 ++++++------ vlib/v/tests/skip_unused/import_json_only.run.out | 0 .../skip_unused/import_json_only.skip_unused.run.out | 0 vlib/v/tests/skip_unused/import_json_only.vv | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 vlib/v/tests/skip_unused/import_json_only.run.out create mode 100644 vlib/v/tests/skip_unused/import_json_only.skip_unused.run.out create mode 100644 vlib/v/tests/skip_unused/import_json_only.vv diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index 513861a6f..b46af4870 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -203,6 +203,12 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a core_fns << 'v.trace_calls.current_time' core_fns << 'v.trace_calls.on_call' } + if 'C.cJSON_Parse' in all_fns { + all_fn_root_names << 'tos5' + all_fn_root_names << 'time.unix' // used by json + table.used_features.used_maps++ // json needs new_map etc + include_panic_deps = true + } all_fn_root_names << core_fns if include_panic_deps { all_fn_root_names << [ @@ -424,12 +430,6 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a } } - if 'C.cJSON_Parse' in all_fns { - all_fn_root_names << 'tos5' - all_fn_root_names << 'time.unix' // used by json - table.used_features.used_maps++ // json needs new_map etc - } - mut walker := Walker.new( table: table files: ast_files diff --git a/vlib/v/tests/skip_unused/import_json_only.run.out b/vlib/v/tests/skip_unused/import_json_only.run.out new file mode 100644 index 000000000..e69de29bb diff --git a/vlib/v/tests/skip_unused/import_json_only.skip_unused.run.out b/vlib/v/tests/skip_unused/import_json_only.skip_unused.run.out new file mode 100644 index 000000000..e69de29bb diff --git a/vlib/v/tests/skip_unused/import_json_only.vv b/vlib/v/tests/skip_unused/import_json_only.vv new file mode 100644 index 000000000..ff9d9d070 --- /dev/null +++ b/vlib/v/tests/skip_unused/import_json_only.vv @@ -0,0 +1 @@ +import json as _ -- 2.39.5