Skip to content

Commit ae898e7

Browse files
committed
v.markused: handle interface implementation methods, and vweb programs
1 parent 106cd38 commit ae898e7

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

vlib/v/ast/table.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mut:
2424
is_fmt bool
2525
used_fns map[string]bool // filled in by the checker, when pref.skip_unused = true;
2626
used_consts map[string]bool // filled in by the checker, when pref.skip_unused = true;
27+
used_vweb_types []Type // vweb context types, filled in by checker, when pref.skip_unused = true;
2728
panic_handler FnPanicHandler = default_table_panic_handler
2829
panic_userdata voidptr = voidptr(0) // can be used to pass arbitrary data to panic_handler;
2930
panic_npanics int
@@ -44,6 +45,7 @@ pub fn (t &Table) free() {
4445
t.cmod_prefix.free()
4546
t.used_fns.free()
4647
t.used_consts.free()
48+
t.used_vweb_types.free()
4749
}
4850
}
4951

vlib/v/checker/checker.v

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ mut:
7979
timers &util.Timers = util.new_timers(false)
8080
comptime_fields_type map[string]ast.Type
8181
fn_scope &ast.Scope = voidptr(0)
82-
used_fns map[string]bool // used_fns['println'] == true
8382
main_fn_decl_node ast.FnDecl
8483
match_exhaustive_cutoff_limit int = 10
8584
// TODO: these are here temporarily and used for deprecations; remove soon
@@ -6746,7 +6745,11 @@ fn (mut c Checker) post_process_generic_fns() {
67466745
node.cur_concrete_types = concrete_types
67476746
c.fn_decl(mut node)
67486747
if node.name in ['vweb.run_app', 'vweb.run'] {
6749-
c.vweb_gen_types << concrete_types
6748+
for ct in concrete_types {
6749+
if ct !in c.vweb_gen_types {
6750+
c.vweb_gen_types << ct
6751+
}
6752+
}
67506753
}
67516754
}
67526755
node.cur_concrete_types = []
@@ -6961,6 +6964,7 @@ fn (mut c Checker) verify_all_vweb_routes() {
69616964
if c.vweb_gen_types.len == 0 {
69626965
return
69636966
}
6967+
c.table.used_vweb_types = c.vweb_gen_types
69646968
typ_vweb_result := c.table.find_type_idx('vweb.Result')
69656969
old_file := c.file
69666970
for vgt in c.vweb_gen_types {

vlib/v/markused/markused.v

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []ast.Fi
158158
continue
159159
}
160160
}
161+
162+
// handle assertions and testing framework callbacks:
161163
if pref.is_debug {
162164
all_fn_root_names << 'panic_debug'
163165
}
@@ -174,6 +176,40 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []ast.Fi
174176
}
175177
}
176178

179+
// handle interface implementation methods:
180+
for isym in table.type_symbols {
181+
if isym.kind != .interface_ {
182+
continue
183+
}
184+
interface_info := isym.info as ast.Interface
185+
if interface_info.methods.len == 0 {
186+
continue
187+
}
188+
for itype in interface_info.types {
189+
for method in interface_info.methods {
190+
interface_implementation_method_name := '${itype}.$method.name'
191+
all_fn_root_names << interface_implementation_method_name
192+
}
193+
}
194+
}
195+
196+
// handle vweb magic router methods:
197+
typ_vweb_result := table.find_type_idx('vweb.Result')
198+
if typ_vweb_result != 0 {
199+
for vgt in table.used_vweb_types {
200+
sym_app := table.get_type_symbol(vgt)
201+
for m in sym_app.methods {
202+
if m.return_type == typ_vweb_result {
203+
pvgt := vgt.set_nr_muls(1)
204+
eprintln('vgt: $vgt | pvgt: $pvgt | sym_app.name: $sym_app.name | m.name: $m.name')
205+
all_fn_root_names << '${pvgt}.$m.name'
206+
}
207+
}
208+
}
209+
}
210+
211+
//
212+
177213
mut walker := Walker{
178214
table: table
179215
files: ast_files

0 commit comments

Comments
 (0)