Skip to content

Commit

Permalink
Merge pull request #2416 from lf-lang/disconnected-port
Browse files Browse the repository at this point in the history
Fix disconnected port handling
  • Loading branch information
edwardalee authored Oct 1, 2024
2 parents b00aafe + 7a0a20b commit b69b696
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,9 @@ private static String deferredReactionOutputs(
// If the port is a multiport, then we need to create an entry for each
// individual channel.

// If this port does not have any destinations, do not generate code for it.
if (effect.eventualDestinations().isEmpty()) continue;

// If the port is an input of a contained reactor, then, if that
// contained reactor is a bank, we will have to iterate over bank
// members.
Expand Down
38 changes: 38 additions & 0 deletions test/C/src/TriggerIssue.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** Testing that unconnected port does not block triggering. */
target C {
logging: debug
}

reactor Source {
output x: bool
output y: bool

reaction(startup) -> x, y {=
lf_print("S");
lf_set(y, true);
=}
}

reactor Destination {
input y: bool

state gotY: bool = false

reaction(y) {=
lf_print("Y");
self->gotY = true;
=}

reaction(shutdown) {=
if (!self->gotY) {
lf_print_error_and_exit("No reaction to Y!");
}
=}
}

main reactor {
ui = new Source()
dlc = new Destination()

ui.y -> dlc.y
}
48 changes: 48 additions & 0 deletions test/C/src/TriggerIssue2.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/** Test that untriggered reactions are not triggered. */
target C

reactor OnlySuccess {
input start: bool
output success: bool
output failure: bool

reaction(start) -> success, failure {=
lf_print("Create Success");
lf_set(success, true);
=}
}

reactor ForwardFailure {
input in: bool
output out: bool

reaction(in) -> out {=
lf_print("Forward Failure");
lf_set(out, true);
=}
}

reactor Sequence {
input start: bool
output success: bool
output failure: bool
s = new OnlySuccess()
f = new ForwardFailure()
start -> s.start
s.success -> success
s.failure -> f.in
f.out -> failure
}

main reactor {
s = new Sequence()

reaction(startup) -> s.start {=
lf_print("Start");
lf_set(s.start, true);
=}

reaction(s.failure) {=
lf_print_error_and_exit("Failure");
=}
}

0 comments on commit b69b696

Please sign in to comment.