From 47593c815a02507f0916c2e2a486e4cc86c7bd8c Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 17 Mar 2026 10:44:11 +0300 Subject: [PATCH] all: fix CI failures from VGC PR - add missing stubs, fix README --- vlib/builtin/builtin_d_vgc.c.v | 4 +--- vlib/builtin/builtin_notd_gcboehm.c.v | 34 +++++++++++---------------- vlib/builtin/vgc_notd_vgc.c.v | 32 +++++++++++++++++++++++++ vlib/goroutines/README.md | 10 +++++--- 4 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 vlib/builtin/vgc_notd_vgc.c.v diff --git a/vlib/builtin/builtin_d_vgc.c.v b/vlib/builtin/builtin_d_vgc.c.v index d139d2198..353215d56 100644 --- a/vlib/builtin/builtin_d_vgc.c.v +++ b/vlib/builtin/builtin_d_vgc.c.v @@ -1,7 +1,5 @@ // builtin_d_vgc.c.v - V Garbage Collector additional support -// Conditionally compiled when -gc vgc is used. -// The public gc_* API is provided by builtin_notd_gcboehm.c.v (which delegates -// to VGC via $if vgc ? blocks) to avoid duplicate function definitions. +// Conditionally compiled when -d vgc is used. // The gc_heap_usage/gc_memory_use functions are in allocation.c.v with $if vgc ? branches. module builtin diff --git a/vlib/builtin/builtin_notd_gcboehm.c.v b/vlib/builtin/builtin_notd_gcboehm.c.v index 53eb7510c..76b9ad60b 100644 --- a/vlib/builtin/builtin_notd_gcboehm.c.v +++ b/vlib/builtin/builtin_notd_gcboehm.c.v @@ -24,38 +24,32 @@ fn C.GC_get_memory_use() usize fn C.GC_gcollect() // gc_check_leaks is useful for detecting leaks, but it needs the GC to run. -// When GC is not used, it is a NOP. When VGC is active, delegates to vgc. +// When GC is not used, it is a NOP. pub fn gc_check_leaks() {} // gc_is_enabled() returns true, if the GC is enabled at runtime. -// With `-gc none` returns false. With `-gc vgc` delegates to the VGC. +// It will always return false, with `-gc none`. +// See also gc_disable() and gc_enable(). pub fn gc_is_enabled() bool { - $if vgc ? { - return C.vgc_atomic_load_u32(unsafe { &vgc_heap.gc_enabled }) != 0 - } return false } // gc_enable explicitly enables the GC. -pub fn gc_enable() { - $if vgc ? { - C.vgc_atomic_store_u32(unsafe { &vgc_heap.gc_enabled }, 1) - } -} +// Note, that garbage collections are done automatically, when needed in most cases, +// and also that by default the GC is on, so you do not need to enable it. +// See also gc_disable() and gc_collect(). +// Note that gc_enable() is a NOP with `-gc none`. +pub fn gc_enable() {} // gc_disable explicitly disables the GC. -pub fn gc_disable() { - $if vgc ? { - C.vgc_atomic_store_u32(unsafe { &vgc_heap.gc_enabled }, 0) - } -} +// Do not forget to enable it again by calling gc_enable(), when your program is otherwise idle, and can afford it. +// See also gc_enable() and gc_collect(). +// Note that gc_disable() is a NOP with `-gc none`. +pub fn gc_disable() {} // gc_collect explicitly performs a garbage collection. -pub fn gc_collect() { - $if vgc ? { - vgc_gc_start() - } -} +// When the GC is not on, (with `-gc none`), it is a NOP. +pub fn gc_collect() {} pub type FnGC_WarnCB = fn (msg &char, arg usize) diff --git a/vlib/builtin/vgc_notd_vgc.c.v b/vlib/builtin/vgc_notd_vgc.c.v new file mode 100644 index 000000000..fd031df39 --- /dev/null +++ b/vlib/builtin/vgc_notd_vgc.c.v @@ -0,0 +1,32 @@ +module builtin + +// Stub declarations for VGC functions, so that V does not error +// because of the missing definitions in $if vgc ? { } blocks. +// Note: they will NOT be called, since calls to them are wrapped with `$if vgc ? { }`. + +fn vgc_malloc(n usize) voidptr { + return unsafe { nil } +} + +fn vgc_malloc_noscan(n usize) voidptr { + return unsafe { nil } +} + +fn vgc_realloc(old_ptr voidptr, new_size usize) voidptr { + return unsafe { nil } +} + +fn vgc_calloc(n usize) voidptr { + return unsafe { nil } +} + +fn vgc_free(ptr voidptr) { +} + +fn vgc_heap_usage() (usize, usize, usize, usize, usize) { + return 0, 0, 0, 0, 0 +} + +fn vgc_memory_use() usize { + return 0 +} diff --git a/vlib/goroutines/README.md b/vlib/goroutines/README.md index 3c81fe616..0fb5cbc6b 100644 --- a/vlib/goroutines/README.md +++ b/vlib/goroutines/README.md @@ -1,10 +1,14 @@ # goroutines -Go-style goroutine runtime for V, implementing the GMP (Goroutine-Machine-Processor) scheduling model translated from the Go runtime (`src/runtime/proc.go`, `runtime2.go`, `chan.go`). +Go-style goroutine runtime for V, implementing the GMP +(Goroutine-Machine-Processor) scheduling model translated +from the Go runtime (`src/runtime/proc.go`, `runtime2.go`, +`chan.go`). ## Overview -This module provides lightweight goroutines for V's `go` keyword, as opposed to `spawn` which creates OS threads. +This module provides lightweight goroutines for V's `go` +keyword, as opposed to `spawn` which creates OS threads. ### GMP Model @@ -22,7 +26,7 @@ This module provides lightweight goroutines for V's `go` keyword, as opposed to ## Usage -```v +```v ignore // `go` launches a goroutine (lightweight, scheduled by GMP) go expensive_computation() -- 2.39.5