From f3408a2484d39cd3803da84e95859993082eceae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kr=C3=BCger?= <45282134+UweKrueger@users.noreply.github.com> Date: Tue, 15 Jun 2021 14:43:00 +0200 Subject: [PATCH] gc: use optimized mode by default (#10466) --- .github/workflows/ci.yml | 16 ++++++++-------- vlib/v/gen/c/cgen.v | 4 +--- vlib/v/gen/c/cmain.v | 8 ++------ vlib/v/gen/c/fn.v | 4 ++-- vlib/v/pref/pref.v | 10 ++++++---- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 148cf1f4cb..a55a20ac12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 828857139d..dd44e3ab77 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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 { diff --git a/vlib/v/gen/c/cmain.v b/vlib/v/gen/c/cmain.v index 1ea32941c4..6e741a671c 100644 --- a/vlib/v/gen/c/cmain.v +++ b/vlib/v/gen/c/cmain.v @@ -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);') diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 4ec39a6469..01c34b6b0a 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -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) diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 3d2f180379..a86de7d7d3 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -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) } }