Repository navigation
Dispatch custom accumulators in Array sum blocks - #290
Conversation
284km
left a comment
There was a problem hiding this comment.
Reviewed exact head f85b3dc6179baa4609f301daf2d822592e15fba3, including both Array sum routes, shared operator dispatch, callers, corpus, structured validation record and discussion. There were no existing reviews or inline threads. Neither fetched base nor head contains tracked AGENTS.md/CLAUDE.md instructions.
One Major / P2 finding: the newly supported general accumulator can return a native number, but the block route then switches back to primitive addition instead of continuing Ruby + dispatch. Integer and Float transition probes reproduce this on both engines. Numeric-only controls still correctly ignore core overrides, and the no-block route continues general dispatch.
Independent Darwin arm64 checks:
- Corpus 945, related corpus 426 and 593, and an additional custom-Numeric/string/Array/control-flow/mutation probe match clean Ruby 4.0.10 in stdout, stderr and exit status on evaluator and VM: 8 successful comparisons.
- The unchanged TestArray/TestArraySubclass
test_sumselection passes 2 tests / 156 assertions on the reference, both head engines and both comparison-main engines. Seed 1, tight GC, 120-second watchdog and 2 GiB family cap; no limit event. This selected check does not establish whole-file acceptance. - Seven source checks pass: dup_defs, dead_defs, meth_writes, name_len, ns_names, rx_caps and name_spec. Diff whitespace and bracket depth (155/1024) pass. The GC-roots check refused the preserved timestamp of reused generated C; no independent pass is claimed for that gate.
Head binary reuse was verified against all 2,574 tracked regular files in its build source, plus all tracked mgz files against pin 661a01d8. Binary SHA-256: 1fbfca8d17b10bd136ed10c8dc9115a239bc536a99f51209e846d8d4b2696c78. Its successful ordinary O2 build log identifies compiler 9dec2ff6, independently checked at that revision with a clean checkout. No fresh head compilation is claimed.
Comparison main 34ba9660efa9839666a999c4877b8a6a24395f99 was freshly built with ordinary O2 and those pinned dependencies; binary SHA-256 f4aa1990a9ea779353bba5aec0ad4273f923ebd7e6e5288a85b14d03b5322fd8. It rejects the custom-accumulator block probe with TypeError, so this is incomplete behavior in the newly enabled path, not a previously passing main case regressing. Main advanced externally through #288 to a6f72af32f85d81da41e2ed45641b1556d555a0f during validation. I fetched it and verified that arr_sum_blk, arr_sum_w, apply_bin_vals and blk_noblk are byte-identical to the tested comparison main. Latest-main merge-tree is clean (tree 5200f6ebb3ed459b40708dcd1282e53154d54caf); neither latest main nor the prospective integration was built/tested here.
The recorded three Rails replay pairs retain all previously passing cases and improve EnumerableTests#test_array_sums; these are inspected author evidence, not fresh independent Rails runs. The recorded whole Array MEMORY_LIMIT and unchanged Enum test_callcc failure remain baseline limitations. No complete corpus sweep, whole upstream file, Rails suite, Linux execution or platform/resource acceptance was independently repeated.
No merge: the finding needs correction, and recorded hold_all_merges / new_failure_review_required conditions remain active. This PR is now ready, but Linux build is executing and downstream corpus/unit/bootstrap coverage plus macOS gem coverage remain incomplete; this is not solely unassigned runner queueing. Latest main CI run 45628795270 is pending with zero jobs exposed at inspection, which clears no recorded failure. Already-reviewed #254 still has an actual failed Linux build; #272 retains its existing requested changes and failed checks. #288 was merged externally, not by this review session. merelang/mere has no open PRs. COMMENT because the authenticated account owns this PR.
| | f -> arr_sum_blk world encl theblk id (i + 1) t ver (arith_bin "+" acc (flow_value f))) | ||
| | f -> | ||
| (let value9 = flow_value f in | ||
| let total9 = (if sum_native_number acc && sum_native_number value9 then arith_bin "+" acc value9 |
There was a problem hiding this comment.
[Major / P2] Keep general addition active after a custom accumulator returns a number. This predicate is recomputed for each element, so a custom + returning an Integer or Float makes the next iteration use arith_bin and skip Ruby dispatch. For example:
class Initial
def +(other); 10; end
end
module ChangedInteger
def +(other); 99; end
end
Integer.prepend(ChangedInteger)
p [1, 2, 3].sum { |x| x }
p [1, 2, 3].sum(Initial.new) { |x| x }
p [1, 2, 3].sum(Initial.new)Ruby 4.0.10 prints 6, 99, 99; this head prints 6, 15, 99 on evaluator and VM. The equivalent Float case gives 6.0, 15.0, 99.0 instead of 6.0, 99.0, 99.0. The numeric-only control should keep ignoring core overrides, but once sum enters general addition it must continue dispatching, as Ruby and this tree's no-block fold do. Carry a general-mode flag through arr_sum_blk, or use a separate general fold after the first non-native accumulator/addend, and add a regression where custom addition returns a native number. Comparison main rejects this custom block input with TypeError; the discrepancy is in the newly supported path.
There was a problem hiding this comment.
Fixed in 8a18fff, published with records in 2605a08. arr_sum_blk now carries a native-mode flag that stays false after entering Ruby + dispatch. Corpus 945 includes custom Integer/Float returns and addend transitions; 945/426/593 match clean Ruby 4.0.10 on both engines. Fresh corpus --both: 942/942 in both modes; VM: 942 VM / 0 fallback / 0 differences. Eight source gates, bracket depth 155 and record hygiene pass. Selected CRuby sum: 2 tests / 156 assertions in reference and both builds/engines. Three fresh seed-12345 Rails pairs are all COMPLETE: Enumerable 33 MATCH / 1 RED -> 34 / 0; TimeWithZone 174 / 0 unchanged. Exact final-runtime RSS and provenance are in the updated loop/JSON and PR body. Historical whole Array MEMORY_LIMIT and Enum callcc observations remain explicitly attributed to the earlier runtime.
284km
left a comment
There was a problem hiding this comment.
Follow-up review of exact head 2605a08e7fba13290ba057601626d0e1b6323a2d and the reply to the earlier Major/P2 finding.
The earlier finding is fixed. arr_sum_blk carries the native-mode flag from the initial accumulator and permanently leaves that mode after a non-native addend. Integer/Float results from custom addition therefore continue through Ruby + dispatch. The regression corpus covers both accumulator and addend transitions while retaining numeric-only override controls. No new actionable code findings in this update. I have left the existing review thread untouched.
Independent Darwin arm64 validation:
- Corpus 945, related 426 and 593 match clean Ruby 4.0.10 (
a704b7cd95) in stdout, stderr and exit status on both evaluator and VM: six comparisons. - Unmodified CRuby TestArray/TestArraySubclass
test_sum: 2 tests / 156 assertions, zero failures/errors/skips, COMPLETE on reference and both head engines. Seed 1, tight GC, 120-second watchdog, unchanged 2 GiB process-family cap; no limit event. The first sandbox preflight deniedpsbefore execution; the automatically approved rerun produced these results. - Seven source gates pass: dup_defs, dead_defs, meth_writes, name_len, ns_names, rx_caps and name_spec. Diff whitespace passes.
The existing ordinary O2 head binary was copied for isolated execution after comparing all 2,574 tracked regular files with fetched head, plus 18 dependency files with mgz pin 661a01d8. Binary SHA-256: 716a220b282d8c2b0316e3e24300bc358af52c7dcd6619b7eb7031f42d1b6d00. Its successful O2 build log names compiler 9dec2ff687a08433247dbdb7729bc19c8522e538; that compiler checkout is clean at the stated revision. No fresh compilation is claimed. Neither fetched head nor main contains tracked AGENTS.md/CLAUDE.md instructions.
Fetched current main 5e0e652c759bac9705e1c4a155771d87f6ae1646; prospective merge-tree is clean, tree 6dab68e5b277a7c5580ee1cc95b022897e16f2e5. I inspected its runtime delta against main: the same sum changes apply cleanly. Current-main and integrated executables were not tested. The author's updated full-corpus/Rails records were inspected, not independently repeated. Historical whole-Array MEMORY_LIMIT and Enum callcc failure remain attributed to the earlier runtime; selected sum passes do not establish whole-file acceptance on this final head.
No merge. The policy's recorded hold_all_merges and new_failure_review_required remain active. Head build-linux is still executing, macOS/reference work is queued, and downstream corpus/upstream matrices are incomplete: this is not solely unassigned queueing with equivalent verified coverage. Latest main CI run 45716514445 exposes no jobs yet; I also inspected all exposed jobs of the other latest-main workflows, which are queued. This clears no recorded failure. Already-reviewed #254 retains a failed Linux build; #272 retains failed harness/Linux/corpus checks. All other open mere-ruby PRs are drafts; merelang/mere has no open PRs. COMMENT because the authenticated account owns the PR.
Array#sum with a block used primitive arithmetic for every accumulator, so a custom initial value and block result missed their Ruby
+/coerce. Dispatch non-native accumulators through the existing operator dispatcher while preserving the native numeric path, including the documented Integer/Float+override behavior.Runtime 8a18fff, base a9e6898; ordinary O2 compiler 9dec2ff6. Reference: clean ruby 4.0.10 via
tools/ref_ruby.sh, revision a704b7cd95a42cc0cf5f307137bf3aac0285b915, no extra gems, Prism 1.8.2. Native gems explicitly reuse the owned 85-package install made by a9e6898; each record separates the installing and measuring binary digests.Local validation:
run_corpus.sh --both: 942/942 ON and OFF.MERE_RUBY_VM=1VM corpus: 942 VM / 0 fallback / 0 differences. New corpus 945 matches both engines.test_sum: 2 tests / 156 assertions pass on reference and before/after in both engines. Isolated wholetest_arrayreaches MEMORY_LIMIT on both builds/engines at the unchanged cap; reference completes 493 tests / 23681 assertions, 2 skips. Wholetest_enumremains COMPLETE with 90 tests / 589 assertions and the same pre-existingtest_callccfailure on both builds/engines. These baseline limits/failures are retained.Review correction: retain general Ruby
+dispatch even after a custom operation returns Integer/Float; corpus 945 includes accumulator and addend transitions. Final runtime 8a18fff reruns the full corpus, selected CRuby sum cases and three alternating Rails pairs. The whole Array/Enum observations above belong to earlier fd7f5ac; no whole-file pass is claimed on this final runtime.Maximum family RSS, KiB, final-runtime three alternating repetitions:
The ranges vary and overlap; no stable memory improvement is claimed. Full component remeasurement uses a separate local integration.
Record:
loop/2026-11-25-codex-rails1-array-sum-operators.mdandrailstest/framework/records/activesupport-array-sum-operators.json.