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] Adding additional long handling for multiple specializations. #2848

Merged
merged 1 commit into from Apr 20, 2015

Conversation

bjfish
Copy link
Contributor

@bjfish bjfish commented Apr 17, 2015

I believe somewhere while running the MRI tests an edge case is causing the AST to change to use some specialization which returns long frequently (possibly Fixnum#-). I’d like to add these specializations to handle long. I’ve added a TODO to indicate these should be reviewed later on for correctness.

@nirvdrum
Copy link
Contributor

Anything that is a @CoreMethod can use lowerFixnumParameters. In the case of MatchDataNodes, the lowerFixnumParameters is present, but is pointing at the wrong parameter index. Note that the index is 0-based and does not include self. I messed this up originally and it looks like you found a couple lingering cases there.

@chrisseaton
Copy link
Contributor

-Xtruffle.randomize_storage.array=true can help you find these problems - it randomly choose a way to represent arrays whenever they are modified - including the rare-in-practice long[].

@chrisseaton chrisseaton added this to the truffle-dev milestone Apr 17, 2015
@bjfish bjfish force-pushed the truffle_long_specializations branch from 21d708d to 9cf2c3f Compare April 17, 2015 22:15
@nirvdrum
Copy link
Contributor

I hate complicating this, but it looks on MRI, Integer#downto and Integer#upto work fine on values > 32-bit. So casting here would be wrong. @chrisseaton should we just effectively duplicate that code for (long, long), (long, int), and (int, long) permutations?

@chrisseaton
Copy link
Contributor

Yes casting long to int without checking the range is absolutely wrong - at least the first specialisation in this PR does that. It will silently truncate, which is the worst behaviour we could have.

Casting int to long is of course fine and often what we want to do.

Note that lowerFixnumParameters only lowers a long to an int if it is in that range. Otherwise it passes it through as a long.

@bjfish
Copy link
Contributor Author

bjfish commented Apr 18, 2015

@chrisseaton what would be the error to raise if the long is outside of the int range for a methods that only currently support int?

could the the same raise exception be thrown from a primitive node?

@chrisseaton
Copy link
Contributor

I think the key one is array indexing - as that is restricted to int by limitations of the JVM. JRuby seems to allow reads from an array with any index, and returns nil. Writes it gives an error that I'm not sure if MRI ever gives.

$ ~/.rbenv/versions/jruby-1.7.19/bin/ruby -e '[1, 2][0xffffffffffffff]'
$ ~/.rbenv/versions/jruby-1.7.19/bin/ruby -e '[1, 2][0xffffffffffffff] = 14'
ArgumentError: index too big
     []= at org/jruby/RubyArray.java:1408
  (root) at -e:1

For a Bignum MRI does give an error message.

$ ruby -e '[1, 2][10000000000000000000000000]'
-e:1:in `[]': bignum too big to convert into `long' (RangeError)
    from -e:1:in `<main>'

Note that you can index an array with some Bignums, as there are some values of the C type long, which is what MRI indexes arrays with, that do not fit into a Fixnum due to tagging.

Short answer - I think it depends on the method! I would concentrate on the specs for now - if the specs cover a case then fix it. Otherwise I am working on some stress test utilities that will help us explore this problem space more in the future.

Yeah primitives could have the lower annotation as well.

@bjfish bjfish force-pushed the truffle_long_specializations branch from 9cf2c3f to 9988e6a Compare April 19, 2015 03:41
@bjfish
Copy link
Contributor Author

bjfish commented Apr 19, 2015

I've updated the PR to just fix String#byteslice #2843. This is used a lot and fixes a stackoverflow.

throw new RaiseException(getContext().getCoreLibrary().argumentError("index out of int range", this));
}
return stringByteSubstring(string, (int) index, length);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just call the (long, long) version to avoid duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this to avoid the duplication.

@bjfish bjfish force-pushed the truffle_long_specializations branch from 9988e6a to d061cbc Compare April 20, 2015 15:31
chrisseaton added a commit that referenced this pull request Apr 20, 2015
[Truffle] Adding additional long handling for multiple specializations.
@chrisseaton chrisseaton merged commit b7ddabb into jruby:master Apr 20, 2015
@bjfish bjfish deleted the truffle_long_specializations branch April 20, 2015 17:24
@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

Successfully merging this pull request may close these issues.

None yet

5 participants