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

TypeError: no case for org.truffleruby.core.cast.ToFNodeGen org.truffleruby.core.numeric.RubyBignum #2184

Closed
rickhull opened this issue Dec 8, 2020 · 6 comments
Assignees
Labels
Milestone

Comments

@rickhull
Copy link

rickhull commented Dec 8, 2020

Here is the full error text: TypeError: TruffleRuby doesn't have a case for the org.truffleruby.core.cast.ToFNodeGen node with values of type org.truffleruby.core.numeric.RubyBignum

I encountered this error as part of a testing matrix for my GitHub Action CI on a project of mine. This failure occurs for truffleruby and truffleruby-head but not for jruby or any MRI I tested. Here is the CI ouput: https://github.com/rickhull/compsci/runs/1520388175?check_suite_focus=true#logs

@eregon
Copy link
Member

eregon commented Dec 9, 2020

Full log (GitHub Actions logs disappear after some time):

  1) Error:
CompSci::Fit::Fit.power#test_0001_must accept power data:
TypeError: TruffleRuby doesn't have a case for the org.truffleruby.core.cast.ToFNodeGen node with values of type org.truffleruby.core.numeric.RubyBignum
	from org.truffleruby.core.cast.ToFNodeGen.executeAndSpecialize(ToFNodeGen.java:107)
	from org.truffleruby.core.cast.ToFNodeGen.executeToDouble(ToFNodeGen.java:49)
	from org.truffleruby.core.MathNodes$LogNode.function(MathNodes.java:477)
	from org.truffleruby.core.MathNodesFactory$LogNodeFactory$LogNodeGen.execute(MathNodesFactory.java:3231)
	from org.truffleruby.language.arguments.CheckArityNode.execute(CheckArityNode.java:41)
	from org.truffleruby.language.methods.ExceptionTranslatingNode.execute(ExceptionTranslatingNode.java:33)
	from org.truffleruby.language.RubyRootNode.execute(RubyRootNode.java:61)
	from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:559)
    /home/runner/work/compsci/compsci/lib/compsci/fit.rb:146:in `log'
    /home/runner/work/compsci/compsci/lib/compsci/fit.rb:146:in `block in power'
    /home/runner/work/compsci/compsci/lib/compsci/fit.rb:48:in `map'
    /home/runner/work/compsci/compsci/lib/compsci/fit.rb:48:in `sigma'
    /home/runner/work/compsci/compsci/lib/compsci/fit.rb:146:in `power'
    /home/runner/work/compsci/compsci/test/fit.rb:134:in `block (5 levels) in <top (required)>'
    /home/runner/work/compsci/compsci/test/fit.rb:132:in `each'
    /home/runner/work/compsci/compsci/test/fit.rb:132:in `block (4 levels) in <top (required)>'
    /home/runner/work/compsci/compsci/test/fit.rb:131:in `each'
    /home/runner/work/compsci/compsci/test/fit.rb:131:in `test_0001_must accept power data'

@eregon
Copy link
Member

eregon commented Dec 9, 2020

Looks like we need negated guards for

protected double function(Object a, NotProvided b,

There is already a specialization handling RubyBignum but it isn't taken (because the Object specialization was activated first).

Also ToFNode independently should try to convert any Object too, not just RubyDynamicObject.

@bjfish Could you do that?

@rickhull
Copy link
Author

rickhull commented Dec 9, 2020

I am looking at the test case in my codebase. I do have a conditional guard on certain values, noting: Fit.error warning: Bignum out of Float range

Depending on platform and implementation details, it seems "legitimate" that certain Bignum's cannot be represented accurately by a float. It's possible this failure has to do with Github's platform moreso than TruffleRuby itself. I'm trying to put together a testcase that doesn't depend on my codebase.

Specifically:

  # y = ax^b
  describe "Fit.power" do
    it "must accept power data" do
      [0.01, 7.5, 500, 1000, 5000, 9999].each { |a|
        [-114, -100, -10, -0.5, -0.1, 0.1, 0.75, 10, 50, 60].each { |b|
          next if b == -114 # Fit.error warning: Bignum out of Float range
          ary = Fit.power(@xs, @xs.map { |x| a * x**b })
          expect(ary[0]).must_be_close_to a
          expect(ary[1]).must_be_close_to b
          expect(ary[2]).must_equal 1.0
        }
      }
    end
  end

Notice I skip the b == -114 case. At b == -115 this code starts generating NaNs, which is why -114 was chosen. Having removed the guard for -114, I am not seeing the Bignum warnings anymore, on my local machine. It's possible that -114 always worked locally and was only a problem for CI (Travis at the time). Not sure if this is relevant or helpful, but thought I would note.

@eregon
Copy link
Member

eregon commented Dec 9, 2020

@rickhull This case is a clear bug, at least in the LogNode, there is already handling for RubyBignum due to some missing check in the generic case.

This is enough to reproduce the bug:
ruby -e 'class C<Numeric; def to_f; 1.0; end; end; obj=C.new; [obj, (1<<65)].each { |e| p Math.log(e) }'

@rickhull
Copy link
Author

rickhull commented Dec 9, 2020

Glad I could help!

@bjfish
Copy link
Contributor

bjfish commented Dec 10, 2020

@rickhull This is fixed at f3b1e5c. Thanks for reporting this.

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

No branches or pull requests

3 participants