Commit ae3bbf34

ae3bbf34743fMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified

Description

Compile bm_fib.rb — recursive function with auto type inference

Infer top-level function parameter types from call sites: puts fib(34) → fib(n: Integer) → Integer return type.

Generates clean recursive C: sp_fib(mrb_int lv_n) with direct integer arithmetic and no dynamic dispatch.

Performance (fib(34)): CRuby: 0.55s mruby: 2.78s AOT: 0.01s (55x faster than CRuby)

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

Details

Commit
ae3bbf34743f
Parent
489bc3376691

bm_fib.rbaddedView file

1+def fib(n)
2+ if n < 2
3+ n
4+ else
5+ fib(n - 1) + fib(n - 2)
6+ end
7+end
8+
9+puts fib(34)