Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub mut:
arr_delete bool // arr.delete()
arr_reverse bool // arr.reverse()
arr_map bool // []map[key]value
type_name bool // var.type_name()
print_options bool // print option type
safe_int bool // needs safe int comparison
print_types map[int]bool // print() idx types
Expand Down
1 change: 0 additions & 1 deletion vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,6 @@ fn (mut c Checker) method_call(mut node ast.CallExpr, mut continue_check &bool)
}
if left_sym.kind in [.sum_type, .interface] {
if method_name == 'type_name' {
c.table.used_features.type_name = true
return ast.string_type
}
if method_name == 'type_idx' {
Expand Down
8 changes: 4 additions & 4 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -1088,9 +1088,9 @@ pub fn (mut g Gen) init() {
if g.use_segfault_handler {
muttable.used_features.used_fns['v_segmentation_fault_handler'] = true
}
muttable.used_features.used_fns['eprintln'] = true
muttable.used_features.used_fns['print_backtrace'] = true
muttable.used_features.used_fns['exit'] = true
// muttable.used_features.used_fns['eprintln'] = true
// muttable.used_features.used_fns['print_backtrace'] = true
// muttable.used_features.used_fns['exit'] = true
}

pub fn (mut g Gen) finish() {
Expand Down Expand Up @@ -6863,7 +6863,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) {
}
if sym.kind == .none && (!g.pref.skip_unused || g.table.used_features.used_none > 0) {
g.type_definitions.writeln('struct none {')
g.type_definitions.writeln('\tEMPTY_STRUCT_DECLARATION;')
g.type_definitions.writeln('\tE_STRUCT_DECL;')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
g.type_definitions.writeln('\tE_STRUCT_DECL;')
g.type_definitions.writeln('\tVESTD;')

g.type_definitions.writeln('};')
g.typedefs.writeln('typedef struct none none;')
}
Expand Down
18 changes: 5 additions & 13 deletions vlib/v/gen/c/cheaders.v
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ static inline void __sort_ptr(uintptr_t a[], bool b[], ${ast.int_type_name} l) {
'

const c_common_macros = '
#define EMPTY_VARG_INITIALIZATION 0
#define EMPTY_STRUCT_DECLARATION
#define E_STRUCT_DECL
#define E_STRUCT
// Due to a tcc bug, the length of an array needs to be specified, but GCC crashes if it is...
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[])
#define TCCSKIP(x) x
#define __NOINLINE __attribute__((noinline))
#define __IRQHANDLER __attribute__((interrupt))
#define __V_architecture 0
Expand Down Expand Up @@ -120,9 +116,9 @@ const c_common_macros = '
#endif
#ifdef _MSC_VER
#undef __V_GCC__
#undef EMPTY_STRUCT_DECLARATION
#undef E_STRUCT_DECL
#undef E_STRUCT
#define EMPTY_STRUCT_DECLARATION unsigned char _dummy_pad
#define E_STRUCT_DECL unsigned char _dummy_pad
#define E_STRUCT 0
#endif
#ifndef _WIN32
Expand All @@ -137,19 +133,15 @@ const c_common_macros = '
#endif
#ifdef __TINYC__
#define _Atomic volatile
#undef EMPTY_STRUCT_DECLARATION
#undef E_STRUCT_DECL
#undef E_STRUCT
#define EMPTY_STRUCT_DECLARATION unsigned char _dummy_pad
#define E_STRUCT_DECL unsigned char _dummy_pad
#define E_STRUCT 0
#undef EMPTY_ARRAY_OF_ELEMS
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[n])
#undef __NOINLINE
#undef __IRQHANDLER
// tcc does not support inlining at all
#define __NOINLINE
#define __IRQHANDLER
#undef TCCSKIP
#define TCCSKIP(x)
// #include <byteswap.h>
int tcc_backtrace(const char *fmt, ...);
#endif
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/gen/c/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ fn (mut g Gen) struct_decl(s ast.Struct, name string, is_anon bool, is_option bo
}
}
} else {
g.type_definitions.writeln('\tEMPTY_STRUCT_DECLARATION;')
g.type_definitions.writeln('\tE_STRUCT_DECL;')
}
ti_attrs := if !g.is_cc_msvc && s.attrs.contains('packed') {
'__attribute__((__packed__))'
Expand Down
4 changes: 0 additions & 4 deletions vlib/v/markused/markused.v
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
trace_skip_unused_just_unused_fns := pref_.compile_values['trace_skip_unused_just_unused_fns'] == 'true'
used_fns := pref_.compile_values['used_fns']

charptr_idx_str := ast.charptr_type_idx.str()
string_idx_str := ast.string_type_idx.str()
array_idx_str := ast.array_type_idx.str()
map_idx_str := ast.map_type_idx.str()
Expand Down Expand Up @@ -125,9 +124,6 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
core_fns << ref_densearray_idx_str + '.clone'
core_fns << map_idx_str + '.clone'
}
if table.used_features.type_name {
core_fns << charptr_idx_str + '.vstring_literal'
}
if pref_.trace_calls || pref_.trace_fns.len > 0 {
include_panic_deps = true
core_fns << 'vgettid'
Expand Down
38 changes: 30 additions & 8 deletions vlib/v/markused/walker.v
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ mut:
level int
is_builtin_mod bool
is_direct_array_access bool
inside_in_op bool

// dependencies finding flags
uses_atomic bool // has atomic
Expand Down Expand Up @@ -78,6 +79,7 @@ mut:
uses_str_index bool // string[k]
uses_str_index_check bool // string[k] or { }
uses_str_range bool // string[a..b]
uses_str_literal bool
uses_fixed_arr_int bool // fixed_arr[k]
uses_append bool // var << item
uses_map_setter bool
Expand All @@ -86,6 +88,7 @@ mut:
uses_arr_getter bool
uses_arr_clone bool
uses_arr_sorted bool
uses_type_name bool // sum_type.type_name()
}

