Three fixes to the parametric-polymorphism checker.
src/check_expr.cpp
- find_or_generate_polymorphic_procedure: close a check-then-act race in the
generated-procedure cache. Both lookups ran under a shared lock that was
released before the insert, so two threads instantiating the same
specialization could both miss and each publish a distinct entity. Re-check
under the exclusive lock, now held across construction and the array_add so
find-then-publish is atomic. Factor the reuse path into
reuse_gen_polymorphic_procedure.
- is_polymorphic_type_assignable: require BOTH components to match for maps and
enumerated arrays (|| -> &&). The old || accepted e.g. map[int]$V against
map[string]f32 (binding $V and deferring the key mismatch to a confusing
assignment error); it now fails cleanly at inference. Both sides are still
evaluated, so modify_type side effects are unchanged.
src/check_type.cpp, src/check_expr.cpp
- check_struct_type: release the originating record's gen_types mutex right after
the instantiation is published, before checking its fields. Holding it across
field-checking (which instantiates other records) allowed a cross-record ABBA
deadlock between mutually-recursive generic structs instantiated concurrently;
concurrent finders now synchronize via the existing fields_wait_signal.
Canonicalize the instantiation name before publishing
(set_polymorphic_record_instantiation_name) so the early release cannot expose
a torn Named.name. Unions are left unchanged: they lack a variants-ready
signal, so early release is not yet safe for them.
`check_scope_decls` iterates a scope's entity map while
`check_entity_decl` can insert into that same scope: a procedure alias
(`f :: e`) goes through `override_entity_in_scope`, which calls
`scope_map_insert`. The map grows at 75% load (12 of 16 slots, then 24
of 32), and `scope_map_insert` grows before it probes for the key, so
even an alias that only replaces an existing value rehashes and
reallocates the table in the middle of the iteration.
`ScopeMapIterator` re-read its map on every step while `end` had
captured the capacity at loop start, so the walk continued over the new
table under the old sentinel: it ran past the end of the reallocated
table and dereferenced whatever followed it as an `Entity *` - a nullptr
dereference for a procedure scope holding exactly 12 or 24 entities - or
it stopped at the stale end index and silently skipped every declaration
that the rehash had moved behind it, which left unused declarations
without any diagnostic at all.
The iterator now snapshots the table pointer and capacity when it is
constructed, so iteration is invariant under any insert or grow and
cannot leave the table it began on. A scope that does not grow behaves
exactly as before: the snapshot points at the same table.
Refs #7598