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

BigInteger support in PInt #346

Merged
4 commits merged into from
Oct 3, 2023

Conversation

JaroslavTulach
Copy link
Contributor

Expose big integers by reacting to asBigInteger message in PInt. Making sure big integer can be passed into Python.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jul 31, 2023
@oracle-contributor-agreement
Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. and removed OCA Verified All contributors have signed the Oracle Contributor Agreement. labels Aug 2, 2023
@JaroslavTulach JaroslavTulach force-pushed the jtulach/BigIntegerSupport branch from 0043631 to 9af32ec Compare August 2, 2023 11:49
@oracle-contributor-agreement
Copy link

Thank you for signing the OCA.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels Aug 2, 2023
@JaroslavTulach
Copy link
Contributor Author

Is anything blocking integration of my PR?

Copy link
Member

@ppisl ppisl left a comment

Choose a reason for hiding this comment

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

Ok, it looks fine.

@@ -1031,6 +1031,28 @@ protected static long doIt(Object object,
gil.acquire();
}
}
@Specialization(limit = "3", guards="lib.fitsInBigInteger(object)")
Copy link
Member

Choose a reason for hiding this comment

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

If the value does not fit in long nor big integer, then this will cause UnsupportedSpecializationException, while previously it would cause Python level exception that the user can handle. Why another @Specialization and not another if in the existing specialization?

Choose a reason for hiding this comment

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

Could we just add a @Fallback raising the Python exception?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but I am not sure if this is correct because of what you pointed out in #346 (comment). I think that one would just need more complex example than the tests that were added to trigger the potential issue. All in all, adding an if to the single @Specialization looks like safe and simple solution.

Copy link
Contributor Author

@JaroslavTulach JaroslavTulach Aug 29, 2023

Choose a reason for hiding this comment

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

OK, merging the two @Specializations back into one: 04bf4c6 - thanks for your review, Štěpáne. There are two reasons why I went with a separate specialization:

  • boxing return type
  • need for additional node

Boxing isn't probably issue, it is going to happen (in the interpreter) later anyway. @Cached PythonObjectFactory factory is however unnecessary unless the value is really big.

Choose a reason for hiding this comment

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

Out of curiosity - is there any (expected, of course in practice one would have to measure this) advantage (e.g. in performance) of having 2 separate simpler specializations VS one more complex one?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I forgot about PythonObjectFactory that's good point. I'd still keep it this way even though it's a small trade off of readability vs efficiency. Regarding performance: the specialization will get new instance for each interop object "type" and each such instance will specialize to that specific "type", so I don't think that two specializations would gain anything in this case except for the removal of the unnecessary PythonObjectFactory allocation. OTOH, more specializations, especially with guards => more complex execute and executeAndSpecialize => can have impact on the interpreter performance (see also host inlining)

@graalvmbot graalvmbot closed this pull request by merging all changes into oracle:master in 8edd56c Oct 3, 2023
@JaroslavTulach
Copy link
Contributor Author

Thank you @ppisl for accepting, adopting and integrating my proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants