Skip to content

canonical type resolver, handler dispatch, file-scoped mangling#17

Open
cs01 wants to merge 9 commits intomainfrom
architecture-improvements
Open

canonical type resolver, handler dispatch, file-scoped mangling#17
cs01 wants to merge 9 commits intomainfrom
architecture-improvements

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Feb 19, 2026

Architecture improvements: canonical type resolver, handler dispatch, file-scoped mangling

Summary

Three independent improvements to the codegen infrastructure:

  1. Canonical type resolver — Replace 8+ divergent TS-to-LLVM type mapping functions with one canonicalTypeToLlvm function. Fix paramIsInterface being hardcoded to false at call sites and getClassType returning i32* instead of i8*.

  2. Handler dispatch refactor — Extract the generate() method's dispatch logic into a separate dispatchHandlers() method with documented priority ordering.

  3. File-scoped function mangling — Add sourceFile to FunctionNode/ClassNode AST nodes. Non-exported functions in multi-file native compilation get file-scoped names (_cs_filename_func) to prevent cross-file collisions.

Changes

Shard 1: Canonical Type Resolver

  • Add canonicalTypeToLlvm(tsType, mode, isEnum, isInterface, fieldName) to type-system.ts
  • Rewrite tsTypeToLlvm, mapParamTypeToLLVM, mapReturnTypeToLLVM, tsTypeToLlvmJson as thin wrappers
  • Fix paramIsInterface: false hardcoding in calls.ts (3 call sites) — now uses interfaceStructGenHasInterface()
  • Fix getClassType() returning i32* instead of i8* in type-context.ts

Shard 2: Handler Dispatch

  • Extract dispatch logic from generate() into dispatchHandlers() in member.ts
  • Document handler priority ordering (15 handlers, priority 10-200)

Shard 3: File-Scoped Mangling

  • Add sourceFile?: string to FunctionNode and ClassNode in ast/types.ts
  • Set sourceFile in native parser (parser-native/transformer.ts)
  • Build exportedNames: Set<string> from ast.exports in LLVMGenerator
  • Update mangleUserName(name, sourceFile?) — non-exported functions get _cs_${fileSlug}_${name}
  • Thread sourceFile through function-generator.ts and calls.ts

Known limitations

  • Class constructors/methods in class.ts don't thread sourceFile yet
  • TS parser doesn't set sourceFile (only matters for multi-file native compilation)
  • Handler dispatch is still an if/else chain (Stage 0 can't do handlers[i](...))

Test plan

  • TypeScript build passes
  • All 299 unit tests pass (Node.js compiler)
  • Self-hosting Stage 0 + Stage 1 + Stage 2 pass with smoke tests
  • Native compiler test failures are pre-existing non-deterministic SIGSEGVs (same rate as main)

@cs01 cs01 changed the title Architecture improvements canonical type resolver, handler dispatch, file-scoped mangling Feb 19, 2026
@cs01 cs01 force-pushed the architecture-improvements branch from 7b5e2e3 to 6694473 Compare February 19, 2026 18:45
@cs01 cs01 force-pushed the architecture-improvements branch from 6694473 to 6db7223 Compare February 19, 2026 19:15
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

Comments