mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gc: use optimized mode by default (#10466)
This commit is contained in:
parent
60c880a0cc
commit
f3408a2484
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
@ -128,27 +128,27 @@ jobs:
|
||||
run: |
|
||||
thirdparty/tcc/tcc.exe -version
|
||||
./v -cg -o v cmd/v # Make sure vtcc can build itself twice
|
||||
- name: v self compilation with -gc boehm_full_opt
|
||||
- name: v self compilation with -gc boehm
|
||||
run: |
|
||||
./v -gc boehm_full_opt -o v2 cmd/v && ./v2 -gc boehm_full_opt -o v3 cmd/v && ./v3 -gc boehm_full_opt -o v4 cmd/v
|
||||
./v -gc boehm -o v2 cmd/v && ./v2 -gc boehm -o v3 cmd/v && ./v3 -gc boehm -o v4 cmd/v
|
||||
mv v4 v
|
||||
- name: v doctor
|
||||
run: |
|
||||
./v doctor
|
||||
- name: Verify `v -gc boehm_full_opt test` works
|
||||
- name: Verify `v -gc boehm test` works
|
||||
run: |
|
||||
./v -gc boehm_full_opt cmd/tools/test_if_v_test_system_works.v
|
||||
./v -gc boehm cmd/tools/test_if_v_test_system_works.v
|
||||
./cmd/tools/test_if_v_test_system_works
|
||||
- name: Self tests with `-gc boehm_full_opt` with V compiler using Boehm-GC itself
|
||||
run: ./v -gc boehm_full_opt -silent test-self
|
||||
- name: Self tests with `-gc boehm` with V compiler using Boehm-GC itself
|
||||
run: ./v -gc boehm -silent test-self
|
||||
- name: Test leak detector
|
||||
run: |
|
||||
./v -gc boehm_leak -o testcase_leak vlib/v/tests/testcase_leak.v
|
||||
./testcase_leak 2>leaks.txt
|
||||
grep "Found 1 leaked object" leaks.txt && grep ", sz=1000," leaks.txt
|
||||
- name: Test leak detector not being active for `-gc boehm_full_opt`
|
||||
- name: Test leak detector not being active for `-gc boehm`
|
||||
run: |
|
||||
./v -gc boehm_full_opt -o testcase_leak vlib/v/tests/testcase_leak.v
|
||||
./v -gc boehm -o testcase_leak vlib/v/tests/testcase_leak.v
|
||||
./testcase_leak 2>leaks.txt
|
||||
[ "$(stat -c %s leaks.txt)" = "0" ]
|
||||
- name: Test leak detector not being active for normal compile
|
||||
|
@ -443,9 +443,7 @@ pub fn (mut g Gen) init() {
|
||||
if g.table.gostmts > 0 {
|
||||
g.comptime_defines.writeln('#define __VTHREADS__ (1)')
|
||||
}
|
||||
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm,
|
||||
.boehm_leak,
|
||||
] {
|
||||
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm_leak] {
|
||||
g.comptime_defines.writeln('#define _VGCBOEHM (1)')
|
||||
}
|
||||
if g.pref.is_debug || 'debug' in g.pref.compile_defines {
|
||||
|
@ -70,9 +70,7 @@ fn (mut g Gen) gen_c_main_function_header() {
|
||||
|
||||
fn (mut g Gen) gen_c_main_header() {
|
||||
g.gen_c_main_function_header()
|
||||
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm,
|
||||
.boehm_leak,
|
||||
] {
|
||||
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm_leak] {
|
||||
g.writeln('#if defined(_VGCBOEHM)')
|
||||
if g.pref.gc_mode == .boehm_leak {
|
||||
g.writeln('\tGC_set_find_leak(1);')
|
||||
@ -176,9 +174,7 @@ pub fn (mut g Gen) gen_c_main_for_tests() {
|
||||
main_fn_start_pos := g.out.len
|
||||
g.writeln('')
|
||||
g.gen_c_main_function_header()
|
||||
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm,
|
||||
.boehm_leak,
|
||||
] {
|
||||
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm_leak] {
|
||||
g.writeln('#if defined(_VGCBOEHM)')
|
||||
if g.pref.gc_mode == .boehm_leak {
|
||||
g.writeln('\tGC_set_find_leak(1);')
|
||||
|
@ -441,7 +441,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
|
||||
g.inside_call = false
|
||||
}
|
||||
gen_keep_alive := node.is_keep_alive && node.return_type != ast.void_type
|
||||
&& g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm]
|
||||
&& g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt]
|
||||
gen_or := node.or_block.kind != .absent // && !g.is_autofree
|
||||
is_gen_or_and_assign_rhs := gen_or && !g.discard_or_result
|
||||
cur_line := if is_gen_or_and_assign_rhs || gen_keep_alive { // && !g.is_autofree {
|
||||
@ -954,7 +954,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
||||
g.write(json_obj)
|
||||
} else {
|
||||
if node.is_keep_alive
|
||||
&& g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm] {
|
||||
&& g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt] {
|
||||
cur_line := g.go_before_stmt(0)
|
||||
tmp_cnt_save = g.keep_alive_call_pregen(node)
|
||||
g.write(cur_line)
|
||||
|
@ -29,7 +29,6 @@ pub enum GarbageCollectionMode {
|
||||
boehm_incr // incremental garbage colletion mode
|
||||
boehm_full_opt // full garbage collection mode
|
||||
boehm_incr_opt // incremental garbage colletion mode
|
||||
boehm // default Boehm-GC mode for architecture
|
||||
boehm_leak // leak detection mode (makes `gc_check_leaks()` work)
|
||||
}
|
||||
|
||||
@ -262,7 +261,7 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
|
||||
'-gc' {
|
||||
gc_mode := cmdline.option(current_args, '-gc', '')
|
||||
match gc_mode {
|
||||
'' {
|
||||
'', 'none' {
|
||||
res.gc_mode = .no_gc
|
||||
}
|
||||
'boehm_full' {
|
||||
@ -288,8 +287,10 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
|
||||
parse_define(mut res, 'gcboehm_opt')
|
||||
}
|
||||
'boehm' {
|
||||
res.gc_mode = .boehm
|
||||
res.gc_mode = .boehm_full_opt // default mode
|
||||
parse_define(mut res, 'gcboehm')
|
||||
parse_define(mut res, 'gcboehm_full')
|
||||
parse_define(mut res, 'gcboehm_opt')
|
||||
}
|
||||
'boehm_leak' {
|
||||
res.gc_mode = .boehm_leak
|
||||
@ -298,12 +299,13 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
|
||||
}
|
||||
else {
|
||||
eprintln('unknown garbage collection mode `-gc $gc_mode`, supported modes are:`')
|
||||
eprintln(' `-gc boehm` ............ default mode for the platform')
|
||||
eprintln(' `-gc boehm` ............ default GC-mode (currently `boehm_full_opt`)')
|
||||
eprintln(' `-gc boehm_full` ....... classic full collection')
|
||||
eprintln(' `-gc boehm_incr` ....... incremental collection')
|
||||
eprintln(' `-gc boehm_full_opt` ... optimized classic full collection')
|
||||
eprintln(' `-gc boehm_incr_opt` ... optimized incremental collection')
|
||||
eprintln(' `-gc boehm_leak` ....... leak detection (for debugging)')
|
||||
eprintln(' `-gc none` ............. no garbage collection')
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user