Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread::Backtrace::Location#label for blocks does not include number of levels #5165

Open
ivoanjo opened this issue May 10, 2018 · 4 comments

Comments

@ivoanjo
Copy link
Contributor

ivoanjo commented May 10, 2018

Hello again!

I'm using Thread#backtrace_locations and noticed several differences between MRI and JRuby.

I'll report them separately because they may have different fixes, but feel free to mark any as duplicate if it makes sense to do so.


Environment

  • JRuby: jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server VM 25.171-b11 on 1.8.0_171-b11 +jit [linux-x86_64]
  • Kernel: Linux u186024434db159d25c92 4.13.0-39-generic #44~16.04.1-Ubuntu SMP Thu Apr 5 16:43:10 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Distro: Ubuntu 16.04.4 LTS

Expected Behavior

When looking at a Thread::Backtrace::Location, for a nested block, MRI returns as part of the #label the nesting level.

Testcase:

puts RUBY_DESCRIPTION

def test
  [:test].map do
    location = Thread.current.backtrace_locations[1]
    puts "1st level: #label '#{location.label}', #to_s '#{location}'"

    [:test].map do
      location = Thread.current.backtrace_locations[1]
      puts "2nd level: #label '#{location.label}', #to_s '#{location}'"

      [:test].map do
        location = Thread.current.backtrace_locations[1]
        puts "3rd level: #label '#{location.label}', #to_s '#{location}'"
      end
    end
  end
end

test

Output on MRI:

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
1st level: #label 'block in test', #to_s 'testcase2.rb:5:in `block in test''
2nd level: #label 'block (2 levels) in test', #to_s 'testcase2.rb:9:in `block (2 levels) in test''
3rd level: #label 'block (3 levels) in test', #to_s 'testcase2.rb:13:in `block (3 levels) in test''

Actual Behavior

JRuby does not include the nesting level in the output:

jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server VM 25.171-b11 on 1.8.0_171-b11 +jit [linux-x86_64]
1st level: #label 'block in test', #to_s 'testcase2.rb:5:in `block in test''
2nd level: #label 'block in test', #to_s 'testcase2.rb:9:in `block in test''
3rd level: #label 'block in test', #to_s 'testcase2.rb:13:in `block in test''

If it would be helpful I can also submit a testcase to RubySpec.

@headius
Copy link
Member

headius commented Aug 7, 2019

This has dragged on for a while but it might be really simple...just count the number of block scopes to the nearest method scope and that's the number.

@ivoanjo If your offer still stands, I'd love to see the specs. You can submit to JRuby's spec/ruby dir too.

@headius
Copy link
Member

headius commented Aug 10, 2019

Ok so some complications here...

  • The logic for maintaining a Backtrace only tracks a host class, method name, filename, line number, and "type" which indicates eval or block or method, etc. We would need to expand this to hold the depth of any block frames.
  • Within the JIT, all the above information gets embedded into the JVM method name; this would also need to expand to be able to support an additional level value for block frames.

And of course the MRI-based backtrace formatter would need to be made aware of this level.

Neither of these are that hard, but they would introduce some possibly-risky changes for 9.2.8.

@headius headius modified the milestones: JRuby 9.2.8.0, JRuby 9.2.9.0 Aug 10, 2019
ivoanjo added a commit to ivoanjo/spec that referenced this issue Aug 13, 2019
@ivoanjo
Copy link
Contributor Author

ivoanjo commented Aug 13, 2019

@ivoanjo If your offer still stands, I'd love to see the specs. You can submit to JRuby's spec/ruby dir too.

Yeap, just sent them! I've opened a PR to ruby spec, but if you have any ideas of specs that would make sense in the context of JRuby's spec/ruby, let me know 🙏

eregon pushed a commit to ruby/spec that referenced this issue Aug 22, 2019
@enebo enebo modified the milestones: JRuby 9.2.9.0, JRuby 9.2.10.0 Oct 21, 2019
@enebo
Copy link
Member

enebo commented Oct 21, 2019

JIT will require extra info in the mangled name and we will be putting out 9.2.9.0 soon...punting

@headius headius modified the milestones: JRuby 9.2.10.0, JRuby 9.3.0.0 Feb 14, 2020
@headius headius modified the milestones: JRuby 9.3.0.0, JRuby 9.3.1.0 Jul 1, 2021
@headius headius removed this from the JRuby 9.3.1.0 milestone Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants