Skip to content

Instantly share code, notes, and snippets.

@shugo
shugo / CLAUDE.md
Created July 18, 2026 01:42
CLAUDE.md for JRuby

Guidelines

Repository

  • origin = shugo/jruby, upstream = jruby/jruby. Pull requests are usually created by Shugo himself; do not create one unless asked.
  • Branches may be amended or rebased in parallel sessions. Before any force-push, verify the remote SHA with git ls-remote and use --force-with-lease. If a push went through an explicit URL instead of the configured remote, the tracking refs are stale; `git fetch
@shugo
shugo / check_setjmp_volatile.rb
Last active July 17, 2026 04:01
Heuristic checker for non-volatile locals read on the longjmp path.
#!/usr/bin/env ruby
# Heuristic checker for non-volatile locals read on the longjmp path.
#
# Scans C sources for functions using EC_EXEC_TAG()/EXEC_TAG()/RUBY_SETJMP
# and reports locals that are declared before the setjmp, are not volatile,
# and are read in the longjmp-reachable region (outside the TAG_NONE block).
#
# Two severities:
# STRICT - also written between setjmp and longjmp: indeterminate per
# C11 7.13.2.1p3, a real portability bug.
@shugo
shugo / packrat_parser_notes.md
Last active June 29, 2026 08:53
A packrat parser-combinator library driven by Ruby's experimental `for ... then` comprehension

I built a small PEG/packrat parser-combinator gem (packrat_parser) whose grammar rules can be written with a Scala-style for-comprehension. The comprehension is a feature of an experimental Ruby fork: for x in p, y in q then ... end desugars (at parse time) to p.flat_map { |x| q.map { |y| ... } }. Along the way I hit a subtle bug caused by the comprehension's loop variables leaking into the enclosing method scope. This writeup is mostly about that bug.

The comprehension is only recognized by the fork's legacy parser, so everything below runs with ruby --parser=parse.y. The default (Prism) parser rejects for ... then.

@shugo
shugo / bench_lock_overhead.rb
Last active June 19, 2026 04:07
Benchmark of Proc#with_refinements in multi-Ractor mode
module M
refine String do
def shout = upcase + "!"
end
end
N = 2_000_000
prc = ->(s) { s }
# Warm up the memo
@shugo
shugo / benchmark_pwr.rb
Last active June 12, 2026 05:16
Proc#with_refinements benchmark
require "objspace"
module M
refine String do
def shout = upcase + "!"
end
end
module A
refine(String) { def shout = "A" }
@shugo
shugo / benchmark.log
Created June 9, 2026 10:54
master vs feature/proc-with_refinements benchmark result
/home/shugo/.rbenv/shims/ruby --disable=gems -rrubygems -I./benchmark/lib ./benchmark/benchmark-driver/exe/benchmark-driver \
--executables="compare-ruby::/home/shugo/src/ruby/ruby -I.ext/common --disable-gem" \
--executables="built-ruby::./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems --disable-gem" \
--output=markdown --output-compare -v $(find ./benchmark -maxdepth 1 -name 'vm' -o -name '*vm*.yml' -o -name '*vm*.rb' | sort)
compare-ruby: ruby 4.1.0dev (2026-01-06T04:38:13Z master ad6b85450d) +PRISM [x86_64-linux]
built-ruby: ruby 4.1.0dev (2026-06-09T07:45:27Z feature/proc-with_.. d58b477bf8) +PRISM [x86_64-linux]
warming up...............................................
# Iteration per second (i/s)
| |compare-ruby|built-ruby|
def hello
puts "hello"
end
Task.new do
using PipeOUT
puts "hello" # パイプに書く
hello # パイプに書く?
end

openpgp4fpr:1e565fa7b310cfc1b144d93c2dfe34085e97ce47

@shugo
shugo / quine.rb
Last active May 11, 2026 02:05
RubyKaigi 2026 STORES Quiz Quine Spinel version
$c=%,$c=%%%%%%%%%c%%%%s%%c;puts$c%%%%%%%%44%%%%%%%%44%%%%%%%%$c,;puts$c%44%44%$c
def foo
x = 1
x
y
end