From 4e6bc27b300955007e33cd30c330e3d540809c3e Mon Sep 17 00:00:00 2001 From: spaceface777 Date: Sun, 29 Nov 2020 19:30:35 +0100 Subject: [PATCH] compiler: fix self compilation with cached modules on macOS (#7023) --- vlib/v/builder/cc.v | 5 +++ vlib/v/gen/auto_str_methods.v | 64 +++++++++++++++++------------------ vlib/v/gen/cgen.v | 17 +++++----- vlib/v/gen/cheaders.v | 4 +-- 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 4e7e17eac9..10380e416f 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -125,6 +125,11 @@ fn (mut v Builder) post_process_c_compiler_output(res os.Result) { } fn (mut v Builder) rebuild_cached_module(vexe string, imp_path string) string { + // TODO: move this check somewhere else, this is really not the best place for it :/ + // strconv is already imported inside builtin, so skip generating its object file + if imp_path == 'vlib/strconv' { + return '' + } res := v.pref.cache_manager.exists('.o', imp_path) or { println('Cached $imp_path .o file not found... Building .o file for $imp_path') // do run `v build-module x` always in main vfolder; x can be a relative path diff --git a/vlib/v/gen/auto_str_methods.v b/vlib/v/gen/auto_str_methods.v index 2a4c9085a9..2f2e4fdcb4 100644 --- a/vlib/v/gen/auto_str_methods.v +++ b/vlib/v/gen/auto_str_methods.v @@ -30,8 +30,8 @@ fn (mut g Gen) gen_str_for_type_with_styp(typ table.Type, styp string) string { already_generated_key_no_ptr := '$styp:$str_fn_name_no_ptr' if already_generated_key_no_ptr !in g.str_types { g.str_types << already_generated_key_no_ptr - g.type_definitions.writeln('string ${str_fn_name_no_ptr}($styp it); // auto no_ptr version') - g.auto_str_funcs.writeln('string ${str_fn_name_no_ptr}($styp it){ return ${str_fn_name}(&it); }') + g.type_definitions.writeln('static string ${str_fn_name_no_ptr}($styp it); // auto no_ptr version') + g.auto_str_funcs.writeln('static string ${str_fn_name_no_ptr}($styp it){ return ${str_fn_name}(&it); }') } /* typ_is_ptr := typ.is_ptr() @@ -102,10 +102,10 @@ fn (mut g Gen) gen_str_for_alias(info table.Alias, styp string, str_fn_name stri parent_str_fn_name = g.gen_str_for_type_with_styp(info.parent_type, parent_styp) } mut clean_type_v_type_name := util.strip_main_name(styp.replace('__', '.')) - g.type_definitions.writeln('string ${str_fn_name}($styp it); // auto') - g.auto_str_funcs.writeln('string ${str_fn_name}($styp it) { return indent_${str_fn_name}(it, 0); }') - g.type_definitions.writeln('string indent_${str_fn_name}($styp it, int indent_count); // auto') - g.auto_str_funcs.writeln('string indent_${str_fn_name}($styp it, int indent_count) {') + g.type_definitions.writeln('static string ${str_fn_name}($styp it); // auto') + g.auto_str_funcs.writeln('static string ${str_fn_name}($styp it) { return indent_${str_fn_name}(it, 0); }') + g.type_definitions.writeln('static string indent_${str_fn_name}($styp it, int indent_count); // auto') + g.auto_str_funcs.writeln('static string indent_${str_fn_name}($styp it, int indent_count) {') g.auto_str_funcs.writeln('\tstring indents = tos_lit("");') g.auto_str_funcs.writeln('\tfor (int i = 0; i < indent_count; ++i) {') g.auto_str_funcs.writeln('\t\tindents = string_add(indents, tos_lit(" "));') @@ -137,10 +137,10 @@ fn (mut g Gen) gen_str_for_array(info table.Array, styp string, str_fn_name stri if !sym_has_str_method { g.gen_str_for_type_with_styp(typ, field_styp) } - g.type_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.type_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.type_definitions.writeln('static string ${str_fn_name}($styp a); // auto') + g.auto_str_funcs.writeln('static string ${str_fn_name}($styp a) { return indent_${str_fn_name}(a, 0);}') + g.type_definitions.writeln('static string indent_${str_fn_name}($styp a, int indent_count); // auto') + g.auto_str_funcs.writeln('static 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(&sb, tos_lit("["));') g.auto_str_funcs.writeln('\tfor (int i = 0; i < a.len; ++i) {') @@ -202,10 +202,10 @@ fn (mut g Gen) gen_str_for_array_fixed(info table.ArrayFixed, styp string, str_f if !sym.has_method('str') { elem_str_fn_name = g.gen_str_for_type_with_styp(typ, field_styp) } - g.type_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.type_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.type_definitions.writeln('static string ${str_fn_name}($styp a); // auto') + g.auto_str_funcs.writeln('static string ${str_fn_name}($styp a) { return indent_${str_fn_name}(a, 0);}') + g.type_definitions.writeln('static string indent_${str_fn_name}($styp a, int indent_count); // auto') + g.auto_str_funcs.writeln('static string indent_${str_fn_name}($styp a, 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(&sb, tos_lit("["));') g.auto_str_funcs.writeln('\tfor (int i = 0; i < $info.size; ++i) {') @@ -246,10 +246,10 @@ fn (mut g Gen) gen_str_for_map(info table.Map, styp string, str_fn_name string) g.gen_str_for_type_with_styp(info.value_type, val_styp) } zero := g.type_default(info.value_type) - g.type_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.type_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.type_definitions.writeln('static string ${str_fn_name}($styp m); // auto') + g.auto_str_funcs.writeln('static string ${str_fn_name}($styp m) { return indent_${str_fn_name}(m, 0);}') + g.type_definitions.writeln('static string indent_${str_fn_name}($styp m, int indent_count); // auto') + g.auto_str_funcs.writeln('static 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(&sb, tos_lit("{"));') g.auto_str_funcs.writeln('\tfor (unsigned int i = 0; i < m.key_values.len; ++i) {') @@ -280,8 +280,8 @@ fn (mut g Gen) gen_str_for_map(info table.Map, styp string, str_fn_name string) } fn (mut g Gen) gen_str_for_varg(styp string, str_fn_name string, has_str_method bool) { - g.definitions.writeln('string varg_${str_fn_name}(varg_$styp it); // auto') - g.auto_str_funcs.writeln('string varg_${str_fn_name}(varg_$styp it) {') + g.definitions.writeln('static string varg_${str_fn_name}(varg_$styp it); // auto') + g.auto_str_funcs.writeln('static string varg_${str_fn_name}(varg_$styp it) {') g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(it.len);') g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, tos_lit("["));') g.auto_str_funcs.writeln('\tfor(int i=0; i