mruby / mruby

Lightweight Ruby
MIT License
5.31k stars 790 forks source link

If the original block of a non-orphan block becomes an orphan block, the copy object does not become an orphan block (incompatibility with CRuby). #6345

Open dearblue opened 2 months ago

dearblue commented 2 months ago

In CRuby, after copying a block object from a directly given block object, when control is returned from that method, the copied object also switches to orphan block. However, mruby does not switch to orphan block, even going back at least to version 1.3.0.

def m(&b)
  b.dup
end

x = m { break 1 }
begin
  x.call

  # Even if mruby goes back at least to version 1.3.0, it gets here.
  raise "BAD!"
rescue LocalJumpError
  # Where CRuby gets here.
  p "GOOD!"
end

The way I see to solve this problem is either to follow the CRuby behaviour, or to compromise and make all copy objects orphan blocks.

Which one looks better for mruby?

:black_cat: I'm in the process of retrying #6282, which was reverted in #6295, and ran into this issue when I thought the previous issue was resolved.

dearblue commented 1 month ago

In relation to commit 204928120bb6c81d660ac1c94fbd3284041b8920.

A version that overcomes #6295 is in https://github.com/mruby/mruby/compare/master...dearblue:mruby:again-6282. It does not do ci->blk entity references, so there is no need to GC mark them. It just compares the address as an identifier.

However, I can't do PR at this time because of the issues I first addressed.