Repository navigation
A call to the collector's API outside -mm=gc is a compile error - #420
Merged
Merged
Conversation
Every program that awaits anything, built ahead of time under rc, none or own, failed to link: TypeScriptAsyncRuntime.lib(AsyncRuntime.obj) : error LNK2019: unresolved external symbol GC_allow_register_threads referenced in function GC_enable_threads (and GC_register_my_thread, GC_unregister_my_thread, GC_get_stack_base) The async runtime registers its pool threads with the collector under gc (AsyncGCThreads.h, from #308). At run time that is inert under the other models - it only switches on through GC_enable_threads, which only the GC pass injects - but it sat in the scheduler's own object file, which every async program links, and only gc programs link gc.lib. `none` linked before #308. GC_enable_threads and the collector calls move to an object file of their own (AsyncGCThreadsCommon.inc, built as AsyncGCThreads.cpp in both TypeScriptAsyncRuntime and TypeScriptRuntime). The scheduler reaches them through two hooks that GC_enable_threads installs, so only the call in a gc program pulls that object in. The scheduler no longer includes gc.h. test-runner links every model with lld and gc.lib itself, which is why the rc and none corpus runs of 00async_await.ts passed. New test-compile-async-without-collector (async-without-collector.cmake) builds 00async_await.ts with `tslang --emit=exe` under rc, none and own, with no GC_LIB_PATH, and runs it. DefaultLib's sleep.ts, which failed the same way under rc, links and runs. 00async_gc_threading.ts under gc (the fault the registration fixed, about 6 runs in 10 at -O0 without it): 0 of 20 failures at -O0 and at -O3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lib.native.d.ts declares GC_gcollect and the weak-link functions
(GC_general_register_disappearing_link, GC_unregister_disappearing_link)
DefaultLib's WeakRef is built on. Only a gc program links the collector,
so under rc, none and own a call to any of them reached the linker as an
unresolved symbol - DefaultLib's weakref_basic under rc:
error LNK2019: unresolved external symbol
GC_general_register_disappearing_link referenced in function makeAndDrop
It is now an error at the call:
error: 'GC_general_register_disappearing_link' is part of the garbage
collector, which -mm=rc does not have; it needs -mm=gc, as does WeakRef,
which is built on it
WeakRef under rc (rc document 9.8: a weak count in front of the strong
one) stays a later piece of work.
Tests test-compile-gc-api-outside-gc-{rc,none,own} (the message) and
test-compile-gc-api-gc (the same file compiles under gc).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #419. This branch also contains #419's commit, so merge #419 first. This PR's own change is the top commit.
Summary
lib.native.d.tsdeclaresGC_gcollectand the weak-link functions that DefaultLib'sWeakRefis built on (GC_general_register_disappearing_link,GC_unregister_disappearing_link). Only agcprogram links the collector. Under rc, none and own, a call to any of them used to reach the linker as an unresolved symbol. This is how DefaultLib'sweakref_basicfailed under rc:It's now an error at the call:
WeakRefis gc-only for now. Real weak references under rc (rc document §9.8: a weak count in front of the strong one) remain later work.Companion DefaultLib PR ASDAlexander77/TypeScriptCompilerDefaultLib#17:
WeakRefnow clears under gc, andweakref_basicasserts that it does.Tests
test-compile-gc-api-outside-gc-{rc,none,own}: the message.test-compile-gc-api-gc: the same file compiles under gc.Results
weakref_basicskipped as gc-only: no failures🤖 Generated with Claude Code