-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fix cycle checking when calculating min delay from nearest physical action #2459
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks for catching and fixing this! It would be nice to add a test case.
TimeValue minDelay = TimeValue.MAX_VALUE; | ||
for (TriggerInstance<? extends Variable> trigger : reaction.triggers) { | ||
if (trigger.getDefinition() instanceof Action action) { | ||
ActionInstance actionInstance = (ActionInstance) trigger; | ||
if (action.getOrigin() == ActionOrigin.PHYSICAL) { | ||
System.out.println("Physical action: " + action); |
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.
Suggest deleting this debug output.
} | ||
else if (action.getOrigin() == ActionOrigin.LOGICAL) { | ||
System.out.println("Logical action: " + action); | ||
System.out.println("Depends on: " + actionInstance.getDependsOnReactions()); |
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.
} | |
else if (action.getOrigin() == ActionOrigin.LOGICAL) { | |
System.out.println("Logical action: " + action); | |
System.out.println("Depends on: " + actionInstance.getDependsOnReactions()); | |
} else if (action.getOrigin() == ActionOrigin.LOGICAL) { |
You could also turn these into debug outputs.
// Avoid a potentially deep loop by checking the visited set. | ||
if (!visited.contains(uReaction)) { | ||
visited.add(uReaction); // Mark the upstream reaction as visited. | ||
System.out.println("Upstream reaction: " + uReaction); |
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.
Delete or convert to debug output.
@@ -713,7 +735,8 @@ public TimeValue findNearestPhysicalActionTrigger(ReactionInstance reaction) { | |||
// Outputs of contained reactions | |||
PortInstance outputInstance = (PortInstance) trigger; | |||
for (ReactionInstance uReaction : outputInstance.getDependsOnReactions()) { | |||
TimeValue uMinDelay = findNearestPhysicalActionTrigger(uReaction); | |||
visited.add(uReaction); // Mark the upstream reaction as visited. |
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.
Is this add premature? Won't the recursive call on the next line add it if it isn't there already? And if added here, won't the recursive call actually not do anything?
As the title suggests, currently, when actions for a deep loop, the recursion never terminates and leads to stack overflow. This PR addresses the issue by introducing a
visited
set.