Commit b21ad532
b21ad532afafMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Value-type objects: allow string ivars (fixes object_new_init)
Extend value-type eligibility to classes with string instance variables, not just int/float/bool. A value-type local lives on the stack, so each of its string (heap-pointer) fields is GC-rooted at the local's declaration -- the field slot is a stable root, so the referent survives collection without per-assignment rooting.
This lets object_new_init's class C (four int ivars plus @e = "c") be a
value type; with by-value return (Stage 4) its test returns the struct
by value and the per-iteration heap allocation disappears.
bm_object_new_init 15x -> 1x vs legacy (the last slow object bench). make test 845, make bench 57, optcarrot checksum 59662.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- b21ad532afaf
- Parent
- 93bd2c0718fe
src/analyze.cmodifiedView file
int scalar = 1; for (int j = 0; j < ci->nivars; j++) { TyKind t = ci->ivar_types[j]; if (t != TY_INT && t != TY_FLOAT && t != TY_BOOL) { scalar = 0; break; } /* int/float/bool need no GC; string fields are heap pointers but get GC-rooted per value-type local (the field slot is a stable root). */ if (t != TY_INT && t != TY_FLOAT && t != TY_BOOL && t != TY_STRING) { scalar = 0; break; } } if (!scalar) continue; int has_sub = 0;src/codegen.cmodifiedView file
Loading diff…