diff --git a/cmd/v/v.v b/cmd/v/v.v index 2ae98a1ca2..b777d7598c 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -1,7 +1,6 @@ // Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved. // Use of this source code is governed by an MIT license // that can be found in the LICENSE file. -@[has_globals] module main import os @@ -60,7 +59,15 @@ const external_tools = [ ] const list_of_flags_that_allow_duplicates = ['cc', 'd', 'define', 'cf', 'cflags'] -__global timers = &util.Timers(unsafe { nil }) +@[unsafe] +fn timers_pointer(p &util.Timers) &util.Timers { + // TODO: the static variable here is used as a workaround for the current incompatibility of -usecache and globals in the main module: + mut static ptimers := unsafe { &util.Timers(nil) } + if p != unsafe { nil } { + ptimers = p + } + return ptimers +} fn main() { unbuffer_stdout() @@ -71,12 +78,18 @@ fn main() { if '-show-timings' in os.args { timers_should_print = true } - timers = util.new_timers(should_print: timers_should_print, label: 'main') + mut timers := unsafe { + timers_pointer(util.new_timers( + should_print: timers_should_print + label: 'main' + )) + } timers.start('v start') timers.show('v start') timers.start('TOTAL') // use at_exit here, instead of defer, since some code paths later do early exit(0) or exit(1), for showing errors, or after `v run` at_exit(fn () { + mut timers := unsafe { timers_pointer(nil) } timers.show('TOTAL') })! timers.start('v parsing CLI args')