Skip to content

Own deferred class metadata and validate initializer completion - #1850

Merged
nickna merged 1 commit into
mainfrom
codex/1599-deferred-class-metadata
Sep 21, 2026
Merged

nickna merged 1 commit into
mainfrom
codex/1599-deferred-class-metadata

Conversation

@nickna

@nickna nickna commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Deferred class initialization previously kept separate mutable metadata maps for class declarations, class expressions, initializers, and computed-field keys. This change gives those handles one compilation-owned registry. Emitters share the same immutable definition by AST and TypeBuilder identity; invalid or duplicate declarations fail before publication, and both compilation finalization paths reject missing initializer bodies.

The registry remains open while nested class bodies are emitted, preserves forward method references and generic computed-key storage, and closes before type finalization. Computed-key order and emitted program behavior remain unchanged.

Validation:

  • 341 focused lifecycle, class, computed-property, hosting/CommonJS, and standalone tests passed, including isolated .ts/.cts/.mts output and IL checks.
  • Four Node/interpreter/Windows/Linux standalone comparisons passed and match the previous merged baseline; IL verification passed for each generated assembly.
  • Code-quality gates passed (28 existing duplicate groups, zero errors).
  • AOT analyzer baseline passed with zero analyzer warnings.
  • Release solution build passed (17 existing package/feed warnings, zero errors).
  • Broad core regression suite passed: 23,299 passed, three skipped, zero failures (10.46 minutes).

Part of #1599. This phase removes deferred-class metadata duplication and adds lifecycle validation. Per-evaluation class identity, dynamic inheritance, remaining registry ownership, and the final residual-state audit remain open.

Summary by CodeRabbit

  • Refactor
    • Consolidated deferred class compilation and computed-field handling into a unified registry.
    • Improved validation and consistency when resolving class definitions, initializers, and computed keys.
    • Strengthened completion tracking to ensure deferred class initialization is fully emitted before compilation finishes.
    • Existing class and class-expression behavior remains supported while improving reliability for forward references and complex class definitions.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: 23914bbd-3f3b-4398-b60e-c58ec3d1b366

📥 Commits

Reviewing files that changed from the base of the PR and between ca9dec4 and 75854c3.

📒 Files selected for processing (13)
  • src/SharpTS/Compilation/CompilationContext.ClassExpressions.cs
  • src/SharpTS/Compilation/DeferredClassDefinitionRegistry.cs
  • src/SharpTS/Compilation/ILCompiler.Classes.ClassExpressions.cs
  • src/SharpTS/Compilation/ILCompiler.Classes.Constructors.cs
  • src/SharpTS/Compilation/ILCompiler.Classes.Methods.cs
  • src/SharpTS/Compilation/ILCompiler.Classes.Static.cs
  • src/SharpTS/Compilation/ILCompiler.ContextFactories.cs
  • src/SharpTS/Compilation/ILCompiler.State.cs
  • src/SharpTS/Compilation/ILCompiler.cs
  • src/SharpTS/Compilation/ILEmitter.Expressions.cs
  • src/SharpTS/Compilation/ILEmitter.Statements.cs
  • src/SharpTS/Compilation/StatementEmitterBase.cs
  • tests/SharpTS.Tests/CompilerTests/DeferredClassDefinitionRegistryTests.cs

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The compiler replaces separate deferred class maps with DeferredClassDefinitionRegistry. The registry validates declarations, stores computed field keys, tracks initializer emission, and supports unified lookups across class declarations and expressions.

Changes

Deferred class registry

Layer / File(s) Summary
Registry contract and validation
src/SharpTS/Compilation/DeferredClassDefinitionRegistry.cs, tests/SharpTS.Tests/CompilerTests/DeferredClassDefinitionRegistryTests.cs
Adds immutable deferred definitions, source and owner lookups, validation, duplicate protection, field-key tracking, and completion checks. Tests cover forward references, invalid declarations, ownership, and emission state.
State and context wiring
src/SharpTS/Compilation/ILCompiler.State.cs, src/SharpTS/Compilation/CompilationContext.ClassExpressions.cs, src/SharpTS/Compilation/ILCompiler.ContextFactories.cs
Replaces separate deferred-class and computed-key dictionaries with one registry in compiler state and contexts.
Deferred declaration registration
src/SharpTS/Compilation/ILCompiler.Classes.Methods.cs, src/SharpTS/Compilation/ILCompiler.Classes.ClassExpressions.cs, src/SharpTS/Compilation/ILCompiler.Classes.Static.cs
Registers deferred definitions through Declare, validates matching source declarations, and stores computed field-key builders with each definition.
Deferred lookup and emission
src/SharpTS/Compilation/ILCompiler.Classes.ClassExpressions.cs, src/SharpTS/Compilation/ILCompiler.Classes.Constructors.cs, src/SharpTS/Compilation/ILCompiler.Classes.Static.cs, src/SharpTS/Compilation/ILEmitter.Expressions.cs, src/SharpTS/Compilation/ILEmitter.Statements.cs, src/SharpTS/Compilation/StatementEmitterBase.cs, src/SharpTS/Compilation/ILCompiler.cs
Uses registry lookups for registrars and field keys, marks emitted initializers, and completes deferred emission in both type-finalization phases.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant ClassCompiler
  participant DeferredClassDefinitionRegistry
  participant ClassEmitter
  participant TypeFinalizer
  ClassCompiler->>DeferredClassDefinitionRegistry: Declare deferred class definition
  ClassEmitter->>DeferredClassDefinitionRegistry: Resolve registrar and field keys
  ClassEmitter->>DeferredClassDefinitionRegistry: Mark initializer emitted
  TypeFinalizer->>DeferredClassDefinitionRegistry: Complete emission
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: centralized ownership of deferred class metadata and validation of initializer completion.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nickna
nickna merged commit 40d4cf6 into main Sep 21, 2026
23 checks passed
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