Skip to content

Commit d1dd361

Browse files
authored
cgen: fix parallel cached_type_to_str access (fix #23980) (#23998)
1 parent bd064dd commit d1dd361

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

vlib/v/ast/table.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub mut:
9494
builtin_pub_fns map[string]bool
9595
pointer_size int
9696
// cache for type_to_str_using_aliases
97-
cached_type_to_str map[u64]string
97+
cached_type_to_str shared map[u64]string
9898
// counters and maps for anon structs and unions, to avoid name conflicts.
9999
anon_struct_names map[string]int // anon struct name -> struct sym idx
100100
anon_struct_counter int

vlib/v/ast/types.v

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,8 +1417,10 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]
14171417
mut res := sym.name
14181418
mut mt := unsafe { &Table(t) }
14191419
defer {
1420-
// Note, that this relies on `res = value return res` if you want to return early!
1421-
mt.cached_type_to_str[cache_key] = res
1420+
lock mt.cached_type_to_str {
1421+
// Note, that this relies on `res = value return res` if you want to return early!
1422+
mt.cached_type_to_str[cache_key] = res
1423+
}
14221424
}
14231425
// Note, that the duplication of code in some of the match branches here
14241426
// is VERY deliberate. DO NOT be tempted to use `else {}` instead, because

0 commit comments

Comments
 (0)