-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Prefer short circuit and membership test #11
Prefer short circuit and membership test #11
Conversation
if | ||
((ND.TCB (Task_Entered).TS = WaitRendzv) | ||
and then | ||
(ND.TCB (Task_Entered).SUSPEND = Ident_Index_of_Called)) or |
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.
Didn't the tool miss here an or else
opportunity?
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.
My suspicion is that the tool (conservatively) assumes that ND.TCB (Task_Entered).TS
has a side effect,
and hence not always executing it (in case of "or else") will change the behaviour.
If I have time, I will double check!
if | ||
((ND.TCB (Task_Entered).TS = WaitRendzv) | ||
and then | ||
(ND.TCB (Task_Entered).SUSPEND = Ident_Index_of_Called)) or |
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.
Again a lost or else
, seemingly...
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.
See before!
if | ||
((ND.TCB (Task_Entered).TS = WaitRendzv) | ||
and then | ||
(ND.TCB (Task_Entered).SUSPEND = Ident_Index_of_Called)) or |
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.
Same pattern, same missed or else
...
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.
See before!
@@ -238,12 +238,13 @@ package body HAC_Sys.PCode.Interpreter.Tasking is | |||
Pop (ND); | |||
H2 := CD.Tasks_Definitions_Count + 1; | |||
H3 := Integer (Random (ND.Gen) * Float (H2)); | |||
while H2 >= 0 and ND.TCB (H3).TS /= WaitSem and ND.TCB (H3).SUSPEND /= H1 | |||
while H2 >= 0 and ND.TCB (H3).TS /= WaitSem |
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.
Here an and then
could have been added, seemingly.
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.
When ND.TCB (H3) is not a function call (with possible side effects) but just an array access, it can indeed be changed.
Integrated a good part of the suggest changes. Thanks! Commit: 8318810. For cases like |
Dear HAC developers,
Dear Gautier de Montmollin,
Thinking about you request to change
into
I realized why we didn't have this find and replace pattern.
On my codebases, we always started with preferring short circuit operators.
See for more info adaic
When the code is changed and uses short circuit operators,
we apply the find-and-replace patterns to prefer membership tests.
So I exactly applied these two steps in succession on the hac archive.
And e.g. src/apps/hac_pkg.adb benefits from both!
Hopes this helps in making hac even better and easier to maintain!
Greetings,
Pierre
P.S. A pretty printer is applied to every rewrite to ensure that no warnings are introduced (such as line too long).
However not all your code seems to adhere to the pretty print settings as specified in your project file.
Problem detected and solved by Rejuvenation-Ada crate
![vote for Rejuvenation-Ada as The 2022 Ada Crate Of The Year](https://user-images.githubusercontent.com/18348654/191469254-1ca1f4a0-6242-43fa-94a2-f39f55817fdc.jpg)