Commit 1af0d84d

1af0d84d0da3Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

docs(codegen): banner the Pre-emission analysis section

Refactor item 2: the pre-emission analysis (the detect_, resolve_, rewrite_, scan_, infer_, collect_ helpers that turn the parsed AST into the per-class / per-method / per-ivar tables the emit phase consumes) spans roughly 3500 lines between collect_all and emit_header with no top-level marker. Adding two banner comments makes the phase boundary visible and indexes the Pass-numbering convention used inside collect_all so a reader landing on a Pass 2.7 call site can find both the driver and the convention.

Pure documentation — no behavior change. Bootstrap (gen2 == gen3) clean; 199 tests + 56 benches pass.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
1af0d84d0da3
Parent
ea8f4043d8f0

spinel_codegen.rbmodifiedView file

@@ -4182,6 +4182,48 @@
41824182 end
41834183 end
41844184
4185+ # ============================================================
4186+ # Pre-emission analysis
4187+ # ============================================================
4188+ #
4189+ # Two top-level drivers turn the parsed AST into the per-class /
4190+ # per-method / per-ivar tables that the emit phase consumes:
4191+ #
4192+ # collect_all — populates @cls_*, @meth_*, @const_*, @module_*
4193+ # tables; runs structural passes (Pass 0-3).
4194+ # infer_all_returns — refines the tables: param types from call
4195+ # sites, ivar types from writers, return types
4196+ # from method bodies.
4197+ #
4198+ # Pass-numbering convention used inside collect_all (mirrored in the
4199+ # `Pass N` comments on each call site):
4200+ #
4201+ # Pass 0 collect_module modules first (used by
4202+ # include lookup later)
4203+ # Pass 1 collect_class class table + parents
4204+ # Pass 1.5 detect_circular_inheritance reject cycles before any
4205+ # parent walker recurses
4206+ # into them (issue #106)
4207+ # Pass 2 collect_toplevel_method, top-level defs, constants,
4208+ # collect_constant, and define_method
4209+ # collect_define_method
4210+ # Pass 2.5 infer_lambda_param_types lambda call-site types
4211+ # flow back into stored
4212+ # lambda value's params
4213+ # Pass 2.6 rewrite_instance_eval_calls hoist `recv.instance_eval`
4214+ # blocks into file-scope
4215+ # functions with typed
4216+ # self
4217+ # Pass 2.7 resolve_module_singleton_ constant-fold module-
4218+ # accessors level singleton accessors
4219+ # (issue #126 stage 1)
4220+ # Pass 3 infer_all_returns return-type inference
4221+ # with param/ivar refines
4222+ #
4223+ # Anything between this banner and `def emit_header` (the start of the
4224+ # emission phase) is part of pre-emission analysis: the various
4225+ # detect_*, resolve_*, rewrite_*, scan_*, infer_*, and collect_*
4226+ # helpers that the two drivers above call into.
41854227 def collect_all
41864228 root = @root_id
41874229 if @nd_type[root] != "ProgramNode"
@@ -9483,6 +9525,15 @@
94839525 0
94849526 end
94859527
9528+ # ============================================================
9529+ # Emission
9530+ # ============================================================
9531+ #
9532+ # End of pre-emission analysis. From here down, the codegen
9533+ # consumes the tables built above and writes C: header, runtime
9534+ # blocks, struct/forward decls, class methods, top-level methods,
9535+ # main(). emit_header is the entry point; generate_code (above)
9536+ # orchestrates the order.
94869537 def emit_header
94879538 emit_raw("/* Generated by Spinel v2 AOT compiler */")
94889539 emit_raw("#include <stdio.h>")