Skip to content

Commit

Permalink
restore static on non-parallel build
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Dec 13, 2024
1 parent 9116790 commit 2b6fbb9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 53 deletions.
6 changes: 3 additions & 3 deletions vlib/v/gen/c/auto_eq_methods.v
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ fn (mut g Gen) gen_interface_equality_fn(left_type ast.Type) string {
g.generated_eq_fns << left_no_ptr

info := left.sym.info
g.definitions.writeln('bool ${ptr_styp}_interface_eq(${ptr_styp} a, ${ptr_styp} b); // auto')
g.definitions.writeln('${g.static_non_parallel}bool ${ptr_styp}_interface_eq(${ptr_styp} a, ${ptr_styp} b); // auto')

mut fn_builder := strings.new_builder(512)
defer {
Expand All @@ -590,8 +590,8 @@ fn (mut g Gen) gen_interface_equality_fn(left_type ast.Type) string {
left_arg := g.read_field(left_type, '_typ', 'a')
right_arg := g.read_field(left_type, '_typ', 'b')

fn_builder.writeln('int v_typeof_interface_idx_${idx_fn}(int sidx); // for auto eq method')
fn_builder.writeln('inline bool ${fn_name}_interface_eq(${ptr_styp} a, ${ptr_styp} b) {')
fn_builder.writeln('${g.static_non_parallel}int v_typeof_interface_idx_${idx_fn}(int sidx); // for auto eq method')
fn_builder.writeln('${g.static_non_parallel}inline bool ${fn_name}_interface_eq(${ptr_styp} a, ${ptr_styp} b) {')
fn_builder.writeln('\tif (${left_arg} == ${right_arg}) {')
fn_builder.writeln('\t\tint idx = v_typeof_interface_idx_${idx_fn}(${left_arg});')
if info is ast.Interface {
Expand Down
16 changes: 8 additions & 8 deletions vlib/v/gen/c/auto_free_methods.v
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ fn (mut g Gen) gen_free_method(typ ast.Type) string {
}

fn (mut g Gen) gen_free_for_interface(sym ast.TypeSymbol, info ast.Interface, styp string, fn_name string) {
g.definitions.writeln('void ${fn_name}(${styp}* it); // auto')
g.definitions.writeln('${g.static_non_parallel}void ${fn_name}(${styp}* it); // auto')
mut fn_builder := strings.new_builder(128)
defer {
g.auto_fn_definitions << fn_builder.str()
}
fn_builder.writeln('void ${fn_name}(${styp}* it) {')
fn_builder.writeln('${g.static_non_parallel}void ${fn_name}(${styp}* it) {')
for t in info.types {
typ_ := g.unwrap_generic(t)
sub_sym := g.table.sym(typ_)
Expand All @@ -106,12 +106,12 @@ fn (mut g Gen) gen_free_for_interface(sym ast.TypeSymbol, info ast.Interface, st
}

fn (mut g Gen) gen_free_for_struct(typ ast.Type, info ast.Struct, styp string, fn_name string) {
g.definitions.writeln('void ${fn_name}(${styp}* it); // auto')
g.definitions.writeln('${g.static_non_parallel}void ${fn_name}(${styp}* it); // auto')
mut fn_builder := strings.new_builder(128)
defer {
g.auto_fn_definitions << fn_builder.str()
}
fn_builder.writeln('void ${fn_name}(${styp}* it) {')
fn_builder.writeln('${g.static_non_parallel}void ${fn_name}(${styp}* it) {')
for field in info.fields {
field_name := c_name(field.name)
sym := g.table.sym(g.unwrap_generic(field.typ))
Expand Down Expand Up @@ -176,12 +176,12 @@ fn (mut g Gen) gen_type_name_for_free_call(typ ast.Type) string {
}

fn (mut g Gen) gen_free_for_array(info ast.Array, styp string, fn_name string) {
g.definitions.writeln('void ${fn_name}(${styp}* it); // auto')
g.definitions.writeln('${g.static_non_parallel}void ${fn_name}(${styp}* it); // auto')
mut fn_builder := strings.new_builder(128)
defer {
g.auto_fn_definitions << fn_builder.str()
}
fn_builder.writeln('void ${fn_name}(${styp}* it) {')
fn_builder.writeln('${g.static_non_parallel}void ${fn_name}(${styp}* it) {')

sym := g.table.sym(g.unwrap_generic(info.elem_type))
if sym.kind in [.string, .array, .map, .struct] {
Expand All @@ -201,12 +201,12 @@ fn (mut g Gen) gen_free_for_array(info ast.Array, styp string, fn_name string) {
}

fn (mut g Gen) gen_free_for_map(typ ast.Type, styp string, fn_name string) {
g.definitions.writeln('void ${fn_name}(${styp}* it); // auto')
g.definitions.writeln('${g.static_non_parallel}void ${fn_name}(${styp}* it); // auto')
mut fn_builder := strings.new_builder(128)
defer {
g.auto_fn_definitions << fn_builder.str()
}
fn_builder.writeln('void ${fn_name}(${styp}* it) {')
fn_builder.writeln('${g.static_non_parallel}void ${fn_name}(${styp}* it) {')

if typ.has_flag(.option) {
fn_builder.writeln('\tif (it->state != 2) {')
Expand Down
78 changes: 39 additions & 39 deletions vlib/v/gen/c/auto_str_methods.v
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string
is_c_struct := parent_sym.is_c_struct() && str_method_expects_ptr
arg_def := if is_c_struct { '${styp}* it' } else { '${styp} it' }

g.definitions.writeln('string ${str_fn_name}(${arg_def}); // auto')
g.auto_str_funcs.writeln('string ${str_fn_name}(${arg_def}) { return indent_${str_fn_name}(it, 0); }')
g.definitions.writeln('string indent_${str_fn_name}(${arg_def}, int indent_count); // auto')
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${arg_def}, int indent_count) {')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def}); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def}) { return indent_${str_fn_name}(it, 0); }')
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, int indent_count); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, int indent_count) {')
g.auto_str_funcs.writeln('\tstring indents = string_repeat(_SLIT(" "), indent_count);')
if str_method_expects_ptr {
it_arg := if is_c_struct { 'it' } else { '&it' }
Expand All @@ -306,9 +306,9 @@ fn (mut g Gen) gen_str_for_multi_return(info ast.MultiReturn, styp string, str_f
$if trace_autostr ? {
eprintln('> gen_str_for_multi_return: ${info.types} | ${styp} | ${str_fn_name}')
}
g.definitions.writeln('string ${str_fn_name}(${styp} a); // auto')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} a); // auto')
mut fn_builder := strings.new_builder(512)
fn_builder.writeln('string ${str_fn_name}(${styp} a) {')
fn_builder.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} a) {')
fn_builder.writeln('\tstrings__Builder sb = strings__new_builder(${info.types.len} * 10);')
fn_builder.writeln('\tstrings__Builder_write_string(&sb, _SLIT("("));')
for i, typ in info.types {
Expand Down Expand Up @@ -354,8 +354,8 @@ fn (mut g Gen) gen_str_for_enum(info ast.Enum, styp string, str_fn_name string)
eprintln('> gen_str_for_enum: ${info} | ${styp} | ${str_fn_name}')
}
s := util.no_dots(styp)
g.definitions.writeln('string ${str_fn_name}(${styp} it); // auto')
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} it) { /* gen_str_for_enum */')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} it); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} it) { /* gen_str_for_enum */')
// Enums tagged with `@[flag]` are special in that they can be a combination of enum values
if info.is_flag {
clean_name := util.strip_main_name(styp.replace('__', '.'))
Expand Down Expand Up @@ -391,12 +391,12 @@ fn (mut g Gen) gen_str_for_interface(info ast.Interface, styp string, typ_str st
eprintln('> gen_str_for_interface: ${info.types} | ${styp} | ${str_fn_name}')
}
// _str() functions should have a single argument, the indenting ones take 2:
g.definitions.writeln('string ${str_fn_name}(${styp} x); // auto')
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} x) { return indent_${str_fn_name}(x, 0); }')
g.definitions.writeln('string indent_${str_fn_name}(${styp} x, int indent_count); // auto')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x) { return indent_${str_fn_name}(x, 0); }')
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count); // auto')
mut fn_builder := strings.new_builder(512)
clean_interface_v_type_name := util.strip_main_name(typ_str)
fn_builder.writeln('string indent_${str_fn_name}(${styp} x, int indent_count) { /* gen_str_for_interface */')
fn_builder.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count) { /* gen_str_for_interface */')
for typ in info.types {
sub_sym := g.table.sym(ast.mktyp(typ))
mut func_name := g.get_str_fn(typ)
Expand Down Expand Up @@ -448,11 +448,11 @@ fn (mut g Gen) gen_str_for_union_sum_type(info ast.SumType, styp string, typ_str
eprintln('> gen_str_for_union_sum_type: ${info.variants} | ${styp} | ${str_fn_name}')
}
// _str() functions should have a single argument, the indenting ones take 2:
g.definitions.writeln('string ${str_fn_name}(${styp} x); // auto')
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} x) { return indent_${str_fn_name}(x, 0); }')
g.definitions.writeln('string indent_${str_fn_name}(${styp} x, int indent_count); // auto')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x) { return indent_${str_fn_name}(x, 0); }')
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count); // auto')
mut fn_builder := strings.new_builder(512)
fn_builder.writeln('string indent_${str_fn_name}(${styp} x, int indent_count) {')
fn_builder.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count) {')
mut clean_sum_type_v_type_name := ''
if info.is_anon {
variant_names := info.variants.map(util.strip_main_name(g.table.sym(it).name))
Expand Down Expand Up @@ -549,26 +549,26 @@ fn (mut g Gen) gen_str_for_fn_type(info ast.FnType, styp string, str_fn_name str
$if trace_autostr ? {
eprintln('> gen_str_for_fn_type: ${info.func.name} | ${styp} | ${str_fn_name}')
}
g.definitions.writeln('string ${str_fn_name}(); // auto')
g.auto_str_funcs.writeln('string ${str_fn_name}() { return _SLIT("${g.fn_decl_str(info)}");}')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}() { return _SLIT("${g.fn_decl_str(info)}");}')
}

fn (mut g Gen) gen_str_for_chan(info ast.Chan, styp string, str_fn_name string) {
$if trace_autostr ? {
eprintln('> gen_str_for_chan: ${info.elem_type.debug()} | ${styp} | ${str_fn_name}')
}
elem_type_name := util.strip_main_name(g.table.get_type_name(g.unwrap_generic(info.elem_type)))
g.definitions.writeln('string ${str_fn_name}(${styp} x); // auto')
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} x) { return sync__Channel_auto_str(x, _SLIT("${elem_type_name}")); }')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x) { return sync__Channel_auto_str(x, _SLIT("${elem_type_name}")); }')
}

