Skip to content

Commit ae1fa8a

Browse files
authored
markused: skip unused symbols, dump fns and generic specialization (fix #24921) (fix #24927) (#24924)
1 parent 938f462 commit ae1fa8a

28 files changed

+558
-163
lines changed

cmd/v/v.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import v.util.version
1212
import v.builder
1313
import v.builder.cbuilder
1414

15+
@[markused]
1516
const external_tools = [
1617
'ast',
1718
'bin2v',

vlib/gg/gg.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub:
3232
thickness f32 = 1
3333
}
3434

35+
@[markused]
3536
pub struct Size {
3637
pub mut:
3738
width int

vlib/gg/image.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import sokol.sgl
99

1010
// Image holds the fields and data needed to
1111
// represent a bitmap/pixel based image in memory.
12-
@[heap]
12+
@[heap; markused]
1313
pub struct Image {
1414
pub mut:
1515
id int

vlib/gx/color.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub const light_red = Color{
112112
}
113113

114114
// Color represents a 32 bit color value in sRGB format
115+
@[markused]
115116
pub struct Color {
116117
pub mut:
117118
r u8

vlib/gx/text.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module gx
44
pub const align_left = HorizontalAlign.left
55
pub const align_right = HorizontalAlign.right
66

7-
@[params]
7+
@[markused; params]
88
pub struct TextCfg {
99
pub:
1010
color Color = black

vlib/os/os.c.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ $if freebsd || openbsd {
99
#include <sys/sysctl.h>
1010
}
1111

12+
@[markused]
1213
pub const args = arguments()
1314

1415
fn C.readdir(voidptr) &C.dirent

vlib/v/ast/ast.v

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ pub:
453453
pub mut:
454454
language Language
455455
fields []StructField
456+
idx int
456457
}
457458

458459
pub struct Embed {
@@ -1484,6 +1485,7 @@ pub:
14841485
comments []Comment
14851486
pub mut:
14861487
parent_type Type
1488+
is_markused bool
14871489
}
14881490

14891491
// SumTypeDecl is the ast node for `type MySumType = string | int`
@@ -1497,7 +1499,8 @@ pub:
14971499
generic_types []Type
14981500
attrs []Attr // attributes of type declaration
14991501
pub mut:
1500-
variants []TypeNode
1502+
variants []TypeNode
1503+
is_markused bool
15011504
}
15021505

15031506
pub struct FnTypeDecl {
@@ -1510,6 +1513,7 @@ pub:
15101513
comments []Comment
15111514
generic_types []Type
15121515
attrs []Attr // attributes of type declaration
1516+
is_markused bool
15131517
}
15141518

15151519
// TODO: handle this differently

vlib/v/ast/table.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mut:
3434
used_fns map[string]bool // filled in by markused
3535
used_consts map[string]bool // filled in by markused
3636
used_globals map[string]bool // filled in by markused
37+
used_syms map[int]bool // filled in by markused
3738
used_veb_types []Type // veb context types, filled in by checker
3839
used_maps int // how many times maps were used, filled in by markused
3940
used_arrays int // how many times arrays were used, filled in by markused
@@ -42,6 +43,7 @@ pub mut:
4243
// json bool // json is imported
4344
debugger bool // debugger is used
4445
comptime_calls map[string]bool // resolved name to call on comptime
46+
comptime_syms map[int]bool // resolved syms (generic)
4547
comptime_for bool // uses $for
4648
memory_align bool // @[aligned] for struct
4749
}

vlib/v/ast/types.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ pub mut:
183183
is_anon bool
184184
is_generic bool
185185
is_shared bool
186+
is_markused bool
186187
has_option bool // contains any option field
187188
generic_types []Type
188189
concrete_types []Type

vlib/v/checker/checker.v

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,6 +3137,10 @@ pub fn (mut c Checker) expr(mut node ast.Expr) ast.Type {
31373137
c.inside_if_guard = true
31383138
node.expr_type = c.expr(mut node.expr)
31393139
c.inside_if_guard = old_inside_if_guard
3140+
if c.pref.skip_unused && node.expr_type.has_flag(.generic) {
3141+
unwrapped_type := c.unwrap_generic(node.expr_type)
3142+
c.table.used_features.comptime_syms[unwrapped_type] = true
3143+
}
31403144
if !node.expr_type.has_flag(.option) && !node.expr_type.has_flag(.result) {
31413145
mut no_opt_or_res := true
31423146
match mut node.expr {
@@ -3435,6 +3439,9 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
34353439
// allow conversion from none to every option type
34363440
} else if to_sym.kind == .sum_type {
34373441
to_sym_info := to_sym.info as ast.SumType
3442+
if c.pref.skip_unused && to_sym_info.concrete_types.len > 0 {
3443+
c.table.used_features.comptime_syms[to_type] = true
3444+
}
34383445
if to_sym_info.generic_types.len > 0 && to_sym_info.concrete_types.len == 0 {
34393446
c.error('generic sumtype `${to_sym.name}` must specify type parameter, e.g. ${to_sym.name}[int]',
34403447
node.pos)
@@ -5227,6 +5234,9 @@ fn (mut c Checker) chan_init(mut node ast.ChanInit) ast.Type {
52275234
if node.has_cap {
52285235
c.check_array_init_para_type('cap', mut node.cap_expr, node.pos)
52295236
}
5237+
if c.pref.skip_unused && node.typ.has_flag(.generic) {
5238+
c.table.used_features.comptime_syms[c.unwrap_generic(node.typ)] = true
5239+
}
52305240
return node.typ
52315241
} else {
52325242
c.error('`chan` of unknown type', node.pos)

0 commit comments

Comments
 (0)