Commit 4c942578
4c9425787398Merged
Sam Ruby <[email protected]> · 5 months ago · 6 files · +3 added · ~3 modified
Description
Fix #1417: coerce poly values into RBS-pinned types at return/arg boundaries
Once RBS seeds reach module-nested classes (#1419), a method's declared return or parameter type can be narrower than the poly value its body produces or its call site supplies. Codegen emitted the raw sp_RbVal into the concrete slot, so the generated C failed to compile:
error: returning 'sp_RbVal' from a function with incompatible result
type 'const char *' (ViewHelpers.content_for_get / get_slot)
error: passing 'sp_RbVal' to parameter of incompatible type
'sp_Article *' (Views::Articles.article_json)
Mirror the existing poly->int/float coercion to strings and objects:
- emit_return / the implicit tail path: a poly value feeding a narrower
return slot is unboxed via a new emit_unbox_node helper. A string uses
.v.s(a nil box has a zeroed union, so this is NULL andString?round-trips nil -> NULL -> nil); an object is cast out via.v.p. - emit_arg_or_default: a poly argument into an object parameter is unboxed
with the same
(sp_<Class> *)(...).v.pform (the string/scalar arg cases already existed).
Extends rbs-seed-test with a boundary fixture that compiles, links, and runs (including the nil round-trip); it fails to compile before this change.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 4c9425787398
- Parent
- 482d4237e7ac
MakefilemodifiedView file
rbs-seed-test: @echo "rbs-seed-test: skipped (vendor/rbs not fetched; run 'make deps')"elserbs-seed-test: $(SPINEL) spinel_rbs_extract$(EXE)rbs-seed-test: $(SPINEL) spinel_rbs_extract$(EXE) $(SP_RT_LIB) @cp -f spinel_rbs_extract$(EXE) $(dir $(SPINEL))spinel_rbs_extract$(EXE) @tmp=$$(mktemp -d /tmp/spinel-rbsseed.XXXXXX); \ @tmp=$$(mktemp -d /tmp/spinel-rbsseed.XXXXXX); ok=1; \ $(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 -Eq 'const char[[:space:]]+\*[[:space:]]*iv_label' "$$tmp/out.c" || ok=0; \ if grep -Eq 'sp_RbVal[[:space:]]+iv_label' "$$tmp/out.c"; then ok=0; fi; \ $(CC) -fsyntax-only -Ilib "$$tmp/out.c" 2>/dev/null || ok=0; \ grep -Eq 'const char[[:space:]]+\*[[:space:]]*iv_label' "$$tmp/out.c" || { echo "rbs-seed-test: FAIL (#1417: module-nested-class seed not applied)"; ok=0; }; \ if grep -Eq 'sp_RbVal[[:space:]]+iv_label' "$$tmp/out.c"; then echo "rbs-seed-test: FAIL (#1417: ivar stayed poly)"; ok=0; fi; \ $(CC) -fsyntax-only -Ilib "$$tmp/out.c" 2>/dev/null || { echo "rbs-seed-test: FAIL (nested_ivar C invalid)"; ok=0; }; \ $(SPINEL) test/rbs-seed/boundary.rb --rbs test/rbs-seed/sig \ -c --no-line-map -o "$$tmp/b.c" 2>/dev/null; \ if $(CC) -O0 -Ilib "$$tmp/b.c" $(SP_RT_LIB) -lm -o "$$tmp/b" 2>"$$tmp/b.err"; then \ "$$tmp/b" > "$$tmp/b.out" 2>/dev/null; \ cmp -s "$$tmp/b.out" test/rbs-seed/boundary.expected || { echo "rbs-seed-test: FAIL (#1417 boundary output mismatch)"; diff -u test/rbs-seed/boundary.expected "$$tmp/b.out" || true; ok=0; }; \ else echo "rbs-seed-test: FAIL (#1417 boundary coercion C did not compile)"; ok=0; fi; \ 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; fi if [ $$ok -eq 1 ]; then echo "rbs-seed-test: pass"; else exit 1; fiendif# Analyze-fail fixtures test the legacy analyzer's rejection diagnostics;src/codegen_fold.cmodifiedView file
Loading diff…
src/codegen_stmt.cmodifiedView file
Loading diff…
test/rbs-seed/boundary.expectedaddedView file
Loading diff…
test/rbs-seed/boundary.rbaddedView file
Loading diff…
test/rbs-seed/sig/boundary.rbsaddedView file
Loading diff…