pub fn Walker.new(params Walker) &Walker {
Expand Down Expand Up @@ -427,13 +430,17 @@ fn (mut w Walker) expr(node_ ast.Expr) {
if sym.info is ast.Thread {
w.mark_by_type(w.table.find_or_register_array(sym.info.return_type))
}
w.mark_by_type(node.typ)
w.expr(node.len_expr)
w.expr(node.cap_expr)
w.expr(node.init_expr)
w.exprs(node.exprs)
if !w.uses_array && !w.is_direct_array_access {
w.uses_array = true
if w.table.final_sym(node.typ).kind == .array {
if !w.inside_in_op {
w.uses_array = true
w.mark_by_type(node.typ)
}
} else {
w.mark_by_type(node.typ)
}
if node.elem_type.has_flag(.option) {
w.used_option++
Expand Down Expand Up @@ -580,7 +587,7 @@ fn (mut w Walker) expr(node_ ast.Expr) {
} else if sym.info is ast.ArrayFixed {
w.mark_by_type(sym.info.elem_type)
}
if !w.uses_arr_range_index {
if !node.is_gated && node.index is ast.RangeExpr && !w.uses_arr_range_index {
w.uses_arr_range_index = true
}
if !w.uses_fixed_arr_int && sym.kind == .array_fixed {
Expand All @@ -589,7 +596,7 @@ fn (mut w Walker) expr(node_ ast.Expr) {
if !w.uses_index && !w.is_direct_array_access {
w.uses_index = true
}
if !w.uses_arr_range_index_gated {
if node.is_gated && node.index is ast.RangeExpr && !w.uses_arr_range_index_gated {
w.uses_arr_range_index_gated = node.is_gated
}
} else if sym.kind == .string {
Expand Down Expand Up @@ -628,7 +635,10 @@ fn (mut w Walker) expr(node_ ast.Expr) {
}
ast.InfixExpr {
w.expr(node.left)
tmp_inside_in_op := w.inside_in_op
w.inside_in_op = node.op in [.key_in, .not_in]
w.expr(node.right)
w.inside_in_op = tmp_inside_in_op
w.or_block(node.or_block)
if node.left_type != 0 {
sym := w.table.sym(node.left_type)
Expand All @@ -652,8 +662,10 @@ fn (mut w Walker) expr(node_ ast.Expr) {
node.right_type
}
if right_type != 0 {
w.mark_by_type(right_type)
right_sym := w.table.sym(right_type)
if !(w.is_direct_array_access && right_sym.kind == .array) {
w.mark_by_type(right_type)
}
if node.op in [.not_in, .key_in] {
if right_sym.kind == .map {
w.features.used_maps++
Expand Down Expand Up @@ -854,7 +866,12 @@ fn (mut w Walker) expr(node_ ast.Expr) {
ast.FloatLiteral {}
ast.CharLiteral {}
ast.IntegerLiteral {}
ast.StringLiteral {}
ast.StringLiteral {
if !w.uses_str_literal && !node.is_raw {
w.mark_by_sym_name('string')
w.uses_str_literal = true
}
}
ast.CTempVar {
w.expr(node.orig)
}
Expand Down Expand Up @@ -970,6 +987,8 @@ pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
if node.is_method && node.left_type != 0 {
w.mark_by_type(node.left_type)
left_sym := w.table.sym(node.left_type)
w.uses_type_name = w.uses_type_name
|| (left_sym.kind in [.sum_type, .interface] && node.name == 'type_name')
if left_sym.info is ast.Aggregate {
for receiver_type in left_sym.info.types {
receiver_sym := w.table.sym(receiver_type)
Expand Down Expand Up @@ -1641,7 +1660,10 @@ pub fn (mut w Walker) finalize(include_panic_deps bool) {
if w.uses_eq {
w.fn_by_name('fast_string_eq')
}

if w.uses_type_name {
charptr_idx_str := ast.charptr_type_idx.str()
w.fn_by_name(charptr_idx_str + '.vstring_literal')
}
// remove unused symbols
w.remove_unused_fn_generic_types()

Expand Down
Loading