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] rescue should try to invoke and use triple equals operator #4405

Closed
PragTob opened this issue Dec 21, 2016 · 4 comments
Closed

[Truffle] rescue should try to invoke and use triple equals operator #4405

PragTob opened this issue Dec 21, 2016 · 4 comments
Milestone

Comments

@PragTob
Copy link

PragTob commented Dec 21, 2016

Environment

Provide at least:

  • head as of f1a26d6
  • Operating system and platform (e.g. uname -a)
Linux speedy 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Expected Behavior

module Rescuer
  AVOID_RESCUING = [NoMemoryError, SignalException, Interrupt, SystemExit]

  def self.===(exception)
    puts 'match invoked!'
    AVOID_RESCUING.none? { |ar| ar === exception }
  end
end

begin
  [:white, nil].sort
rescue Rescuer
  puts 'rescued!'
end

this is expected (apparently, I didn't know this before...) to invoke === on the Rescuer module, print match invoked, rescue the error and then of course print rescued and not error out. Like ruby/JRuby do:

tobi@speedy ~/github/rubykon $ rvm use 2.3.3
Using /home/tobi/.rvm/gems/ruby-2.3.3
tobi@speedy ~/github/rubykon $ ruby spec/array_sort.rb 
match invoked!
rescued!

Actual Behavior

instead it errors our apparently never unvoking ===

tobi@speedy ~/github/rubykon $ ../jruby/bin/jruby-truffle-tool --graal-path ~/dev/graalvm-0.18-re/bin/java run --graal --  spec/array_sort.rb 
jtt: detected gem/app: rubykon
jtt: executing "run" command
jtt: $ JAVACMD="/home/tobi/dev/graalvm-0.18-re/bin/java" /home/tobi/github/jruby/tool/jt.rb ruby -X\+T -J-Xmx2G -J-ea -J-esa -Xtruffle.core.load_path\=/home/tobi/github/jruby/truffle/src/main/ruby -r /home/tobi/github/rubykon/.jruby-truffle-tool_bundle/bundler/setup.rb -I /home/tobi/github/jruby/lib/ruby/truffle/jruby-truffle-tool/lib spec/array_sort.rb
$ /home/tobi/github/jruby/bin/jruby -X+T -Xtruffle.core.load_path=/home/tobi/github/jruby/truffle/src/main/ruby -Xtruffle.graal.warn_unless=false -X+T -J-Xmx2G -J-ea -J-esa -Xtruffle.core.load_path=/home/tobi/github/jruby/truffle/src/main/ruby -r /home/tobi/github/rubykon/.jruby-truffle-tool_bundle/bundler/setup.rb -I /home/tobi/github/jruby/lib/ruby/truffle/jruby-truffle-tool/lib spec/array_sort.rb
spec/array_sort.rb:11:in `sort': expecting a Fixnum to sort (ArgumentError)
	from spec/array_sort.rb:11:in `<main>'

Context

Obviously I didn't come up with this myself. I noticed that on rubykon a lot of specs involving rspecs contain_exactly matcher fail. The matcher eventually calls safe_sort which does basically what I reproduced in this script along with the bad input where sort actually errors out :)

@chrisseaton
Copy link
Contributor

Slightly simpler test case

rescuer = Class.new

def rescuer.===(exception)
  true
end

begin
  raise Exception
rescue rescuer
  p 'here'
rescue Exception
  p 'not here'
end

We are using is_a? without late dispatch for rescue comparisons. I'm not sure why we'd get that so clearly wrong. There isn't a spec for it but presumably we would have though about it to make such a deliberate decision.

@chrisseaton
Copy link
Contributor

Failing spec in 0dfd7cb.

@chrisseaton
Copy link
Contributor

Fixed in 82f9332.

@eregon
Copy link
Member

eregon commented Dec 22, 2016

We are using is_a? without late dispatch for rescue comparisons. I'm not sure why we'd get that so clearly wrong. There isn't a spec for it but presumably we would have though about it to make such a deliberate decision.

It was just my oversight.

@enebo enebo added this to the truffle-dev milestone Jan 10, 2017
@enebo enebo added this to the Non-Release milestone Dec 7, 2017
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

4 participants