fn (mut g Gen) gen_str_for_thread(info ast.Thread, styp string, str_fn_name string) {
$if trace_autostr ? {
eprintln('> gen_str_for_thread: ${info.return_type.debug()} | ${styp} | ${str_fn_name}')
}
ret_type_name := util.strip_main_name(g.table.get_type_name(info.return_type))
g.definitions.writeln('string ${str_fn_name}(${styp} _); // auto}')
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} _) { return _SLIT("thread(${ret_type_name})");}')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} _); // auto}')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} _) { return _SLIT("thread(${ret_type_name})");}')
}

@[inline]
Expand Down Expand Up @@ -607,10 +607,10 @@ fn (mut g Gen) gen_str_for_array(info ast.Array, styp string, str_fn_name string
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
elem_str_fn_name := g.get_str_fn(typ)

g.definitions.writeln('string ${str_fn_name}(${styp} a); // auto')
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} a) { return indent_${str_fn_name}(a, 0);}')
g.definitions.writeln('string indent_${str_fn_name}(${styp} a, int indent_count); // auto')
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${styp} a, int indent_count) {')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} a); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} a) { return indent_${str_fn_name}(a, 0);}')
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} a, int indent_count); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} a, int indent_count) {')
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(a.len * 10);')
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _SLIT("["));')
g.auto_str_funcs.writeln('\tfor (int i = 0; i < a.len; ++i) {')
Expand Down Expand Up @@ -714,10 +714,10 @@ fn (mut g Gen) gen_str_for_array_fixed(info ast.ArrayFixed, styp string, str_fn_
elem_str_fn_name := g.get_str_fn(typ)
def_arg := if info.is_fn_ret { '${g.styp(typ)} a[${info.size}]' } else { '${styp} a' }

g.definitions.writeln('string ${str_fn_name}(${def_arg}); // auto')
g.auto_str_funcs.writeln('string ${str_fn_name}(${def_arg}) { return indent_${str_fn_name}(a, 0);}')
g.definitions.writeln('string indent_${str_fn_name}(${def_arg}, int indent_count); // auto')
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${def_arg}, int indent_count) {')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${def_arg}); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${def_arg}) { return indent_${str_fn_name}(a, 0);}')
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${def_arg}, int indent_count); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${def_arg}, int indent_count) {')
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(${info.size} * 10);')
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _SLIT("["));')
g.auto_str_funcs.writeln('\tfor (int i = 0; i < ${info.size}; ++i) {')
Expand Down Expand Up @@ -810,10 +810,10 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
g.get_str_fn(val_typ)
}

