From: deivid.rodriguez@... Date: 2018-12-11T22:20:50+00:00 Subject: [ruby-core:90428] [Ruby trunk Bug#15303] Return tracepoint doesn't fire when tailcall optimization is applied Issue #15303 has been updated by deivid (David Rodr��guez). Hello! I have very similar views to alanwu. The original proposal of extending the API to be able to distinguish between regular method calls and tail calls sounds good to me in principle and looks like it would solve the problem in the general case. It would be a niche feature, but tailcall optimization is a niche feature too, right? It just happens to be used in a standard lib method, that's why it's biting byebug. Regarding koichi's first proposal, it's not bad either. The `return_value` method in return events is only marginally used in byebug, so it's not a big deal to lose it on these egde cases. Regarding koichi's last proposal.. Again I agree with alanwu. Couldn't using the tracepoint API over programs relying on tailcall optimization actually break those programs? ---------------------------------------- Bug #15303: Return tracepoint doesn't fire when tailcall optimization is applied https://bugs.ruby-lang.org/issues/15303#change-75581 * Author: alanwu (Alan Wu) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.0dev (2018-11-14 trunk 65727) [x86_64-darwin17] * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- After a tailcall, the "return" tracepoint event is only fired once. Normally, after a call at the end of a method, the return event is fired twice, once for the callee returning and once for the caller returning. The following script outputs ~~~ :call :call :call :return ~~~ ~~~ ruby method_source = <<-RB def toy(n) return if n == 2 toy(n+1) end RB iseq = RubyVM::InstructionSequence.compile(method_source, tailcall_optimization: true) #puts iseq.disasm iseq.eval trace = TracePoint.new(:call, :return) do |tp| p tp.event end trace.enable toy(0) ~~~ The "return" event behaves more like a "stack frame pop" event currently. I don't think it's feasible/desirable to have the same behavior when TCO is applied, but it would be nice if there was some way for the tracepoint to know a tail call is going to happen. I'm raising this issue because the popular debugger "byebug" relies on these events to track execution in various stack frames. https://github.com/deivid-rodriguez/byebug/issues/481 Forwardable explicitly uses TCO which triggers this issue. ---Files-------------------------------- no-tco-no-problem.patch (520 Bytes) -- https://bugs.ruby-lang.org/ Unsubscribe: