Commit 61d1cdfe
61d1cdfec6f7Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Type an unresolved stdlib constructor as int, not an undeclared struct
Storing a stdlib class with no Spinel struct (Mutex, Pathname,
OpenStruct, IPAddr, ...) in an instance variable or local made analyze
type the slot obj_<Class>, so codegen emitted an sp_<Class> * field
it never defined and the C build failed with unknown type name 'sp_<Class>'. This was the largest spinelgems codegen cluster (21
gems), each blocked on a different stdlib type.
The two .new fallbacks (infer_type and infer_ivar_init_type) returned
obj_<name> for any constructor not otherwise special-cased. Guard them
with constructable_class_struct?, which is true only for user-defined
classes and the builtin Object (the one struct-backed builtin that
reaches this fallback). An unconstructable class now types as int —
codegen already lowers the unresolved .new to integer 0 — so the
local/ivar compiles. The stdlib object stays inert (its methods remain
unresolved), which is the boxed-fallback behavior the issue allows.
Fixes #1305
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 61d1cdfec6f7
- Parent
- 12f205197ae4
spinel_analyze.rbmodifiedView file
-1 end # True when codegen can emit a real `sp_<name> *` for `name.new`: a # user-defined class, or the builtin `Object` (the only struct-backed # builtin that reaches the generic `.new` fallback — Array/Hash/ # String/Random/StringIO/StringScanner/Fiber are special-cased # before it). Unimplemented stdlib classes (Mutex, Pathname, # OpenStruct, ...) have no struct, so their `.new` falls back to the # int slot rather than an undeclared `sp_<Class> *`. Issue #1305. def constructable_class_struct?(name) find_class_idx(name) >= 0 || name == "Object" end # Walk @cls_parents starting from `child_idx` and return 1 if we # ever land on `ancestor_idx`. Used by `is_a?(<Klass>)` on poly # receivers to enumerate descendant cls_ids — `recv.is_a?(C)` is if is_exception_class_name(rn) == 1 return "exception" end return "obj_" + rn # A constructor whose target class has no Spinel struct (an # unimplemented stdlib class such as Mutex/Pathname/OpenStruct) # can't be pointed at by a typed `sp_<Class> *` slot, which codegen # would emit but never define. Codegen already lowers the unresolved # `.new` to the integer `0`, so type the slot as int — the value's # natural C type — and the local/ivar compiles. if constructable_class_struct?(rn) == true return "obj_" + rn end return "int" end end end if module_name_exists(rname) == 1 return "" end return "obj_" + rname # An unresolved stdlib class (no Spinel struct) can't back an # `sp_<Class> *` ivar field. Codegen lowers the unresolved `.new` # to integer 0, so type the slot as int; mirrors the infer_type # `.new` fallback. Issue #1305. if constructable_class_struct?(rname) == true return "obj_" + rname end return "int" end end endtest/stdlib_class_in_ivar.rbaddedView file
Loading diff…
test/stdlib_class_in_ivar.rb.expectedaddedView file
Loading diff…