Skip to content

Commit 16683ed

Browse files
authored
markused: reduce unused code by removing unused safe_int fns (#25402)
1 parent 42d5c0b commit 16683ed

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎vlib/v/ast/table.v‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub mut:
2626
arr_map bool // []map[key]value
2727
type_name bool // var.type_name()
2828
print_options bool // print option type
29+
safe_int bool // needs safe int comparison
2930
print_types map[int]bool // print() idx types
3031
used_fns map[string]bool // filled in by markused
3132
used_consts map[string]bool // filled in by markused

‎vlib/v/gen/c/cgen.v‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,9 @@ pub fn (mut g Gen) init() {
10031003
} else {
10041004
g.cheaders.writeln(c_headers)
10051005
}
1006+
if !g.pref.skip_unused || g.table.used_features.safe_int {
1007+
g.cheaders.writeln(c_unsigned_comparison_functions)
1008+
}
10061009
if !g.pref.skip_unused || g.table.used_features.used_attr_weak {
10071010
g.cheaders.writeln(c_common_weak_attr)
10081011
}

‎vlib/v/gen/c/cheaders.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ const c_helper_macros = '//============================== HELPER C MACROS ======
309309
#define _PUSH_MANY_noscan(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); builtin__array_push_many_noscan(arr, tmp.data, tmp.len);}
310310
'
311311

312-
const c_headers = c_helper_macros + c_unsigned_comparison_functions + c_common_macros +
312+
const c_headers = c_helper_macros + c_common_macros +
313313
r'
314314
// c_headers
315315
typedef int (*qsort_callback_func)(const void*, const void*);
@@ -491,7 +491,7 @@ typedef void (*MapCloneFn)(voidptr, voidptr);
491491
typedef void (*MapFreeFn)(voidptr);
492492
'
493493

494-
const c_bare_headers = c_helper_macros + c_unsigned_comparison_functions + c_common_macros +
494+
const c_bare_headers = c_helper_macros + c_common_macros +
495495
'
496496
#define _VFREESTANDING
497497
typedef long unsigned int size_t;

‎vlib/v/markused/walker.v‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,15 @@ fn (mut w Walker) expr(node_ ast.Expr) {
666666
w.mark_by_sym(right_sym)
667667
}
668668
}
669-
if !w.uses_eq && node.op in [.eq, .ne] {
670-
w.uses_eq = true
669+
if node.op in [.eq, .ne, .gt, .ge, .lt, .le] {
670+
if !w.table.used_features.safe_int && node.left_type != 0 && node.right_type != 0 {
671+
left := w.table.unaliased_type(node.left_type)
672+
right := w.table.unaliased_type(node.right_type)
673+
w.table.used_features.safe_int = (
674+
(left.idx() in [ast.u32_type_idx, ast.u64_type_idx] && right.is_signed())
675+
|| (right.idx() in [ast.u32_type_idx, ast.u64_type_idx] && left.is_signed()))
676+
}
677+
w.uses_eq = w.uses_eq || node.op in [.eq, .ne]
671678
}
672679
}
673680
ast.IfGuardExpr {

0 commit comments

Comments
 (0)