-
Notifications
You must be signed in to change notification settings - Fork 72
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
Dubious code duplication in destabilize_vs
#1433
Comments
I think the reason we kept it so far is because there's a distinct check there HM.mem called y || destabilize_vs y || b || was_stable && List.mem_cmp S.Var.compare y vs The key question would be why that check is different and why that is. |
destabilize_vs
As I understand, the check is different because the HM.mem called y || destabilize_vs y is effectively equivalent to if not (HM.mem called y) then destabilize_vs y else true So it behaves the same, except that it also returns this boolean. As mentioned in #1434, this boolean whether a start var etc. was destabilized could be computed in an optional callback action (including the remainder of the check |
I had another look, and not calling the Not using destabilize_ref := destabilize_normal; (* always use normal destabilize during actual solve *) Maybe it suffices to add the call to the What do you think @Red-Panda64 @sim642? |
Adding the hook call isn't controversial I think. I don't understand what's the issue with |
It's a clean code thing, I find the more explicit if not (HM.mem called y) then destabilize_vs y else true to be a lot more readable than the formulation with |
But it's also not a hill I'm willing to die on 😉 |
I stand by the opinion that the duplicate code itself is problematic. Namely, that adjustments of either Of course, if you think think the cost of refactoring this outweighs the benefits, we can also just add the Hook and call it a day. As for the short-circuiting |
Ah, that seems reasonable. I thought there might've been some subtle issue with the recursion not happening in some cases when it should've. For example, reordering the disjuncts could easily cause this (e.g. putting |
As to the code duplication, Lines 568 to 605 in 06bc1e1
Getting rid of the duplication is a bit of a separate issue and should probably cover all the instances then. |
The destabilize_vs function is an almost verbatim copy of destabilize_normal, except that it is supposed to determine whether any called or start variables were destabilized. This is needed for the side_widen option "cycle".
For comparison, here is the normally used
destabilize_normal
function:It seems that
destabilize_vs
has a few peculiarities:destabilize_vs
does not call the Hook (which is probably unintentional)destabilize_vs
uses the short-circuiting of the||
operator to influence control flow and control recursiondestabilize
might refer either todestabilize_normal
ordestabilize_with_side
. Howeverdestabilize_vs
, used by side-effects when thecycle
strategy is active, will never behave likedestabilize_with_side
.In a discussion with @michael-schwarz, we came to the conclusion that it is a bit dangerous to have this kind of code duplication, as it is likely that future updates in the destabilize variants will not be reflected in destabilize_vs. It might be best to drop
destabilize_vs
in favor of a more generaldestabilize
function, which takes an optional callback to notify the caller about any destabilized variables. The caller could then perform the check done indestabilize_vs
where it is needed.The text was updated successfully, but these errors were encountered: