< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #12082 has been reported by Kazuki Yamaguchi.
----------------------------------------
Bug #12082: Tail-calling method can't catch exception raised by tail-called method
https://bugs.ruby-lang.org/issues/12082
* Author: Kazuki Yamaguchi
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v:
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
The following code doesn't work as expected, on all versions of Ruby with tail call optimization (1.9.1 to 2.3.0).
~~~ruby
def do_raise
raise "should be rescued"
end
options = {
tailcall_optimization: true,
trace_instruction: false,
}
RubyVM::InstructionSequence.compile(<<EOF, __FILE__, __FILE__, __LINE__, options).eval
def test_rescue
return do_raise
1 + 2
rescue
:ok
end
EOF
p test_rescue # should print :ok, but raises "should be rescued"
~~~
Looks like `nop` instruction is (also) used to avoid this optimization ([compile.c](https://github.com/ruby/ruby/blob/1282a4a/compile.c#L4321)), but when doing early return, no `nop` is inserted.
I attached a (dirty) fix for this. Maybe there is a cleaner way.
---Files--------------------------------
0001-compile.c-don-t-do-tail-call-optimization-if-covered.patch (7.21 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>