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
RBS_OBJ = $(patsubst $(RBS_DIR)/src/%.c,build/rbs/%.o,$(RBS_SRC))RBS_LIB = build/librbs.a.PHONY: all parse legacy bootstrap codegen regexp rbs_extract rbs-test \.PHONY: all parse legacy bootstrap codegen regexp rbs_extract rbs-test rbs-seed-test \ analyze-fail-test test test-run clean-test-results regen-rbs-expected \ regen-expected bench optcarrot gate check gate-legs gate-test gate-bench \ gate-optcarrot clean install uninstall deps +@$(MAKE) --no-print-directory test-run# The actual run. rbs-test golden-checks the RBS extractor (cheap, C-only).# analyze-fail (legacy-analyzer diagnostics) lives in legacy/ now and runs# as part of `make gate`, not the hot `make test` loop.test-run: rbs-test $(TEST_TARGETS)# rbs-seed-test checks the seeds actually reach the analyzer (incl. nested# classes, #1417). analyze-fail (legacy-analyzer diagnostics) lives in legacy/# now and runs as part of `make gate`, not the hot `make test` loop.test-run: rbs-test rbs-seed-test $(TEST_TARGETS) @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi @if [ -t 1 ]; then printf '\n'; fi @pass=$$(grep -l '^PASS' build/test-results/*.ok 2>/dev/null | wc -l); \ doneendif# End-to-end --rbs seeding check (#1417). The extractor emits a module-nested# class under its qualified name (`Outer_Box`), but the compiler's class table# stores the leaf name (`Box`) + enclosing_class. seed_class_index must match# the two so the seed reaches the class. The fixture's `@label` is declared# `String?` but only ever assigned nil, so inference alone leaves it poly --# only an applied seed pins it to a `const char *` field. The extractor must sit# beside $(SPINEL) (main.c looks for it as a sibling), so copy it there first.ifeq ($(wildcard $(RBS_INC)/rbs/parser.h),)rbs-seed-test: @echo "rbs-seed-test: skipped (vendor/rbs not fetched; run 'make deps')"elserbs-seed-test: $(SPINEL) spinel_rbs_extract$(EXE) @cp -f spinel_rbs_extract$(EXE) $(dir $(SPINEL))spinel_rbs_extract$(EXE) @tmp=$$(mktemp -d /tmp/spinel-rbsseed.XXXXXX); \ $(SPINEL) test/rbs-seed/nested_ivar.rb --rbs test/rbs-seed/sig \ -c --no-line-map -o "$$tmp/out.c" 2>/dev/null; \ ok=1; \ grep -q 'const char \* iv_label' "$$tmp/out.c" || ok=0; \ if grep -q 'sp_RbVal iv_label' "$$tmp/out.c"; then ok=0; fi; \ $(CC) -fsyntax-only -Ilib "$$tmp/out.c" 2>/dev/null || ok=0; \ rm -rf "$$tmp"; \ if [ $$ok -eq 1 ]; then echo "rbs-seed-test: pass"; \ else echo "rbs-seed-test: FAIL (#1417: module-nested-class seed not applied)"; exit 1; fiendif# Analyze-fail fixtures test the legacy analyzer's rejection diagnostics;# the recipe lives in legacy/Makefile. Thin delegator for `make gate`.analyze-fail-test:src/analyze.cmodifiedView file
Loading diff…
test/rbs-seed/nested_ivar.rbaddedView file
Loading diff…
test/rbs-seed/sig/nested_ivar.rbsaddedView file
Loading diff…