Repository navigation
32-bit: link the default library into i686 programs - #340
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
getDefaultLibSubDir gains a required arch parameter: for a Windows x86
target it inserts an "x86" segment outermost under lib/ or dll/, giving
defaultlib/{lib,dll}/x86/{debug,release}/{gc,rc,none}/, the same rule
getTargetLibDir already applies to the collector and the runtime. Every
other target, x64 included, keeps its existing flat layout - there is no
x64 segment and no fallback from x86 to the x64 tree.
exe.cpp computes x86DefaultLib from the triple already resolved for the
link, passes it through, and reports an x86-specific message (naming the
TSLANG_ARCH=x86 build script) when the tree is missing. It also checks
the linked TypeScriptDefaultLib.lib's COFF machine against the target,
the same protection resolveWindowsLibPath gives the collector and
runtime, so a wrong-arch default library fails with a named reason
instead of a page of unresolved symbols. jit.cpp and defaultlib.cpp pass
an empty arch: the JIT is host-only and the install check verifies the
host build.
check-x86-libs.sh gains three cases for this path: a missing x86 tree,
an x64 library staged where the x86 tree is expected, and an x64 control
that must keep working unchanged. Verified: check-x86-libs.sh 14/14,
ctest 2771/2771, compare-ir.sh noise only (confirmed by rerunning the
same binary twice - the diffing file set changes between runs), and an
x64 DefaultLib test compiled and run against the real default library.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…spec
check-x86-run.sh gains a default-library section, skipped (not failed)
when TypeScriptCompilerDefaultLib has no x86 tree yet. It builds
defaultlib_smoke.ts (Array, Map, string, Date and RegExp, including the
replaceAll(regex, ...) overload whose missing native argument crashed i686) without
--no-default-lib, under gc, rc and none release, then the gc case again
against the debug tree with --di. It also builds a gc --emit=dll library
that links the default library and an exe that imports it - the shape
of defaultlib-collector.cmake's compile mode, reused in bash - copying
TypeScriptDefaultLib.dll and the x86 gc.dll next to the importing exe.
tester/CMakeLists.txt hand-registers test-x86-compile-gc-defaultlib-
collector (labelled x86) as the x86 twin of the existing compile-mode
default-library collector test, since that test uses plain add_test
rather than tslang_add_test and so gets no twin automatically.
defaultlib-collector.cmake's own skip test now checks the x86 tree when
an X86 flag is passed, so the twin skips correctly when the x86 default
library is absent. There is still no JIT twin: the JIT refuses an x86
target regardless of the default library.
Verified: check-x86-run.sh all ok, including the new section (not
skipped). With -DTSLANG_TEST_X86=ON, ctest -C Release -L x86: 1396/1399
pass (the 1395 existing twins plus the new collector twin), 3 disabled.
With it OFF, CTestTestfile.cmake is unchanged except for
_BACKTRACE_TRIPLES line numbers (this CMakeLists.txt now has more lines
above existing add_test calls), and ctest -j 16 -C Release: 2771/2771.
Spec updated: status line drops the x86-default-library exception,
Phase 4 gets an "As built" note (layout, TSLANG_ARCH, the machine
check, test counts, the replaceAll root cause), the "x86 default library"
open issue is closed, and the 4c bullet's stale "(the default library
has no x86 build)" parenthetical is removed. New open issues record
what stays uncovered: tslang has no arity check on declare-function
calls (TS2554) - what hid the replaceAll bug - the pre-existing
"xxx".replaceAll("", "_") bug, and that neither CI nor the release
workflows build an x86 default library, so the x86 test-runner twins
still pass --no-default-lib like their x64 counterparts.
check-x86-libs.sh no longer needs an x64 default-library build: the
two error-path cases use the x64 gc.lib as a stand-in (the directory
and machine checks run before any link), and only the x64 control case
needs the real library - it prints SKIPPED when that is absent.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Summary
This finishes 32-bit support. A 32-bit Windows program (
-mtriple=i686-pc-windows-msvc) can now link and run against the default library, for gc, rc and none, debug and release, static and DLL. It no longer needs--no-default-lib. This was the one piece deferred from Phase 4; the spec's status line now says Phases 1-4 are implemented. The plan is indocs/superpowers/plans/2026-09-22-32-bit-x86-default-lib.md.Merge this first. It is paired with a TypeScriptCompilerDefaultLib PR (branch
x86-default-lib, stacked on DefaultLib PR #7) that builds and tests the x86 libraries.Compiler changes
getDefaultLibSubDirgains a requiredarchparameter. For a Windows x86 target the default library is taken fromdefaultlib/{lib,dll}/x86/{debug,release}/{gc,rc,none}/, the layout the spec gives. This is the same Windows-x86-only rule the gc and runtime libraries already follow. Every other target, x64 included, keeps its current path.jit.cppand the--install-default-libcheck pass the host, because the JIT refuses x86 anyway.TSLANG_ARCH=x86).TypeScriptDefaultLib.libit links, using the check it already applies to the gc and runtime libraries. A library built for the wrong CPU is now a named error rather than LNK4272 followed by a page of unresolved symbols.Tests
check-x86-libs.shgains three cases:check-x86-run.shgains a default-library section, which is skipped when the DefaultLib repo has no x86 tree. It runstslang/test/x86/defaultlib_smoke.ts(Array, Map, string, Date, RegExp includingreplaceAll(regex, ...)) as a 32-bit exe under gc, rc and none, then the gc case again with--di. It also runs a gc--emit=dllthat links the default library, plus an exe that imports it.test-x86-compile-gc-defaultlib-collectoris a new test, registered only underTSLANG_TEST_X86.Found on the way
replaceAllcrash was a library bug.RegExp.replaceAllcrashed at i686.lib.tscalled the nativeregexp_replacewith three of its four arguments. On x64 the missing argument happened to still be in a register; on x86 it was an uninitialised stack slot. It is fixed in the DefaultLib PR.declare functions (TypeScript's TS2554)."xxx".replaceAll("", "_")returns___where JavaScript gives_x_x_x_. This happens on both archs and predates this change.Not covered
Neither CI nor the release workflows build x86 libraries, so the x86
test-runnertwins still pass--no-default-lib, like the x64 ones.Test plan
ctest -j 16 -C Release: 2771/2771. WithTSLANG_TEST_X86=OFF,CTestTestfile.cmakechanges only in_BACKTRACE_TRIPLESline numbers.-DTSLANG_TEST_X86=ON,ctest -C Release -L x86: 1396 pass (the 1395 existing twins plus the new collector twin), 3 disabled.check-x86-libs.sh14/14. It also passes (exit 0) with the x64 default library made unfindable, and the x64 control case then prints SKIPPED.check-x86-run.sh21/21, with the default-library section running rather than skipped.compare-ir.sh): unchanged apart from the known nondeterministic files.TSLANG_ARCH=x86 tests.ps1: 150/150 release, 150/150 debug.🤖 Generated with Claude Code