1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

make V compile itself using cached modules: ~0.3s speed-up

This commit is contained in:
Alexander Medvednikov 2019-10-10 02:59:33 +03:00
parent 2ee252be5f
commit 4d941b5fdb
3 changed files with 23 additions and 11 deletions

View File

@ -106,25 +106,29 @@ fn (v mut V) cc() {
a << f a << f
} }
libs := ''// builtin.o os.o http.o etc mut libs := ''// builtin.o os.o http.o etc
if v.pref.build_mode == .build_module { if v.pref.build_mode == .build_module {
a << '-c' a << '-c'
} }
else if v.pref.build_mode == .default_mode { else if v.pref.is_debug {
libs = '$v_modules_path/vlib/builtin.o ' +
'$v_modules_path/vlib/strings.o '+
'$v_modules_path/vlib/math.o '
/* /*
// TODO
libs = '$v_modules_path/vlib/builtin.o'
if !os.file_exists(libs) { if !os.file_exists(libs) {
println('object file `$libs` not found') println('object file `$libs` not found')
exit(1) exit(1)
} }
*/
for imp in v.table.imports { for imp in v.table.imports {
if imp == 'webview' { if imp == 'webview' {
continue continue
} }
libs += ' "$v_modules_path/vlib/${imp}.o"' path := '"$v_modules_path/vlib/${imp}.o"'
if os.file_exists(path) {
libs += ' ' + path
}
} }
*/
} }
if v.pref.sanitize { if v.pref.sanitize {
a << '-fsanitize=leak' a << '-fsanitize=leak'

View File

@ -11,7 +11,7 @@ import (
/* /*
.vh generation logic. .vh generation logic.
.vh files contains only function signatures, consts, and types. .vh files contain only function signatures, consts, and types.
They are used together with pre-compiled modules. They are used together with pre-compiled modules.
*/ */
@ -95,7 +95,11 @@ fn v_type_str(typ_ string) string {
return '[]' + typ.right(6) return '[]' + typ.right(6)
} }
if typ.contains('__') { if typ.contains('__') {
return typ.all_after('__') opt := typ.starts_with('?')
typ = typ.all_after('__')
if opt {
typ = '?' + typ
}
} }
return typ return typ
} }
@ -213,8 +217,8 @@ fn (v &V) generate_vh() {
// Methods // Methods
file.writeln('\n// Methods //////////////////') file.writeln('\n// Methods //////////////////')
for _, typ in v.table.typesmap { for _, typ in v.table.typesmap {
if typ.mod != v.mod { //&& typ.mod != '' { if typ.mod != v.mod && !(v.mod == 'builtin' && typ.mod == '') {
//println('skipping method typ $typ.name mod=$typ.mod') println('skipping method typ $typ.name mod=$typ.mod')
continue continue
} }
for method in typ.methods { for method in typ.methods {

View File

@ -509,6 +509,8 @@ fn (p mut Parser) const_decl() {
// .vh files don't have const values, just types: `const (a int)` // .vh files don't have const values, just types: `const (a int)`
typ = p.get_type() typ = p.get_type()
p.table.register_const(name, typ, p.mod) p.table.register_const(name, typ, p.mod)
p.cgen.consts << ('extern ' +
p.table.cgen_name_type_pair(name, typ)) + ';'
continue // Don't generate C code when building a .vh file continue // Don't generate C code when building a .vh file
} else { } else {
p.check_space(.assign) p.check_space(.assign)
@ -524,7 +526,9 @@ fn (p mut Parser) const_decl() {
// TODO hack // TODO hack
// cur_line has const's value right now. if it's just a number, then optimize generation: // cur_line has const's value right now. if it's just a number, then optimize generation:
// output a #define so that we don't pollute the binary with unnecessary global vars // output a #define so that we don't pollute the binary with unnecessary global vars
if is_compile_time_const(p.cgen.cur_line) { // Do not do this when building a module, otherwise the consts
// will not be accessible.
if p.pref.build_mode != .build_module && is_compile_time_const(p.cgen.cur_line) {
p.cgen.consts << '#define $name $p.cgen.cur_line' p.cgen.consts << '#define $name $p.cgen.cur_line'
p.cgen.resetln('') p.cgen.resetln('')
p.fgenln('') p.fgenln('')