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

[Truffle] Incorrect frame used for block variable access #3001

Closed
nirvdrum opened this issue May 28, 2015 · 1 comment
Closed

[Truffle] Incorrect frame used for block variable access #3001

nirvdrum opened this issue May 28, 2015 · 1 comment
Milestone

Comments

@nirvdrum
Copy link
Contributor

This is a complicated example that's been distilled down from a larger problem JRuby+Truffle has running RSpec. What appears to be happening is a variable declared in some ancestor frame is being accessed from the current frame instead. In this case, the frame slot index exceeds the number of locals in the frame and an exception is thrown.

Example:

class X
  def y(new_name)
    yield(:y_name)
  end

  def z(name, opts)
    yield
  end

  def w(category, name, backtrace_line, *args)
    p backtrace_line
  end

  def x(new_name, label = 'default')
    y(new_name) do |name, *args, &block|
      group = z(name, :caller => (the_caller = caller)) do
        w("examples", name, the_caller.first, *args, &block)
      end
    end
  end
end

X.new.x(:x_name)

MRI 2.2.2:

> ruby -v blah.rb 
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
blah.rb:16: warning: assigned but unused variable - group
"blah.rb:3:in `y'

JRuby+Truffle:

> bin/jruby -X+T -v blah.rb 
jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-05-28 e0b1489 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [linux-amd64]
blah.rb:6:in `z': internal implementation error - IllegalArgumentException The frame slot '[4,the_caller,Object]' is not known by the frame descriptor. com.oracle.truffle.api.impl.DefaultVirtualFrame.getSlotIndexChecked(DefaultVirtualFrame.java:161) (RubyTruffleError)
    from blah.rb:16:in `block in x'
    from blah.rb:3:in `y'
    from blah.rb:15:in `x'
    from blah.rb:23:in `<main>'
@nirvdrum nirvdrum changed the title [Truffle] Incorrect frame use for block variable access [Truffle] Incorrect frame used for block variable access May 28, 2015
@chrisseaton chrisseaton added this to the truffle-dev milestone May 28, 2015
@nirvdrum
Copy link
Contributor Author

This looks like a much simpler case showing the same problem:

def m(arg)
  p arg
  yield
end

def z
  yield
end

z do
  m(something_unique = :arg) do
    p something_unique
  end
end

z {}

In order for this to fail, it needs to be a block-declared variable with a depth > 0 that hasn't been previously seen before. Doing a local variable assignment in a method call seems to be the easiest way to induce this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants