compiler: fix self compilation with cached modules on macOS (#7023)

pull/7026/head
spaceface777 2020-11-29 19:30:35 +01:00 committed by GitHub
parent c7cefa9ce6
commit 4e6bc27b30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 42 deletions

View File

@ -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

View File

@ -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<it.len; ++i) {')
@ -303,8 +303,8 @@ fn (mut g Gen) gen_str_for_multi_return(info table.MultiReturn, styp string, str
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) {')
g.type_definitions.writeln('static string ${str_fn_name}($styp a); // auto')
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp a) {')
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder($info.types.len * 10);')
g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, tos_lit("("));')
for i, typ in info.types {
@ -362,10 +362,10 @@ fn (mut g Gen) gen_str_for_struct(info table.Struct, styp string, str_fn_name st
}
}
// _str() functions should have a single argument, the indenting ones take 2:
g.type_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.type_definitions.writeln('string indent_${str_fn_name}($styp x, int indent_count); // auto')
g.auto_str_funcs.writeln('string indent_${str_fn_name}($styp x, int indent_count) {')
g.type_definitions.writeln('static string ${str_fn_name}($styp x); // auto')
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp x) { return indent_${str_fn_name}(x, 0);}')
g.type_definitions.writeln('static string indent_${str_fn_name}($styp x, int indent_count); // auto')
g.auto_str_funcs.writeln('static string indent_${str_fn_name}($styp x, int indent_count) {')
mut clean_struct_v_type_name := styp.replace('__', '.')
if clean_struct_v_type_name.contains('_T_') {
// TODO: this is a bit hacky. styp shouldn't be even parsed with _T_
@ -470,8 +470,8 @@ fn struct_auto_str_func(sym table.TypeSymbol, field_type table.Type, fn_name str
fn (mut g Gen) gen_str_for_enum(info table.Enum, styp string, str_fn_name string) {
s := util.no_dots(styp)
g.type_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.type_definitions.writeln('static string ${str_fn_name}($styp it); // auto')
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp it) { /* gen_str_for_enum */')
g.auto_str_funcs.writeln('\tswitch(it) {')
// Only use the first multi value on the lookup
mut seen := []string{len: info.vals.len}
@ -499,10 +499,10 @@ fn (mut g Gen) gen_str_for_union_sum_type(info table.SumType, styp string, str_f
}
}
// _str() functions should have a single argument, the indenting ones take 2:
g.type_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.type_definitions.writeln('string indent_${str_fn_name}($styp x, int indent_count); // auto')
g.auto_str_funcs.writeln('string indent_${str_fn_name}($styp x, int indent_count) {')
g.type_definitions.writeln('static string ${str_fn_name}($styp x); // auto')
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp x) { return indent_${str_fn_name}(x, 0); }')
g.type_definitions.writeln('static string indent_${str_fn_name}($styp x, int indent_count); // auto')
g.auto_str_funcs.writeln('static string indent_${str_fn_name}($styp x, int indent_count) {')
mut clean_sum_type_v_type_name := styp.replace('__', '.')
if styp.ends_with('*') {
clean_sum_type_v_type_name = '&' + clean_sum_type_v_type_name.replace('*', '')

View File

@ -388,7 +388,7 @@ pub fn (mut g Gen) write_typeof_functions() {
if typ.kind == .sum_type {
sum_info := typ.info as table.SumType
tidx := g.table.find_type_idx(typ.name)
g.writeln('char * v_typeof_sumtype_${tidx}(int sidx) { /* $typ.name */ ')
g.writeln('static char * v_typeof_sumtype_${tidx}(int sidx) { /* $typ.name */ ')
g.writeln(' switch(sidx) {')
g.writeln(' case $tidx: return "${util.strip_main_name(typ.name)}";')
for v in sum_info.variants {
@ -899,13 +899,13 @@ fn (mut g Gen) stmt(node ast.Stmt) {
// if node.name.contains('parse_text') {
// println('!!! $node.name mod=$node.mod, built=$g.module_built')
// }
if !node.name.starts_with(g.module_built + '.') && node.mod != g.module_built.after('/') {
// Skip functions that don't have to be generated
// for this module.
println('skip bm $node.name mode=$node.mod module_built=$g.module_built')
mod := if g.is_builtin_mod { 'builtin' } else { node.name.all_before_last('.') }
if mod != g.module_built && node.mod != g.module_built.after('/') {
// Skip functions that don't have to be generated for this module.
// println('skip bm $node.name mod=$node.mod module_built=$g.module_built')
skip = true
}
if g.is_builtin_mod && g.module_built == 'builtin' {
if g.is_builtin_mod && g.module_built == 'builtin' && node.mod == 'builtin' {
skip = false
}
if !skip {
@ -4044,12 +4044,13 @@ fn (mut g Gen) const_decl_init_later(mod string, name string, val string, typ ta
}
fn (mut g Gen) global_decl(node ast.GlobalDecl) {
mod := if g.pref.build_mode == .build_module && g.is_builtin_mod { 'static ' } else { '' }
for field in node.fields {
styp := g.typ(field.typ)
if field.has_expr {
g.definitions.writeln('$styp $field.name = $field.expr; // global')
g.definitions.writeln('$mod$styp $field.name = $field.expr; // global')
} else {
g.definitions.writeln('$styp $field.name; // global')
g.definitions.writeln('$mod$styp $field.name; // global')
}
}
}

View File

@ -263,7 +263,7 @@ $c_common_macros
#endif
// g_live_info is used by live.info()
void* g_live_info = NULL;
static void* g_live_info = NULL;
//============================== HELPER C MACROS =============================*/
//#define tos4(s, slen) ((string){.str=(s), .len=(slen)})
@ -436,7 +436,7 @@ void _vcleanup();
#endif
voidptr memdup(voidptr src, int sz);
voidptr memfreedup(voidptr ptr, voidptr src, int sz) {
static voidptr memfreedup(voidptr ptr, voidptr src, int sz) {
free(ptr);
return memdup(src, sz);
}