g.definitions.writeln('string ${str_fn_name}(${styp} m); // auto')
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} m) { return indent_${str_fn_name}(m, 0);}')
g.definitions.writeln('string indent_${str_fn_name}(${styp} m, int indent_count); // auto')
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${styp} m, int indent_count) { /* gen_str_for_map */')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} m); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} m) { return indent_${str_fn_name}(m, 0);}')
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} m, int indent_count); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} m, int indent_count) { /* gen_str_for_map */')
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(m.key_values.len*10);')
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _SLIT("{"));')
g.auto_str_funcs.writeln('\tbool is_first = true;')
Expand Down Expand Up @@ -945,9 +945,9 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, lang ast.Language, styp strin
// _str() functions should have a single argument, the indenting ones take 2:
is_c_struct := lang == .c
arg_def := if is_c_struct { '${styp}* it' } else { '${styp} it' }
g.definitions.writeln('string ${str_fn_name}(${arg_def}); // auto')
g.auto_str_funcs.writeln('string ${str_fn_name}(${arg_def}) { return indent_${str_fn_name}(it, 0);}')
g.definitions.writeln('string indent_${str_fn_name}(${arg_def}, int indent_count); // auto')
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def}); // auto')
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def}) { return indent_${str_fn_name}(it, 0);}')
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, int indent_count); // auto')
mut fn_builder := strings.new_builder(512)
defer {
g.auto_fn_definitions << fn_builder.str()
Expand Down Expand Up @@ -1281,9 +1281,9 @@ fn (mut g Gen) gen_enum_static_from_string(fn_name string, mod_enum_name string,
enum_field_vals := g.table.get_enum_field_vals(mod_enum_name)

mut fn_builder := strings.new_builder(512)
g.definitions.writeln('${option_enum_styp} ${fn_name}(string name); // auto')
g.definitions.writeln('${g.static_non_parallel}${option_enum_styp} ${fn_name}(string name); // auto')

fn_builder.writeln('${option_enum_styp} ${fn_name}(string name) {')
fn_builder.writeln('${g.static_non_parallel}${option_enum_styp} ${fn_name}(string name) {')
fn_builder.writeln('\t${option_enum_styp} t1;')
fn_builder.writeln('\tbool exists = false;')
fn_builder.writeln('\tint inx = 0;')
Expand Down
7 changes: 4 additions & 3 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ mut:
out_fn_start_pos []int // for generating multiple .c files, stores locations of all fn positions in `out` string builder
out0_start int
static_modifier string // for parallel_cc
static_non_parallel string // for non -parallel_cc
has_reflection bool // v.reflection has been imported
has_debugger bool // $dbg has been used in the code
reflection_strings &map[string]int
Expand Down Expand Up @@ -338,6 +339,7 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) (str
use_segfault_handler: !('no_segfault_handler' in pref_.compile_defines
|| pref_.os in [.wasm32, .wasm32_emscripten])
static_modifier: if pref_.parallel_cc { 'static ' } else { '' }
static_non_parallel: if !pref_.parallel_cc { 'static ' } else { '' }
has_reflection: 'v.reflection' in table.modules
has_debugger: 'v.debug' in table.modules
reflection_strings: &reflection_strings
Expand Down Expand Up @@ -1102,12 +1104,11 @@ pub fn (mut g Gen) write_typeof_functions() {
if inter_info.is_generic {
continue
}
static_modifier := if g.pref.parallel_cc { '' } else { 'static ' }
g.definitions.writeln('${static_modifier}char * v_typeof_interface_${sym.cname}(int sidx);')
g.definitions.writeln('${g.static_non_parallel}char * v_typeof_interface_${sym.cname}(int sidx);')
if g.pref.parallel_cc {
g.extern_out.writeln('extern char * v_typeof_interface_${sym.cname}(int sidx);')
}
g.writeln('${static_modifier}char * v_typeof_interface_${sym.cname}(int sidx) {')
g.writeln('${g.static_non_parallel}char * v_typeof_interface_${sym.cname}(int sidx) {')
for t in inter_info.types {
sub_sym := g.table.sym(ast.mktyp(t))
if sub_sym.info is ast.Struct && sub_sym.info.is_unresolved_generic() {
Expand Down

0 comments on commit 2b6fbb9

Please sign in to comment.