-
Notifications
You must be signed in to change notification settings - Fork 68
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
Silent cast errors #91
Conversation
Previously, integer overflows and underflows were silent errors during expression evaluation. This may lead to models that are broken without a chance for the author to recognise the error. This commit tackles the problem by modifying the evaluation of binary operators and functions in the spirit of java.Math.
If a PrismLangException is detected, use toString() instead of getMessage() to ensure that the line and column numbers are included.
To be clear: This change does affect the |
…f Booleans, Integers and Doubles During the evaluate calls, the code previously used 'new Boolean' and 'new Integer' constructors for the result values. By removing these allocations and simply letting Java take care of boxing the resulting primitive values, the integrated caching of Java can avoid creating objects in a lot of cases (always for Boolean, and often for Integers in a certain range). (adapted by Joachim Klein from #91) Tag: performance
…r integer evaluation For the evaluation of integer math operations, use the ...Exact methods from java.lang.Math to catch integer under-/overflows and throw PrismLangExceptions. (adapted by Joachim Klein from #91) Tag: performance
(adapted by Joachim Klein from #91) Tag: performance
Hi @merkste, thanks for the PR. I've split up and tweaked the commits a bit so that the unboxing changes are in a seperate commit (for performance testing) and added overflow-aware handling for the unary minus as well; those are pushed to master. I did some cursory performance testing by building models from the prism-benchmark suite; the boxing stuff seems to have a minor positive impact, the overflow-aware math a minor negative impact (as always depending on the particular model). Overall it seems to be reasonable to include for the benefit of better checking. For the "Change error message for PrismLangExceptions" commit, I had a look and did not see how the change has an effect, the I've also started writing test cases for these integer overflows, however currently the As you mentioned the |
Currently, integer overflows and underflows are silent errors during expression evaluation. This may lead to models that are broken without a chance for the author to recognise the error.
This PR addresses issue #92 and consists of two parts:
Throw an error if a double cannot be casted to int
Two classes are touched that cast the result of some prism functions and operators to int values. There might be more but non-obvious places where this happens. The commit also gets rid of unnecessary manual boxing and outmost scope variable declarations in the touched code.
Change error message for PrismLangExceptions
This part allows to see the line and column numbers if a PrismLangException is raised, e.g., on cast errors.