-
Notifications
You must be signed in to change notification settings - Fork 37
Fix for TS copy assignment and a test for it #88
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
Conversation
|
Even if/when this is approved, lets wait to merge it until the other PRs are merged. |
|
Oops, looks like this doesn't work -- I forgot about other issues with ordering. Looks like there's simply destructor issues now. Might have to go with the copy assignment implementation approach. I'll close it for now. |
|
All right, I fixed it by using copy-and-swap (see updated description). I'd be interested in your thoughts on this approach. Additionally, how should the copy assignment operator be tested? Should we check that all member variables were copied correctly somehow? But then if we update the members, the test would have to be updated as well to catch the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I left one comment above, where some member variable was missing in the swap function.
| std::swap(ts1.statevars_, ts2.statevars_); | ||
| std::swap(ts1.next_statevars_, ts2.next_statevars_); | ||
| std::swap(ts1.inputvars_, ts2.inputvars_); | ||
| std::swap(ts1.named_terms_, ts2.named_terms_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add also TS member term_to_name_ here
Yes, I think that checking that all member variables were copied correctly would be the right approach. Maybe by implementing the
It's a neat and tidy solution. I was reading a bit about copy-and-swap. It would be interesting to see whether performance could be impacted when copying large transition systems. |
|
Thanks for the review and for catching the missing member variable! I fixed that and implemented Currently in the code, we mostly use references to avoid copies, but this can be cumbersome sometimes, especially when new systems are created. It also makes constructors complicated because often there's a lot of initialization happening there. We can include this in our next discussion. We can also use your profiling #94 to evaluate this. |
|
Thanks for your update and including |
Before, the following code would result in a
FloatingPointException:That was because the member variables in the TS had the solver listed before
init_andtrans_. The default solver isCVC4, softsstarts with aCVC4smt-switch solver and initializesinit_andtrans_to true. But then the copy assignment copies the solver first, followed by the two terms. Since there was only one reference to the initial solver, it goes out of scope and wheninit_andtrans_are overwritten, their destructor is called which results in the exception due to the null pointer to the CVC4 in CVC4's Term objects: https://github.com/CVC4/CVC4/blob/c59345b93b2ecf3552f5205b312c262a1ae5eab8/src/api/cvc4cpp.h#L1109. This would also be a problem for any solver, because the solver should exist as long as terms from it are present.The fix used in this PR is to implement copy assignment using the copy-and-swap idiom. This PR also adds a test to make sure no exception is thrown on copy assignment.