Commit 387299c7
387299c7427bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
fix(analyze,codegen): split(",", -1) / split(";", -1) preserve trailing empties (#807)
Same family of bugs as the split("|") fix in 73e52c8: when the last field in a serialized list is empty, MRI's split drops it during the bootstrap stage 1 run, so the fixpoint sees a shorter table than what was written. Spinel's runtime split keeps trailing empties already, so the bug only manifests during the MRI-driven boot.
Wholesale replacement: every .split(",") -> .split(",", -1) and every .split(";") -> .split(";", -1) across analyze + codegen. Loud diff, mechanical change -- each call site that round-trips through serialize/deserialize now preserves the trailing empty fields that signal "param without default", "method without body" etc.
Closes #807
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 387299c7427b
- Parent
- b7bf771f317c
spinel_analyze.rbmodifiedView file
def initialize @out_lines = "".split(",") @out_lines = "".split(",", -1) @out = "" @deferred_tuple = "" @deferred_lambda = "" @cur_writer_body = -1 # ---- AST node storage (parallel arrays by node ID) ---- # Use "".split(",") for StrArray init (v1 infers StrArray from split) @nd_type = "".split(",") @nd_name = "".split(",") # Use "".split(",", -1) for StrArray init (v1 infers StrArray from split) @nd_type = "".split(",", -1) @nd_name = "".split(",", -1) @nd_value = [] @nd_content = "".split(",") @nd_content = "".split(",", -1) @nd_flags = [] @nd_operator = "".split(",") @nd_binop = "".split(",") @nd_callop = "".split(",") @nd_unescaped = "".split(",") @nd_operator = "".split(",", -1) @nd_binop = "".split(",", -1) @nd_callop = "".split(",", -1) @nd_unescaped = "".split(",", -1) # Node references (integer node IDs, -1 = nil) @nd_receiver = [] @nd_collection = [] # Node array fields: stored as comma-separated ID strings @nd_stmts = "".split(",") @nd_args = "".split(",") @nd_requireds = "".split(",") @nd_optionals = "".split(",") @nd_keywords = "".split(",") @nd_elements = "".split(",") @nd_parts = "".split(",") @nd_conditions = "".split(",") @nd_exceptions = "".split(",") @nd_targets = "".split(",") @nd_rights = "".split(",") @nd_stmts = "".split(",", -1) @nd_args = "".split(",", -1) @nd_requireds = "".split(",", -1) @nd_optionals = "".split(",", -1) @nd_keywords = "".split(",", -1) @nd_elements = "".split(",", -1) @nd_parts = "".split(",", -1) @nd_conditions = "".split(",", -1) @nd_exceptions = "".split(",", -1) @nd_targets = "".split(",", -1) @nd_rights = "".split(",", -1) # ParametersNode#posts -- required params after the splat # (def f(*r, x, y) → posts = [x, y]). Currently unused by codegen # (post-rest parameters aren't observed in test/), but the parser # emits the field so future tests get a proper AST. @nd_posts = "".split(",") @nd_posts = "".split(",", -1) # AliasMethodNode / AliasGlobalVariableNode -- parallel ref slots # for the new and old names (SymbolNode for methods, GlobalVariableReadNode # for globals). @nd_new_name = [] @nd_old_name = [] # UndefNode -- comma-separated child ids for the SymbolNode names. @nd_names = "".split(",") @nd_names = "".split(",", -1) # Per-node inferred type, parallel to the other @nd_* arrays. # Empty string means "not yet annotated"; node_type falls back to # `freeze_analysis` runs, every reachable node gets a non-empty # entry so the codegen path becomes O(1) per node lookup instead # of recursively re-walking the subtree on every infer_type call. @nd_inferred_type = "".split(",") @nd_inferred_type = "".split(",", -1) # Scratch state used by promote_reinfer_array_returns + # walk_reinfer_lv_writes. Self-host can't capture block params # across closures yet, so the helpers thread per-walk parameters # @nd_scope_names[bid] means "no precomputed scope decls for this # bid"; codegen falls back to its own scan_locals path in that # case (block-iteration bodies, ad-hoc temp scopes, etc.). @nd_scope_names = "".split(",") @nd_scope_types = "".split(",") @nd_scope_names = "".split(",", -1) @nd_scope_types = "".split(",", -1) @nd_count = 0 @root_id = 0 # Issue: unresolved-call warnings deduped by "<mname>:<recv_type>" # so a hot call site that fails to resolve emits one warning, not N. @unresolved_call_warnings = "".split(",") @unresolved_call_warnings = "".split(",", -1) # ---- Top-level methods (parallel arrays) ---- @meth_names = "".split(",") @meth_param_names = "".split(",") @meth_param_types = "".split(",") @meth_names = "".split(",", -1) @meth_param_names = "".split(",", -1) @meth_param_types = "".split(",", -1) # Per-param "deferred element" flag: "1" means at least one caller # passed an empty `[]` literal (or a local that itself was assigned # an empty literal). Used by the param body-push promotion pass # to decide whether the param's int_array can be safely # promoted to a concrete typed-array based on body usage. @meth_param_empty = "".split(",") @meth_return_types = "".split(",") @meth_param_empty = "".split(",", -1) @meth_return_types = "".split(",", -1) @meth_body_ids = [] @meth_has_defaults = "".split(",") @meth_has_defaults = "".split(",", -1) @meth_rest_index = [] # Position of the **kwrest param in @meth_param_names (-1 if no # kwrest). Lets call-site arg-packing detect the slot that should @meth_kwrest_index = [] # ---- Classes (parallel arrays) ---- @cls_names = "".split(",") @cls_parents = "".split(",") @cls_names = "".split(",", -1) @cls_parents = "".split(",", -1) # per-class list of included module # names, semicolon-separated. Modules live in @module_names so # the resolution from name -> id is deferred to codegen time. @cls_includes = "".split(",") @cls_ivar_names = "".split(",") @cls_ivar_types = "".split(",") @cls_includes = "".split(",", -1) @cls_ivar_names = "".split(",", -1) @cls_ivar_types = "".split(",", -1) # Per-ivar flag: was the ivar's first scanned write a definite # literal (IntegerNode / FloatNode / StringNode / ...)? Used to # distinguish concrete-literal writes from best-guess inference # definite — non-recognized CallNodes default to "int" through # infer_ivar_init_type and a naive trust of that produces # spurious disagreement. @cls_ivar_init_definite = "".split(",") @cls_ivar_init_definite = "".split(",", -1) # Per-(class, ivar) accumulator of distinct concrete writer # types observed by scan_writer_calls. After all writer-scan # iterations finish, slots with 2+ distinct entries widen to # comma-separated list of distinct types per ivar; the outer # dimension is semicolon-separated and parallel to # `@cls_ivar_names[ci]`. @cls_ivar_observed_types = "".split(",") @cls_ivar_observed_types = "".split(",", -1) # Per-class shadow of `@cls_ivar_types`, populated only by # `apply_rbs_seeds`. Each entry mirrors `@cls_ivar_names[ci]`'s # `;`-separated layout: an RBS-pinned slot carries its declared # `arbitrate_rbs_vs_inferred_ivars` after the iterative inference # loop -- when inference and RBS disagree, this table is what # we restore the slot to. Issue #626 sub-issue 2. @cls_ivar_rbs_types = "".split(",") @cls_ivar_rbs_types = "".split(",", -1) # Per-class set of ivar names that are read with a nil predicate # somewhere in the program — `<ivar>.nil?`, `<ivar> == nil`, # `<ivar> != nil`. Gates nil-scalar widening to poly so an ivar # widening cascaded `@freq` / `@timer` / `@step` to poly and broke # the int math emit). Populated by scan_ivar_nil_predicates before # the iter loop; semicolon-joined names parallel to @cls_ivar_names. @cls_ivar_nil_checked = "".split(",") @cls_ivar_nil_checked = "".split(",", -1) # Memoization for `find_lv_ivar_alias_in_ast`. Keyed by # `"<class_idx>:<lv_name>"`, value is the resolved ivar name (or # `""` when the LV has multiple sources / non-ivar writes). # Single-slot caches for the outer "|" split of joined per-class # method/param fields. cls_meth_ptypes_get / cls_meth_pnames_get / # cls_cmeth_*_get all do `field[ci].split("|", -1)` then # `[midx].split(",")` — the outer split is repeated for every # `[midx].split(",", -1)` — the outer split is repeated for every # (ci, midx) pair. Cache one ci's outer split per field; # consecutive calls with the same ci skip the outer split. @cmp_outer_ci = -1 @cmp_outer_split = "".split(",") @cmp_outer_split = "".split(",", -1) @cmp_outer_version = 0 @cmn_outer_ci = -1 @cmn_outer_split = "".split(",") @cmn_outer_split = "".split(",", -1) @cmn_outer_version = 0 @ccmp_outer_ci = -1 @ccmp_outer_split = "".split(",") @ccmp_outer_split = "".split(",", -1) @ccmp_outer_version = 0 @ccmn_outer_ci = -1 @ccmn_outer_split = "".split(",") @ccmn_outer_split = "".split(",", -1) @ccmn_outer_version = 0 @cls_meth_ptypes_version = 0 @cls_meth_params_version = 0 @cls_cmeth_params_version = 0 # Top-level (script-scope) ivars. Lowered to `static` file-scope # globals because `main()` / top-level `def` bodies have no `self`. @toplevel_ivar_names = "".split(",") @toplevel_ivar_types = "".split(",") @cls_meth_names = "".split(",") @cls_meth_params = "".split(",") @cls_meth_ptypes = "".split(",") @cls_meth_returns = "".split(",") @cls_meth_bodies = "".split(",") @cls_meth_defaults = "".split(",") @toplevel_ivar_names = "".split(",", -1) @toplevel_ivar_types = "".split(",", -1) @cls_meth_names = "".split(",", -1) @cls_meth_params = "".split(",", -1) @cls_meth_ptypes = "".split(",", -1) @cls_meth_returns = "".split(",", -1) @cls_meth_bodies = "".split(",", -1) @cls_meth_defaults = "".split(",", -1) # Mirror of @meth_param_empty for class methods. Pipe-separated by # method, comma-separated by param. . @cls_meth_ptypes_empty = "".split(",") @cls_attr_readers = "".split(",") @cls_attr_writers = "".split(",") @cls_cmeth_names = "".split(",") @cls_cmeth_params = "".split(",") @cls_cmeth_ptypes = "".split(",") @cls_cmeth_returns = "".split(",") @cls_cmeth_bodies = "".split(",") @cls_cmeth_defaults = "".split(",") @cls_meth_ptypes_empty = "".split(",", -1) @cls_attr_readers = "".split(",", -1) @cls_attr_writers = "".split(",", -1) @cls_cmeth_names = "".split(",", -1) @cls_cmeth_params = "".split(",", -1) @cls_cmeth_ptypes = "".split(",", -1) @cls_cmeth_returns = "".split(",", -1) @cls_cmeth_bodies = "".split(",", -1) @cls_cmeth_defaults = "".split(",", -1) # RBS shadow tables for method ptypes / returns (#626 sub-issue 2 # phase 2). Hash-keyed lookups -- RBS info is sparse compared to # the dense per-class method tables, so we don't bother mirroring # ";" indexes by cmj (mirrors @cls_cmeth_bodies); inner # separator "|" matches @nd_scope_names' format so the codegen # consumer can split into the same (lnames, ltypes) pair. @cls_cmeth_scope_names = "".split(",") @cls_cmeth_scope_types = "".split(",") @cls_cmeth_scope_names = "".split(",", -1) @cls_cmeth_scope_types = "".split(",", -1) @cls_is_value_type = [] # SRA (scalar replacement of aggregates) eligibility flag per class. # Classes marked here can have their non-escaping instances replaced @cls_is_sra = [] # ---- Constants (parallel arrays) ---- @const_names = "".split(",") @const_types = "".split(",") @const_names = "".split(",", -1) @const_types = "".split(",", -1) # ---- Class variables (@@var) ---- # Per-(class,name) parallel arrays. Storage is a per-class C global # are a known footgun (mame, ko1, et al. publicly disrecommend # them); the simpler per-class semantics fit Spinel's compile-time # storage model better. Documented in the test fixtures. @cvar_names = "".split(",") @cvar_types = "".split(",") @cvar_names = "".split(",", -1) @cvar_types = "".split(",", -1) # Compile-time literal initializer per cvar, if the class-body # write was `@@x = <literal>`. "" means "use type-default". This # is necessary because Spinel doesn't run class-body statements # at startup, so any initializer that's not a fold-able literal # leaves the cvar at its type-default until first write. @cvar_init_values = "".split(",") @cvar_init_values = "".split(",", -1) @const_expr_ids = [] @const_scope_names = "".split(",") @const_scope_names = "".split(",", -1) # Parallel to @const_names: when const `<X>`'s init RHS is the # canonical `<Class>.new(...)` shape, record `<Class>` here so # codegen can emit the per-const in-progress flag + read-side # initialized slot during the same RHS evaluation. Empty string # means "no guard needed" (other init shape — literal, helper- # built, etc.). Issue #646. @const_init_class = "".split(",") @const_init_class = "".split(",", -1) # `redo` -- labeled-goto target stack. Each loop emitter pushes # a fresh label name when entering an iteration body and pops on # exit; a `redo` jumps to the top of the innermost label. @redo_label_stack = "".split(",") @redo_label_stack = "".split(",", -1) @redo_label_counter = 0 # `alias $copy $orig` -- maps new gvar name to its target. # Populated by collect_all from AliasGlobalVariableNode # statements; consulted by sanitize_gvar / scan_features / # infer_type so $copy and $orig share storage. @galias_new = "".split(",") @galias_old = "".split(",") @galias_new = "".split(",", -1) @galias_old = "".split(",", -1) # `undef foo` -- per-(class, method-name) registry of removed # methods. Recorded by collect_class_method_undef; compile-time # enforcement of "call after undef fails" is currently a # documented out-of-scope. @undef_class_idx = [] @undef_method = "".split(",") @undef_method = "".split(",", -1) # `BEGIN { ... }` bodies, in source-encounter order. Hoisted to # the top of main() during emit_main. @post_execution_blocks = [] # ---- Scope stack for local variables ---- @scope_names = "".split(",") @scope_types = "".split(",") @scope_names = "".split(",", -1) @scope_types = "".split(",", -1) # Parallel to `@scope_names`: when a local was assigned directly # from an ivar read (`lv = @ivar`), record the ivar name here so # later sites that need ivar-side metadata (notably the # `<poly>[k]` narrowing in `compile_poly_method_call`) can # resolve through the alias. Empty string when the local has no # such alias (or had a non-ivar write since). @scope_ivar_alias = "".split(",") @scope_ivar_alias = "".split(",", -1) # Type-narrow stack for `is_a?`/`kind_of?` guards. While walking # the then-arm of `if v.is_a?(Hash)` or the truthy branch of # narrowed_type)` is pushed here; find_var_type's top-down # lookup picks it up so infer_type / scan / codegen see the # narrowed type without per-pass plumbing. @type_narrow_names = "".split(",") @type_narrow_types = "".split(",") @type_narrow_names = "".split(",", -1) @type_narrow_types = "".split(",", -1) @current_class_idx = -1 @current_method_name = "" # Yield/block tracking (parallel with meth_names / cls_meth_names) @meth_has_yield = [] @cls_meth_has_yield = "".split(",") @cls_meth_has_yield = "".split(",", -1) # Block function accumulator (emitted before forward decls) @block_funcs = "" @needs_system = 0 @needs_int_array = 0 @needs_float_array = 0 @tuple_types = "".split(",") @tuple_types = "".split(",", -1) @needs_str_array = 0 @needs_str_int_hash = 0 @needs_str_str_hash = 0 # emitted at the top of each rescue body. A bare `raise` inside a # rescue body re-raises with the snapshotted class+message rather # than fabricating a fresh RuntimeError. Empty outside any rescue. @rescue_cls_stack = "".split(",") @rescue_msg_stack = "".split(",") @rescue_cls_stack = "".split(",", -1) @rescue_msg_stack = "".split(",", -1) @rescue_depth = 0 # Stack of ensure-clause node IDs (encoded as strings) currently in # scope. Each entry corresponds to an enclosing `begin..ensure..end` # whose body is being compiled. When `return` is emitted from inside # the body, each ensure body is replayed (innermost-first) before # the C `return`, so writebacks in `ensure` execute on early return. @ensure_stack = "".split(",") @ensure_stack = "".split(",", -1) # Number of `sp_exc_top++` pushes emitted along the static # fall-through path leading to the current emit point but not # yet matched by an emitted `sp_exc_top--`. An early `return` @needs_rb_value = 0 @needs_regexp = 0 @needs_rand = 0 @regexp_patterns = "".split(",") @regexp_flags = "".split(",") @regexp_patterns = "".split(",", -1) @regexp_flags = "".split(",", -1) # Dynamic-regex (InterpolatedRegularExpressionNode) call-site cache. # Each AST node gets a unique idx so the emitter can produce one # `sp_re_dyn_<idx>` helper per source location with its own # function-scope cache (string key + compiled pattern). Collected # in scan_features so indexes are stable across compile_expr visits. @dyn_regex_node_ids = [] @dyn_regex_flags = "".split(",") @dyn_regex_flags = "".split(",", -1) # `var = /lit/` resolution. Parallel arrays: `@local_regex_names` # holds the local-variable name; `@local_regex_idx` holds the # corresponding `@regexp_patterns` index (-1 when the LV is # holds the AST node id of a single-write `Regexp.new(<dyn>)` # right-hand side (-1 otherwise), so the read-site dyn-cache emit # can locate the call. Multi-write resets both to -1 / -1. @local_regex_names = "".split(",") @local_regex_names = "".split(",", -1) @local_regex_idx = [] @local_regex_call_nids = [] @needs_sym_poly_hash = 0 @cls_cmeth_live = "" @cls_meth_live = "" @multi_const_inits = "".split(",") @multi_const_inits = "".split(",", -1) # Lambda support @needs_lambda = 0 @lambda_counter = 0 @lambda_funcs = "" @lambda_params = "".split(",") @lambda_captures = "".split(",") @lambda_capture_cell_types = "".split(",") @lambda_var_ret_names = "".split(",") @lambda_var_ret_types = "".split(",") @lambda_params = "".split(",", -1) @lambda_captures = "".split(",", -1) @lambda_capture_cell_types = "".split(",", -1) @lambda_var_ret_names = "".split(",", -1) @lambda_var_ret_types = "".split(",", -1) @last_lambda_ret_type = "" # `Klass.method(:cls_meth)` generates an adapter trampoline so the # Method object's `(void *self, mrb_int...)` ABI fits a class # method's no-self C signature. Tracks emitted (Klass, method) # pairs to avoid duplicate definitions. @cls_method_adapters = "".split(",") @cls_method_adapters = "".split(",", -1) # Proc closure support (Phase 2) @in_proc_body = 0 @proc_captures = "".split(",") @proc_capture_types = "".split(",") @proc_captures = "".split(",", -1) @proc_capture_types = "".split(",", -1) # Fiber support @needs_fiber = 0 @fiber_counter = 0 @fiber_funcs = "" @in_fiber_body = 0 @fiber_captures = "".split(",") @fiber_capture_types = "".split(",") @heap_promoted_names = "".split(",") @heap_promoted_cells = "".split(",") @fiber_captures = "".split(",", -1) @fiber_capture_types = "".split(",", -1) @heap_promoted_names = "".split(",", -1) @heap_promoted_cells = "".split(",", -1) # Global variables ($x) @gvar_names = "".split(",") @gvar_types = "".split(",") @gvar_names = "".split(",", -1) @gvar_types = "".split(",", -1) # Poly tracking: functions with params called with different types @poly_funcs = "".split(",") @poly_param_types = "".split(",") @poly_funcs = "".split(",", -1) @poly_param_types = "".split(",", -1) # Method reference tracking: var_name -> method_name @method_ref_vars = "".split(",") @method_ref_names = "".split(",") @method_ref_vars = "".split(",", -1) @method_ref_names = "".split(",", -1) # Open class tracking for built-in types @open_class_names = "".split(",") @open_class_names = "".split(",", -1) # Module tracking: module_name -> body node id @module_names = "".split(",") @module_names = "".split(",", -1) @module_body_ids = [] # `@module_includes[mi]`: `;`-separated list of names the module # introduced by row `mi` itself includes. Modules can re-open, so # each row tracks its own block's `include` calls; const lookup # walks every row matching the module name. @module_includes = "".split(",") @module_includes = "".split(",", -1) # Module-level singleton accessors : # `class << self; attr_accessor :foo; end` inside `module M`. # `@module_acc_consts[i]` is a `;`-separated list of distinct # inline; Stage 2: multiple names → runtime sentinel switch). # Empty string means at least one write was non-constant — the # slot falls through to the un-folded path. @module_acc_keys = "".split(",") @module_acc_consts = "".split(",") @module_acc_keys = "".split(",", -1) @module_acc_consts = "".split(",", -1) # ---- FFI state (parallel arrays, populated by scan_ffi_decl) ---- # Per-module registry: @ffi_modules = "".split(",") # module names that declared FFI @ffi_module_libs = "".split(",") # ";"-joined -l names @ffi_module_cflags = "".split(",") # ";"-joined cc flag strings @ffi_modules = "".split(",", -1) # module names that declared FFI @ffi_module_libs = "".split(",", -1) # ";"-joined -l names @ffi_module_cflags = "".split(",", -1) # ";"-joined cc flag strings # Function registry (one entry per ffi_func decl): @ffi_func_modules = "".split(",") # owning module name @ffi_func_names = "".split(",") # C symbol name @ffi_func_arg_types = "".split(",") # ";"-joined Spinel type tokens @ffi_func_ret_types = "".split(",") # single Spinel type token @ffi_func_arg_specs = "".split(",") # ";"-joined original specs (uint32, str, …) @ffi_func_ret_specs = "".split(",") # original return spec @ffi_func_modules = "".split(",", -1) # owning module name @ffi_func_names = "".split(",", -1) # C symbol name @ffi_func_arg_types = "".split(",", -1) # ";"-joined Spinel type tokens @ffi_func_ret_types = "".split(",", -1) # single Spinel type token @ffi_func_arg_specs = "".split(",", -1) # ";"-joined original specs (uint32, str, …) @ffi_func_ret_specs = "".split(",", -1) # original return spec # Buffer registry (one entry per ffi_buffer decl): @ffi_buf_modules = "".split(",") @ffi_buf_names = "".split(",") @ffi_buf_modules = "".split(",", -1) @ffi_buf_names = "".split(",", -1) @ffi_buf_sizes = [] # int sizes in bytes # Reader registry (one entry per ffi_read_* decl): @ffi_reader_modules = "".split(",") @ffi_reader_names = "".split(",") @ffi_reader_kinds = "".split(",") # "u32", "i32", "ptr" @ffi_reader_modules = "".split(",", -1) @ffi_reader_names = "".split(",", -1) @ffi_reader_kinds = "".split(",", -1) # "u32", "i32", "ptr" @ffi_reader_offsets = [] # int byte offsets @pending_method_ref = "" @lambda_counter = 0 @lambda_funcs = "" @lambda_params = "".split(",") @lambda_captures = "".split(",") @lambda_params = "".split(",", -1) @lambda_captures = "".split(",", -1) @lambda_insert_pos = 0 @cls_method_adapters = "".split(",") @cls_method_adapters = "".split(",", -1) # Proc closure support (Phase 2) @in_proc_body = 0 @proc_captures = "".split(",") @proc_capture_types = "".split(",") @proc_captures = "".split(",", -1) @proc_capture_types = "".split(",", -1) # Symbol type Phase 2 Step 1: intern table (infrastructure only; unused yet). @sym_names = "".split(",") @sym_names = "".split(",", -1) # instance_eval block hoisting: parallel arrays indexed by synthetic # function id N. Each lifted block becomes a file-scope static @ieval_counter = 0 @ieval_class_idxs = [] @ieval_body_ids = [] @ieval_return_types = "".split(",") @ieval_return_types = "".split(",", -1) # Self-bound block-param name per lift (empty for the no-param # forms). emit_ieval_func seeds it via `lv_<name> = self;`. @ieval_self_param_names = "".split(",") @ieval_self_param_names = "".split(",", -1) # Extra required block-param names (";"-joined) beyond the # self-bound first. CRuby binds these to nil (arity tolerance); # precompute_all_scope_decls declares them as nil-typed locals. @ieval_extra_param_names = "".split(",") @ieval_extra_param_names = "".split(",", -1) # Receiver classes flagged out of value-type / SRA promotion so # the lifted sp_ieval_<N>'s self-pointer signature can mutate. @cls_with_internal_ieval_lift = "".split(",") @cls_with_internal_ieval_lift = "".split(",", -1) # RBS-derived seed lines. Populated by load_rbs_seeds before # analyze_phase; consumed by apply_rbs_seeds after collect_all # has built the class/method tables. Empty when no seed file was # passed -- inference behaves exactly as before. @rbs_seed_lines = "".split(",") @rbs_seed_lines = "".split(",", -1) # Set of "ci_midx" tokens for class instance methods whose ptypes # were RBS-seeded. Heuristic narrowing passes (notably the # `narrow_param_hash_types_from_body_writes` Option-B fallback # when no concrete writes signal a value type) consult this set # and skip the narrowing -- the explicit RBS declaration is # authoritative over heuristic inference. Issue #613. @rbs_seeded_cls_meth = "".split(";") @rbs_seeded_cls_meth = "".split(";", -1) end def rbs_mark_cls_meth_seeded(ci, midx) # Returns the body node id for class ci's midx'th method, or -1 # if midx is out of range or the body id is invalid. Centralises # the @cls_meth_bodies[ci].split(";")[midx].to_i parse so detectors # the @cls_meth_bodies[ci].split(";", -1)[midx].to_i parse so detectors # don't have to inline it. # Returns the name of the class method's single proc-typed param if incs_str == "" return "" end incs = incs_str.split(";") incs = incs_str.split(";", -1) ii = 0 while ii < incs.length inc = incs[ii] return "0" end f = @nd_flags[nid] parts = "".split(",") parts = "".split(",", -1) if f & 4 != 0 parts.push("1") end # Find method in class (search parent chain) def cls_find_method(ci, mname) names = @cls_meth_names[ci].split(";") names = @cls_meth_names[ci].split(";", -1) j = 0 while j < names.length if names[j] == mname if ci < 0 return -1 end cmnames = @cls_cmeth_names[ci].split(";") cmnames = @cls_cmeth_names[ci].split(";", -1) cj = 0 while cj < cmnames.length if cmnames[cj] == mname if owner < 0 return "" end cmnames = @cls_cmeth_names[owner].split(";") cm_returns = @cls_cmeth_returns[owner].split(";") cmnames = @cls_cmeth_names[owner].split(";", -1) cm_returns = @cls_cmeth_returns[owner].split(";", -1) cj = 0 while cj < cmnames.length if cmnames[cj] == mname if @cls_meth_return_cache.key?(ck) return @cls_meth_return_cache[ck] end names = @cls_meth_names[ci].split(";") returns = @cls_meth_returns[ci].split(";") names = @cls_meth_names[ci].split(";", -1) returns = @cls_meth_returns[ci].split(";", -1) j = 0 while j < names.length if names[j] == mname if @cls_ivar_type_cache.key?(ck) return @cls_ivar_type_cache[ck] end names = @cls_ivar_names[ci].split(";") types = @cls_ivar_types[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) types = @cls_ivar_types[ci].split(";", -1) own_t = "" j = 0 while j < names.length # this arm spinel falls back to int (the default), and string- # returning rescue bodies fail C compilation when the ret_tmp # slot's type doesn't match the value being assigned. types_b = "".split(",") types_b = "".split(",", -1) bodies_b = begin_node_arm_bodies(nid) bi = 0 while bi < bodies_b.length else_type = infer_type(sub) end end types = "".split(",") types = "".split(",", -1) types.push(then_type) types.push(else_type) return unify_return_type(types) end end end types = "".split(",") types = "".split(",", -1) types.push(then_type) types.push(else_type) return unify_return_type(types) end if t == "CaseMatchNode" types = "".split(",") types = "".split(",", -1) conds = parse_id_list(@nd_conditions[nid]) k = 0 while k < conds.length return "int" end if t == "CaseNode" types = "".split(",") types = "".split(",", -1) conds = parse_id_list(@nd_conditions[nid]) k = 0 while k < conds.length if module_name_exists(mod_name) == 1 rconsts = module_acc_resolved(mod_name, inner_mname) if rconsts != "" && rconsts != "?" cands = rconsts.split(";") cands = rconsts.split(";", -1) common = "" cands.each { |cn| mi = find_method_idx(cn + "_cls_" + mname) end cci_cm = find_class_idx(owning_cm) if cci_cm >= 0 cmnames_cm = @cls_cmeth_names[cci_cm].split(";") cmreturns_cm = @cls_cmeth_returns[cci_cm].split(";") cmnames_cm = @cls_cmeth_names[cci_cm].split(";", -1) cmreturns_cm = @cls_cmeth_returns[cci_cm].split(";", -1) cmidx_cm = 0 while cmidx_cm < cmnames_cm.length if cmnames_cm[cmidx_cm] == mname && cmidx_cm < cmreturns_cm.length end end if @current_class_idx >= 0 && @current_method_has_self == 0 cmnames_cm_r = @cls_cmeth_names[@current_class_idx].split(";") cmreturns_cm_r = @cls_cmeth_returns[@current_class_idx].split(";") cmnames_cm_r = @cls_cmeth_names[@current_class_idx].split(";", -1) cmreturns_cm_r = @cls_cmeth_returns[@current_class_idx].split(";", -1) cmidx_cm_r = 0 while cmidx_cm_r < cmnames_cm_r.length if cmnames_cm_r[cmidx_cm_r] == mname && cmidx_cm_r < cmreturns_cm_r.length def any_user_class_defines_imeth(mname) ck = 0 while ck < @cls_names.length names = @cls_meth_names[ck].split(";") names = @cls_meth_names[ck].split(";", -1) kk = 0 while kk < names.length if names[kk] == mname if inner_ci >= 0 owner = cls_cmethod_owner(inner_ci, mname) if owner >= 0 cmnames = @cls_cmeth_names[owner].split(";") cmreturns = @cls_cmeth_returns[owner].split(";") cmnames = @cls_cmeth_names[owner].split(";", -1) cmreturns = @cls_cmeth_returns[owner].split(";", -1) base_rt = "" cmidx = 0 while cmidx < cmnames.length if ck != inner_ci && cls_is_descendant(ck, inner_ci) == 1 own = cls_cmethod_owner(ck, mname) if own == ck ck_cmnames = @cls_cmeth_names[ck].split(";") ck_cmreturns = @cls_cmeth_returns[ck].split(";") ck_cmnames = @cls_cmeth_names[ck].split(";", -1) ck_cmreturns = @cls_cmeth_returns[ck].split(";", -1) ki = 0 while ki < ck_cmnames.length if ck_cmnames[ki] == mname && ki < ck_cmreturns.length end if heterogeneous == 1 || multi_arg == 1 # Build tuple type: receiver elem + each arg elem parts = "".split(",") parts = "".split(",", -1) parts.push(elem_type_of_array(rt)) aargs2 = get_args(args_id) k2 = 0 # that the dispatch site source-level can't reach (mirrors # codegen-side narrow). Issue #549. args_id_pdrt = @nd_arguments[nid] arg_types_pdrt = "".split(",") arg_types_pdrt = "".split(",", -1) if args_id_pdrt >= 0 a_ids_pdrt = get_args(args_id_pdrt) kp_pdrt = 0 ci = 0 while ci < @cls_names.length # Check zero-arg methods (getters) ci2_mnames = @cls_meth_names[ci].split(";") ci2_mnames = @cls_meth_names[ci].split(";", -1) ci2_mparams = @cls_meth_params[ci].split("|", -1) mi2 = 0 while mi2 < ci2_mnames.length end def tuple_elem_type_at(t, idx) parts = tuple_elem_types_str(t).split(",") parts = tuple_elem_types_str(t).split(",", -1) if idx < parts.length return parts[idx] end # Build "tuple:T0,T1,..." from a list of element node ids and register it. def tuple_type_from_elems(elems) parts = "".split(",") parts = "".split(",", -1) k = 0 while k < elems.length parts.push(infer_type(elems[k])) if ci < 0 return 0 end writers = @cls_attr_writers[ci].split(";") writers = @cls_attr_writers[ci].split(";", -1) wi = 0 while wi < writers.length if writers[wi] == bname if arg_ids.length > 0 && @nd_type[arg_ids[0]] == "ConstantReadNode" rhs_name = @nd_name[arg_ids[0]] cur = @module_acc_consts[idx] cur_list = cur.split(";") cur_list = cur.split(";", -1) if not_in(rhs_name, cur_list) == 1 if cur == "" @module_acc_consts[idx] = rhs_name def propagate_inherited_class_methods ci = 0 while ci < @cls_names.length seen = @cls_cmeth_names[ci].split(";") seen = @cls_cmeth_names[ci].split(";", -1) cur_parent = @cls_parents[ci] while cur_parent != "" pi = find_class_idx(cur_parent) if pi < 0 cur_parent = "" else p_cmnames = @cls_cmeth_names[pi].split(";") p_cmreturns = @cls_cmeth_returns[pi].split(";") p_cmbodies = @cls_cmeth_bodies[pi].split(";") p_cmnames = @cls_cmeth_names[pi].split(";", -1) p_cmreturns = @cls_cmeth_returns[pi].split(";", -1) p_cmbodies = @cls_cmeth_bodies[pi].split(";", -1) p_cmparams = @cls_cmeth_params[pi].split("|", -1) p_cmptypes = @cls_cmeth_ptypes[pi].split("|", -1) p_cmdefaults = @cls_cmeth_defaults[pi].split("|", -1) def detect_circular_inheritance i = 0 while i < @cls_names.length visited = "".split(",") visited = "".split(",", -1) visited.push(@cls_names[i]) cur = @cls_parents[i] while cur != "" # from analyze get appended to instead of replaced. @ieval_class_idxs = [] @ieval_body_ids = [] @ieval_return_types = "".split(",") @ieval_self_param_names = "".split(",") @ieval_extra_param_names = "".split(",") @cls_with_internal_ieval_lift = "".split(",") @ieval_return_types = "".split(",", -1) @ieval_self_param_names = "".split(",", -1) @ieval_extra_param_names = "".split(",", -1) @cls_with_internal_ieval_lift = "".split(",", -1) # Widen class-method ptypes through obj-typed receivers before the # walk so a method-param receiver (e.g. `def configure(app); # app.instance_eval { } end` invoked as `cfg.configure(routes)`) ci = 0 while ci < @cls_names.length @current_class_idx = ci bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) bj = 0 while bj < bodies.length bid = bodies[bj].to_i # infer_all_returns does in its class-methods preamble # (Pass 3). Pulls in `routes = Routes.new` with type # obj_Routes when the RHS is statically classifiable. lnames = "".split(",") ltypes = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) scan_locals_first_type(bid, lnames, ltypes, pnames) lk = 0 while lk < lnames.length # needing extra args at the call boundary (opts/posts/rest/kw/ # kwrest/&blk) or on `_2`+ numbered params. self_param_name = "" extra_param_names = "".split(",") extra_param_names = "".split(",", -1) bp = @nd_parameters[blk] if bp >= 0 if @nd_type[bp] == "NumberedParametersNode" parent = "" sp = @nd_superclass[nid] struct_fields = "".split(",") struct_fields = "".split(",", -1) if sp >= 0 if @nd_type[sp] == "CallNode" if @nd_name[sp] == "new" end pnames_all = @cls_meth_params[ci].split("|", -1) ptypes_all = @cls_meth_ptypes[ci].split("|", -1) rets_all = @cls_meth_returns[ci].split(";") bodies_all = @cls_meth_bodies[ci].split(";") rets_all = @cls_meth_returns[ci].split(";", -1) bodies_all = @cls_meth_bodies[ci].split(";", -1) defs_all = @cls_meth_defaults[ci].split("|", -1) params = pnames_all[src] || "" ptypes = ptypes_all[src] || "" # then walks to the parent (or returns -1), so `c.meth` after # `undef meth` raises NoMethodError just like CRuby. Issue #717. if @cls_meth_names[ci] != "" cur_names_u = @cls_meth_names[ci].split(";") cur_names_u = @cls_meth_names[ci].split(";", -1) hit_u = -1 ki_u = 0 while ki_u < cur_names_u.length if hit_u >= 0 cur_params_u = @cls_meth_params[ci].split("|", -1) cur_ptypes_u = @cls_meth_ptypes[ci].split("|", -1) cur_returns_u = @cls_meth_returns[ci].split(";") cur_bodies_u = @cls_meth_bodies[ci].split(";") cur_returns_u = @cls_meth_returns[ci].split(";", -1) cur_bodies_u = @cls_meth_bodies[ci].split(";", -1) cur_defaults_u = @cls_meth_defaults[ci].split("|", -1) cur_pempty_u = @cls_meth_ptypes_empty[ci].split("|", -1) while cur_pempty_u.length < cur_names_u.length end cur = @cls_includes[ci] # Dedup: a re-included module shouldn't duplicate in ancestors. parts = cur.split(";") parts = cur.split(";", -1) pk = 0 while pk < parts.length if parts[pk] == mod_name mname_e = @nd_name[sid] # Only add if this class doesn't already have a class # method with that name. cm_names_e = @cls_cmeth_names[ci].split(";") cm_names_e = @cls_cmeth_names[ci].split(";", -1) already_e = 0 ki_e = 0 while ki_e < cm_names_e.length includes_str = @cls_includes[ci] if includes_str != "" before_meths = @cls_meth_names[ci] names = includes_str.split(";") names = includes_str.split(";", -1) ni = 0 while ni < names.length if names[ni] != "" # user can spot the divergence from CRuby's intermediate-version # behaviour. $stderr.puts "warning: method '" + name + "' on " + @cls_names[ci] + " is being redefined; spinel uses last-def-wins semantics (calls before the redefinition won't see the original body — subset limitation)" cur_names = @cls_meth_names[ci].split(";") cur_names = @cls_meth_names[ci].split(";", -1) cur_params = @cls_meth_params[ci].split("|", -1) cur_ptypes = @cls_meth_ptypes[ci].split("|", -1) cur_returns = @cls_meth_returns[ci].split(";") cur_bodies = @cls_meth_bodies[ci].split(";") cur_returns = @cls_meth_returns[ci].split(";", -1) cur_bodies = @cls_meth_bodies[ci].split(";", -1) cur_defaults = @cls_meth_defaults[ci].split("|", -1) cur_pempty = @cls_meth_ptypes_empty[ci].split("|", -1) while cur_pempty.length < cur_names.length # Class re-open semantics for `def self.<m>` (#489). # Last-definition-wins, same shape as append_cls_meth above. if @cls_cmeth_names[ci] != "" cm_names_re = @cls_cmeth_names[ci].split(";") cm_names_re = @cls_cmeth_names[ci].split(";", -1) existing_cmi = 0 found_cmi = -1 while existing_cmi < cm_names_re.length if found_cmi >= 0 cur_cm_params = @cls_cmeth_params[ci].split("|", -1) cur_cm_ptypes = @cls_cmeth_ptypes[ci].split("|", -1) cur_cm_returns = @cls_cmeth_returns[ci].split(";") cur_cm_bodies = @cls_cmeth_bodies[ci].split(";") cur_cm_returns = @cls_cmeth_returns[ci].split(";", -1) cur_cm_bodies = @cls_cmeth_bodies[ci].split(";", -1) cur_cm_defaults = @cls_cmeth_defaults[ci].split("|", -1) cm_names_re[found_cmi] = name if found_cmi < cur_cm_params.length def collect_ivars(ci) # Scan all methods for ivar writes meths = @cls_meth_bodies[ci].split(";") meths = @cls_meth_bodies[ci].split(";", -1) j = 0 while j < meths.length bid = meths[j].to_i j = j + 1 end # Add ivars from attr_readers/writers that might not have explicit writes readers = @cls_attr_readers[ci].split(";") readers = @cls_attr_readers[ci].split(";", -1) j = 0 while j < readers.length iname = "@" + readers[j] end j = j + 1 end writers = @cls_attr_writers[ci].split(";") writers = @cls_attr_writers[ci].split(";", -1) j = 0 while j < writers.length iname = "@" + writers[j] # already determined the new type is correct (e.g. promoting an # empty-hash default to a concrete hash type from a `[]=` write). def replace_ivar_type(ci, iname, new_type) names = @cls_ivar_names[ci].split(";") types = @cls_ivar_types[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) types = @cls_ivar_types[ci].split(";", -1) k = 0 while k < names.length if names[k] == iname end def update_ivar_type(ci, iname, new_type) names = @cls_ivar_names[ci].split(";") types = @cls_ivar_types[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) types = @cls_ivar_types[ci].split(";", -1) k = 0 while k < names.length if names[k] == iname end def ivar_exists(ci, iname) names = @cls_ivar_names[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) k = 0 while k < names.length if names[k] == iname # one per `<Class>.new(args)` callsite. Plain arrays instead of a Hash # because the empty-hash-literal default type would land on # str_int_hash and reject the string values. ctor_class_idxs = "".split(",") ctor_arg_csvs = "".split(",") ctor_class_idxs = "".split(",", -1) ctor_arg_csvs = "".split(",", -1) nid = 0 n = @nd_type.length while nid < n # matching arg type as an observation. ci = 0 while ci < @cls_names.length callsites = "".split(",") callsites = "".split(",", -1) ki = 0 ci_str = ci.to_s while ki < ctor_class_idxs.length if callsites.length > 0 init_midx = cls_find_method_direct(ci, "initialize") if init_midx >= 0 bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) if init_midx < bodies.length init_body = bodies[init_midx].to_i if init_body >= 0 if is_concrete == 0 return end names = @cls_ivar_names[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) # Pad obs to names.length: split(";", -1) preserves trailing "" but # an entirely-empty storage gives a 0-length array. Walk by index # and treat missing entries as "". while k < names.length if names[k] == iname # Build an array of slots, one per ivar, defaulting empty. slots = "".split(",") slots = "".split(",", -1) ix = 0 while ix < names.length slots.push("") px = px + 1 end end existing = slots[k].split(",") existing = slots[k].split(",", -1) ex = 0 while ex < existing.length if existing[ex] == at end def cls_ivar_definite_flag(ci, iname) names = @cls_ivar_names[ci].split(";") flags = @cls_ivar_init_definite[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) flags = @cls_ivar_init_definite[ci].split(";", -1) k = 0 while k < names.length if names[k] == iname if @cls_ivar_nil_checked[ci] == "" return 0 end names = @cls_ivar_nil_checked[ci].split(";") names = @cls_ivar_nil_checked[ci].split(";", -1) k = 0 while k < names.length if names[k] == iname cur_incs = @module_includes[mi_for_includes] already = 0 if cur_incs != "" parts = cur_incs.split(";") parts = cur_incs.split(";", -1) pk = 0 while pk < parts.length if parts[pk] == inc_name (cur == "nil" && @nd_type[expr_id] == "NilNode") # Walk all class methods in the module looking for writes to # this ivar. key_t_set = "".split(",") val_t_set = "".split(",") direct_t_set = "".split(",") key_t_set = "".split(",", -1) val_t_set = "".split(",", -1) direct_t_set = "".split(",", -1) body_stmts.each { |sid2| next unless @nd_type[sid2] == "DefNode" bid = @nd_body[sid2] mi3 = find_method_idx(synth_name) push_scope if mi3 >= 0 pnames3 = @meth_param_names[mi3].split(",") ptypes3 = @meth_param_types[mi3].split(",") pnames3 = @meth_param_names[mi3].split(",", -1) ptypes3 = @meth_param_types[mi3].split(",", -1) k3 = 0 while k3 < pnames3.length pt3 = "int" # pick_array_class returns the same int_array we started # with. The ivar shape (`@slots[k] = v` where k/v are # params) only needs the params declared above. local_names = "".split(",") local_types = "".split(",") local_names = "".split(",", -1) local_types = "".split(",", -1) scan_locals(bid, local_names, local_types, pnames3) lk = 0 while lk < local_names.length return end if @multi_const_inits == nil @multi_const_inits = "".split(",") @multi_const_inits = "".split(",", -1) end @multi_const_inits.push(scope_name + "|" + nid.to_s) end # Get field names from symbol args (skip keyword_init hash) args_id = @nd_arguments[call_nid] field_names = "".split(",") field_names = "".split(",", -1) if args_id >= 0 aids = get_args(args_id) k = 0 # Store struct info for synthetic constructor generation # We'll use a special marker in the body id (-2 = synthetic struct) bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) if bodies.length > 0 bodies[0] = "-2" @cls_meth_bodies[ci] = bodies.join(";") if @nd_type[@root_id] == "ProgramNode" tl_body = @nd_body[@root_id] if tl_body >= 0 empty_params = "".split(",") tl_lnames = "".split(",") tl_ltypes = "".split(",") empty_params = "".split(",", -1) tl_lnames = "".split(",", -1) tl_ltypes = "".split(",", -1) scan_locals_first_type(tl_body, tl_lnames, tl_ltypes, empty_params) ti = 0 while ti < tl_lnames.length # arg infers off the local's literal type. The same guard keeps # nested def/class/module bodies from leaking back out. push_scope lnames = "".split(",") ltypes = "".split(",") empty_p = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) empty_p = "".split(",", -1) scan_locals(body, lnames, ltypes, empty_p) k = 0 while k < lnames.length args_id = @nd_arguments[nid] if args_id >= 0 arg_ids = get_args(args_id) ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",", -1) pnames = @meth_param_names[mi].split(",", -1) rest_param_idx = method_rest_index(mi) if rest_param_idx >= ptypes.length rest_param_idx = -1 owning = @current_method_name[0, marker] cci = find_class_idx(owning) if cci >= 0 cmnames = @cls_cmeth_names[cci].split(";") cmnames = @cls_cmeth_names[cci].split(";", -1) cmidx = 0 while cmidx < cmnames.length if cmnames[cmidx] == mname args_id_m = @nd_arguments[nid] if args_id_m >= 0 arg_ids_m = get_args(args_id_m) ptypes_m = @meth_param_types[sib_mi_m].split(",") pnames_m = @meth_param_names[sib_mi_m].split(",") ptypes_m = @meth_param_types[sib_mi_m].split(",", -1) pnames_m = @meth_param_names[sib_mi_m].split(",", -1) widen_ptypes_from_args(arg_ids_m, pnames_m, ptypes_m) @meth_param_types[sib_mi_m] = ptypes_m.join(",") end arg_ids_p = get_args(args_id_p) obs_ids = observed_class_ids_for_recv(@nd_receiver[nid], @current_class_idx) obs_filter = (obs_ids != "") obs_list = "".split(",") obs_list = "".split(",", -1) if obs_filter obs_list = obs_ids.split(",") obs_list = obs_ids.split(",", -1) end ci_p = 0 while ci_p < @cls_names.length cci = find_class_idx(rcname) if cci >= 0 cmname = @nd_name[nid] cmnames = @cls_cmeth_names[cci].split(";") cmnames = @cls_cmeth_names[cci].split(";", -1) cmidx = 0 while cmidx < cmnames.length if cmnames[cmidx] == cmname mod_args_id = @nd_arguments[nid] if mod_args_id >= 0 mod_arg_ids = get_args(mod_args_id) mod_pnames = @meth_param_names[mod_mi].split(",") mod_ptypes = @meth_param_types[mod_mi].split(",") mod_pnames = @meth_param_names[mod_mi].split(",", -1) mod_ptypes = @meth_param_types[mod_mi].split(",", -1) widen_ptypes_from_args(mod_arg_ids, mod_pnames, mod_ptypes) @meth_param_types[mod_mi] = mod_ptypes.join(",") end if module_name_exists(mua_mod_name) == 1 mua_rconsts = module_acc_resolved(mua_mod_name, mua_inner_mname) if mua_rconsts != "" && mua_rconsts != "?" mua_cands = mua_rconsts.split(";") mua_cands = mua_rconsts.split(";", -1) mua_outer_mname = @nd_name[nid] mua_args_id = @nd_arguments[nid] if mua_args_id >= 0 mua_cands.each { |mua_cn| mua_cci = find_class_idx(mua_cn) if mua_cci >= 0 mua_cmnames = @cls_cmeth_names[mua_cci].split(";") mua_cmnames = @cls_cmeth_names[mua_cci].split(";", -1) mua_cmpall = @cls_cmeth_ptypes[mua_cci].split("|", -1) mua_cmidx = 0 while mua_cmidx < mua_cmnames.length if mua_cmnames[mua_cmidx] == mua_outer_mname && mua_cmidx < mua_cmpall.length mua_cmpt = mua_cmpall[mua_cmidx].split(",") mua_cmpt = mua_cmpall[mua_cmidx].split(",", -1) mua_k = 0 while mua_k < mua_arg_ids.length mua_at = infer_type(mua_arg_ids[mua_k]) mua_mod_mfn = mua_cn + "_cls_" + mua_outer_mname mua_mod_mi = find_method_idx(mua_mod_mfn) if mua_mod_mi >= 0 mua_mod_pnames = @meth_param_names[mua_mod_mi].split(",") mua_mod_ptypes = @meth_param_types[mua_mod_mi].split(",") mua_mod_pnames = @meth_param_names[mua_mod_mi].split(",", -1) mua_mod_ptypes = @meth_param_types[mua_mod_mi].split(",", -1) widen_ptypes_from_args(mua_arg_ids, mua_mod_pnames, mua_mod_ptypes) @meth_param_types[mua_mod_mi] = mua_mod_ptypes.join(",") end if child_init_idx < 0 return end bodies = @cls_meth_bodies[child_ci].split(";") bodies = @cls_meth_bodies[child_ci].split(";", -1) if child_init_idx >= bodies.length return end ci = 0 while ci < @cls_names.length if @cls_parents[ci] != "" child_method_names = @cls_meth_names[ci].split(";") child_method_names = @cls_meth_names[ci].split(";", -1) j = 0 while j < child_method_names.length mname = child_method_names[j] end def propagate_super_method_one(child_ci, child_mi, parent_ci, mname) bodies = @cls_meth_bodies[child_ci].split(";") bodies = @cls_meth_bodies[child_ci].split(";", -1) if child_mi >= bodies.length return end def propagate_bare_new_to_subclass_initialize ci = 0 while ci < @cls_names.length cmnames = @cls_cmeth_names[ci].split(";") cm_bodies = @cls_cmeth_bodies[ci].split(";") cmnames = @cls_cmeth_names[ci].split(";", -1) cm_bodies = @cls_cmeth_bodies[ci].split(";", -1) j = 0 while j < cmnames.length bid = -1 while i < @cls_names.length init_idx2 = cls_find_method_direct(i, "initialize") if init_idx2 >= 0 bodies = @cls_meth_bodies[i].split(";") bodies = @cls_meth_bodies[i].split(";", -1) if init_idx2 < bodies.length if bodies[init_idx2].to_i == -2 # Synthetic struct - update ivar types from init param types # For each class method, if it assigns @ivar = param, update ivar type from param type i = 0 while i < @cls_names.length mnames = @cls_meth_names[i].split(";") mnames = @cls_meth_names[i].split(";", -1) mi = 0 while mi < mnames.length init_idx = mi pnames = cls_meth_pnames_get(i, init_idx) ptypes = cls_meth_ptypes_get(i, init_idx) bodies = @cls_meth_bodies[i].split(";") bodies = @cls_meth_bodies[i].split(";", -1) bid = -1 if init_idx < bodies.length bid = bodies[init_idx].to_i if pi < ptypes.length # Update ivar type iname = @nd_name[sid] ivar_names = @cls_ivar_names[i].split(";") ivar_types = @cls_ivar_types[i].split(";") ivar_names = @cls_ivar_names[i].split(";", -1) ivar_types = @cls_ivar_types[i].split(";", -1) ij = 0 while ij < ivar_names.length if ij < ivar_types.length # Check all classes' methods (not just the class owning the readers). oci = 0 while oci < @cls_names.length mnames = @cls_meth_names[oci].split(";") bodies = @cls_meth_bodies[oci].split(";") mnames = @cls_meth_names[oci].split(";", -1) bodies = @cls_meth_bodies[oci].split(";", -1) j = 0 while j < mnames.length if mnames[j] != "initialize" # only one reader and ignoring later accesses # would pick a class that fails to satisfy the # full method set. called = "".split(",") called = "".split(",", -1) collect_param_methods(bid, pnames[pk], called) if called.length > 0 && called_methods_only_on_container_builtins(called) == 0 # Check the param's default expression first: if it's an if j < @cls_meth_defaults[oci].split("|", -1).length defs_str_cm = @cls_meth_defaults[oci].split("|", -1)[j] end defs_arr_cm = defs_str_cm.split(",") defs_arr_cm = defs_str_cm.split(",", -1) if pk < defs_arr_cm.length def_id_cm = defs_arr_cm[pk].to_i if def_id_cm > 0 while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) pk = 0 while pk < pnames.length if pk < ptypes.length if ptypes[pk] == "int" called = "".split(",") called = "".split(",", -1) collect_param_methods(bid, pnames[pk], called) if called.length > 0 && called_methods_only_on_container_builtins(called) == 0 # Same precedence rule as the cls_meth side above: if the if mi < @meth_has_defaults.length defs_str_mp = @meth_has_defaults[mi] end defs_arr_mp = defs_str_mp.split(",") defs_arr_mp = defs_str_mp.split(",", -1) if pk < defs_arr_mp.length def_id_mp = defs_arr_mp[pk].to_i if def_id_mp > 0 while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) changed_top = 0 pk = 0 while pk < pnames.length if pk < ptypes.length && (ptypes[pk] == "int" || ptypes[pk] == "nil") called = "".split(",") called = "".split(",", -1) collect_param_methods(bid, pnames[pk], called) sawa = 0 kk = 0 end ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") bodies = @cls_meth_bodies[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) bodies = @cls_meth_bodies[ci].split(";", -1) cls_changed = 0 mj = 0 while mj < mnames.length pk = 0 while pk < pnames_j.length if pk < ptypes_j.length && (ptypes_j[pk] == "int" || ptypes_j[pk] == "nil") called_c = "".split(",") called_c = "".split(",", -1) collect_param_methods(bid_j, pnames_j[pk], called_c) sawc = 0 kk = 0 while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) changed_top = 0 pk = 0 while pk < pnames.length if pk < ptypes.length && (ptypes[pk] == "int" || ptypes[pk] == "nil") called = "".split(",") called = "".split(",", -1) collect_param_methods(bid, pnames[pk], called) saw = 0 kk = 0 end ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") bodies = @cls_meth_bodies[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) bodies = @cls_meth_bodies[ci].split(";", -1) cls_changed = 0 mj = 0 while mj < mnames.length pk = 0 while pk < pnames_j.length if pk < ptypes_j.length && (ptypes_j[pk] == "int" || ptypes_j[pk] == "nil") called_c = "".split(",") called_c = "".split(",", -1) collect_param_methods(bid_j, pnames_j[pk], called_c) sawc = 0 kk = 0 while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) changed_cs = 0 # Derive the lexical scope from the method name itself — # `Db_cls_column_bool` → "Db" — so a bare sibling call like pk = 0 while pk < pnames.length if pk < ptypes.length && ptypes[pk] == "int" obs = "".split(",") obs = "".split(",", -1) collect_param_callee_slots(bid, pnames[pk], obs) agreed = "" disagree = 0 # assign_form_pair's `into` widened to str_poly_hash via body # heterogeneous `into[k] = val` + `into[k] = {}` writes. if pk < ptypes.length && is_hash_type(ptypes[pk]) == 1 && ptypes[pk].include?("poly") == false obs_h = "".split(",") obs_h = "".split(",", -1) collect_param_callee_slots(bid, pnames[pk], obs_h) cur_kt_h = hash_key_part(ptypes[pk]) agreed_h = "" # @meth_* walk over each registered class's cmeth table. cci_cs = 0 while cci_cs < @cls_names.length cmnames_cs = @cls_cmeth_names[cci_cs].split(";") cmbodies_cs = @cls_cmeth_bodies[cci_cs].split(";") cmnames_cs = @cls_cmeth_names[cci_cs].split(";", -1) cmbodies_cs = @cls_cmeth_bodies[cci_cs].split(";", -1) cls_changed_cs = 0 cmj_cs = 0 while cmj_cs < cmnames_cs.length pk_cs = 0 while pk_cs < pnames_cm_cs.length if pk_cs < ptypes_cm_cs.length && ptypes_cm_cs[pk_cs] == "int" obs_cs = "".split(",") obs_cs = "".split(",", -1) collect_param_callee_slots(bid_cm_cs, pnames_cm_cs[pk_cs], obs_cs) agreed_cs = "" disagree_cs = 0 # slot is a poly variant of the same hash family, widen the # caller's param accordingly. if pk_cs < ptypes_cm_cs.length && is_hash_type(ptypes_cm_cs[pk_cs]) == 1 && ptypes_cm_cs[pk_cs].include?("poly") == false obs_ch = "".split(",") obs_ch = "".split(",", -1) collect_param_callee_slots(bid_cm_cs, pnames_cm_cs[pk_cs], obs_ch) cur_kt_ch = hash_key_part(ptypes_cm_cs[pk_cs]) agreed_ch = "" lvi = 0 while lvi < sn_lv.length if lvi < st_lv.length && is_hash_type(st_lv[lvi]) == 1 && st_lv[lvi].include?("poly") == false obs_lv = "".split(",") obs_lv = "".split(",", -1) collect_param_callee_slots(bid_lv, sn_lv[lvi], obs_lv) cur_kt_lv = hash_key_part(st_lv[lvi]) agreed_lv = "" # entries, so the widening propagates on the next iteration. ci_lv = 0 while ci_lv < @cls_names.length bodies_lv = @cls_meth_bodies[ci_lv].split(";") bodies_lv = @cls_meth_bodies[ci_lv].split(";", -1) bj_lv = 0 while bj_lv < bodies_lv.length bid_im = bodies_lv[bj_lv].to_i lvii = 0 while lvii < sn_im.length if lvii < st_im.length && is_hash_type(st_im[lvii]) == 1 && st_im[lvii].include?("poly") == false obs_im = "".split(",") obs_im = "".split(",", -1) collect_param_callee_slots(bid_im, sn_im[lvii], obs_im) cur_kt_im = hash_key_part(st_im[lvii]) agreed_im = "" def callee_kwarg_slot_type(callee_name, kwarg_name) cmi = find_method_idx(callee_name) if cmi >= 0 cpnames = @meth_param_names[cmi].split(",") cptypes = @meth_param_types[cmi].split(",") cpnames = @meth_param_names[cmi].split(",", -1) cptypes = @meth_param_types[cmi].split(",", -1) pi = 0 while pi < cpnames.length if cpnames[pi] == kwarg_name && pi < cptypes.length synth = @current_lexical_scope + "_cls_" + callee_name smi = find_method_idx(synth) if smi >= 0 spnames = @meth_param_names[smi].split(",") sptypes = @meth_param_types[smi].split(",") spnames = @meth_param_names[smi].split(",", -1) sptypes = @meth_param_types[smi].split(",", -1) pi = 0 while pi < spnames.length if spnames[pi] == kwarg_name && pi < sptypes.length end sci = find_class_idx(@current_lexical_scope) if sci >= 0 sc_cmnames = @cls_cmeth_names[sci].split(";") sc_cmnames = @cls_cmeth_names[sci].split(";", -1) smj = 0 while smj < sc_cmnames.length if sc_cmnames[smj] == callee_name while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) changed = 0 saved_scope = @current_lexical_scope mname_ks = @meth_names[mi] pk = 0 while pk < pnames.length if pk < ptypes.length && (ptypes[pk] == "int" || ptypes[pk] == "nil") obs = "".split(",") obs = "".split(",", -1) collect_param_kwarg_passthroughs(bid, pnames[pk], obs) agreed = "" disagree = 0 def callee_slot_type(callee_name, pos) cmi = find_method_idx(callee_name) if cmi >= 0 cpts = @meth_param_types[cmi].split(",") cpts = @meth_param_types[cmi].split(",", -1) if pos < cpts.length return cpts[pos] end synth = @current_lexical_scope + "_cls_" + callee_name smi = find_method_idx(synth) if smi >= 0 spts = @meth_param_types[smi].split(",") spts = @meth_param_types[smi].split(",", -1) if pos < spts.length return spts[pos] end # resolves here. sci = find_class_idx(@current_lexical_scope) if sci >= 0 sc_cmnames = @cls_cmeth_names[sci].split(";") sc_cmnames = @cls_cmeth_names[sci].split(";", -1) smj = 0 while smj < sc_cmnames.length if sc_cmnames[smj] == callee_name while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) changed_top = 0 pk = 0 while pk < pnames.length if pk < ptypes.length && ptypes[pk] == "int" called = "".split(",") called = "".split(",", -1) collect_param_methods(bid, pnames[pk], called) sawk = 0 kk = 0 end ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") bodies = @cls_meth_bodies[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) bodies = @cls_meth_bodies[ci].split(";", -1) cls_changed = 0 mj = 0 while mj < mnames.length pk = 0 while pk < pnames_j.length if pk < ptypes_j.length && ptypes_j[pk] == "int" called_c = "".split(",") called_c = "".split(",", -1) collect_param_methods(bid_j, pnames_j[pk], called_c) sawc = 0 kk = 0 if defaults_str == "" return 0 end defs = defaults_str.split(",") defs = defaults_str.split(",", -1) if pi >= defs.length return 0 end while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) defaults_str_m = @meth_has_defaults[mi] changed_m = 0 pk = 0 end ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") bodies = @cls_meth_bodies[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) bodies = @cls_meth_bodies[ci].split(";", -1) defaults_per = @cls_meth_defaults[ci].split("|", -1) cls_changed = 0 mj = 0 def widen_params_from_ivar_hash_aset ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") bodies = @cls_meth_bodies[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) bodies = @cls_meth_bodies[ci].split(";", -1) cls_changed = 0 mj = 0 while mj < mnames.length bid_j = bodies[mj].to_i end if bid_j >= 0 && bid_j != -2 && pnames_j.length > 0 key_widen = "".split(",") val_widen = "".split(",") key_widen = "".split(",", -1) val_widen = "".split(",", -1) while key_widen.length < pnames_j.length key_widen.push("") val_widen.push("") while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) ptypes_changed = 0 # Set up the method's scope so scan_param_body_write_unify's # LV-read arm (used by is_reliable_literal_for_widen) can look # Per-class instance and class methods. ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) all_params = @cls_meth_params[ci].split("|", -1) all_ptypes = @cls_meth_ptypes[ci].split("|", -1) bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) cls_changed = 0 mj = 0 while mj < mnames.length if mj < all_params.length && mj < all_ptypes.length && mj < bodies.length bid_j = bodies[mj].to_i if bid_j >= 0 pnames_j = all_params[mj].split(",") ptypes_j = all_ptypes[mj].split(",") pnames_j = all_params[mj].split(",", -1) ptypes_j = all_ptypes[mj].split(",", -1) inner_changed = 0 # Same scope setup as the top-level branch so the LV-read # widening picks up sibling-param types. # observed as the RHS-is-pname target, and promote to # "poly" when found. if new_t != "poly" && mnames[mj] == "[]=" ivt_set = "".split(",") ivt_set = "".split(",", -1) collect_param_ivar_write_slot_types(bid_j, pnames_j[pk], ci, ivt_set) if ivt_set.length >= 2 new_t = "poly" def widen_uninit_attr_ivars_to_poly ci = 0 while ci < @cls_names.length readers = @cls_attr_readers[ci].split(";") writers = @cls_attr_writers[ci].split(";") attr_iname_set = "".split(",") readers = @cls_attr_readers[ci].split(";", -1) writers = @cls_attr_writers[ci].split(";", -1) attr_iname_set = "".split(",", -1) k = 0 while k < readers.length if readers[k] != "" && not_in("@" + readers[k], attr_iname_set) == 1 ci = ci + 1 next end names = @cls_ivar_names[ci].split(";") types = @cls_ivar_types[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) types = @cls_ivar_types[ci].split(";", -1) changed_c = 0 k = 0 while k < names.length # widening to poly would break the body's `@amp -= int` arithmetic. def ivar_assigned_in_init_chain?(ci, iname) cur = ci visited = "".split(",") visited = "".split(",", -1) while cur >= 0 && cur < @cls_names.length && not_in(@cls_names[cur], visited) == 1 visited.push(@cls_names[cur]) bodies_w = @cls_meth_bodies[cur].split(";") bodies_w = @cls_meth_bodies[cur].split(";", -1) bi = 0 while bi < bodies_w.length bid_w = bodies_w[bi].to_i end # `super` call anywhere in initialize delegates to the parent's # initialize path — assume that may assign any ancestor ivar. mnames_w = @cls_meth_names[cur].split(";") bodies_w2 = @cls_meth_bodies[cur].split(";") mnames_w = @cls_meth_names[cur].split(";", -1) bodies_w2 = @cls_meth_bodies[cur].split(";", -1) mi_init_w = 0 while mi_init_w < mnames_w.length if mnames_w[mi_init_w] == "initialize" && mi_init_w < bodies_w2.length def widen_nil_default_params_to_poly mi = 0 while mi < @meth_names.length pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") defaults = @meth_has_defaults[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) defaults = @meth_has_defaults[mi].split(",", -1) changed = 0 pk = 0 while pk < pnames.length mj = 0 while mj < all_params.length if mj < all_ptypes.length pnames_j = all_params[mj].split(",") ptypes_j = all_ptypes[mj].split(",") pnames_j = all_params[mj].split(",", -1) ptypes_j = all_ptypes[mj].split(",", -1) defs_str_j = "" if mj < all_defaults.length defs_str_j = all_defaults[mj] end defs_arr_j = defs_str_j.split(",") defs_arr_j = defs_str_j.split(",", -1) inner_changed = 0 pk = 0 while pk < pnames_j.length cmj = 0 while cmj < cmeth_params_all.length if cmj < cmeth_ptypes_all.length cm_pnames = cmeth_params_all[cmj].split(",") cm_ptypes = cmeth_ptypes_all[cmj].split(",") cm_pnames = cmeth_params_all[cmj].split(",", -1) cm_ptypes = cmeth_ptypes_all[cmj].split(",", -1) cm_defs_str = "" if cmj < cmeth_defaults_all.length cm_defs_str = cmeth_defaults_all[cmj] end cm_defs_arr = cm_defs_str.split(",") cm_defs_arr = cm_defs_str.split(",", -1) cm_inner_changed = 0 cpk = 0 while cpk < cm_pnames.length # App.new internally) would need call-graph analysis and is left # to a follow-up. def detect_const_init_classes @const_init_class = "".split(",") @const_init_class = "".split(",", -1) i = 0 while i < @const_expr_ids.length cls_name_cic = "" def infer_yield_blk_param_types_for_body(body_id, ptypes_str) arity = body_max_yield_arity(body_id, 0) return "" if arity == 0 || body_id < 0 types = "".split(",") types = "".split(",", -1) k = 0 while k < arity types.push("") # Locate the method's params (top-level or class-instance) so the # `yield <param>` shape resolves through find_var_type to the # (post-promote) param type instead of falling back to "int". pnames_arr = "".split(",") ptypes_arr = ptypes_str.split(",") pnames_arr = "".split(",", -1) ptypes_arr = ptypes_str.split(",", -1) mi_ll = 0 while mi_ll < @meth_body_ids.length if @meth_body_ids[mi_ll] == body_id pnames_arr = @meth_param_names[mi_ll].split(",") pnames_arr = @meth_param_names[mi_ll].split(",", -1) mi_ll = @meth_body_ids.length else mi_ll = mi_ll + 1 if pnames_arr.length == 0 ci_ll = 0 while ci_ll < @cls_names.length bodies_ll = ci_ll < @cls_meth_bodies.length ? @cls_meth_bodies[ci_ll].split(";") : "".split(",") bodies_ll = ci_ll < @cls_meth_bodies.length ? @cls_meth_bodies[ci_ll].split(";", -1) : "".split(",", -1) midx_ll = 0 while midx_ll < bodies_ll.length if bodies_ll[midx_ll].to_i == body_id end j_p = j_p + 1 end lnames = "".split(",") ltypes = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) sn_b = @nd_scope_names[body_id] if sn_b != "" lnames = sn_b.split("|", -1) end project_yield_arg_types(body_id, types) pop_scope proj = "".split(",") proj = "".split(",", -1) j = 0 while j < types.length t = types[j] end def infer_proc_blk_param_types @meth_blk_param_types = "".split(",") @meth_blk_param_types = "".split(",", -1) mi = 0 while mi < @meth_param_names.length types = @meth_param_types[mi].split(",") types = @meth_param_types[mi].split(",", -1) if types.length > 0 && types.last == "proc" bpname = @meth_param_names[mi].split(",").last acc = "".split(",") bpname = @meth_param_names[mi].split(",", -1).last acc = "".split(",", -1) collect_blk_call_arg_types(@meth_body_ids[mi], bpname, acc, @meth_body_ids[mi]) @meth_blk_param_types.push(acc.join("|")) elsif @meth_has_yield[mi] == 1 end mi = mi + 1 end @cls_cmeth_blk_param_types = "".split(",") @cls_cmeth_blk_param_types = "".split(",", -1) ci = 0 while ci < @cls_names.length if ci < @cls_cmeth_names.length cmnames = @cls_cmeth_names[ci].split(";") cm_bodies = @cls_cmeth_bodies[ci].split(";") cmnames = @cls_cmeth_names[ci].split(";", -1) cm_bodies = @cls_cmeth_bodies[ci].split(";", -1) cm_ptypes = @cls_cmeth_ptypes[ci].split("|", -1) cmidx = 0 while cmidx < cmnames.length if cmidx < cm_ptypes.length cpts = cm_ptypes[cmidx].split(",") cpts = cm_ptypes[cmidx].split(",", -1) if cpts.length > 0 && cpts.last == "proc" cpnames = cls_cmeth_pnames_get(ci, cmidx) bpname = cpnames[cpnames.length - 1] acc = "".split(",") acc = "".split(",", -1) body_id = cm_bodies[cmidx].to_i collect_blk_call_arg_types(body_id, bpname, acc, body_id) @cls_cmeth_blk_param_types.push(acc.join("|")) while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) changed_top = 0 pk = 0 while pk < pnames.length end ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") bodies = @cls_meth_bodies[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) bodies = @cls_meth_bodies[ci].split(";", -1) cls_changed = 0 mj = 0 while mj < mnames.length while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) empty_str = "" if mi < @meth_param_empty.length empty_str = @meth_param_empty[mi] end empties = empty_str.split(",") empties = empty_str.split(",", -1) push_scope dj = 0 while dj < pnames.length declare_var(pnames[dj], pt) dj = dj + 1 end ml = "".split(",") mt = "".split(",") ml = "".split(",", -1) mt = "".split(",", -1) scan_locals(bid, ml, mt, pnames) lk = 0 while lk < ml.length while pk < pnames.length if pk < ptypes.length && pk < empties.length if empties[pk] == "1" && ptypes[pk] == "int_array" elem_acc = "".split(",") elem_acc = "".split(",", -1) collect_param_push_elem_types(bid, pnames[pk], elem_acc) promoted_type = empty_array_promotion_for(elem_acc) if promoted_type != "" all_params = @cls_meth_params[ci].split("|", -1) all_ptypes = @cls_meth_ptypes[ci].split("|", -1) all_empty = @cls_meth_ptypes_empty[ci].split("|", -1) bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) cls_changed = 0 mj = 0 while mj < all_params.length bid = bodies[mj].to_i end if bid >= 0 cm_pnames = all_params[mj].split(",") cm_ptypes = "".split(",") cm_empties = "".split(",") cm_pnames = all_params[mj].split(",", -1) cm_ptypes = "".split(",", -1) cm_empties = "".split(",", -1) if mj < all_ptypes.length cm_ptypes = all_ptypes[mj].split(",") cm_ptypes = all_ptypes[mj].split(",", -1) end if mj < all_empty.length cm_empties = all_empty[mj].split(",") cm_empties = all_empty[mj].split(",", -1) end push_scope cdj = 0 declare_var(cm_pnames[cdj], cpt) cdj = cdj + 1 end cml = "".split(",") cmt = "".split(",") cml = "".split(",", -1) cmt = "".split(",", -1) scan_locals(bid, cml, cmt, cm_pnames) cmlk = 0 while cmlk < cml.length while pk < cm_pnames.length if pk < cm_ptypes.length && pk < cm_empties.length if cm_empties[pk] == "1" && cm_ptypes[pk] == "int_array" elem_acc = "".split(",") elem_acc = "".split(",", -1) collect_param_push_elem_types(bid, cm_pnames[pk], elem_acc) promoted_type = empty_array_promotion_for(elem_acc) if promoted_type != "" while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") observations = "".split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) observations = "".split(",", -1) collect_param_method_calls(bid, pnames, observations) changed = 0 pk = 0 while ci < @cls_names.length all_params = @cls_meth_params[ci].split("|", -1) all_ptypes = @cls_meth_ptypes[ci].split("|", -1) bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) cls_changed = 0 mj = 0 while mj < all_params.length bid = bodies[mj].to_i end if bid >= 0 cm_pnames = all_params[mj].split(",") cm_ptypes = "".split(",") cm_pnames = all_params[mj].split(",", -1) cm_ptypes = "".split(",", -1) if mj < all_ptypes.length cm_ptypes = all_ptypes[mj].split(",") cm_ptypes = all_ptypes[mj].split(",", -1) end observations = "".split(",") observations = "".split(",", -1) collect_param_method_calls(bid, cm_pnames, observations) m_changed = 0 pk = 0 # Does class `ci` define `mname` directly — instance method, attr # reader, or attr writer — without walking the parent chain? def class_has_method_local(ci, mname) readers = @cls_attr_readers[ci].split(";") readers = @cls_attr_readers[ci].split(";", -1) if not_in(mname, readers) == 0 return 1 end if mname.length > 1 && mname[mname.length - 1] == "=" bname = mname[0, mname.length - 1] writers = @cls_attr_writers[ci].split(";") writers = @cls_attr_writers[ci].split(";", -1) if not_in(bname, writers) == 0 return 1 end end mnames = @cls_meth_names[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) if not_in(mname, mnames) == 0 return 1 end # Cheap guard: the user must define a class with this method. ci2 = 0 while ci2 < @cls_names.length mns = @cls_meth_names[ci2].split(";") mns = @cls_meth_names[ci2].split(";", -1) jj = 0 while jj < mns.length if mns[jj] == mname # Set up main scope for type inference push_scope stmts = get_body_stmts(@root_id) lnames = "".split(",") ltypes = "".split(",") empty_p = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) empty_p = "".split(",", -1) stmts.each { |sid| if @nd_type[sid] != "DefNode" if @nd_type[sid] != "ClassNode" # recorded type. saved_meth = @current_method_name @current_method_name = @meth_names[i] pnames = @meth_param_names[i].split(",") ptypes = @meth_param_types[i].split(",") pnames = @meth_param_names[i].split(",", -1) ptypes = @meth_param_types[i].split(",", -1) j = 0 while j < pnames.length pt = "int" j = j + 1 end if @meth_body_ids[i] >= 0 ml = "".split(",") mt = "".split(",") ml = "".split(",", -1) mt = "".split(",", -1) scan_locals(@meth_body_ids[i], ml, mt, pnames) lk = 0 ci = 0 while ci < @cls_names.length @current_class_idx = ci bodies = @cls_meth_bodies[ci].split(";") mnames = @cls_meth_names[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) mnames = @cls_meth_names[ci].split(";", -1) bj = 0 while bj < bodies.length bid = bodies[bj].to_i declare_var(pnames2[pk], pt) pk = pk + 1 end ml2 = "".split(",") mt2 = "".split(",") ml2 = "".split(",", -1) mt2 = "".split(",", -1) scan_locals(bid, ml2, mt2, pnames2) lk2 = 0 while lk2 < ml2.length # Also scan class method bodies (def self.<m>) so an # attr_writer call on a freshly-`new`'d instance inside a # `def self.from_raw(...)` factory widens the ivar's type. cm_bodies = @cls_cmeth_bodies[ci].split(";") cm_names = @cls_cmeth_names[ci].split(";") cm_bodies = @cls_cmeth_bodies[ci].split(";", -1) cm_names = @cls_cmeth_names[ci].split(";", -1) saved_meth = @current_method_name cbj = 0 while cbj < cm_bodies.length declare_var(cpnames[cpk], cpt) cpk = cpk + 1 end cml = "".split(",") cmt = "".split(",") cml = "".split(",", -1) cmt = "".split(",", -1) scan_locals(cbid, cml, cmt, cpnames) clk = 0 while clk < cml.length # ivar to poly just because Pass 1 recorded the bare name and a # later pass recorded the qualified one. def drop_stale_unqualified_obj_obs(obs) out = "".split(",") out = "".split(",", -1) # Type-prime locals as strings so spinel-self-compile picks the # right C type (sp_str_sub_range / sp_str_concat returns # `const char *`; without the empty-string seed scan_locals def finalize_ivar_heterogeneity ci = 0 while ci < @cls_names.length names = @cls_ivar_names[ci].split(";") types = @cls_ivar_types[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) types = @cls_ivar_types[ci].split(";", -1) obs = @cls_ivar_observed_types[ci].split(";", -1) changed = 0 ivk = 0 while ivk < names.length if ivk < types.length && ivk < obs.length && types[ivk] != "poly" distinct = obs[ivk].split(",") distinct = obs[ivk].split(",", -1) # Collapse stale unqualified obj-name observations against # their qualified form before the distinct-count widening # decision. A first-pass `@x = Foo.new(...)` recorded inside # Without this, callers that read the slot through an attr_ # reader then forward into another method's typed param see a # poly value and degrade every downstream slot. collapsed = "".split(",") collapsed = "".split(",", -1) ck = 0 while ck < distinct.length cur = distinct[ck] if midx < 0 return "" end bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) if midx >= bodies.length return "" end # CallNode rhs (`@a = @b = make_int`) bypasses scan_ivars's # dual-definite-literal widening and tail slots stay at # their pre-existing concrete type. chain_inames = "".split(",") chain_inames = "".split(",", -1) chain_inames.push(iname) bottom = expr_id while bottom >= 0 && @nd_type[bottom] == "InstanceVariableWriteNode" # the promoted type before recording. if at == "int_array" && @cur_writer_body >= 0 && @nd_type[bottom] == "LocalVariableReadNode" lname_a = @nd_name[bottom] elem_acc_a = "".split(",") elem_acc_a = "".split(",", -1) collect_param_push_elem_types(@cur_writer_body, lname_a, elem_acc_a) promoted_a = empty_array_promotion_for(elem_acc_a) if promoted_a != "" cname = rt[4, rt.length - 4] ci = find_class_idx(cname) if ci >= 0 writers = @cls_attr_writers[ci].split(";") writers = @cls_attr_writers[ci].split(";", -1) wk = 0 while wk < writers.length if writers[wk] == bname # poly across the program. Issue #684. obs_ids_pw = observed_class_ids_for_recv(@nd_receiver[nid], @current_class_idx) obs_filter_pw = (obs_ids_pw != "") obs_list_pw = "".split(",") obs_list_pw = "".split(",", -1) if obs_filter_pw obs_list_pw = obs_ids_pw.split(",") obs_list_pw = obs_ids_pw.split(",", -1) end ci_p = 0 while ci_p < @cls_names.length end end if skip_pw == 0 writers_p = @cls_attr_writers[ci_p].split(";") writers_p = @cls_attr_writers[ci_p].split(";", -1) wk_p = 0 while wk_p < writers_p.length if writers_p[wk_p] == bname # For setter methods (def x=(v); @x = v; end), infer param type from ivar type ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) all_ptypes = @cls_meth_ptypes[ci].split("|", -1) ivar_names = @cls_ivar_names[ci].split(";") ivar_types = @cls_ivar_types[ci].split(";") ivar_names = @cls_ivar_names[ci].split(";", -1) ivar_types = @cls_ivar_types[ci].split(";", -1) changed = 0 j = 0 bname = "" # or passed to functions that expect lambda args (transitive closure) changed = 1 iter = 0 sig_hist = "".split(",") sig_hist = "".split(",", -1) while changed == 1 iter = iter + 1 if iter > 256 while mi < @meth_names.length bid = @meth_body_ids[mi] if bid >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) pk = 0 while pk < pnames.length if pk < ptypes.length if recv < 0 fmi = find_method_idx(mname) if fmi >= 0 fptypes = @meth_param_types[fmi].split(",") fptypes = @meth_param_types[fmi].split(",", -1) args_id = @nd_arguments[nid] if args_id >= 0 aargs = get_args(args_id) args_id = @nd_arguments[nid] if args_id >= 0 aargs = get_args(args_id) ptypes = @meth_param_types[mi].split(",") ptypes = @meth_param_types[mi].split(",", -1) changed = 0 k = 0 while k < aargs.length # (raise-only bodies would otherwise re-derive as "int"). def unify_imeth_override_returns if @unified_imeth_returns == nil @unified_imeth_returns = "".split(",") @unified_imeth_returns = "".split(",", -1) end ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") returns = @cls_meth_returns[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) returns = @cls_meth_returns[ci].split(";", -1) changed = 0 mi = 0 while mi < mnames.length mname = mnames[mi] if mname != "" types = "".split(",") types = "".split(",", -1) base_ret = "" if mi < returns.length base_ret = returns[mi] if dci != ci && cls_is_descendant(dci, ci) == 1 dmidx = cls_find_method_direct(dci, mname) if dmidx >= 0 d_returns = @cls_meth_returns[dci].split(";") d_returns = @cls_meth_returns[dci].split(";", -1) if dmidx < d_returns.length types.push(d_returns[dmidx]) have_descendant_override = 1 if dci2 != ci && cls_is_descendant(dci2, ci) == 1 dmidx2 = cls_find_method_direct(dci2, mname) if dmidx2 >= 0 d_returns2 = @cls_meth_returns[dci2].split(";") d_returns2 = @cls_meth_returns[dci2].split(";", -1) if dmidx2 < d_returns2.length && d_returns2[dmidx2] != unified d_returns2[dmidx2] = unified @cls_meth_returns[dci2] = d_returns2.join(";") declare_var(pnames[k], pt) k = k + 1 end lnames = "".split(",") ltypes = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) refine_method_body_locals(bid, lnames, ltypes, pnames) need = method_returns_need_poly_widening(bid, declared_rt) pop_scope while mi < @meth_names.length bid = @meth_body_ids[mi] cur_rt = @meth_return_types[mi] pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) saved_meth = @current_method_name @current_method_name = @meth_names[mi] if widen_check_with_scope(bid, cur_rt, pnames, ptypes) == 1 while ci < @cls_names.length saved_ci = @current_class_idx @current_class_idx = ci bodies = @cls_meth_bodies[ci].split(";") mnames = @cls_meth_names[ci].split(";") returns = @cls_meth_returns[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) mnames = @cls_meth_names[ci].split(";", -1) returns = @cls_meth_returns[ci].split(";", -1) changed = 0 j = 0 while j < bodies.length while ci < @cls_names.length saved_ci = @current_class_idx @current_class_idx = ci cbodies = @cls_cmeth_bodies[ci].split(";") cmnames = @cls_cmeth_names[ci].split(";") creturns = @cls_cmeth_returns[ci].split(";") cbodies = @cls_cmeth_bodies[ci].split(";", -1) cmnames = @cls_cmeth_names[ci].split(";", -1) creturns = @cls_cmeth_returns[ci].split(";", -1) changed = 0 j = 0 while j < cbodies.length def unify_imeth_override_ptypes ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) mi = 0 while mi < mnames.length mname = mnames[mi] n = base_pt.length # Determine, per slot, whether at least one family member # has "poly". If so, widen every member at that slot. poly_slot = "".split(",") poly_slot = "".split(",", -1) k = 0 while k < n poly_slot.push("0") if mfn.start_with?("__oc_Float_") declare_var("__self_type", "float") end pnames = @meth_param_names[i].split(",") ptypes = @meth_param_types[i].split(",") pnames = @meth_param_names[i].split(",", -1) ptypes = @meth_param_types[i].split(",", -1) j = 0 while j < pnames.length pt = "int" # time, after `infer_body_return` has already pinned the # function's return type at the unrefined value. if @meth_body_ids[i] >= 0 lnames = "".split(",") ltypes = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) refine_method_body_locals(@meth_body_ids[i], lnames, ltypes, pnames) end rt = infer_body_return(@meth_body_ids[i]) i = 0 while i < @cls_names.length @current_class_idx = i mnames = @cls_meth_names[i].split(";") mnames = @cls_meth_names[i].split(";", -1) all_params = @cls_meth_params[i].split("|", -1) all_ptypes = @cls_meth_ptypes[i].split("|", -1) bodies = @cls_meth_bodies[i].split(";") returns = @cls_meth_returns[i].split(";") bodies = @cls_meth_bodies[i].split(";", -1) returns = @cls_meth_returns[i].split(";", -1) j = 0 while j < mnames.length push_scope pnames = "".split(",") ptypes = "".split(",") pnames = "".split(",", -1) ptypes = "".split(",", -1) if j < all_params.length pnames = all_params[j].split(",") pnames = all_params[j].split(",", -1) end if j < all_ptypes.length ptypes = all_ptypes[j].split(",") ptypes = all_ptypes[j].split(",", -1) end # Infer param types for initialize end # Declare locals for better return type inference if bid >= 0 rlnames = "".split(",") rltypes = "".split(",") rlnames = "".split(",", -1) rltypes = "".split(",", -1) scan_locals(bid, rlnames, rltypes, pnames) rlk = 0 while rlk < rlnames.length # encounters disagreeing concrete-literal writes; that's a # superset of scan_locals_first_type's "never-poly" rule but # produces strictly more accurate types for return inference. rlnames2 = "".split(",") rltypes2 = "".split(",") rlnames2 = "".split(",", -1) rltypes2 = "".split(",", -1) scan_locals(bid, rlnames2, rltypes2, pnames) rlk2 = 0 while rlk2 < rlnames2.length # setup the instance-method side does so a `def self.<m>` # body's return type sees its locals (instance = new etc.) # and bare `new` resolves via current_class_method_owning_class. cmnames = @cls_cmeth_names[i].split(";") cm_bodies = @cls_cmeth_bodies[i].split(";") cm_returns = @cls_cmeth_returns[i].split(";") cmnames = @cls_cmeth_names[i].split(";", -1) cm_bodies = @cls_cmeth_bodies[i].split(";", -1) cm_returns = @cls_cmeth_returns[i].split(";", -1) cm_params = @cls_cmeth_params[i].split("|", -1) cm_ptypes = @cls_cmeth_ptypes[i].split("|", -1) saved_meth = @current_method_name bid = cm_bodies[j].to_i end @current_method_name = @cls_names[i] + "_cls_" + cmnames[j] cpnames = "".split(",") cptypes = "".split(",") cpnames = "".split(",", -1) cptypes = "".split(",", -1) if j < cm_params.length cpnames = cm_params[j].split(",") cpnames = cm_params[j].split(",", -1) end if j < cm_ptypes.length cptypes = cm_ptypes[j].split(",") cptypes = cm_ptypes[j].split(",", -1) end cpk = 0 while cpk < cpnames.length # actually-emitted local is correctly typed `sp_<C> *`, # so the function signature and the body's `return` # statement disagree at the C boundary. ml = "".split(",") mt = "".split(",") ml = "".split(",", -1) mt = "".split(",", -1) refine_method_body_locals(bid, ml, mt, cpnames) end rt = infer_body_return(bid) # Top-level method variant of widen_nil_ptypes: reads/writes # @meth_param_types[i] directly. def widen_nil_defaults_to(table, i, rt) ptypes = table[i].split(",") ptypes = table[i].split(",", -1) if widen_nil_ptypes(ptypes, rt) == 1 table[i] = ptypes.join(",") end # has already propagated call-site-inferred types into ivars by this point. init_idx0 = cls_find_method_direct(ci, "initialize") if init_idx0 >= 0 bodies0 = @cls_meth_bodies[ci].split(";") bodies0 = @cls_meth_bodies[ci].split(";", -1) if init_idx0 < bodies0.length && bodies0[init_idx0].to_i == -2 return cls_ivar_type(ci, "@" + pname) end end # Check if param is assigned to an ivar in initialize mnames = @cls_meth_names[ci].split(";") bodies = @cls_meth_bodies[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) bodies = @cls_meth_bodies[ci].split(";", -1) j = 0 while j < mnames.length if mnames[j] == "initialize" if parent_init >= 0 parent_ptypes = @cls_meth_ptypes[parent_ci].split("|", -1) if parent_init < parent_ptypes.length ppt = parent_ptypes[parent_init].split(",") ppt = parent_ptypes[parent_init].split(",", -1) if sk < ppt.length return ppt[sk] end return "void" end # Collect all explicit return types types = "".split(",") types = "".split(",", -1) collect_return_types_nid(body_id, types) # Push sibling-scope narrows from preceding guards so the # implicit-return type sees the narrowed local types. Without last_type = infer_type(last_id) if last_type == "int_array" && @nd_type[last_id] == "LocalVariableReadNode" lname_lr = @nd_name[last_id] elem_acc_lr = "".split(",") elem_acc_lr = "".split(",", -1) collect_param_push_elem_types(body_id, lname_lr, elem_acc_lr) promoted_lr = empty_array_promotion_for(elem_acc_lr) if promoted_lr != "" # filtering out missing bodies (negative IDs). Used by both the # `infer_type` BeginNode arm (last-stmt type unification) and the # `collect_return_types` BeginNode arm (explicit-return walk). # `[]` (not `"".split(",")`) is the int_array init idiom in this # `[]` (not `"".split(",", -1)`) is the int_array init idiom in this # codebase — see the @nd_* parallel arrays in `initialize`. def begin_node_arm_bodies(nid) out = [] push_scope stmts = get_body_stmts(@root_id) pre_scan_simple_local_writes(stmts) lnames = "".split(",") ltypes = "".split(",") empty_p = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) empty_p = "".split(",", -1) stmts.each { |sid| if @nd_type[sid] != "DefNode" if @nd_type[sid] != "ClassNode" stmts = get_body_stmts(@root_id) # First, figure out main local types push_scope lnames = "".split(",") ltypes = "".split(",") empty_p = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) empty_p = "".split(",", -1) stmts.each { |sid| if @nd_type[sid] != "DefNode" if @nd_type[sid] != "ClassNode" # Check if it's a method parameter with a known type mi = 0 while mi < @meth_names.length pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) pi = 0 while pi < pnames.length if pnames[pi] == vn && pi < ptypes.length ci = find_class_idx(cname) if ci >= 0 mname = @nd_name[nid] readers = @cls_attr_readers[ci].split(";") readers = @cls_attr_readers[ci].split(";", -1) rk = 0 while rk < readers.length if readers[rk] == mname # Scan initialize body for @ivar = param assignments bj = cls_find_method_direct(ci, "initialize") if bj >= 0 bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) bid = bj < bodies.length ? bodies[bj].to_i : -1 if bid >= 0 pnames = cls_meth_pnames_get(ci, bj) args_id = @nd_arguments[nid] if args_id >= 0 arg_ids = get_args(args_id) ptypes = @meth_param_types[mi].split(",") ptypes = @meth_param_types[mi].split(",", -1) rest_param_idx = method_rest_index(mi) # Splat slot widening: a `def f(*args)` slot defaults to int_array # (the splat default in collect_ptypes_str). Every call site packs def detect_poly_locals # Detect local variables assigned different types in main scope stmts = get_body_stmts(@root_id) local_types = "".split(",") local_names = "".split(",") local_types = "".split(",", -1) local_names = "".split(",", -1) stmts.each { |sid| if @nd_type[sid] != "DefNode" if @nd_type[sid] != "ClassNode" # leaving the inner class's initialize ptypes un-widened. saved_method_name = @current_method_name @current_method_name = @meth_names[mi] pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) pk = 0 while pk < pnames.length if pnames[pk] != "" pk = pk + 1 end # Scan locals in the body lnames = "".split(",") ltypes = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) scan_locals(bid, lnames, ltypes, pnames) lk = 0 while lk < lnames.length while pass < 5 ci = 0 while ci < @cls_names.length mnames = @cls_meth_names[ci].split(";") bodies = @cls_meth_bodies[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) bodies = @cls_meth_bodies[ci].split(";", -1) mi = 0 while mi < mnames.length bid = -1 pk = pk + 1 end # Scan locals using first-type-only (no poly marking) lnames = "".split(",") ltypes = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) scan_locals_first_type(bid, lnames, ltypes, pnames_arr) lk = 0 while lk < lnames.length lk = lk + 1 end # Second pass: rescan with locals now in scope for better inference lnames2 = "".split(",") ltypes2 = "".split(",") lnames2 = "".split(",", -1) ltypes2 = "".split(",", -1) scan_locals_first_type(bid, lnames2, ltypes2, pnames_arr) lk2 = 0 while lk2 < lnames2.length # so a `params.fetch(:k, "")` call inside a `def # self.from_raw` widens P.fetch's default param via the # receiver-method unify path inside scan_new_calls. cm_names = @cls_cmeth_names[ci].split(";") cm_bodies = @cls_cmeth_bodies[ci].split(";") cm_names = @cls_cmeth_names[ci].split(";", -1) cm_bodies = @cls_cmeth_bodies[ci].split(";", -1) cm_params = @cls_cmeth_params[ci].split("|", -1) cm_ptypes = @cls_cmeth_ptypes[ci].split("|", -1) saved_meth_cb = @current_method_name @current_class_idx = ci @current_method_name = @cls_names[ci] + "_cls_" + cm_names[cmi] push_scope cpnames = "".split(",") cptypes = "".split(",") cpnames = "".split(",", -1) cptypes = "".split(",", -1) if cmi < cm_params.length cpnames = cm_params[cmi].split(",") cpnames = cm_params[cmi].split(",", -1) end if cmi < cm_ptypes.length cptypes = cm_ptypes[cmi].split(",") cptypes = cm_ptypes[cmi].split(",", -1) end cpk = 0 while cpk < cpnames.length end cpk = cpk + 1 end cml = "".split(",") cmt = "".split(",") cml = "".split(",", -1) cmt = "".split(",", -1) scan_locals_first_type(cbid, cml, cmt, cpnames) clk = 0 while clk < cml.length ci = 0 while ci < @cls_names.length cname = @cls_names[ci] writers = @cls_attr_writers[ci].split(";") names = @cls_ivar_names[ci].split(";") types = @cls_ivar_types[ci].split(";") writers = @cls_attr_writers[ci].split(";", -1) names = @cls_ivar_names[ci].split(";", -1) types = @cls_ivar_types[ci].split(";", -1) changed = 0 k = 0 while k < names.length end ck = 0 while ck < @cls_includes.length incs = @cls_includes[ck].split(";") incs = @cls_includes[ck].split(";", -1) ik = 0 while ik < incs.length if incs[ik] == current_cls_name ci = ci + 1 next end names = @cls_ivar_names[ci].split(";") types = @cls_ivar_types[ci].split(";") defs = @cls_ivar_init_definite[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) types = @cls_ivar_types[ci].split(";", -1) defs = @cls_ivar_init_definite[ci].split(";", -1) # observed_types are the actual concrete types the inference # passes saw written into this slot, accumulated separately from # the running @cls_ivar_types (which apply_rbs_seeds may already definite = 1 end if definite == 1 && k < obs_row.length && obs_row[k] != "" obs_list = obs_row[k].split(",") obs_list = obs_row[k].split(",", -1) oi = 0 while oi < obs_list.length ot = obs_list[oi] if ci >= ret_tbl.length return end rets = ret_tbl[ci].split(";") bodies = ci < body_tbl.length ? body_tbl[ci].split(";") : "".split(",") rets = ret_tbl[ci].split(";", -1) bodies = ci < body_tbl.length ? body_tbl[ci].split(";", -1) : "".split(",", -1) changed = 0 mj = 0 while mj < rets.length # Top-level methods. mi = 0 while mi < @meth_param_types.length pt = @meth_param_types[mi].split(",") pt = @meth_param_types[mi].split(",", -1) changed = 0 pk = 0 while pk < pt.length @meth_return_types[mi] = "bigint" @needs_bigint = 1 elsif @meth_return_types[mi].start_with?("tuple:") tparts_mr = @meth_return_types[mi][6, @meth_return_types[mi].length - 6].split(",") tparts_mr = @meth_return_types[mi][6, @meth_return_types[mi].length - 6].split(",", -1) changed_tup_mr = 0 tpm_i = 0 while tpm_i < tparts_mr.length promote_meth_returns_table(ci, @cls_cmeth_returns) end # Ivars. ivt = @cls_ivar_types[ci].split(";") ivt = @cls_ivar_types[ci].split(";", -1) changed_iv = 0 ik = 0 while ik < ivt.length changed = 0 mj = 0 while mj < all_pt.length pts = all_pt[mj].split(",") pts = all_pt[mj].split(",", -1) pk = 0 while pk < pts.length if pts[pk] == "int" if ci >= tbl.length return end rets = tbl[ci].split(";") rets = tbl[ci].split(";", -1) changed = 0 mj = 0 while mj < rets.length # promote mode lifting the ivars to bigint, the tuple build emit # produces sp_Tuple_bigint_bigint_bigint at the call site, so # the return type slot must move too. tparts_ret = rets[mj][6, rets[mj].length - 6].split(",") tparts_ret = rets[mj][6, rets[mj].length - 6].split(",", -1) changed_tup_ret = 0 tpr_i = 0 while tpr_i < tparts_ret.length if ci < 0 || ci >= @cls_meth_returns.length next end rets = @cls_meth_returns[ci].split(";") rets = @cls_meth_returns[ci].split(";", -1) if midx < rets.length && rets[midx] != rbs_ret rets[midx] = rbs_ret @cls_meth_returns[ci] = rets.join(";") if ci < 0 || ci >= @cls_cmeth_returns.length next end rets = @cls_cmeth_returns[ci].split(";") rets = @cls_cmeth_returns[ci].split(";", -1) if midx < rets.length && rets[midx] != rbs_ret rets[midx] = rbs_ret @cls_cmeth_returns[ci] = rets.join(";") rcname = @nd_name[recv] rci = find_class_idx(rcname) if rci >= 0 && rci < @cls_cmeth_bodies.length cmnames = @cls_cmeth_names[rci].split(";") cmnames = @cls_cmeth_names[rci].split(";", -1) cmj = 0 while cmj < cmnames.length if cmnames[cmj] == mname cmbodies = @cls_cmeth_bodies[rci].split(";") cmbodies = @cls_cmeth_bodies[rci].split(";", -1) if cmj < cmbodies.length bid = cmbodies[cmj].to_i end if ci < 0 || ci >= @cls_meth_bodies.length next end bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) if midx >= bodies.length next end if bid < 0 next end lits = "".split(",") lits = "".split(",", -1) collect_rbs_literal_returns(bid, lits) implicit = rbs_body_implicit_return_literal(bid) if implicit != "" lits.push(implicit) end mnames = @cls_meth_names[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) mname = midx < mnames.length ? mnames[midx] : "?" li = 0 while li < lits.length if ci < 0 || ci >= @cls_cmeth_bodies.length next end bodies = @cls_cmeth_bodies[ci].split(";") bodies = @cls_cmeth_bodies[ci].split(";", -1) if midx >= bodies.length next end if bid < 0 next end lits = "".split(",") lits = "".split(",", -1) collect_rbs_literal_returns(bid, lits) implicit = rbs_body_implicit_return_literal(bid) if implicit != "" lits.push(implicit) end cmnames = @cls_cmeth_names[ci].split(";") cmnames = @cls_cmeth_names[ci].split(";", -1) mname = midx < cmnames.length ? cmnames[midx] : "?" li = 0 while li < lits.length if bid < 0 next end lits = "".split(",") lits = "".split(",", -1) collect_rbs_literal_returns(bid, lits) implicit = rbs_body_implicit_return_literal(bid) if implicit != "" rcname = @nd_name[recv] rci = find_class_idx(rcname) if rci >= 0 mnames_c = @cls_cmeth_names[rci].split(";") mnames_c = @cls_cmeth_names[rci].split(";", -1) cmidx = -1 mc = 0 while mc < mnames_c.length if rbs_pt == "" return end rbs_ptypes = rbs_pt.split(",") rbs_ptypes = rbs_pt.split(",", -1) ak = 0 while ak < arg_ids.length && ak < rbs_ptypes.length arg_id = arg_ids[ak] end key = ci.to_s + "|" + midx.to_s if ptypes_token != "-" && ptypes_token != "" ptypes = ptypes_token.split(",") ptypes = ptypes_token.split(",", -1) cls_meth_ptypes_put(ci, midx, ptypes) rbs_mark_cls_meth_seeded(ci, midx) @cls_meth_rbs_ptypes[key] = ptypes_token end if ret != "-" && ret != "" rets = @cls_meth_returns[ci].split(";") rets = @cls_meth_returns[ci].split(";", -1) if midx < rets.length rets[midx] = ret @cls_meth_returns[ci] = rets.join(";") if ci < 0 || ci >= @cls_cmeth_names.length return false end cmnames = @cls_cmeth_names[ci].split(";") cmnames = @cls_cmeth_names[ci].split(";", -1) midx = -1 j = 0 while j < cmnames.length end key = ci.to_s + "|" + midx.to_s if ptypes_token != "-" && ptypes_token != "" ptypes = ptypes_token.split(",") ptypes = ptypes_token.split(",", -1) cls_cmeth_ptypes_put(ci, midx, ptypes) @cls_cmeth_rbs_ptypes[key] = ptypes_token end if ret != "-" && ret != "" rets = @cls_cmeth_returns[ci].split(";") rets = @cls_cmeth_returns[ci].split(";", -1) if midx < rets.length rets[midx] = ret @cls_cmeth_returns[ci] = rets.join(";") if iname.length > 0 && !iname.start_with?("@") iname = "@" + iname end names = @cls_ivar_names[ci].split(";") types = @cls_ivar_types[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) types = @cls_ivar_types[ci].split(";", -1) j = 0 found = -1 while j < names.length # arbitrate_rbs_vs_inferred_ivars can restore it after the # iterative inference loop, in case some pass widens the slot # off the RBS pin. Issue #626 sub-issue 2. rbs_names = @cls_ivar_names[ci].split(";") rbs_names = @cls_ivar_names[ci].split(";", -1) rbs_types = @cls_ivar_rbs_types[ci].split(";", -1) while rbs_types.length < rbs_names.length rbs_types.push("") # Top-level method params + returns. rmi = 0 while rmi < @meth_names.length rpt = @meth_param_types[rmi].split(",") rpt = @meth_param_types[rmi].split(",", -1) rpi = 0 while rpi < rpt.length if rpt[rpi] != "" rci = 0 while rci < @cls_names.length r_im_pall = @cls_meth_ptypes[rci].split("|", -1) r_im_ret = @cls_meth_returns[rci].split(";") r_im_ret = @cls_meth_returns[rci].split(";", -1) r_imj = 0 while r_imj < r_im_pall.length r_im_pt = r_im_pall[r_imj].split(",") r_im_pt = r_im_pall[r_imj].split(",", -1) r_imk = 0 while r_imk < r_im_pt.length if r_im_pt[r_imk] != "" r_imrj = r_imrj + 1 end r_cmpall = @cls_cmeth_ptypes[rci].split("|", -1) r_cmret = @cls_cmeth_returns[rci].split(";") r_cmret = @cls_cmeth_returns[rci].split(";", -1) r_cmj = 0 while r_cmj < r_cmpall.length r_cmpt = r_cmpall[r_cmj].split(",") r_cmpt = r_cmpall[r_cmj].split(",", -1) r_cmk = 0 while r_cmk < r_cmpt.length if r_cmpt[r_cmk] != "" r_cmrj = r_cmrj + 1 end # ivars r_ivt = @cls_ivar_types[rci].split(";") r_ivt = @cls_ivar_types[rci].split(";", -1) r_ivj = 0 while r_ivj < r_ivt.length if r_ivt[r_ivj] != "" # Top-level + module class methods params. bmi = 0 while bmi < @meth_names.length bpn = @meth_param_names[bmi].split(",") bpt = @meth_param_types[bmi].split(",") bpn = @meth_param_names[bmi].split(",", -1) bpt = @meth_param_types[bmi].split(",", -1) bj = 0 while bj < bpn.length if bj < bpt.length bcn = @cls_names[bci] b_im_pn = @cls_meth_params[bci].split("|", -1) b_im_pt = @cls_meth_ptypes[bci].split("|", -1) b_im_mn = @cls_meth_names[bci].split(";") b_im_rn = @cls_meth_returns[bci].split(";") b_im_mn = @cls_meth_names[bci].split(";", -1) b_im_rn = @cls_meth_returns[bci].split(";", -1) b_imj = 0 while b_imj < b_im_pn.length b_im_n = b_im_pn[b_imj].split(",") b_im_t = b_im_pt[b_imj].split(",") b_im_n = b_im_pn[b_imj].split(",", -1) b_im_t = b_im_pt[b_imj].split(",", -1) b_im_mname = b_imj < b_im_mn.length ? b_im_mn[b_imj] : "?" b_imk = 0 while b_imk < b_im_n.length end b_cm_pn = @cls_cmeth_params[bci].split("|", -1) b_cm_pt = @cls_cmeth_ptypes[bci].split("|", -1) b_cm_mn = @cls_cmeth_names[bci].split(";") b_cm_rn = @cls_cmeth_returns[bci].split(";") b_cm_mn = @cls_cmeth_names[bci].split(";", -1) b_cm_rn = @cls_cmeth_returns[bci].split(";", -1) b_cmj = 0 while b_cmj < b_cm_pn.length b_cm_n = b_cm_pn[b_cmj].split(",") b_cm_t = b_cm_pt[b_cmj].split(",") b_cm_n = b_cm_pn[b_cmj].split(",", -1) b_cm_t = b_cm_pt[b_cmj].split(",", -1) b_cm_mname = b_cmj < b_cm_mn.length ? b_cm_mn[b_cmj] : "?" b_cmk = 0 while b_cmk < b_cm_n.length end b_cmj = b_cmj + 1 end b_ivn = @cls_ivar_names[bci].split(";") b_ivt = @cls_ivar_types[bci].split(";") b_ivn = @cls_ivar_names[bci].split(";", -1) b_ivt = @cls_ivar_types[bci].split(";", -1) b_ivj = 0 while b_ivj < b_ivn.length if b_ivj < b_ivt.length def pre_detect_bigint stmts = get_body_stmts(@root_id) bigint_names = "".split(",") bigint_names = "".split(",", -1) stmts.each { |sid| scan_bigint_candidates(sid, bigint_names) } return 0 end # Search for assignments where src == var_name pairs = @bi_assigns.split(",") pairs = @bi_assigns.split(",", -1) i = 0 while i < pairs.length parts = pairs[i].split(":") # them here also means codegen no longer needs them once it stops # doing its own scope refinement. def detect_bigint_vars(stmts, names, types) bigint_names = "".split(",") bigint_names = "".split(",", -1) stmts.each { |sid| scan_bigint_candidates(sid, bigint_names) } def scan_bigint_propagate(stmts, names, types) changed = 1 iter = 0 sig_hist = "".split(",") sig_hist = "".split(",", -1) while changed == 1 iter = iter + 1 if iter > 256 # Build into a local array and assign at the end. # (Pushing directly to @sym_names in this loop triggers a # self-host codegen regression — see HANDOFF notes.) local = "".split(",") local = "".split(",", -1) i = 0 while i < @nd_type.length t = @nd_type[i] elsif t == "StatementsNode" stmts = @nd_stmts[bid] if stmts != "" parts = stmts.split(",") parts = stmts.split(",", -1) if parts.length == 1 sid = parts[0].to_i if sid >= 0 && sid < @nd_count && @nd_type[sid] == "InstanceVariableWriteNode" if mnames_str == "" return 0 end mnames = mnames_str.split(";") bodies = @cls_meth_bodies[ci].split(";") writers = @cls_attr_writers[ci].split(";") mnames = mnames_str.split(";", -1) bodies = @cls_meth_bodies[ci].split(";", -1) writers = @cls_attr_writers[ci].split(";", -1) mi = 0 while mi < mnames.length mn = mnames[mi] while i < @cls_names.length mnames_str = @cls_meth_names[i] if mnames_str != "" mnames = mnames_str.split(";") bodies = @cls_meth_bodies[i].split(";") writers = @cls_attr_writers[i].split(";") mnames = mnames_str.split(";", -1) bodies = @cls_meth_bodies[i].split(";", -1) writers = @cls_attr_writers[i].split(";", -1) mi = 0 while mi < mnames.length mn = mnames[mi] if t == "StatementsNode" stmts = @nd_stmts[bid] if stmts != "" parts = stmts.split(",") parts = stmts.split(",", -1) if parts.length == 1 sid = parts[0].to_i if sid >= 0 && sid < @nd_count while i < @cls_names.length mnames_str = @cls_meth_names[i] if mnames_str != "" mnames = mnames_str.split(";") bodies = @cls_meth_bodies[i].split(";") readers = @cls_attr_readers[i].split(";") mnames = mnames_str.split(";", -1) bodies = @cls_meth_bodies[i].split(";", -1) readers = @cls_attr_readers[i].split(";", -1) mi = 0 while mi < mnames.length mn = mnames[mi] # such classes from the value-type optimization keeps `<C>` heap- # allocated, so the constructor returns `sp_<C> *` and boxing is # well-typed. Mirrors the ptr_array exclusion . @poly_returned_types = "".split(",") @poly_returned_types = "".split(",", -1) mi = 0 while mi < @meth_names.length if mi < @meth_return_types.length && @meth_return_types[mi] == "poly" end ci = 0 while ci < @cls_names.length bodies = @cls_meth_bodies[ci].split(";") returns = @cls_meth_returns[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) returns = @cls_meth_returns[ci].split(";", -1) mj = 0 while mj < bodies.length if mj < returns.length && returns[mj] == "poly" # same struct-by-void-* mismatch the ptr_array / poly-return # passes already guard against. def detect_poly_arg_passed_types @poly_arg_passed_types = "".split(",") @poly_arg_passed_types = "".split(",", -1) nid = 0 while nid < @nd_type.length if @nd_type[nid] == "CallNode" if mfn != "" mi = find_method_idx(mfn) if mi >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) args_id = @nd_arguments[nid] if args_id >= 0 arg_ids = get_args(args_id) if init_idx >= 0 all_params = @cls_meth_params[ci2].split("|", -1) all_ptypes = @cls_meth_ptypes[ci2].split("|", -1) pnames2 = "".split(",") ptypes2 = "".split(",") pnames2 = "".split(",", -1) ptypes2 = "".split(",", -1) if init_idx < all_params.length pnames2 = all_params[init_idx].split(",") pnames2 = all_params[init_idx].split(",", -1) end if init_idx < all_ptypes.length ptypes2 = all_ptypes[init_idx].split(",") ptypes2 = all_ptypes[init_idx].split(",", -1) end args_id2 = @nd_arguments[nid] if args_id2 >= 0 # `_push` takes `void *`; if `<C>` were optimized into a value type # then `sp_<C>_new(...)` would return the struct by value and the # generated push call would be a C type error. @ptr_array_stored_types = "".split(",") @ptr_array_stored_types = "".split(",", -1) nid = 0 while nid < @nd_type.length if @nd_type[nid] == "ArrayNode" def detect_param_mutated_types # Find classes whose instances are mutated when passed as method parameters @param_mutated_types = "".split(",") @param_mutated_types = "".split(",", -1) i = 0 while i < @cls_names.length mnames_str = @cls_meth_names[i] if mnames_str != "" mnames = mnames_str.split(";") mnames = mnames_str.split(";", -1) all_params = @cls_meth_params[i].split("|", -1) all_ptypes = @cls_meth_ptypes[i].split("|", -1) bodies = @cls_meth_bodies[i].split(";") bodies = @cls_meth_bodies[i].split(";", -1) mi = 0 while mi < mnames.length if mi < bodies.length && mi < all_params.length bid = bodies[mi].to_i pnames = all_params[mi].split(",") ptypes = "".split(",") pnames = all_params[mi].split(",", -1) ptypes = "".split(",", -1) if mi < all_ptypes.length ptypes = all_ptypes[mi].split(",") ptypes = all_ptypes[mi].split(",", -1) end # Collect object-type param names obj_param_names = "".split(",") obj_param_types = "".split(",") obj_param_names = "".split(",", -1) obj_param_types = "".split(",", -1) pj = 0 while pj < pnames.length pt = "int" mi = 0 while mi < @meth_names.length bid = @meth_body_ids[mi] pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") obj_param_names = "".split(",") obj_param_types = "".split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) obj_param_names = "".split(",", -1) obj_param_types = "".split(",", -1) pj = 0 while pj < pnames.length pt = "int" # `<recv>.method(:foo)` can resolve `<recv>` (a local, an ivar via # attr_reader, or a chained call) back to its `obj_<X>` type. def detect_method_taken_classes @method_taken_class_indices = "".split(",") @method_taken_class_indices = "".split(",", -1) # Walk class methods first. i = 0 while i < @cls_names.length mnames_str = @cls_meth_names[i] if mnames_str != "" mnames = mnames_str.split(";") mnames = mnames_str.split(";", -1) all_params = @cls_meth_params[i].split("|", -1) all_ptypes = @cls_meth_ptypes[i].split("|", -1) bodies = @cls_meth_bodies[i].split(";") bodies = @cls_meth_bodies[i].split(";", -1) saved_ci = @current_class_idx @current_class_idx = i mi = 0 if @nd_type[@root_id] == "ProgramNode" stmts = get_body_stmts(@root_id) push_scope lnames = "".split(",") ltypes = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) sk = 0 while sk < stmts.length scan_locals(stmts[sk], lnames, ltypes, "".split(",")) scan_locals(stmts[sk], lnames, ltypes, "".split(",", -1)) sk = sk + 1 end lk = 0 def method_taken_walk_with_scope(bid, pnames_str, ptypes_str, enclosing_ci) push_scope pnames = pnames_str.split(",") ptypes = ptypes_str.split(",") pnames = pnames_str.split(",", -1) ptypes = ptypes_str.split(",", -1) k = 0 while k < pnames.length pt = "int" declare_var(pnames[k], pt) k = k + 1 end lnames = "".split(",") ltypes = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) scan_locals(bid, lnames, ltypes, pnames) lk = 0 while lk < lnames.length 2.times do i = 0 while i < @cls_names.length names = @cls_ivar_names[i].split(";") types = @cls_ivar_types[i].split(";") names = @cls_ivar_names[i].split(";", -1) types = @cls_ivar_types[i].split(";", -1) # Value-type candidates: small immutable scalar classes. # Limit to 8 ivars so the struct stays register-friendly. if names.length > 0 && names.length <= 8 if cls_has_self_mutating_methods(i) == 1 all_val = 0 end writers = @cls_attr_writers[i].split(";") writers = @cls_attr_writers[i].split(";", -1) if writers.length > 0 && writers[0] != "" all_val = 0 end i = i + 1 next end names = @cls_ivar_names[i].split(";") types = @cls_ivar_types[i].split(";") names = @cls_ivar_names[i].split(";", -1) types = @cls_ivar_types[i].split(";", -1) eligible = 1 if names.length == 0 || names.length > 8 eligible = 0 end # Only initialize + attr_* methods (no custom methods). if eligible == 1 mnames = @cls_meth_names[i].split(";") readers = @cls_attr_readers[i].split(";") writers = @cls_attr_writers[i].split(";") mnames = @cls_meth_names[i].split(";", -1) readers = @cls_attr_readers[i].split(";", -1) writers = @cls_attr_writers[i].split(";", -1) mk = 0 while mk < mnames.length mn = mnames[mk] def ivar_in_chain(ci, iname) names = @cls_ivar_names[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) k = 0 while k < names.length if names[k] == iname if @cls_meth_idx_cache.key?(ck) return @cls_meth_idx_cache[ck] end mnames = @cls_meth_names[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) j = 0 while j < mnames.length if mnames[j] == mname # site closes with two join() calls. def cls_meth_ptypes_get(ci, midx) if ci < 0 || ci >= @cls_meth_ptypes.length || midx < 0 return "".split(",") return "".split(",", -1) end if @cmp_outer_version != @cls_meth_ptypes_version || @cmp_outer_ci != ci @cmp_outer_split = @cls_meth_ptypes[ci].split("|", -1) @cmp_outer_version = @cls_meth_ptypes_version end if midx >= @cmp_outer_split.length return "".split(",") return "".split(",", -1) end @cmp_outer_split[midx].split(",") @cmp_outer_split[midx].split(",", -1) end def cls_meth_ptypes_put(ci, midx, ptypes) def cls_meth_pnames_get(ci, midx) if ci < 0 || ci >= @cls_meth_params.length || midx < 0 return "".split(",") return "".split(",", -1) end if @cmn_outer_version != @cls_meth_params_version || @cmn_outer_ci != ci @cmn_outer_split = @cls_meth_params[ci].split("|", -1) @cmn_outer_version = @cls_meth_params_version end if midx >= @cmn_outer_split.length return "".split(",") return "".split(",", -1) end @cmn_outer_split[midx].split(",") @cmn_outer_split[midx].split(",", -1) end def cls_cmeth_ptypes_get(ci, midx) if ci < 0 || ci >= @cls_cmeth_ptypes.length || midx < 0 return "".split(",") return "".split(",", -1) end if @ccmp_outer_version != @cls_cmeth_ptypes_version || @ccmp_outer_ci != ci @ccmp_outer_split = @cls_cmeth_ptypes[ci].split("|", -1) @ccmp_outer_version = @cls_cmeth_ptypes_version end if midx >= @ccmp_outer_split.length return "".split(",") return "".split(",", -1) end @ccmp_outer_split[midx].split(",") @ccmp_outer_split[midx].split(",", -1) end def cls_cmeth_ptypes_put(ci, midx, ptypes) def cls_cmeth_pnames_get(ci, midx) if ci < 0 || ci >= @cls_cmeth_params.length || midx < 0 return "".split(",") return "".split(",", -1) end if @ccmn_outer_version != @cls_cmeth_params_version || @ccmn_outer_ci != ci @ccmn_outer_split = @cls_cmeth_params[ci].split("|", -1) @ccmn_outer_version = @cls_cmeth_params_version end if midx >= @ccmn_outer_split.length return "".split(",") return "".split(",", -1) end @ccmn_outer_split[midx].split(",") @ccmn_outer_split[midx].split(",", -1) end # Walk the inheritance chain starting at class `ci` looking for the while iter < 8 i = 0 while i < @cls_names.length cmnames = @cls_cmeth_names[i].split(";") cm_bodies = @cls_cmeth_bodies[i].split(";") cmnames = @cls_cmeth_names[i].split(";", -1) cm_bodies = @cls_cmeth_bodies[i].split(";", -1) j = 0 while j < cmnames.length if cmnames[j] != "" && cls_cmeth_is_live(i, cmnames[j]) == 1 "+", "-", "*", "/", "%", "<<", "coerce", "<<="] ci = 0 while ci < @cls_names.length mnames_init = @cls_meth_names[ci].split(";") mnames_init = @cls_meth_names[ci].split(";", -1) mj_init = 0 while mj_init < mnames_init.length ai = 0 end # Step 2/3: collect every CallNode name + SymbolNode value, mark # methods on every class that has them. # `"".split(",")` initializer types `used` as a str_array, since # `"".split(",", -1)` initializer types `used` as a str_array, since # `acc` in collect_used_method_names is pushed strings only. used = "".split(",") used = "".split(",", -1) collect_used_method_names(@root_id, used) # Lifted instance_eval blocks: their bodies were detached from # @root_id by ieval_rewrite_call and stashed in @ieval_body_ids, end ci_b = 0 while ci_b < @cls_names.length mb_list = @cls_meth_bodies[ci_b].split(";") mb_list = @cls_meth_bodies[ci_b].split(";", -1) mbk = 0 while mbk < mb_list.length bid_mb = mb_list[mbk].to_i end mbk = mbk + 1 end cmb_list = @cls_cmeth_bodies[ci_b].split(";") cmb_list = @cls_cmeth_bodies[ci_b].split(";", -1) cmbk = 0 while cmbk < cmb_list.length bid_cmb = cmb_list[cmbk].to_i uname = used[ui] ci2 = 0 while ci2 < @cls_names.length mns = @cls_meth_names[ci2].split(";") mns = @cls_meth_names[ci2].split(";", -1) mj2 = 0 while mj2 < mns.length if mns[mj2] == uname if ci < 0 || ci >= @cls_names.length return end cmnames = @cls_cmeth_names[ci].split(";") cmnames = @cls_cmeth_names[ci].split(";", -1) has = 0 k = 0 while k < cmnames.length mod_name = @nd_name[inner_recv] resolved = module_acc_resolved(mod_name, @nd_name[recv]) if resolved != "" && resolved != "?" rnames = resolved.split(";") rnames = resolved.split(";", -1) ri = 0 while ri < rnames.length tci2 = find_class_idx(rnames[ri]) # by an explicit literal write, "" otherwise. Reset when called with # a fresh (empty) names array. if names.length == 0 @scan_literal_flags = "".split(",") @scan_literal_flags = "".split(",", -1) # Parallel to `names`: "1" if every write to this local so far was # an empty `[]` literal — used to defer the array element type # until first `push` . A subsequent write with a # concrete element resets the flag to "". @scan_empty_flags = "".split(",") @scan_empty_flags = "".split(",", -1) # Parallel to `names`: "1" if the FIRST write to this local was an # empty `{}` literal — promote_empty_hash_local_writes uses this to # decide whether to refine str_int_hash (the empty-hash default) # to a more specific variant on first []= write. @scan_empty_hash_flags = "".split(",") @scan_empty_hash_flags = "".split(",", -1) end # `case x in [a, b, c]` -- the bound LVs in the array pattern's # requireds list need to live in the surrounding scope so the icm_aargs = get_args(icm_args_id) icm_all_ptypes = @cls_meth_ptypes[icm_owner_ci].split("|", -1) icm_all_empty = @cls_meth_ptypes_empty[icm_owner_ci].split("|", -1) icm_ptypes = "".split(",") icm_empties = "".split(",") icm_ptypes = "".split(",", -1) icm_empties = "".split(",", -1) if icm_midx < icm_all_ptypes.length icm_ptypes = icm_all_ptypes[icm_midx].split(",") icm_ptypes = icm_all_ptypes[icm_midx].split(",", -1) end if icm_midx < icm_all_empty.length icm_empties = icm_all_empty[icm_midx].split(",") icm_empties = icm_all_empty[icm_midx].split(",", -1) end icm_changed = 0 icm_k = 0 ea_args_id = @nd_arguments[nid] if ea_args_id >= 0 ea_aargs = get_args(ea_args_id) ea_ptypes = @meth_param_types[ea_mi].split(",") ea_ptypes = @meth_param_types[ea_mi].split(",", -1) ea_empty_str = "" if ea_mi < @meth_param_empty.length ea_empty_str = @meth_param_empty[ea_mi] end ea_empties = ea_empty_str.split(",") ea_empties = ea_empty_str.split(",", -1) ea_changed = 0 ea_k = 0 while ea_k < ea_aargs.length if owner_ci_each >= 0 owner_midx_each = cls_find_method(owner_ci_each, mname) arity_each = cls_method_yield_arity(owner_ci_each, owner_midx_each) ytypes_each = "".split(",") ytypes_each = "".split(",", -1) ka = 0 while ka < arity_each ytypes_each.push("") # default) and we'd miss the body-driven type. if ybid_each >= 0 push_scope yl_names = "".split(",") yl_types = "".split(",") yl_names = "".split(",", -1) yl_types = "".split(",", -1) saved_ci_each = @current_class_idx @current_class_idx = owner_ci_each scan_locals(ybid_each, yl_names, yl_types, "".split(",")) scan_locals(ybid_each, yl_names, yl_types, "".split(",", -1)) yj = 0 while yj < yl_names.length declare_var(yl_names[yj], yl_types[yj]) ybid_628 = @meth_body_ids[mi_628] if ybid_628 >= 0 arity_628 = method_yield_arity(mi_628) ytypes_628 = "".split(",") ytypes_628 = "".split(",", -1) ka_628 = 0 while ka_628 < arity_628 ytypes_628.push("") ka_628 = ka_628 + 1 end push_scope yl_names_628 = "".split(",") yl_types_628 = "".split(",") scan_locals(ybid_628, yl_names_628, yl_types_628, "".split(",")) yl_names_628 = "".split(",", -1) yl_types_628 = "".split(",", -1) scan_locals(ybid_628, yl_names_628, yl_types_628, "".split(",", -1)) yj_628 = 0 while yj_628 < yl_names_628.length declare_var(yl_names_628[yj_628], yl_types_628[yj_628]) return @current_method_name[0, cls_idx] end if @current_class_idx >= 0 && @current_class_idx < @cls_names.length cm = @cls_cmeth_names[@current_class_idx].split(";") cm = @cls_cmeth_names[@current_class_idx].split(";", -1) k = 0 while k < cm.length if cm[k] == @current_method_name # parent chain so a subclass call to an inherited # attr_accessor reader is recognised (issue #508 analyze side). def cls_has_attr_reader(ci, mname) readers = @cls_attr_readers[ci].split(";") readers = @cls_attr_readers[ci].split(";", -1) j = 0 while j < readers.length if readers[j] == mname if obs == "" return 0 end distinct = obs.split(",") distinct = obs.split(",", -1) saw_any = 0 di = 0 while di < distinct.length return @lv_alias_cache[cache_key] end found = "" bodies = @cls_meth_bodies[@current_class_idx].split(";") bodies = @cls_meth_bodies[@current_class_idx].split(";", -1) bi = 0 while bi < bodies.length bid = bodies[bi].to_i if ci < 0 || ci >= @cls_ivar_observed_types.length return "" end names = @cls_ivar_names[ci].split(";") names = @cls_ivar_names[ci].split(";", -1) parts = @cls_ivar_observed_types[ci].split(";", -1) k = 0 while k < names.length have_poly = 0 seen_non_obj = 0 if obs != "" parts = obs.split(",") parts = obs.split(",", -1) k = 0 while k < parts.length t = parts[k] return "" end if walked != "" walked.split(",").each { |w| out = obs_add(out, w) } walked.split(",", -1).each { |w| out = obs_add(out, w) } end if out == "" return "" if out == "" return cidx_str end cur = out.split(",") cur = out.split(",", -1) k = 0 while k < cur.length if cur[k] == cidx_str return @ivar_concrete_recover_cache[ck] end out = "" mnames_w = @cls_meth_names[ci].split(";") bodies_w = @cls_meth_bodies[ci].split(";") mnames_w = @cls_meth_names[ci].split(";", -1) bodies_w = @cls_meth_bodies[ci].split(";", -1) mi_w = 0 while mi_w < mnames_w.length bid_w = -1 return "?" end if result_for_meth != "" result_for_meth.split(",").each { |w| out = obs_add(out, w) } result_for_meth.split(",", -1).each { |w| out = obs_add(out, w) } end end mi_w = mi_w + 1 if call_obs == "?" poison = 1 elsif call_obs != "" call_obs.split(",").each { |w| out = obs_add(out, w) } call_obs.split(",", -1).each { |w| out = obs_add(out, w) } end end end if ci < 0 return "" end mnames = @cls_meth_names[ci].split(";") mnames = @cls_meth_names[ci].split(";", -1) j = 0 while j < mnames.length if mnames[j] == mname end # if midx is out of range or the body id is invalid. Centralises # the @cls_meth_bodies[ci].split(";")[midx].to_i parse so detectors # the @cls_meth_bodies[ci].split(";", -1)[midx].to_i parse so detectors # don't have to inline it. def cls_method_body_id(ci, midx) bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) if midx >= bodies.length return -1 end end def cls_method_has_yield(ci, midx) ystr = @cls_meth_has_yield[ci].split(";") ystr = @cls_meth_has_yield[ci].split(";", -1) if midx < ystr.length if ystr[midx] == "1" return 1 if ci < 0 || midx < 0 return 1 end bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) if midx >= bodies.length return 1 end # (one per reachable node, ~150K on spinel_codegen.rb) that # quadratic blew up the spinel-compiled binary's heap to 60GB # before crashing. rec_buf = "".split(",") rec_buf = "".split(",", -1) ni = 0 while ni < @nd_count t = @nd_inferred_type[ni] if nt == "CallNode" && @nd_receiver[nid] < 0 && @nd_name[nid] != "new" && @current_class_idx >= 0 mn_check = @nd_name[nid] if find_method_idx(mn_check) < 0 cmnames_check = @cls_cmeth_names[@current_class_idx].split(";") cmnames_check = @cls_cmeth_names[@current_class_idx].split(";", -1) ccheck = 0 while ccheck < cmnames_check.length if cmnames_check[ccheck] == mn_check # Refinement passes — re-scan with declared scope; promote refined types. pass = 0 while pass < 2 ln = "".split(",") lt = "".split(",") ln = "".split(",", -1) lt = "".split(",", -1) si = 0 while si < stmts.length sid = stmts[si] ybid_bp = @meth_body_ids[mi_bp] if ybid_bp >= 0 arity_bp = method_yield_arity(mi_bp) ytypes_bp = "".split(",") ytypes_bp = "".split(",", -1) ka_bp = 0 while ka_bp < arity_bp ytypes_bp.push("") ka_bp = ka_bp + 1 end push_scope yl_names_bp = "".split(",") yl_types_bp = "".split(",") scan_locals(ybid_bp, yl_names_bp, yl_types_bp, "".split(",")) yl_names_bp = "".split(",", -1) yl_types_bp = "".split(",", -1) scan_locals(ybid_bp, yl_names_bp, yl_types_bp, "".split(",", -1)) yj_bp = 0 while yj_bp < yl_names_bp.length declare_var(yl_names_bp[yj_bp], yl_types_bp[yj_bp]) ybid_bp = @meth_body_ids[mi_bp] if ybid_bp >= 0 arity_bp = method_yield_arity(mi_bp) ytypes_bp = "".split(",") ytypes_bp = "".split(",", -1) ka_bp = 0 while ka_bp < arity_bp ytypes_bp.push("") ka_bp = ka_bp + 1 end push_scope yl_names_bp = "".split(",") yl_types_bp = "".split(",") scan_locals(ybid_bp, yl_names_bp, yl_types_bp, "".split(",")) yl_names_bp = "".split(",", -1) yl_types_bp = "".split(",", -1) scan_locals(ybid_bp, yl_names_bp, yl_types_bp, "".split(",", -1)) yj_bp = 0 while yj_bp < yl_names_bp.length declare_var(yl_names_bp[yj_bp], yl_types_bp[yj_bp]) j = j + 1 end # Pass 2: re-scan with vars declared lnames2 = "".split(",") ltypes2 = "".split(",") lnames2 = "".split(",", -1) ltypes2 = "".split(",", -1) scan_locals(bid, lnames2, ltypes2, params) j = 0 while j < lnames2.length # set pp's scope to the merged type; redo scan_locals so the # `[]=` arm now sees pp resolved to its real type and re-picks # the right hash variant. Mirror the merge rules from pass 2. lnames3 = "".split(",") ltypes3 = "".split(",") lnames3 = "".split(",", -1) ltypes3 = "".split(",", -1) scan_locals(bid, lnames3, ltypes3, params) j = 0 while j < lnames3.length j = 0 while j < lnames.length if is_hash_type(ltypes[j]) == 1 && ltypes[j].include?("poly") == false obs_p5 = "".split(",") obs_p5 = "".split(",", -1) collect_param_callee_slots(bid, lnames[j], obs_p5) cur_kt_p5 = hash_key_part(ltypes[j]) agreed_p5 = "" while mi < @meth_names.length bid_h = @meth_body_ids[mi] if bid_h >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) changed = 0 pk = 0 while pk < pnames.length while ci < @cls_names.length all_params = @cls_meth_params[ci].split("|", -1) all_ptypes = @cls_meth_ptypes[ci].split("|", -1) bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) cls_changed = 0 mj = 0 while mj < all_params.length bid_c = bodies[mj].to_i end if bid_c >= 0 cm_pnames = all_params[mj].split(",") cm_ptypes = "".split(",") cm_pnames = all_params[mj].split(",", -1) cm_ptypes = "".split(",", -1) if mj < all_ptypes.length cm_ptypes = all_ptypes[mj].split(",") cm_ptypes = all_ptypes[mj].split(",", -1) end m_changed = 0 pk2 = 0 while mi < @meth_names.length bid_h = @meth_body_ids[mi] if bid_h >= 0 pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) each_widen_walk(bid_h, pnames, ptypes) end mi = mi + 1 while ci < @cls_names.length all_params = @cls_meth_params[ci].split("|", -1) all_ptypes = @cls_meth_ptypes[ci].split("|", -1) bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) mj = 0 while mj < all_params.length bid_c = -1 bid_c = bodies[mj].to_i end if bid_c >= 0 cm_pnames = all_params[mj].split(",") cm_ptypes = "".split(",") cm_pnames = all_params[mj].split(",", -1) cm_ptypes = "".split(",", -1) if mj < all_ptypes.length cm_ptypes = all_ptypes[mj].split(",") cm_ptypes = all_ptypes[mj].split(",", -1) end each_widen_walk(bid_c, cm_pnames, cm_ptypes) end while ci < @cls_names.length all_params = @cls_cmeth_params[ci].split("|", -1) all_ptypes = @cls_cmeth_ptypes[ci].split("|", -1) bodies = @cls_cmeth_bodies[ci].split(";") bodies = @cls_cmeth_bodies[ci].split(";", -1) mj = 0 while mj < all_params.length bid_c = -1 bid_c = bodies[mj].to_i end if bid_c >= 0 cm_pnames = all_params[mj].split(",") cm_ptypes = "".split(",") cm_pnames = all_params[mj].split(",", -1) cm_ptypes = "".split(",", -1) if mj < all_ptypes.length cm_ptypes = all_ptypes[mj].split(",") cm_ptypes = all_ptypes[mj].split(",", -1) end each_widen_walk(bid_c, cm_pnames, cm_ptypes) end cls_name_w = @nd_name[recv_w] ci_w = find_class_idx(cls_name_w) if ci_w >= 0 cm_names_w = @cls_cmeth_names[ci_w].split(";") cm_names_w = @cls_cmeth_names[ci_w].split(";", -1) cmpall_w = @cls_cmeth_ptypes[ci_w].split("|", -1) cmi_w = 0 while cmi_w < cm_names_w.length if cm_names_w[cmi_w] == mname_w && cmi_w < cmpall_w.length cmpt_w = cmpall_w[cmi_w].split(",") cmpt_w = cmpall_w[cmi_w].split(",", -1) arg_ids_w = get_args(args_id_w) ai_w = 0 changed_w = 0 return "" end # Track all observed value types via a single string accumulator. val_types = "".split(",") key_types = "".split(",") val_types = "".split(",", -1) key_types = "".split(",", -1) collect_param_hash_writes(nid, pname, val_types, key_types) # also harvest signals from `pname.each do |k, v|` # block bodies. Programs that read-only-iterate the hash never # ---- Top-level main ---- push_scope stmts = get_body_stmts(@root_id) ml = "".split(",") mt = "".split(",") empty_p = "".split(",") ml = "".split(",", -1) mt = "".split(",", -1) empty_p = "".split(",", -1) refine_locals_multi_pass_full(stmts, ml, mt, empty_p, 1, 1) @nd_scope_names[@root_id] = ml.join("|") @nd_scope_types[@root_id] = mt.join("|") push_scope saved_method_name = @current_method_name @current_method_name = @meth_names[mi] pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) pk = 0 while pk < pnames.length if pnames[pk] != "" end pk = pk + 1 end ml = "".split(",") mt = "".split(",") ml = "".split(",", -1) mt = "".split(",", -1) refine_method_body_locals(bid, ml, mt, pnames) @nd_scope_names[bid] = ml.join("|") @nd_scope_types[bid] = mt.join("|") while ci < @cls_names.length saved_ci = @current_class_idx @current_class_idx = ci bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) bj = 0 while bj < bodies.length bid = bodies[bj].to_i declare_var(pnames2[pk], pt) pk = pk + 1 end ml2 = "".split(",") mt2 = "".split(",") ml2 = "".split(",", -1) mt2 = "".split(",", -1) refine_method_body_locals(bid, ml2, mt2, pnames2) @nd_scope_names[bid] = ml2.join("|") @nd_scope_types[bid] = mt2.join("|") end bj = bj + 1 end cm_bodies = @cls_cmeth_bodies[ci].split(";") cm_names = @cls_cmeth_names[ci].split(";") cm_bodies = @cls_cmeth_bodies[ci].split(";", -1) cm_names = @cls_cmeth_names[ci].split(";", -1) saved_meth = @current_method_name # Build per-(ci, cmj) scope tables alongside the per-bid # @nd_scope_names entry. Inherited cmeths share their body id # leaving every other subclass with the wrong LV types — see # Comment.find returning sp_Article *). Per-(ci, cmj) keeps # each subclass's specialized result alive for codegen. cms_per_ci = "".split(",") cmt_per_ci = "".split(",") cms_per_ci = "".split(",", -1) cmt_per_ci = "".split(",", -1) cbj = 0 while cbj < cm_bodies.length cbid = cm_bodies[cbj].to_i declare_var(cpnames[cpk], cpt) cpk = cpk + 1 end cml = "".split(",") cmt = "".split(",") cml = "".split(",", -1) cmt = "".split(",", -1) refine_method_body_locals(cbid, cml, cmt, cpnames) @nd_scope_names[cbid] = cml.join("|") @nd_scope_types[cbid] = cmt.join("|") # their typed slots, then refine body locals with those names # excluded from the rescan so reassigns hit the param slot # rather than inventing a fresh local of the RHS type. ie_pnames = "".split(",") ie_pnames = "".split(",", -1) spn_iv = "" if iv < @ieval_self_param_names.length spn_iv = @ieval_self_param_names[iv] if iv < @ieval_extra_param_names.length extra_iv_csv = @ieval_extra_param_names[iv] end extra_iv_names = "".split(",") extra_iv_names = "".split(",", -1) if extra_iv_csv != "" extra_iv_names = extra_iv_csv.split(";") extra_iv_names = extra_iv_csv.split(";", -1) end kex_iv = 0 while kex_iv < extra_iv_names.length ie_pnames.push(extra_iv_names[kex_iv]) kex_iv = kex_iv + 1 end ml_iv = "".split(",") mt_iv = "".split(",") ml_iv = "".split(",", -1) mt_iv = "".split(",", -1) refine_method_body_locals(bid_iv, ml_iv, mt_iv, ie_pnames) # Order: self-bound at slot 0, extras, then body locals. final_names = "".split(",") final_types = "".split(",") final_names = "".split(",", -1) final_types = "".split(",", -1) if spn_iv != "" final_names.push(spn_iv) final_types.push("obj_" + @cls_names[@ieval_class_idxs[iv]]) end if body_bn >= 0 # Collect syntactic block param names bp_list = "".split(",") bp_list = "".split(",", -1) params_n = @nd_parameters[bn] if params_n >= 0 inner_p = @nd_parameters[params_n] end end end bn_names = "".split(",") bn_types = "".split(",") bn_names = "".split(",", -1) bn_types = "".split(",", -1) scan_locals(body_bn, bn_names, bn_types, bp_list) @nd_scope_names[body_bn] = bn_names.join("|") @nd_scope_types[body_bn] = bn_types.join("|") # ---- Top-level (main) ---- stmts = get_body_stmts(@root_id) push_scope empty_p = "".split(",") ml = "".split(",") mt = "".split(",") empty_p = "".split(",", -1) ml = "".split(",", -1) mt = "".split(",", -1) refine_locals_multi_pass_full(stmts, ml, mt, empty_p, 1, 1) si = 0 while si < stmts.length push_scope saved_method_name = @current_method_name @current_method_name = @meth_names[mi] pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") pnames = @meth_param_names[mi].split(",", -1) ptypes = @meth_param_types[mi].split(",", -1) pk = 0 while pk < pnames.length if pnames[pk] != "" end pk = pk + 1 end lnames = "".split(",") ltypes = "".split(",") lnames = "".split(",", -1) ltypes = "".split(",", -1) refine_method_body_locals(bid, lnames, ltypes, pnames) walk_and_cache(bid) @current_method_name = saved_method_name while ci < @cls_names.length saved_ci = @current_class_idx @current_class_idx = ci bodies = @cls_meth_bodies[ci].split(";") bodies = @cls_meth_bodies[ci].split(";", -1) bj = 0 while bj < bodies.length bid = bodies[bj].to_i declare_var(pnames2[pk], pt) pk = pk + 1 end ml2 = "".split(",") mt2 = "".split(",") ml2 = "".split(",", -1) mt2 = "".split(",", -1) refine_method_body_locals(bid, ml2, mt2, pnames2) walk_and_cache(bid) pop_scope end bj = bj + 1 end cm_bodies = @cls_cmeth_bodies[ci].split(";") cm_names = @cls_cmeth_names[ci].split(";") cm_bodies = @cls_cmeth_bodies[ci].split(";", -1) cm_names = @cls_cmeth_names[ci].split(";", -1) saved_meth = @current_method_name cbj = 0 while cbj < cm_bodies.length declare_var(cpnames[cpk], cpt) cpk = cpk + 1 end cml = "".split(",") cmt = "".split(",") cml = "".split(",", -1) cmt = "".split(",", -1) refine_method_body_locals(cbid, cml, cmt, cpnames) walk_and_cache(cbid) pop_scopespinel_codegen.rbmodifiedView file
Loading diff…