Skip to content

Commit 8eba7b2

Browse files
committed
Revert "markused: clean up features tracking from checker - remove 1 all_fns loop (#24999)"
This reverts commit 844b700.
1 parent 844b700 commit 8eba7b2

8 files changed

Lines changed: 114 additions & 149 deletions

File tree

‎vlib/v/ast/table.v‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import v.util
1010
@[heap; minify]
1111
pub struct UsedFeatures {
1212
pub mut:
13-
dump bool // filled in by markused
13+
dump bool // dump()
14+
index bool // string[0]
1415
range_index bool // string[0..1]
16+
cast_ptr bool // &u8(...)
1517
anon_fn bool // fn () { }
1618
auto_str bool // auto str fns
1719
auto_str_ptr bool // auto str fns for ptr type
18-
auto_str_arr bool // auto str fns for array
1920
arr_prepend bool // arr.prepend()
2021
arr_insert bool // arr.insert()
2122
arr_first bool // arr.first()

‎vlib/v/checker/checker.v‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,6 +3069,7 @@ pub fn (mut c Checker) expr(mut node ast.Expr) ast.Type {
30693069
return c.concat_expr(mut node)
30703070
}
30713071
ast.DumpExpr {
3072+
c.table.used_features.dump = true
30723073
c.expected_type = ast.string_type
30733074
node.expr_type = c.expr(mut node.expr)
30743075
c.markused_dumpexpr(mut node)
@@ -5013,6 +5014,7 @@ fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
50135014
if node.index is ast.RangeExpr {
50145015
c.table.used_features.range_index = true
50155016
}
5017+
c.table.used_features.index = true
50165018
}
50175019
is_aggregate_arr := typ_sym.kind == .aggregate
50185020
&& (typ_sym.info as ast.Aggregate).types.filter(c.table.type_kind(it) !in [.array, .array_fixed, .string, .map]).len == 0

‎vlib/v/checker/fn.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
14411441
if args_len > 0 && fn_name in print_everything_fns {
14421442
node.args[0].ct_expr = c.comptime.is_comptime(node.args[0].expr)
14431443
c.builtin_args(mut node, fn_name, func)
1444-
c.markused_print_call(mut node)
1444+
c.markused_fn_call(mut node)
14451445
return func.return_type
14461446
}
14471447
// `return error(err)` -> `return err`

‎vlib/v/checker/infix.v‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
6060
if left_type.has_flag(.option) {
6161
c.error('cannot push to Option array that was not unwrapped first', node.left.pos())
6262
}
63+
c.markused_infixexpr(!c.is_builtin_mod && c.mod != 'strings')
6364
if mut node.right is ast.IfExpr {
6465
if node.right.is_expr && node.right.branches.len > 0 {
6566
mut last_stmt := node.right.branches[0].stmts.last()

‎vlib/v/checker/used_features.v‎

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ fn (mut c Checker) markused_dumpexpr(mut node ast.DumpExpr) {
3636
if node.expr_type.is_ptr() {
3737
c.table.used_features.auto_str_ptr = true
3838
}
39-
if !c.table.used_features.auto_str_arr {
40-
c.table.used_features.auto_str_arr = c.table.final_sym(unwrapped_type).kind == .array
41-
}
4239
} else {
4340
c.table.used_features.print_types[node.expr_type.idx()] = true
4441
}
@@ -61,6 +58,9 @@ fn (mut c Checker) markused_castexpr(mut node ast.CastExpr, to_type ast.Type, mu
6158
c.table.used_features.used_maps++
6259
}
6360
}
61+
if c.mod !in ['strings', 'math.bits'] && to_type.is_ptr() {
62+
c.table.used_features.cast_ptr = true
63+
}
6464
}
6565

6666
fn (mut c Checker) markused_comptimecall(mut node ast.ComptimeCall) {
@@ -91,6 +91,7 @@ fn (mut c Checker) markused_comptimecall(mut node ast.ComptimeCall) {
9191
}
9292

9393
fn (mut c Checker) markused_comptimefor(mut node ast.ComptimeFor, unwrapped_expr_type ast.Type) {
94+
c.table.used_features.dump = true
9495
if c.table.used_features.used_maps == 0 {
9596
final_sym := c.table.final_sym(unwrapped_expr_type)
9697
if final_sym.info is ast.Map {
@@ -107,45 +108,34 @@ fn (mut c Checker) markused_call_expr(left_type ast.Type, mut node ast.CallExpr)
107108
if left_type != 0 && left_type.is_ptr() && !c.table.used_features.auto_str_ptr
108109
&& node.name == 'str' {
109110
c.table.used_features.auto_str_ptr = true
110-
if !c.table.used_features.auto_str_arr {
111-
c.table.used_features.auto_str_arr = c.table.final_sym(left_type).kind == .array
112-
}
113111
}
114112
}
115113

116-
fn (mut c Checker) markused_print_call(mut node ast.CallExpr) {
114+
fn (mut c Checker) markused_fn_call(mut node ast.CallExpr) {
117115
if !c.is_builtin_mod && c.mod != 'math.bits' && node.args[0].expr !is ast.StringLiteral {
118-
arg_typ := c.unwrap_generic(node.args[0].typ)
119116
if (node.args[0].expr is ast.CallExpr && node.args[0].expr.is_method
120117
&& node.args[0].expr.name == 'str')
121-
|| !c.table.sym(arg_typ).has_method('str') {
118+
|| !c.table.sym(c.unwrap_generic(node.args[0].typ)).has_method('str') {
122119
c.table.used_features.auto_str = true
123120
} else {
124-
if arg_typ.has_option_or_result() {
121+
if node.args[0].typ.has_option_or_result() {
125122
c.table.used_features.print_options = true
126123
}
127-
c.table.used_features.print_types[arg_typ.idx()] = true
124+
c.table.used_features.print_types[node.args[0].typ.idx()] = true
128125
if !c.table.used_features.auto_str_ptr && node.args[0].expr is ast.Ident {
129126
var_obj := node.args[0].expr.obj
130127
if var_obj is ast.Var {
131-
if var_obj.orig_type != 0 {
132-
fsym := c.table.final_sym(var_obj.orig_type)
133-
if fsym.kind == .interface {
134-
c.table.used_features.auto_str_ptr = true
135-
} else if fsym.kind == .array {
136-
c.table.used_features.auto_str_arr = true
137-
}
128+
if var_obj.orig_type != 0
129+
&& c.table.final_sym(var_obj.orig_type).kind == .interface {
130+
c.table.used_features.auto_str_ptr = true
138131
return
139132
}
140133
}
141134
}
142135
}
143-
if arg_typ.is_ptr() {
136+
if node.args[0].typ.is_ptr() {
144137
c.table.used_features.auto_str_ptr = true
145138
}
146-
if !c.table.used_features.auto_str_arr {
147-
c.table.used_features.auto_str_arr = c.table.final_sym(arg_typ).kind == .array
148-
}
149139
}
150140
}
151141

@@ -175,14 +165,18 @@ fn (mut c Checker) markused_string_inter_lit(mut node ast.StringInterLiteral, ft
175165
if ftyp.is_ptr() {
176166
c.table.used_features.auto_str_ptr = true
177167
}
178-
if !c.table.used_features.auto_str_arr {
179-
c.table.used_features.auto_str_arr = c.table.final_sym(ftyp).kind == .array
180-
}
181168
if ftyp.has_option_or_result() {
182169
c.table.used_features.print_options = true
183170
}
184171
}
185172

173+
fn (mut c Checker) markused_infixexpr(check bool) {
174+
if !check {
175+
return
176+
}
177+
c.table.used_features.index = true
178+
}
179+
186180
fn (mut c Checker) markused_array_method(check bool, method_name string) {
187181
if !check {
188182
return

‎vlib/v/gen/c/dumpexpr.v‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ fn (mut g Gen) dump_expr_definitions() {
107107
}
108108
_, str_method_expects_ptr, _ := dump_sym.str_method_info()
109109
typ := ast.idx_to_type(dump_type)
110-
if g.pref.skip_unused
111-
&& (!g.table.used_features.dump || typ.idx() !in g.table.used_features.used_syms) {
112-
continue
113-
}
114110
is_ptr := typ.is_ptr()
115111
deref, _ := deref_kind(str_method_expects_ptr, is_ptr, typ)
116112
to_string_fn_name := g.get_str_fn(typ.clear_flags(.shared_f, .result))

‎vlib/v/markused/markused.v‎

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
8585
core_fns << '__new_array_with_array_default_noscan'
8686
core_fns << 'new_array_from_c_array'
8787
}
88+
if table.used_features.index || pref_.is_shared {
89+
include_panic_deps = true
90+
core_fns << string_idx_str + '.at_with_check'
91+
core_fns << string_idx_str + '.clone'
92+
core_fns << string_idx_str + '.clone_static'
93+
core_fns << string_idx_str + '.at'
94+
core_fns << array_idx_str + '.set'
95+
core_fns << array_idx_str + '.get_with_check' // used for `x := a[i] or {}`
96+
core_fns << ref_array_idx_str + '.set'
97+
core_fns << map_idx_str + '.get'
98+
core_fns << map_idx_str + '.set'
99+
core_fns << '__new_array_noscan'
100+
core_fns << ref_array_idx_str + '.push_noscan'
101+
core_fns << ref_array_idx_str + '.push_many_noscan'
102+
}
88103
if table.used_features.range_index || pref_.is_shared {
89104
core_fns << string_idx_str + '.substr_with_check'
90105
core_fns << string_idx_str + '.substr_ni'
@@ -94,6 +109,10 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
94109
core_fns << array_idx_str + '.clone_static_to_depth'
95110
core_fns << array_idx_str + '.clone_to_depth'
96111
}
112+
if table.used_features.auto_str || table.used_features.dump {
113+
core_fns << string_idx_str + '.repeat'
114+
core_fns << 'tos3'
115+
}
97116
if table.used_features.arr_prepend {
98117
core_fns << ref_array_idx_str + '.prepend_many'
99118
}
@@ -102,7 +121,6 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
102121
}
103122
if table.used_features.arr_pop {
104123
core_fns << ref_array_idx_str + '.pop'
105-
core_fns << ref_array_idx_str + '.pop_noscan'
106124
}
107125
if table.used_features.arr_first {
108126
core_fns << array_idx_str + '.first'
@@ -112,7 +130,15 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
112130
}
113131
if table.used_features.arr_insert {
114132
core_fns << ref_array_idx_str + '.insert_many'
115-
core_fns << ref_array_idx_str + '.insert_noscan'
133+
}
134+
if table.used_features.dump {
135+
include_panic_deps = true
136+
builderptr_idx := int(table.find_type('strings.Builder').ref()).str()
137+
core_fns << [
138+
builderptr_idx + '.str',
139+
builderptr_idx + '.free',
140+
builderptr_idx + '.write_rune',
141+
]
116142
}
117143
if table.used_features.print_options {
118144
include_panic_deps = true
@@ -259,6 +285,26 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
259285
handle_vweb(mut table, mut all_fn_root_names, 'vweb.Result', 'vweb.filter', 'vweb.Context')
260286
handle_vweb(mut table, mut all_fn_root_names, 'x.vweb.Result', 'x.vweb.filter', 'x.vweb.Context')
261287

288+
// handle ORM drivers:
289+
orm_connection_implementations := table.iface_types['orm.Connection'] or { []ast.Type{} }
290+
if orm_connection_implementations.len > 0 {
291+
for k, _ in all_fns {
292+
if k.starts_with('orm.') {
293+
all_fn_root_names << k
294+
}
295+
}
296+
for orm_type in orm_connection_implementations {
297+
typ := int(orm_type).str()
298+
all_fn_root_names << typ + '.select'
299+
all_fn_root_names << typ + '.insert'
300+
all_fn_root_names << typ + '.update'
301+
all_fn_root_names << typ + '.delete'
302+
all_fn_root_names << typ + '.create'
303+
all_fn_root_names << typ + '.drop'
304+
all_fn_root_names << typ + '.last_id'
305+
}
306+
}
307+
262308
if 'debug_used_features' in pref_.compile_defines {
263309
eprintln('> debug_used_features: ${table.used_features}')
264310
}

0 commit comments

Comments
 (0)