diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 1d13cd2763..a305a27ce4 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -21,6 +21,9 @@ pub mut: auto_str bool // auto str fns auto_str_ptr bool // auto str fns for ptr type arr_prepend bool // arr.prepend() + arr_first bool // arr.first() + arr_last bool // arr.last() + arr_pop bool // arr.pop() option_or_result bool // has panic call print_types map[int]bool // print() idx types } diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index d73b3c1a80..50127844f2 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -3548,6 +3548,17 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as } node.return_type = ast.int_type } else if method_name in ['first', 'last', 'pop'] { + if c.pref.skip_unused { + if method_name == 'first' { + c.table.used_features.arr_first = true + } + if method_name == 'last' { + c.table.used_features.arr_last = true + } + if method_name == 'pop' { + c.table.used_features.arr_pop = true + } + } if node.args.len != 0 { c.error('`.${method_name}()` does not have any arguments', node.args[0].pos) } diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index 83b41f077a..df6bd2847f 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -15,9 +15,10 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a } mut allow_noscan := true // Functions that must be generated and can't be skipped - mut all_fn_root_names := if pref_.backend == .native { + mut all_fn_root_names := []string{} + if pref_.backend == .native { // Note: this is temporary, until the native backend supports more features! - ['main.main'] + all_fn_root_names << 'main.main' } else { byteptr_idx_str := '${ast.byteptr_type_idx}' charptr_idx_str := '${ast.charptr_type_idx}' @@ -138,7 +139,17 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a if table.used_features.arr_prepend { core_fns << ref_array_idx_str + '.prepend_many' } + if table.used_features.arr_pop { + core_fns << ref_array_idx_str + '.pop' + } + if table.used_features.arr_first { + core_fns << array_idx_str + '.first' + } + if table.used_features.arr_last { + core_fns << array_idx_str + '.last' + } } else { + // TODO: this *should not* depend on the used compiler, which is brittle, but only on info in the AST... // hello world apps if pref_.ccompiler_type == .tinyc { // unused on tcc @@ -175,7 +186,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a if table.used_features.anon_fn { core_fns << 'memdup_uncollectable' } - core_fns + all_fn_root_names << core_fns } if pref_.is_bare { @@ -349,9 +360,9 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a } } + handle_vweb(mut table, mut all_fn_root_names, 'veb.Result', 'veb.filter', 'veb.Context') handle_vweb(mut table, mut all_fn_root_names, 'vweb.Result', 'vweb.filter', 'vweb.Context') handle_vweb(mut table, mut all_fn_root_names, 'x.vweb.Result', 'x.vweb.filter', 'x.vweb.Context') - handle_vweb(mut table, mut all_fn_root_names, 'veb.Result', 'veb.filter', 'veb.Context') // handle ORM drivers: orm_connection_implementations := table.iface_types['orm.Connection'] or { []ast.Type{} }