Skip to content

feat: gate GC_init() and -lgc behind usesGC#112

Open
cs01 wants to merge 5 commits intomainfrom
feature/gate-gc
Open

feat: gate GC_init() and -lgc behind usesGC#112
cs01 wants to merge 5 commits intomainfrom
feature/gate-gc

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 7, 2026

Summary

  • Auto-detect GC usage via emit() override in LLVMGenerator — any instruction containing @GC_ sets usesGC = 1 without manual tagging at 250+ call sites
  • Pre-scan fallback in generateParts() scans irParts and globalStrings before generateMain() to catch GC references from string-builder helpers (ir += patterns) that bypass emit()
  • Gate GC_init() behind usesGC in generateMain() — only called when program uses heap allocation
  • Gate GC declarations behind gc: flag in getLLVMDeclarations()declare void @GC_init(), declare noalias i8* @GC_malloc(i64) etc. only emitted when used
  • Gate -lgc behind usesGC in both compiler.ts and native-compiler-lib.ts
  • Explicit tagging in json.ts::generateJsonParser() for json parser functions that build IR via lines.push() rather than ctx.emit()

Status

The infrastructure is complete and correct. For programs that use path/fs/string helpers (which are unconditionally emitted and reference @GC_malloc), usesGC is still always true — these helpers need to be gated in a follow-up PR before "hello world" can skip GC entirely. The linker/IR gate correctly responds to usesGC and will automatically skip GC once those helpers are gated.

Test plan

  • All 426 tests pass (node + native)
  • Hello world compiles and runs correctly
  • JSON parse test compiles and runs correctly
  • Self-hosting stage 0 failure is pre-existing on main (unrelated to this PR)

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