Commit Graph
4 Commits
Author SHA1 Message Date
Chris Tate bddb5c7205 Address review feedback 2026-10-25 17:13:16 -05:00
Chris Tate d378a4dee7 Keep static-object rewrites where receivers, setters or enumerability differ
- A direct call drops its receiver's evaluation, so a name receiver must
  hold its value whenever the read runs: a parameter, a function
  declaration, or a variable declared with an initializer by an earlier
  top-level statement and never assigned again. A variable read before it
  is assigned (undefined, a TypeError) or in its temporal dead zone (a
  ReferenceError) keeps the member read.
- A store between a constructor and its methods counts as a definition
  only when its receiver is a constant object, which has no setters,
  reached without running code, and its key is not `__proto__`. A store
  that may run a setter keeps the constructor function, since the setter
  could see the prototype without its methods.
- `propertyIsEnumerable` asked of the prototype or the constructor, or
  reached other than as a direct method call, keeps the constructor
  function: assigned methods are enumerable and class methods are not.

The static-ns fixture covers each case and prints what Node prints.
2026-10-25 05:29:55 -05:00
Chris Tate f07329f569 Fix CI, address review feedback and merge main 2026-10-25 04:57:15 -05:00
Malte UblandClaude Opus 5.5 22b686c7da Compile pre-module constructor functions as classes and namespace functions as direct functions
With the shape overlay on, a first round of structural rewrites runs before
the typed overlay (shape-inference/static-objects.ts, stage 2b of
DESIGN-constant-objects.md), proven by the constant object graphs:

- An ES5 constructor stored by a top-level statement whose prototype is a
  constant object of plain methods becomes a class declaration with those
  methods, when the program cannot tell: the function is only ever
  constructed and never escapes, its prototype is never replaced, nothing
  enumerates instances with for-in or reflects on the prototype or the
  function, nothing reads their names or sources, the bodies are
  strict-mode safe, and only definitions run between the constructor and
  its last method.
- A constant namespace member holding a `this`-free function expression
  becomes a function declaration, and reads of the member in the same file
  whose receiver is exactly that constant object refer to it directly.

The rounds rerun the analysis on the rebuilt program, the overlay now also
covers the program's own JavaScript files, and the build report counts the
rewrites. A JavaScript switch whose case tests lower to another type than
the discriminant compares with === instead of being refused.

Namespace benchmark (n=20000): 1.55 s -> 0.42-0.47 s, output identical to
Node (typed TypeScript twin 85 ms, Node 21 ms).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 20:25:14 -07:00