Skip to content

fix(codegen): extend type resolution for call/method chains#523

Merged
cs01 merged 1 commit intomainfrom
fuzz-batch
Apr 17, 2026
Merged

fix(codegen): extend type resolution for call/method chains#523
cs01 merged 1 commit intomainfrom
fuzz-batch

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Apr 17, 2026

User impact

More patterns that used to silently read garbage or fail LLVM IR compilation now work correctly:

  • `const last = fn()[i]; last.field` where `fn()` returns an interface array
  • `const inner = obj.method().field; inner.nested` where `obj.method()` returns an interface with a nested interface field

Context

Part of an ongoing effort to plug gaps in ChadScript's fragmented type-resolution layer. CLAUDE.md rule: ObjectArray element access loses type info. PR #522 added method-call indexed access; this PR extends to free-function indexed access AND `member_access where the object is a method_call or call`.

Change

  • `array-allocator.ts getIndexedObjectArrayType` — add `call` branch (free function) using AST function lookup, mirroring the existing `method_call` branch.
  • `variable-allocator.ts getMemberAccessInterfaceType` — add `method_call` and `call` branches, resolving the method/function return type and looking up the property's interface type. Previously only handled `variable` objects.
  • `tests/fixtures/interfaces/fn-returning-array-indexed.ts`, `tests/fixtures/interfaces/method-return-inner-interface.ts` — regression fixtures.

Fuzz results

Running a 20-case fuzz corpus against the compiler:

Remaining 10 gaps (for future PRs): `.filter()[i]`, `.map(f)[i]`, array-literal indexed, `grid[i][j]`, `arr.find()`, `arr.sort()`, chained inline `x.method().inner.v`, etc.

Test plan

  • `npm run verify` green (tests + stage 1 + stage 2)
  • 2 new regression fixtures

…, obj.method()[i], and const x = obj.method().field now correctly propagate interface types to prevent garbage reads
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark Results (Linux x86-64)

Benchmark C ChadScript Go Node Place
Binary Trees 1.158s 1.018s 2.080s 1.017s 🥈
Cold Start 0.8ms 0.7ms 1.0ms 23.9ms 🥇
Fibonacci 0.705s 0.706s 1.343s 2.611s 🥈
File I/O 0.070s 0.075s 0.070s 0.147s 🥉
JSON Parse/Stringify 0.003s 0.004s 0.013s 0.011s 🥈
Matrix Multiply 0.380s 0.394s 0.600s 0.443s 🥈
Monte Carlo Pi 0.341s 0.348s 0.355s 2.011s 🥈
N-Body Simulation 1.387s 1.747s 1.777s 1.844s 🥈
Quicksort 0.191s 0.218s 0.188s 0.224s 🥉
SQLite 0.253s 0.273s 0.331s 🥈
Sieve of Eratosthenes 0.011s 0.021s 0.016s 0.033s 🥉
String Manipulation 0.006s 0.016s 0.013s 0.030s 🥉

CLI Tool Benchmarks

Benchmark ChadScript grep node xxd Place
Hex Dump 0.338s 0.784s 0.109s 🥈
Recursive Grep 0.017s 0.009s 0.080s 🥈

@cs01 cs01 merged commit 138b1f9 into main Apr 17, 2026
13 checks passed
@cs01 cs01 deleted the fuzz-batch branch April 17, 2026 23:52
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