truffleruby
truffleruby copied to clipboard
Getting max time fails
ruby -e 'puts Time.at((2**64)-1)'
ruby 3:
584554051223-11-09 08:00:15 +0100
truffleruby fails with:
<internal:core> core/time.rb:303:in `at': TruffleRuby doesn't have a case for the org.truffleruby.core.time.TimeNodesFactory$TimeAtPrimitiveNodeFactory$TimeAtPrimitiveNodeGen node with values of type Class(org.truffleruby.core.klass.RubyClass) org.truffleruby.core.numeric.RubyBignum java.lang.Integer=0 (TypeError)
from org.truffleruby.core.time.TimeNodesFactory$TimeAtPrimitiveNodeFactory$TimeAtPrimitiveNodeGen.executeAndSpecialize(TimeNodesFactory.java:733)
from org.truffleruby.core.time.TimeNodesFactory$TimeAtPrimitiveNodeFactory$TimeAtPrimitiveNodeGen.execute(TimeNodesFactory.java:715)
from org.truffleruby.language.control.IfElseNode.execute(IfElseNode.java:43)
from org.truffleruby.language.control.IfElseNode.execute(IfElseNode.java:45)
from org.truffleruby.language.control.IfNode.execute(IfNode.java:39)
from org.truffleruby.language.locals.WriteLocalVariableNode.execute(WriteLocalVariableNode.java:32)
from org.truffleruby.language.RubyNode.doExecuteVoid(RubyNode.java:63)
from org.truffleruby.language.control.SequenceNode.execute(SequenceNode.java:33)
from org.truffleruby.language.RubyMethodRootNode.execute(RubyMethodRootNode.java:58)
from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:655)
from -e:1:in `<main>'
Note that (2**64)-1 is not LONG_MAX, LONG_MAX is (2**63)-1.
With (2**63)-1 it also fails:
$ ruby -e 'puts Time.at((2**63)-1)'
<internal:core> core/time.rb:313:in `at': UNIX epoch + 9223372036854775807 seconds out of range for Time (java.time limitation) (RangeError)
from -e:1:in `<main>'
And this is basically not fixable without a huge effort, yet I don't think it makes any sense in many applications to use a time 292 billion years in the future (we'll all be dead by then).
Also Time is for timestamps close to our days, for precise calendars far in the future or past, one should use DateTime: https://docs.ruby-lang.org/en/3.1/DateTime.html#class-DateTime-label-When+should+you+use+DateTime+and+when+should+you+use+Time-3F
We should add a specialization so that the Bignum case fails the same way as a too large long.
Any test relying on this should be fixed to use a more sensible Time, or to use DateTime.
> DateTime.new 292277026596
=> #<DateTime: 292277026596-01-01T00:00:00+00:00 ((581465470j,0s,0n),+0s,2299161j)>
works fine on TruffleRuby