Commit 07d622b3
07d622b3b225Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 10 files · +2 added · -8 deleted
Description
test: collapse 4 ptr_array_* tests into one ptr_array.rb
Pointer-array (<obj>_ptr_array) coverage — typed-obj [] map,
value-class instances in [] / push / << (PR #87 + #91), and
slot widening from [nil] * N writes. Four tests; merged. The
only class-name collisions were Foo (same definition reused
across the two value-class sections — kept once) and Bag (two
unrelated shapes — section 1's renamed to MapBag).
4 .rb → 1. ~5s saved on Windows test step at the ~1.2s/test rate.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 07d622b3b225
- Parent
- 57409b7d3815
test/ptr_array.rbaddedView file
1+
# Pointer-array (`<obj>_ptr_array`) coverage — typed-obj `[]` map,2+
# value-class instances in array literals (and via `push`/`<<`),3+
# and slot widening from `[nil] * N` writes. Was four tests; the4+
# only class-name collisions were Foo (same definition reused5+
# across the two value-class sections — kept once) and Bag (two6+
# unrelated shapes — section 1's Bag renamed to MapBag).7+
8+
# === Section 1: ptr_array map ===9+
# `compile_map_expr` had no `ptr_array` recv branch — `.map { ... }`10+
# on a typed `obj_X[]` ivar/local fell through to the trailing11+
# `"0"` placeholder.12+
class Box13+
attr_reader :v14+
def initialize(v); @v = v; end15+
end16+
17+
class MapBag18+
def initialize19+
@items = [Box.new(1), Box.new(2), Box.new(3)]20+
end21+
def doubled22+
@items.map { |b| b.v * 2 }23+
end24+
def names25+
@items.map { |b| "v=#{b.v}" }26+
end27+
end28+
29+
mbag = MapBag.new30+
mints = mbag.doubled31+
puts mints.length # 332+
puts mints[0] # 233+
puts mints[2] # 634+
mnames = mbag.names35+
puts mnames.length # 336+
puts mnames[0] # v=137+
puts mnames[2] # v=338+
39+
# === Section 2 + 3: value-class instances in ptr_array (literal + push) ===40+
# A class with no attr_writers / no mutating methods would normally41+
# be value-type'd, but its instances landing in an array literal or42+
# being push'd into one must demote it to a heap-allocated obj so43+
# `sp_PtrArray_push`'s `void *` arg type-checks. PR #87 covered the44+
# literal case; #91 (follow-up) extended it to push / <<.45+
class Foo46+
def initialize(x); @x = x; end47+
attr_reader :x48+
end49+
50+
# Literal form.51+
flit = [Foo.new(1), Foo.new(2), Foo.new(3)]52+
puts flit.length53+
flit.each { |f| puts f.x }54+
55+
# `push` form.56+
fpush = []57+
fpush.push(Foo.new(1))58+
fpush.push(Foo.new(2))59+
puts fpush.length60+
fpush.each { |f| puts f.x }61+
62+
# `<<` form (same code path through the parser).63+
fsh = []64+
fsh << Foo.new(10)65+
fsh << Foo.new(20)66+
fsh << Foo.new(30)67+
puts fsh.length68+
fsh.each { |f| puts f.x }69+
70+
# === Section 4: ptr_array slot widening from [nil] * N ===71+
# `@arr = [nil] * N` followed by `@arr[i] = obj` widens the slot72+
# to `<obj>_ptr_array`. Without the widening, the slot stays at73+
# the default IntArray and the object pointer write is truncated.74+
class Item75+
def initialize(label)76+
@label = label77+
@history = [0] # array ivar keeps Item off the value-type fast path78+
end79+
def visit80+
@history << @history.last + 181+
@label82+
end83+
def visits84+
@history.length - 185+
end86+
end87+
88+
class Bag89+
def initialize90+
@slots = [nil] * 491+
@slots[0] = Item.new("a")92+
@slots[1] = Item.new("b")93+
@slots[3] = Item.new("d")94+
end95+
attr_reader :slots96+
def visit_at(i)97+
@slots[i].visit98+
end99+
end100+
101+
b = Bag.new102+
puts b.visit_at(0)103+
puts b.visit_at(1)104+
puts b.visit_at(3)105+
puts b.slots[0].visits # 1106+
puts b.slots[1].visits # 1107+
puts b.slots[3].visits # 1test/ptr_array.rb.expectedaddedView file
Loading diff…
test/ptr_array_map.rbdeleted
Loading diff…
test/ptr_array_map.rb.expecteddeleted
Loading diff…
test/ptr_array_of_value_class.rbdeleted
Loading diff…
test/ptr_array_of_value_class.rb.expecteddeleted
Loading diff…
test/ptr_array_of_value_class_push.rbdeleted
Loading diff…
test/ptr_array_of_value_class_push.rb.expecteddeleted
Loading diff…
test/ptr_array_set_widening.rbdeleted
Loading diff…
test/ptr_array_set_widening.rb.expecteddeleted
Loading diff…