cgen: fix parallel cached_type_to_str access (fix #23980) (#23998)

This commit is contained in:
Felipe Pena 2025-03-21 19:01:12 -03:00 committed by GitHub
parent bd064dd695
commit d1dd3616c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -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

View File

@ -1417,9 +1417,11 @@ 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 {
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
// that strongly reduces the usefulness of the exhaustive checking that