SC9001 ICE: varRef type object != binding dyn on bundled circular module-level consts

オープン
#4,405 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js, typescript
領域
backend, compilers

調査の方向性

Start by reading the compiler’s handling of module-level const bindings, returned closures, and varRef type validation; the issue does not name source files or tests for these paths. Reproduce with the 12-line JavaScript example using scriptc build, then compare it with the controls that compile. Done when the bundled JavaScript builds successfully and its runtime output remains 1.

索引モデルが issue の本文から書いたものです。

説明

Summary

scriptc build hits SC9001 (internal compiler error: varRef "…" type object != binding dyn) on legal JavaScript that bundlers emit: a module-level const closes over another module-level const that is initialized later by a factory returning new SomeClass(...).

scriptc coverage of the same file is 100% static. Node runs it. The identical program as TypeScript compiles. So this is a codegen/IR-validation ICE, not a coverage or language-service crash.

Reduced from rolldown-bundled effect/Schema (t3code vp pack chunk Schema-CHz9fEw2.mjs, four ICEs at the Go-nil codec consts nullAsMissing / nullAsEmptyArray / emptyRecord / nullAsEmptyRecord). Please do not ask applications to unminify that chunk by hand — the 12-line program below is sufficient.

Reproduction

repro.mjs:

class Box {
  constructor(v) {
    this.v = v;
  }
}
function apply(f) {
  return f;
}
const earlier = apply(() => later);
const make = (v) => new Box(v);
const later = make(1);
console.log(earlier().v);
$ node repro.mjs
1

$ scriptc coverage repro.mjs
# 6/6 statements static (100%)

$ scriptc build repro.mjs -o out
repro.mjs:9:29 - error SC9001: internal compiler error: in %fn.309985bfdfc6: varRef "%g.e.later" type object != binding dyn — please report this

   8 | }
   9 | const earlier = apply(() => later);
     |                             ^~~~~
  10 | const make = (v) => new Box(v);

1 error.

Minified to one line, same ICE:

class Box{constructor(v){this.v=v}}function apply(f){return f}const earlier=apply(ast=>later),make=v=>new Box(v),later=make(1);console.log(earlier(0).v)

apply can be the identity (return f). What matters is that the closing lambda is returned from a call, not assigned directly.

Controls that compile and print 1

Same program as TypeScript (repro.ts with a typed apply / make) — scriptc build succeeds.

Reordering so later is initialized first:

const make = (v) => new Box(v);
const later = make(1);
const earlier = apply(() => later);

Direct new instead of a factory (still a circular const):

const earlier = apply(() => later);
const later = new Box(1);

Unbundled modules (the factory and later in a second file, imported by the closer) also compile. That is why unminified npm effect source (scriptc build entry.mjs --npm-static=effect) succeeds while a rolldown bundle of the same library fails.

Original trigger

scriptc build of a rolldown bundle of [email protected] Schema (pretty-printed, original names kept) reports four ICEs, all this pattern:

Schema.unmin.mjs:12937:39 - error SC9001: … varRef "%g.e.nullAsMissing" type object != binding dyn
Schema.unmin.mjs:12941:144 - error SC9001: … varRef "%g.e.nullAsEmptyArray" type object != binding dyn
Schema.unmin.mjs:12942:139 - error SC9001: … varRef "%g.e.emptyRecord" type object != binding dyn
Schema.unmin.mjs:12942:165 - error SC9001: … varRef "%g.e.nullAsEmptyRecord" type object != binding dyn

Those names are module-level consts in effect/src/internal/schema/toCodec.ts:

const nilAsMissingAtEncoded = applyToSelfOrLastLinkEncoding((ast) => {
  return orNull(ast, decodeNull(never, nullAsMissing));
});
const nilAsEmptyAtEncoded = applyToSelfOrLastLinkEncoding((ast) => {
  // …
  return orNull(ast, decodeNull(replaceChecks(emptyRecord, ast.checks), nullAsEmptyRecord));
});
const nullTo = (decode) => new Transformation(decode, forbidden(() => "…"));
const nullAsMissing = nullTo(transformOptional(() => none()));
const nullAsEmptyArray = nullTo(transform(() => []));
const nullAsEmptyRecord = nullTo(transform(() => ({})));
const emptyRecord = record(string, never);

Circular module-level consts through a helper that only stores the callback are legal JS (const TDZ is not hit because applyToSelfOrLastLinkEncoding does not call f during init). Rolldown concatenates them into one module; scriptc then types the binding as dyn and the varRef as object.

Workaround for consumers

Compile TypeScript / npm source (ordinary per-file modules), not bundler output. t3code will feed scriptc build src/binMain.ts rather than vp pack chunks for this reason. That is a consumer dodge, not a fix.

Environment

  • scriptc 0.4.17 and 0.4.16 (identical ICE on the 12-line repro; not a 0.4.17 regression)
  • @scriptc/cli-linux-x64-gnu, Node.js 24.13.1, linux x64
  • effect 4.1.5 for the original Schema bundle; the reduced repro has no dependencies

Relationship to existing reports

Searched open and closed SC9001 / ICE issues (varRef, binding dyn, emptyRecord, nullAsMissing, minified circular consts). Closest hits are other SC9001 shapes (recordKeyGet, bytesSet, toString protocol) — none are varRef type object vs binding dyn. Distinct from #4381 (tsc-ts SIGSEGV on one large file) and from #4171 (coverage abort on @effect/platform-node).

主要言語
TypeScript
スター
6.7k
フォーク
229
平均マージ
14時間 29分
マージ済み PR(30日)
787

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vercel-labs/scriptc のほかの issue

vercel-labs/scriptc の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。