Skip to content

[annotator] admit type_assertion expressions (class-only, #658 step 3)#671

Merged
cs01 merged 1 commit intomainfrom
type-assert-admit
Apr 23, 2026
Merged

[annotator] admit type_assertion expressions (class-only, #658 step 3)#671
cs01 merged 1 commit intomainfrom
type-assert-admit

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Apr 23, 2026

Before

Type assertions (x as Foo) were never admitted to the annotator's typeOf cache. Every as Foo expression fired a cache miss at codegen time, forcing resolveExpressionTypeRich to recompute a type that's literal in the AST.

After

Annotator admits type_assertion expressions when:

  • assertedType passes isSafelyAnnotatable (no unions, nullable, function types, or inline object shapes)
  • Resolved type has sourceKind === "class" and passes isSafeVariableAnnotationType

Interface-kind assertions intentionally excluded — an earlier attempt to admit them broke stage 2 self-hosting (same arch-divergence class as #662 member_access). Re-evaluate after Tier 3 #11 (interface concretization pass).

Description

Follows data posted in #658 (comment 2026-04-22): divergence tracer showed 1249 codegen-time miss events for type_assertion sourceKind=interface on chad-native compile, zero hit-diff events anywhere. Class-only subset is the narrowest safe admission. ~25 LOC.

Verified with full npm run verify (stage 2 self-hosting green).

Gate-loosen table

Kind Class Interface
variable #660 #661
member_access #668 ❌ blocked (Tier 3 #11)
type_assertion this PR ❌ blocked (Tier 3 #11)

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark Results (Linux x86-64)

Benchmark C ChadScript Go Node Place
Cold Start 1.0ms 0.9ms 1.2ms 27.5ms 🥇
Fibonacci 0.814s 0.762s 1.561s 3.196s 🥇
Hash Map Lookup 0.094s 0.063s 0.092s 0.112s 🥇
Regex Match 0.017s 0.005s 0.022s 0.005s 🥇
Binary Trees 1.502s 1.290s 2.735s 1.150s 🥈
File I/O 0.117s 0.088s 0.086s 0.196s 🥈
JSON Parse/Stringify 0.035s 0.051s 0.174s 0.135s 🥈
N-Body Simulation 1.695s 2.119s 2.211s 2.386s 🥈
SQLite 0.052s 0.371s 0.493s 0.451s 🥈
Matrix Multiply 0.493s 0.592s 0.613s 0.378s 🥉
Monte Carlo Pi 0.389s 0.410s 0.404s 2.248s 🥉
Quicksort 0.215s 0.247s 0.213s 0.262s 🥉
Sieve of Eratosthenes 0.016s 0.026s 0.018s 0.039s 🥉
String Manipulation 0.008s 0.018s 0.017s 0.037s 🥉

CLI Tool Benchmarks

Benchmark ChadScript grep node xxd Place
Hex Dump 0.566s 0.968s 0.130s 🥈
Recursive Grep 0.020s 0.011s 0.108s 🥈

@cs01 cs01 merged commit 40d7b03 into main Apr 23, 2026
13 checks passed
@cs01 cs01 deleted the type-assert-admit branch April 23, 2026 00:47
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