Commit 25c6cc35
25c6cc357a4aMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): pre-scan no-arg-new classes to lift @needs_class_table
A program that declared a namespaced class with no other class-
hierarchy usage (no .class, no is_a?, no ancestors) left
@needs_class_table at 0, which skipped the #define SP_CLASS_COUNT N emit. The Tier 5 dispatch table
(emit_class_new_dispatch) still fired -- it's gated on any user
class supporting a no-arg new -- and the emitted
sp_class_constructors[SP_CLASS_COUNT] table tripped a C
"undeclared identifier" error.
Add a pre-scan alongside the existing @needs_class_parents/@needs_class_ancestors/@needs_class_for_poly lift: walk @cls_names and set @needs_class_table = 1 the moment we find a class that supports no-arg new. SP_CLASS_COUNT then lands ahead of the Tier 5 table that references it.
Issue #524's reproduction (class SomeUnknown::Thing with
SomeUnknown undefined) was the visible trigger -- the issue
suggested either a clean diagnostic (option 1) or permissive
synthesis (option 2). Going with the permissive shape because the
real-world case is class Minitest::Test reopens against external
rubygem-defined classes that spinel-AOT can't see; emit the table
and let unresolved call sites fall through to the existing
cannot-resolve warning.
Closes #524
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 25c6cc357a4a
- Parent
- d80c0225978e
spinel_codegen.rbmodifiedView file
if @needs_class_parents == 1 || @needs_class_ancestors == 1 || @needs_class_for_poly == 1 @needs_class_table = 1 end # Tier 5 (`emit_class_new_dispatch`) emits a # `sp_class_constructors[SP_CLASS_COUNT]` table whenever any # user class supports a no-arg `new`. That table references # `SP_CLASS_COUNT`, which only lands when @needs_class_table # is set. Without this pre-scan, a program that only declares # a class (no `.class` / `is_a?` / ancestors usage anywhere) # left @needs_class_table at 0, skipped the `#define # SP_CLASS_COUNT` emit, and the Tier 5 table tripped a C # `undeclared identifier` error. Issue #524. if @needs_class_table == 0 && @cls_names.length > 0 ci_scan = 0 while ci_scan < @cls_names.length if cls_supports_noarg_new(ci_scan) == 1 @needs_class_table = 1 ci_scan = @cls_names.length else ci_scan = ci_scan + 1 end end end emit_sym_runtime emit_ffi_externs # Emit program-specific regexp patternstest/class_with_undefined_namespace.rbaddedView file
Loading diff…
test/class_with_undefined_namespace.rb.expectedaddedView file
Loading diff…