From 9faefe85e1a6646ae3c351334ffa1904bc1132b9 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Sat, 12 Oct 2019 11:38:56 +1100 Subject: [PATCH] compiler: cached module - cleanup, remove unneeded code (#2297) * test * only call existing module init * add back comment --- compiler/main.v | 53 ++++++----------------------------------------- compiler/parser.v | 2 +- 2 files changed, 7 insertions(+), 48 deletions(-) diff --git a/compiler/main.v b/compiler/main.v index c339426510..605fded22c 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -271,14 +271,6 @@ fn (v mut V) compile() { v.parse(file, .decl) } - // generate missing module init's - init_parsers := v.module_gen_init_parsers() - // run decl pass - for i in 0..init_parsers.len { - mut ip := init_parsers[i] - ip.parse(.decl) - } - // Main pass cgen.pass = Pass.main if v.pref.is_debug { @@ -344,11 +336,6 @@ fn (v mut V) compile() { // new vfmt is not ready yet } } - // run main parser on the init parsers - for i in 0..init_parsers.len { - mut ip := init_parsers[i] - ip.parse(.main) - } // Generate .vh if we are building a module if v.pref.build_mode == .build_module { v.generate_vh() @@ -400,36 +387,6 @@ fn (v mut V) compile() { v.cc() } -fn (v mut V) module_gen_init_parsers() []Parser { - mut parsers := []Parser - if v.pref.build_mode == .build_module { - init_fn_name := mod_gen_name(v.mod) + '__init' - if !v.table.known_fn(init_fn_name) { - mod_def := if v.mod.contains('.') { v.mod.all_after('.') } else { v.mod } - mut fn_v := 'module $mod_def\n\n' - fn_v += 'fn init() { /*println(\'$v.mod module init\')*/ }' - mut p := v.new_parser_from_string(fn_v, 'init_gen_$v.mod') - p.mod = v.mod - parsers << p - } - } - else if v.pref.build_mode == .default_mode { - for mod in v.table.imports { - if mod in v.cached_mods { continue } - init_fn_name := mod_gen_name(mod) + '__init' - if !v.table.known_fn(init_fn_name) { - mod_def := if mod.contains('.') { mod.all_after('.') } else { mod } - mut fn_v := 'module $mod_def\n\n' - fn_v += 'fn init() { /*println(\'$v.mod module init\')*/ }' - mut p := v.new_parser_from_string(fn_v, 'init_gen_$mod') - p.mod = mod - parsers << p - } - } - } - return parsers -} - fn (v mut V) generate_init() { $if js { return } if v.pref.build_mode == .build_module { @@ -437,7 +394,6 @@ fn (v mut V) generate_init() { v.cgen.nogen = false consts_init_body := v.cgen.consts_init.join_lines() init_fn_name := mod_gen_name(v.mod) + '__init_consts' - println('generating init for $v.mod: $init_fn_name') v.cgen.genln('void ${init_fn_name}() {\n$consts_init_body\n}') v.cgen.nogen = nogen } @@ -446,7 +402,9 @@ fn (v mut V) generate_init() { mut call_mod_init_consts := '' for mod in v.table.imports { init_fn_name := mod_gen_name(mod) + '__init' - call_mod_init += '${init_fn_name}();\n' + if v.table.known_fn(init_fn_name) { + call_mod_init += '${init_fn_name}();\n' + } if mod in v.cached_mods { call_mod_init_consts += '${init_fn_name}_consts();\n' } @@ -655,7 +613,7 @@ fn (v &V) v_files_from_dir(dir string) []string { fn (v mut V) add_v_files_to_compile() { mut builtin_files := v.get_builtin_files() // Builtin cache exists? Use it. - builtin_vh := '$v_modules_path/builtin.vh' + builtin_vh := '$v_modules_path${os.PathSeparator}builtin.vh' if v.pref.is_debug && os.file_exists(builtin_vh) { builtin_files = [builtin_vh] } @@ -672,7 +630,8 @@ fn (v mut V) add_v_files_to_compile() { for file in v.get_user_files() { mut p := v.new_parser_from_file(file) // set mod so we dont have to resolve submodule - if v.pref.build_mode == .build_module && file.contains(v.mod.replace('.', os.PathSeparator)) { + if v.pref.build_mode == .build_module && + file.contains(v.mod.replace('.', os.PathSeparator)) { p.mod = v.mod } p.parse(.imports) diff --git a/compiler/parser.v b/compiler/parser.v index 9568ea762c..570d83fef1 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -278,7 +278,7 @@ fn (p mut Parser) parse(pass Pass) { p.builtin_mod = p.mod == 'builtin' p.can_chash = p.mod=='ui' || p.mod == 'darwin'// TODO tmp remove // Import pass - the first and the smallest pass that only analyzes imports - + // fully qualify the module name, eg base64 to encoding.base64 fq_mod := p.table.qualify_module(p.mod, p.file_path) p.import_table.module_name = fq_mod p.table.register_module(fq_mod)