From d1dd3616c4f57fa13064d48ed804d06c58f99750 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Fri, 21 Mar 2025 19:01:12 -0300 Subject: [PATCH] cgen: fix parallel cached_type_to_str access (fix #23980) (#23998) --- vlib/v/ast/table.v | 2 +- vlib/v/ast/types.v | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index dc2dec7d7e..f453c8b03b 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -94,7 +94,7 @@ pub mut: builtin_pub_fns map[string]bool pointer_size int // cache for type_to_str_using_aliases - cached_type_to_str map[u64]string + cached_type_to_str shared map[u64]string // counters and maps for anon structs and unions, to avoid name conflicts. anon_struct_names map[string]int // anon struct name -> struct sym idx anon_struct_counter int diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 52afd493c7..646beae879 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -1417,8 +1417,10 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string] mut res := sym.name mut mt := unsafe { &Table(t) } defer { - // Note, that this relies on `res = value return res` if you want to return early! - mt.cached_type_to_str[cache_key] = res + lock mt.cached_type_to_str { + // Note, that this relies on `res = value return res` if you want to return early! + mt.cached_type_to_str[cache_key] = res + } } // Note, that the duplication of code in some of the match branches here // is VERY deliberate. DO NOT be tempted to use `else {}` instead, because