mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-03 07:54:40 +08:00
A union retype between two shape unions (or two class unions) shares the pointer when both encode their unit arms the same way. Narrowing a field read past `=== undefined` or `=== null` retypes a union with a unit arm to one without it, so the encodings differ and each listed arm was rebuilt: a retain, a tag switch, a second retain and a release, for the same pointer. The unit encodings only matter when the value may hold a unit arm. When the retype lists none of the source's unit tags, every value is a record or class pointer whose arm the target derives from the record or class itself, so the pointer is the target value. The rebuild's release also made the pointer a nursery cycle candidate, and in the native compiler those candidates kept the nursery bypass's probes of closures and boxes succeeding. Without them, a probe window can open while young cycles of the type are held by older garbage that the bypass promoted earlier. The window then frees nothing, the type stays bypassed, and the garbage waits for a mature pass, which on a cold tsc-ts build raised the compiler's peak RSS by about 100 MB. A nursery probe window that opens now makes the next release-triggered pass that would run at the nursery run at the mature level, which reclaims that garbage before the window is judged.