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

markused: fix compilation of gg programs with -skip-unused, add test to prevent regressions (#15821)

This commit is contained in:
Delyan Angelov 2022-09-20 08:03:03 +03:00 committed by GitHub
parent 42059ee099
commit 993802f6a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 64 additions and 11 deletions

View File

@ -169,6 +169,11 @@ fn get_all_commands() []Command {
okmsg: 'V compiles hello_world.v on the JS backend, with -skip-unused' okmsg: 'V compiles hello_world.v on the JS backend, with -skip-unused'
rmfile: 'hw_skip_unused.js' rmfile: 'hw_skip_unused.js'
} }
res << Command{
line: '$vexe -skip-unused examples/2048'
okmsg: 'V can compile 2048 with -skip-unused.'
rmfile: 'examples/2048/2048'
}
} }
res << Command{ res << Command{
line: '$vexe -o vtmp cmd/v' line: '$vexe -o vtmp cmd/v'

View File

@ -155,6 +155,7 @@ const (
skip_on_musl = [ skip_on_musl = [
'vlib/v/tests/profile/profile_test.v', 'vlib/v/tests/profile/profile_test.v',
'vlib/gg/draw_fns_api_test.v', 'vlib/gg/draw_fns_api_test.v',
'vlib/v/tests/skip_unused/gg_code.vv',
] ]
skip_on_ubuntu_musl = [ skip_on_ubuntu_musl = [
//'vlib/v/gen/js/jsgen_test.v', //'vlib/v/gen/js/jsgen_test.v',

View File

@ -19,6 +19,11 @@ const skip_on_cstrict = [
const skip_on_ubuntu_musl = [ const skip_on_ubuntu_musl = [
'vlib/v/checker/tests/vweb_tmpl_used_var.vv', 'vlib/v/checker/tests/vweb_tmpl_used_var.vv',
'vlib/v/checker/tests/vweb_routing_checks.vv', 'vlib/v/checker/tests/vweb_routing_checks.vv',
'vlib/v/tests/skip_unused/gg_code.vv',
]
const skip_on_ci_musl = [
'vlib/v/tests/skip_unused/gg_code.vv',
] ]
const vexe = os.getenv('VEXE') const vexe = os.getenv('VEXE')
@ -37,6 +42,8 @@ const github_job = os.getenv('GITHUB_JOB')
const v_ci_ubuntu_musl = os.getenv('V_CI_UBUNTU_MUSL').len > 0 const v_ci_ubuntu_musl = os.getenv('V_CI_UBUNTU_MUSL').len > 0
const v_ci_musl = os.getenv('V_CI_MUSL').len > 0
const v_ci_cstrict = os.getenv('V_CI_CSTRICT').len > 0 const v_ci_cstrict = os.getenv('V_CI_CSTRICT').len > 0
struct TaskDescription { struct TaskDescription {
@ -217,6 +224,9 @@ fn (mut tasks Tasks) run() {
if v_ci_ubuntu_musl { if v_ci_ubuntu_musl {
m_skip_files << skip_on_ubuntu_musl m_skip_files << skip_on_ubuntu_musl
} }
if v_ci_musl {
m_skip_files << skip_on_ci_musl
}
if v_ci_cstrict { if v_ci_cstrict {
m_skip_files << skip_on_cstrict m_skip_files << skip_on_cstrict
} }

View File

@ -13,6 +13,7 @@ pub mut:
used_fns map[string]bool // used_fns['println'] == true used_fns map[string]bool // used_fns['println'] == true
used_consts map[string]bool // used_consts['os.args'] == true used_consts map[string]bool // used_consts['os.args'] == true
used_globals map[string]bool used_globals map[string]bool
used_structs map[string]bool
n_asserts int n_asserts int
pref &pref.Preferences = unsafe { nil } pref &pref.Preferences = unsafe { nil }
mut: mut:
@ -402,17 +403,7 @@ fn (mut w Walker) expr(node_ ast.Expr) {
sym := w.table.sym(node.typ) sym := w.table.sym(node.typ)
if sym.kind == .struct_ { if sym.kind == .struct_ {
info := sym.info as ast.Struct info := sym.info as ast.Struct
for ifield in info.fields { w.a_struct_info(sym.name, info)
if ifield.has_default_expr {
w.expr(ifield.default_expr)
}
if ifield.typ != 0 {
fsym := w.table.sym(ifield.typ)
if fsym.kind == .map {
w.table.used_maps++
}
}
}
} }
if node.has_update_expr { if node.has_update_expr {
w.expr(node.update_expr) w.expr(node.update_expr)
@ -463,6 +454,27 @@ fn (mut w Walker) expr(node_ ast.Expr) {
} }
} }
pub fn (mut w Walker) a_struct_info(sname string, info ast.Struct) {
if sname in w.used_structs {
return
}
w.used_structs[sname] = true
for ifield in info.fields {
if ifield.has_default_expr {
w.expr(ifield.default_expr)
}
if ifield.typ != 0 {
fsym := w.table.sym(ifield.typ)
if fsym.kind == .map {
w.table.used_maps++
}
if fsym.kind == .struct_ {
w.a_struct_info(fsym.name, fsym.struct_info())
}
}
}
}
pub fn (mut w Walker) fn_decl(mut node ast.FnDecl) { pub fn (mut w Walker) fn_decl(mut node ast.FnDecl) {
if node.language == .c { if node.language == .c {
return return

View File

@ -0,0 +1 @@
OK

View File

@ -0,0 +1 @@
OK

View File

@ -0,0 +1,23 @@
module main
import gg
import gx
[console]
fn main() {
x := gg.new_context(
bg_color: gx.rgb(174, 198, 255)
window_title: 'GG Hello'
frame_fn: fn (mut ctx gg.Context) {
ctx.begin()
ctx.draw_text_def(10, 25, 'Hello')
ctx.end()
if ctx.frame > 10 {
println('OK')
exit(0)
}
}
)
_ := x.user_data
println('OK')
}