Commit e07a1805
e07a18051babMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
Fix two undefined-reference paths: post-backstop rebind and NLR blocks
Two ways the generated C could reference a function that was never emitted:
-
A method whose params are bound only from reads of an ivar that stayed TY_UNKNOWN through the main fixpoint (e.g.
@left = nilin initialize, then written solely through poly-receiver attr writers). The post-fixpoint backstop widens such ivars to poly, but parameters bound from those reads were never re-bound, so the untyped-param backstop dropped the method while its call sites stayed — an undefined reference (bm_rbtree's is_red). Track whether the ivar backstops changed anything and re-run the param/return/write mini fixpoint in that case. -
foo { return 1 }— a block ending in a non-local return. The block value type inferred TY_UNKNOWN, so the yield-method call site failed the scalar-return gate, skipped inlining, and emitted a direct call to the never-emitted sp_foo (bm_throw). Type a block-final ReturnNode as its argument's type in yield_value_type / method_call_ret, and have emit_block_invoke append an unreachable default value after a block-finalreturnso the ({...}) statement-expr keeps its type.
bm_throw now passes end-to-end; bm_rbtree compiles and links (its remaining failure is the GC-rooting class shared with bm_binary_trees). make test stays green (845 pass).
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- e07a18051bab
- Parent
- 99e8dee66559
src/analyze.cmodifiedView file
/* A read-only ivar (referenced but never assigned a typed value) stays TY_UNKNOWN -> it has no C type. Such a slot always reads nil at runtime; give it a boxed-nil poly field so `.nil?`/`.inspect` behave (#712). */ int ivar_backstop_changed = 0; for (int ci = 0; ci < c->nclasses; ci++) { ClassInfo *cl = &c->classes[ci]; for (int iv = 0; iv < cl->nivars; iv++) if (cl->ivar_types[iv] == TY_UNKNOWN) cl->ivar_types[iv] = TY_POLY; if (cl->ivar_types[iv] == TY_UNKNOWN) { cl->ivar_types[iv] = TY_POLY; ivar_backstop_changed = 1; } } /* An attr_reader/attr_accessor ivar typed via a writer call (scalar type), but whose class has no initialize that writes it, starts nil on fresh if (t != TY_INT && t != TY_FLOAT && t != TY_STRING && t != TY_SYMBOL && t != TY_BOOL) continue; cl->ivar_types[iv] = TY_POLY; ivar_backstop_changed = 1; /* Also patch the node-type cache for all InstanceVariableReadNode and InstanceVariableWriteNode nodes that reference this ivar, so codegen sees TY_POLY for both the struct field and the node type. */ /* Post-fixpoint body-usage inference: type any param still TY_UNKNOWN from how it is used inside the method body (hash subscript patterns, array-specific calls). Runs after the main fixpoint so caller-side types always win; the mini-loop below propagates the new types. */ if (infer_hash_params(c) | infer_array_params(c) | infer_params_from_ivar_hash_ops(c)) { types always win; the mini-loop below propagates the new types. Also re-runs after the ivar backstops above widened an UNKNOWN slot to poly: reads of such an ivar inferred UNKNOWN during the fixpoint, leaving params bound from them untyped (and the method dropped, turning its call sites into undefined references). */ if (infer_hash_params(c) | infer_array_params(c) | infer_params_from_ivar_hash_ops(c) | ivar_backstop_changed) { for (int iter = 0; iter < 16; iter++) { int ch = 0; ch |= infer_param_types(c);src/analyze_util.cmodifiedView file
Loading diff…
src/codegen_call.cmodifiedView file
Loading diff…