Commit 33d72326

33d7232698c8Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified

Description

fix(codegen): DCE walks instance method bodies for . calls

Issue #229 hotfix: compute_live_cls_methods skipped all DefNode bodies during phase A — but only nested DefNodes inside a live cls method body should be skipped (their scope differs from the outer's). Instance method bodies need to be walked so explicit <Const>.<method>(...) calls inside them get marked live.

Reproducer (benchmark/bm_setivar_young.rb):

class TheClass
  def initialize
    @levar = TheClass.new_inner   # <-- instance method body
  end
  def self.new_inner; 0; end
end

Pre-fix, DCE missed the TheClass.new_inner call site so the forward decl + body emit both skipped, leaving the call sites emitted but the symbol unresolved at link time:

undefined reference to `sp_TheClass_cls_new_inner'

Fix: gate the DefNode-skip on ctx_ci >= 0. In phase A (ctx_ci < 0) descend into DefNode bodies normally; bare/self calls there stay unmatched because ctx_ci is still -1, so no mis-attribution. In phase B (ctx_ci >= 0, walking a live cls method body) the skip still applies — a nested def helper inside a cls method body should not bleed its bare calls into the outer class's cls method live set.

Bench result: bm_setivar_young now passes. README bumped from "55 benchmarks pass" to "56 benchmarks pass" since the only errored bench is now green.

290 tests pass, 56 benchmarks pass, bootstrap clean (gen2 == gen3).

Refs #229

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
33d7232698c8
Parent
3804f1d20d30

README.mdmodifiedView file

@@ -81,7 +81,7 @@
8181
8282 ## Benchmarks
8383
84-290 tests pass. 55 benchmarks pass.
84+290 tests pass. 56 benchmarks pass.
8585 Geometric mean: **~11.6x faster** than miniruby (Ruby 4.1.0dev) across
8686 the 28 benchmarks below. Baseline is the latest CRuby `miniruby` build
8787 (without bundled gems), which is considerably faster than the system