Skip to content
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

Do not create the temporary dependency link if a connection between f… #1085

Merged
merged 15 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ jobs:

# Run the C integration tests.
c-tests:
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@federated-delay-fix
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, we probably don't want these changes in ci.yml to be committed when this is merged to master, right?

Copy link
Member

@lhstrh lhstrh May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do. After merging, it's a matter of changing these to master. This will work as long as the referenced branch exists.

needs: cancel

# Run the CCpp integration tests.
ccpp-tests:
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@federated-delay-fix
with:
use-cpp: true
needs: cancel
Expand All @@ -83,7 +83,7 @@ jobs:

# Run the Python integration tests.
py-tests:
uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@federated-delay-fix
needs: cancel

# Run the Rust integration tests.
Expand All @@ -105,5 +105,5 @@ jobs:

# Run the serialization tests
serialization-tests:
uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@federated-delay-fix
needs: cancel
31 changes: 19 additions & 12 deletions org.lflang/src/org/lflang/federated/FedASTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.lflang.ASTUtils;
import org.lflang.InferredType;
import org.lflang.ASTUtils;
import org.lflang.TargetProperty.CoordinationType;
import org.lflang.TimeValue;
import org.lflang.federated.serialization.SupportedSerializers;
Expand Down Expand Up @@ -208,15 +207,16 @@ private static void addNetworkReceiverReaction(
destRef.setContainer(destination.getParent().getDefinition());
destRef.setVariable(destination.getDefinition());

if (!connection.isPhysical()) {
// If the connection is not physical,
if (!connection.isPhysical() && connection.getDelay() == null) {
// If the connection is not physical and there is no delay,
// add the original output port of the source federate
// as a trigger to keep the overall dependency structure.
// This is useful when assigning levels.
VarRef senderOutputPort = factory.createVarRef();
senderOutputPort.setContainer(source.getParent().getDefinition());
senderOutputPort.setVariable(source.getDefinition());
networkReceiverReaction.getTriggers().add(senderOutputPort);

// Add this trigger to the list of disconnected network reaction triggers
destinationFederate.remoteNetworkReactionTriggers.add(senderOutputPort);
}
Expand Down Expand Up @@ -266,6 +266,7 @@ private static void addNetworkReceiverReaction(
* Added as a trigger to the network control reaction to preserve the
* overall dependency structure of the program across federates.
* @param destination The input port of the destination federate reactor.
* @param connection The network connection.
* @param recevingPortID The ID of the receiving port
* @param bankIndex The bank index of the receiving federate, or -1 if not in a bank.
* @param instance The federate instance is used to keep track of all
Expand All @@ -275,14 +276,14 @@ private static void addNetworkReceiverReaction(
private static void addNetworkInputControlReaction(
PortInstance source,
PortInstance destination,
Connection connection,
int recevingPortID,
int bankIndex,
FederateInstance instance,
GeneratorBase generator
) {
LfFactory factory = LfFactory.eINSTANCE;
Reaction reaction = factory.createReaction();
VarRef sourceRef = factory.createVarRef();
VarRef destRef = factory.createVarRef();

// If the sender or receiver is in a bank of reactors, then we want
Expand All @@ -297,8 +298,6 @@ private static void addNetworkInputControlReaction(
// Set the container and variable according to the network port
destRef.setContainer(destination.getParent().getDefinition());
destRef.setVariable(destination.getDefinition());
sourceRef.setContainer(source.getParent().getDefinition());
sourceRef.setVariable(source.getDefinition());

Reactor top = destination.getParent().getParent().reactorDefinition;

Expand All @@ -315,12 +314,19 @@ private static void addNetworkInputControlReaction(
// Add the appropriate triggers to the list of triggers of the reaction
reaction.getTriggers().add(newTriggerForControlReaction);

// Add the original output port of the source federate
// as a trigger to keep the overall dependency structure.
// This is useful when assigning levels.
reaction.getTriggers().add(sourceRef);
// Add this trigger to the list of disconnected network reaction triggers
instance.remoteNetworkReactionTriggers.add(sourceRef);
if (!connection.isPhysical() && connection.getDelay() == null) {
// If the connection is not physical and there is no delay,
// add the original output port of the source federate
// as a trigger to keep the overall dependency structure.
// This is useful when assigning levels.
VarRef sourceRef = factory.createVarRef();

sourceRef.setContainer(source.getParent().getDefinition());
sourceRef.setVariable(source.getDefinition());
reaction.getTriggers().add(sourceRef);
// Add this trigger to the list of disconnected network reaction triggers
instance.remoteNetworkReactionTriggers.add(sourceRef);
}

// Add the destination port as an effect of the reaction
reaction.getEffects().add(destRef);
Expand Down Expand Up @@ -730,6 +736,7 @@ public static void makeCommunication(
FedASTUtils.addNetworkInputControlReaction(
source,
destination,
connection,
receivingPortID,
rightBankIndex,
destinationFederate,
Expand Down
5 changes: 2 additions & 3 deletions org.lflang/src/org/lflang/generator/GeneratorBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1174,9 +1174,8 @@ private void replaceConnectionFromFederate(
errorReporter.reportError(output.definition,
"Unexpected error. Cannot find output connection for port");
} else {
if (srcFederate != dstFederate
&& !connection.isPhysical()
&& targetConfig.coordination != CoordinationType.DECENTRALIZED) {
if (!connection.isPhysical()
&& targetConfig.coordination != CoordinationType.DECENTRALIZED) {
// Map the delays on connections between federates.
// First see if the cache has been created.
Set<Delay> dependsOnDelays = dstFederate.dependsOn.get(srcFederate);
Expand Down
36 changes: 36 additions & 0 deletions test/C/src/federated/FeedbackDelaySimple.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
target C {
timeout: 1 sec
}
reactor Loop {
input in:int;
output out:int;
timer t(0, 100 msec);
state count:int(1);
reaction(in) {=
info_print("Received %d.", in->value);
if (in->value != self->count) {
error_print_and_exit(
"Expected %d. Got %d.",
self->count,
in->value
);
}
self->count++;
=}
reaction(t) -> out {=
SET(out, self->count);
=}
reaction(shutdown) {=
if (self->count != 11) {
error_print_and_exit(
"Expected 11 messages. Got %d.",
self->count
);
}
=}
}
federated reactor {
l = new Loop()

l.out -> l.in after 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ federated reactor (delay:time(0)) {
right = new Looper(incr = -1);
left.out -> right.in;
right.out -> left.in;
}
}