Commit 13491db2

13491db23d03Merged

Sam Ruby <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified

Description

Fix #1417: match RBS seeds for module-nested classes

The RBS extractor emits a seed class line under the fully-qualified name (ActionDispatch_Flash, ActionView_ViewHelpers, Views_Articles), but the compiler's class table stores a nested class under its leaf name (Flash) plus an enclosing_class link. seed_class_index matched by exact name only, so every module-nested class's seed block silently resolved to -1 and was dropped -- 39 of 77 seed classes in the published blog archive.

For ActionDispatch::Flash, that means @notice: String? is never pinned, so inference widens the ivar to poly (it is assigned from the []= value param and the each block var). to_h then stores a sp_RbVal into a Hash[String, String] (StrStrHash, const char * values) and the generated C fails to compile:

error: passing 'sp_RbVal' to parameter of incompatible type 'const char *'

Reconstruct each class's qualified name from the enclosing_class chain (Outer_Inner_Leaf) and match the seed name against it when the direct lookup misses. Top-level classes still resolve via the direct lookup first, so they are unaffected.

Adds an end-to-end rbs-seed-test (the suite otherwise never exercises --rbs): a module-nested class whose String? ivar is only ever assigned nil, so only an applied seed pins it to a const char * field. It also copies spinel_rbs_extract beside build/spinel, which main.c requires as a sibling -- without it, local --rbs is a silent no-op.

Full suite: 886 pass, 0 fail; rbs-seed-test pass.

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

Details

Commit
13491db23d03
Parent
e16d3e7fd82f

MakefilemodifiedView file

@@ -38,7 +38,7 @@
3838 RBS_OBJ = $(patsubst $(RBS_DIR)/src/%.c,build/rbs/%.o,$(RBS_SRC))
3939 RBS_LIB = build/librbs.a
4040
41-.PHONY: all parse legacy bootstrap codegen regexp rbs_extract rbs-test \
41+.PHONY: all parse legacy bootstrap codegen regexp rbs_extract rbs-test rbs-seed-test \
4242 analyze-fail-test test test-run clean-test-results regen-rbs-expected \
4343 regen-expected bench optcarrot gate check gate-legs gate-test gate-bench \
4444 gate-optcarrot clean install uninstall deps
@@ -270,9 +270,10 @@
270270 +@$(MAKE) --no-print-directory test-run
271271
272272 # The actual run. rbs-test golden-checks the RBS extractor (cheap, C-only).
273-# analyze-fail (legacy-analyzer diagnostics) lives in legacy/ now and runs
274-# as part of `make gate`, not the hot `make test` loop.
275-test-run: rbs-test $(TEST_TARGETS)
273+# rbs-seed-test checks the seeds actually reach the analyzer (incl. nested
274+# classes, #1417). analyze-fail (legacy-analyzer diagnostics) lives in legacy/
275+# now and runs as part of `make gate`, not the hot `make test` loop.
276+test-run: rbs-test rbs-seed-test $(TEST_TARGETS)
276277 @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi
277278 @if [ -t 1 ]; then printf '\n'; fi
278279 @pass=$$(grep -l '^PASS' build/test-results/*.ok 2>/dev/null | wc -l); \
@@ -324,6 +325,31 @@
324325 done
325326 endif
326327
328+# End-to-end --rbs seeding check (#1417). The extractor emits a module-nested
329+# class under its qualified name (`Outer_Box`), but the compiler's class table
330+# stores the leaf name (`Box`) + enclosing_class. seed_class_index must match
331+# the two so the seed reaches the class. The fixture's `@label` is declared
332+# `String?` but only ever assigned nil, so inference alone leaves it poly --
333+# only an applied seed pins it to a `const char *` field. The extractor must sit
334+# beside $(SPINEL) (main.c looks for it as a sibling), so copy it there first.
335+ifeq ($(wildcard $(RBS_INC)/rbs/parser.h),)
336+rbs-seed-test:
337+ @echo "rbs-seed-test: skipped (vendor/rbs not fetched; run 'make deps')"
338+else
339+rbs-seed-test: $(SPINEL) spinel_rbs_extract$(EXE)
340+ @cp -f spinel_rbs_extract$(EXE) $(dir $(SPINEL))spinel_rbs_extract$(EXE)
341+ @tmp=$$(mktemp -d /tmp/spinel-rbsseed.XXXXXX); \
342+ $(SPINEL) test/rbs-seed/nested_ivar.rb --rbs test/rbs-seed/sig \
343+ -c --no-line-map -o "$$tmp/out.c" 2>/dev/null; \
344+ ok=1; \
345+ grep -q 'const char \* iv_label' "$$tmp/out.c" || ok=0; \
346+ if grep -q 'sp_RbVal iv_label' "$$tmp/out.c"; then ok=0; fi; \
347+ $(CC) -fsyntax-only -Ilib "$$tmp/out.c" 2>/dev/null || ok=0; \
348+ rm -rf "$$tmp"; \
349+ if [ $$ok -eq 1 ]; then echo "rbs-seed-test: pass"; \
350+ else echo "rbs-seed-test: FAIL (#1417: module-nested-class seed not applied)"; exit 1; fi
351+endif
352+
327353 # Analyze-fail fixtures test the legacy analyzer's rejection diagnostics;
328354 # the recipe lives in legacy/Makefile. Thin delegator for `make gate`.
329355 analyze-fail-test: