Skip to content

Own class property dispatch declarations and completion - #1852

Open
nickna wants to merge 1 commit into
mainfrom
codex/1599-class-property-dispatch
Open

nickna wants to merge 1 commit into
mainfrom
codex/1599-class-property-dispatch

Conversation

@nickna

@nickna nickna commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Generated class property-dispatch methods previously lived in a mutable name-keyed map, and required body emission could silently skip missing declarations. This change gives each emitted type one immutable dispatch declaration, with qualified names as lookup aliases, checked registration, required forward-reference lookup, and completion validation before type finalization in both compilation pipelines.

The registry rejects duplicate or foreign declarations and requires all five dispatch method bodies before completion. Class declarations and expressions share the lifecycle; optional base-class lookup preserves the existing built-in fallback. Generated dispatch instructions and lazy storage behavior remain unchanged. Lifecycle tests cover absence, incomplete bodies, ownership, duplicate rejection, isolation, and access after completion.

Refs #1599. This chunk does not complete the remaining construction-state migrations, recorded semantic fixes, or final residual-state audit.

Validation:

  • 533 focused lifecycle, class, feature, and CLI standalone tests passed.
  • Broad core suite: 23,304 passed, 3 skipped, 0 failed.
  • 11 standalone programs matched Node, interpreter, Windows, Linux, and prior-phase output; every generated assembly passed IL verification.
  • Code-quality gates passed (28 existing duplicate groups, 0 errors).
  • AOT/trim/single-file analyzer baseline passed with 0 analyzer warnings.
  • Release solution build passed with 0 errors and 17 existing package/feed warnings.

Summary by CodeRabbit

  • Refactor

    • Improved internal class property dispatch handling during compilation.
    • Added validation to ensure property dispatch declarations and generated method bodies are complete before types are finalized.
    • Missing or invalid property dispatch definitions now fail clearly instead of being silently skipped.
  • Tests

    • Added coverage for declaration validation, duplicate registrations, emission completion, and property lookup behavior.

@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: 8b9f33be-59c6-4510-93b7-b8fac3b8f3fc

📥 Commits

Reviewing files that changed from the base of the PR and between 90bef9c and 9747cc5.

📒 Files selected for processing (7)
  • src/SharpTS/Compilation/ClassPropertyDispatchRegistry.cs
  • src/SharpTS/Compilation/ILCompiler.Classes.ClassExpressions.cs
  • src/SharpTS/Compilation/ILCompiler.Classes.Constructors.cs
  • src/SharpTS/Compilation/ILCompiler.Classes.HasFields.cs
  • src/SharpTS/Compilation/ILCompiler.State.cs
  • src/SharpTS/Compilation/ILCompiler.cs
  • tests/SharpTS.Tests/CompilerTests/ClassPropertyDispatchRegistryTests.cs

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


📝 Walkthrough

Walkthrough

Changes

The compiler replaces the HasFieldsStubs map with ClassPropertyDispatchRegistry. The registry validates declarations, tracks method-body emission, and blocks mutation after completion. Class emission and type finalization now use this registry. Tests cover lifecycle and declaration invariants.

Class property dispatch

Layer / File(s) Summary
Registry contract and lifecycle
src/SharpTS/Compilation/ClassPropertyDispatchRegistry.cs, tests/SharpTS.Tests/CompilerTests/ClassPropertyDispatchRegistryTests.cs
The registry stores validated dispatch declarations, tracks emitted bodies, requires complete emission, and rejects invalid or late mutations. Tests cover these rules.
Compiler dispatch wiring
src/SharpTS/Compilation/ILCompiler.State.cs, src/SharpTS/Compilation/ILCompiler.Classes.HasFields.cs, src/SharpTS/Compilation/ILCompiler.Classes.ClassExpressions.cs, src/SharpTS/Compilation/ILCompiler.Classes.Constructors.cs
Class state and property emission use PropertyDispatch for declaration, lookup, body emission, constructor helpers, and base-class resolution.
Type finalization integration
src/SharpTS/Compilation/ILCompiler.cs
Single-file and multi-module compilation complete property-dispatch emission before finalizing generated types.

Priority: ⬇️ Low

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

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant DefineHasFieldsInterfaceMethods
  participant ClassPropertyDispatchRegistry
  participant EmitHasFieldsInterfaceMethodBodies
  participant ILCompiler
  DefineHasFieldsInterfaceMethods->>ClassPropertyDispatchRegistry: Declare dispatch
  EmitHasFieldsInterfaceMethodBodies->>ClassPropertyDispatchRegistry: Require dispatch
  EmitHasFieldsInterfaceMethodBodies->>ClassPropertyDispatchRegistry: MarkBodiesEmitted
  ILCompiler->>ClassPropertyDispatchRegistry: CompleteEmission during finalization
Loading

Merge Risk: ⚪ Minimal · up to 9747c

The registry lifecycle test exercises its intended successful path correctly. No actionable merge risk remains.

🚥 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 change: introducing owned class property dispatch declarations and completing their emission lifecycle.
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.

This branch has not been deployed

No deployments
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