Skip to content

fix(gc-check): loads from constant globals are not heap-value sources - #13020

Merged
proggeramlug merged 1 commit into
mainfrom
gcchk-constant-handles
Oct 21, 2026
Merged

proggeramlug merged 1 commit into
mainfrom
gcchk-constant-handles

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

After #13017, running scripts/gc_root_dominance_check.py on tssrc's fully optimized Project unit with zero budgets still reported 97 unrooted values and 0 stale ones. The findings are identical on main before and after #12999.

Cause

All 97 are strhandle loads from string-literal handle globals. Each handle global is defined constant and points at an executable string image, which the collector never moves or reclaims (string_pool/image.rs, runtime is_image_string). -Os hoists these loads above safepoints:

How the load ended up above the safepoint Count
i64 hoisted out of a loop or region 62
double hoisted the same way 26
GVN partial-redundancy elimination (PRE) 5
Inlined callee 4

A register loaded from a constant global can't go stale relative to that global. If the object could move, the global itself would be stale. So these registers aren't heap-value sources. The standard pmdom corpora don't hit this because they run only always-inline, mem2reg, sccp and dce before RS4GC.

Change

The checker collects each module's constant global definitions and doesn't treat a load whose pointer operand is one of them as a heap-value source. This applies in both statepoint and stale-register modes. global handles (dylib, staticlib, Mach-O runtime-boxed images, TLS strings) keep the #7240 classification.

Verification

  • --self-test passes. The new positive cases fail without the fix. The negative control, the same handle declared global, still reports 1 unrooted strhandle.
  • Full Project unit: 97 → 0 unrooted, 0 stale, on both base and head.
  • Standard native and dep corpora: 0/0, with 40/40 planted violations caught in each.

Not covered: on macOS the handles are mutable globals pointing to the same immovable images, so a fully optimized Mac IR check would still flag them. That needs a separate exemption grounded in the runtime's guarantee.

A string-literal handle global is defined `constant` and holds a pointer to an
executable string image the collector never moves. After -Os hoists such a load
above a safepoint, the checker reported the register as unrooted: 97 findings on
tssrc's Project unit, identical before and after #12999. Loads whose pointer
operand is a module-level `constant` global are no longer treated as heap-value
sources; `global` handles keep the #7240 classification. The self-test adds
positive cases and a negative control (the same handle declared `global` is
still reported).
@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: da554ed6-2375-4de7-a0df-a15b9355673a
📥 Commits

Reviewing files that changed from the base of the PR and between 76aa5f1 and 725df52.

📒 Files selected for processing: 1
  • scripts/gc_root_dominance_check.py
+---------------------------------------------------------------------------------------------------------------+
| Walking on water and developing software from a specification are easy if both are frozen. - Edward V. Berard |
+---------------------------------------------------------------------------------------------------------------+
  \
   \     /)/)
        ( '')
        /  |
      o(___)
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug
proggeramlug merged commit 1422455 into main Oct 21, 2026
95 of 100 checks passed
@proggeramlug
proggeramlug deleted the gcchk-constant-handles branch October 21, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant