Skip to content

Commit

Permalink
Merge pull request #1026 from lf-lang/reaction-self-loop-cycles
Browse files Browse the repository at this point in the history
Fixed causality loop detection bug
  • Loading branch information
lhstrh authored Mar 12, 2022
2 parents f6e4534 + 1aae575 commit b1c7b20
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
18 changes: 8 additions & 10 deletions org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,13 @@ protected void addDownstreamReactions(PortInstance port, ReactionInstance reacti
List<Runtime> dstRuntimes = dstReaction.getRuntimeInstances();
Runtime srcRuntime = srcRuntimes.get(srcIndex);
Runtime dstRuntime = dstRuntimes.get(dstIndex);
if (dstRuntime != srcRuntime) {
// Only add this dependency if the reactions are not in modes at all or in the same mode or in modes of separate reactors
// This allows modes to break cycles since modes are always mutually exclusive.
if (srcRuntime.getReaction().getMode(true) == null ||
dstRuntime.getReaction().getMode(true) == null ||
srcRuntime.getReaction().getMode(true) == dstRuntime.getReaction().getMode(true) ||
srcRuntime.getReaction().getParent() != dstRuntime.getReaction().getParent()) {
addEdge(dstRuntime, srcRuntime);
}
// Only add this dependency if the reactions are not in modes at all or in the same mode or in modes of separate reactors
// This allows modes to break cycles since modes are always mutually exclusive.
if (srcRuntime.getReaction().getMode(true) == null ||
dstRuntime.getReaction().getMode(true) == null ||
srcRuntime.getReaction().getMode(true) == dstRuntime.getReaction().getMode(true) ||
srcRuntime.getReaction().getParent() != dstRuntime.getReaction().getParent()) {
addEdge(dstRuntime, srcRuntime);
}

// Propagate the deadlines, if any.
Expand Down Expand Up @@ -263,7 +261,7 @@ private void assignLevels() {
Set<Runtime> toRemove = new LinkedHashSet<Runtime>();
Set<Runtime> downstreamAdjacentNodes = getDownstreamAdjacentNodes(origin);
// All downstream adjacent nodes start with a level 0. Adjust the
// <code>maxNumOfReactionPerLevel<code> field accordingly (to be
// <code>numReactionsPerLevel<code> field accordingly (to be
// updated in the for loop below).
adjustNumReactionsPerLevel(0, downstreamAdjacentNodes.size());
// Visit effect nodes.
Expand Down
1 change: 0 additions & 1 deletion org.lflang/src/org/lflang/generator/ReactorInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY

import org.lflang.ASTUtils;
import org.lflang.ErrorReporter;
import org.lflang.ASTUtils;
import org.lflang.TimeValue;
import org.lflang.generator.TriggerInstance.BuiltinTriggerVariable;
import org.lflang.lf.Action;
Expand Down
3 changes: 1 addition & 2 deletions org.lflang/src/org/lflang/validation/LFValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import static org.lflang.ASTUtils.inferPortWidth;
import static org.lflang.ASTUtils.isGeneric;
import static org.lflang.ASTUtils.isInteger;
import static org.lflang.ASTUtils.isOfTimeType;
import static org.lflang.ASTUtils.isParameterized;
import static org.lflang.ASTUtils.isValidTime;
import static org.lflang.ASTUtils.isZero;
import static org.lflang.ASTUtils.toDefinition;
import static org.lflang.ASTUtils.toText;
import static org.lflang.ASTUtils.isOfTimeType;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -56,7 +56,6 @@
import org.eclipse.xtext.validation.CheckType;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
import org.lflang.ASTUtils;
import org.lflang.ASTUtils;
import org.lflang.ModelInfo;
import org.lflang.Target;
import org.lflang.TargetProperty;
Expand Down
4 changes: 2 additions & 2 deletions test/C/src/modal_models/ModalCycleBreaker.lf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ reactor Modal {
mode Two { // Defining reaction to in2 before in1 would cause cycle if no mode were present
timer wait(150msec, 1sec)

reaction(in2) -> out {=
SET(out, in2->value);
reaction(in2) {=
// SET(out, in2->value);
=}

reaction(wait) -> One {=
Expand Down

0 comments on commit b1c7b20

Please sign in to comment.