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

Watchdogs #1605

Closed
wants to merge 94 commits into from
Closed
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
718eaab
added func for watchdog name, created watchdog instance class
Dec 26, 2022
43bb491
made some progress on code generation
Jan 5, 2023
20531f0
more functions added for code generation
Jan 5, 2023
371385e
saving progress before pushing
Jan 8, 2023
86c369d
fixed grammar(added watchdog to 'varreformodetransition', removed wat…
Jan 8, 2023
15fc495
added watchdog grammar to reactor
Jan 8, 2023
6124cae
making sure updated before push
Jan 12, 2023
3798f3a
code generation steps (excluding mutex initialization) should be done…
Jan 18, 2023
bf4fd4c
generatewatchdogstruct in generateselfstruct
Jan 18, 2023
b87327f
save changes to watchdog
Feb 1, 2023
4f2fbb1
merge conflicts resolved
Feb 1, 2023
c8c569c
Added a few missing imports, but plenty compile errors remain
lhstrh Feb 8, 2023
10cf741
saving before merging
Feb 8, 2023
63c624f
think fixed merge conflicts?
Feb 8, 2023
90d002f
at least it compiles now
Feb 8, 2023
45f0f9f
Merge remote-tracking branch 'origin/master' into watchdogs
Feb 10, 2023
4db9e0f
fixed build problems
Feb 13, 2023
f7b177e
tried, unsuccessfully, to fix variable grammar error
Feb 13, 2023
0487e8e
watchdog example test
Feb 17, 2023
ca78125
saving reactorc and changes to scopeprovider
Feb 17, 2023
c36cc80
saving changes to scope provider
Feb 17, 2023
94185e7
Fixed the scope provider
lhstrh Feb 18, 2023
41e9487
Merge branch 'watchdogs' of github.com:lf-lang/lingua-franca into wat…
Feb 18, 2023
1726124
fixed trigger table
Feb 20, 2023
6994d46
saved?
Feb 26, 2023
29b7890
merged from main
Feb 26, 2023
43f8999
Merge master into watchdogs
lhstrh Mar 2, 2023
3393c58
fixed compile issues
Mar 3, 2023
78405a3
fixing before merge
Mar 3, 2023
976b102
added casewatchdogs, still not fixed
Mar 9, 2023
0d31103
Also produce code for watchdogs in reactor definition
lhstrh Mar 9, 2023
59b3737
Apply formatter to test
lhstrh Mar 9, 2023
ccb0b6a
Merge remote-tracking branch 'origin/master' into watchdogs
Mar 9, 2023
9d83f55
Fix submodule issues and remove files that should not be checked in
lhstrh Mar 9, 2023
ec8afa7
Remove spurious file
lhstrh Mar 9, 2023
da5b43a
Change order of submodules
lhstrh Mar 9, 2023
9460c1a
Let version of reactor-cpp be the same as in master
lhstrh Mar 9, 2023
f1ae73f
Merge branch 'master' into watchdogs
lhstrh Mar 9, 2023
043cfbc
Make submodule entries uniform
lhstrh Mar 9, 2023
bacf3af
Merge branch 'master' into watchdogs
lhstrh Mar 9, 2023
774411b
Merge branch 'watchdogs' of github.com:lf-lang/lingua-franca into wat…
Mar 9, 2023
41c5430
Update org.lflang/src/org/lflang/ast/ToLf.java
Benichiwa Mar 9, 2023
89abf74
Update org.lflang/src/org/lflang/ast/IsEqual.java
Benichiwa Mar 9, 2023
e4be4d5
Update org.lflang/src/org/lflang/ast/IsEqual.java
Benichiwa Mar 9, 2023
a81d25b
removed fixmes, updated grammar
Mar 9, 2023
f453bc4
Merge branch 'watchdogs' of github.com:lf-lang/lingua-franca into wat…
Mar 9, 2023
88dbef7
fixed ccpp test issue?
Mar 9, 2023
06b338e
Merge branch 'master' into watchdogs
lhstrh Mar 10, 2023
5670e27
saving before pull again
Mar 13, 2023
0b27dd0
save before second pull
Mar 13, 2023
8df2efa
Merge branch 'watchdogs' of github.com:lf-lang/lingua-franca into wat…
Mar 13, 2023
c0ecf59
fixed
Mar 13, 2023
945bffe
added error reporting for unthreaded w watchdog
Mar 15, 2023
8228827
saving before checkout out klighd-workaround
Mar 20, 2023
2af0fa7
saving before klighd workaround
Mar 20, 2023
78b7fb5
merged reacotr-c
Mar 20, 2023
be2a4c9
some changes to code review
Mar 20, 2023
d87274f
Align lingua-franca/watchdogs with reactor-c/watchdogs
edwardalee Mar 25, 2023
aaa7368
Merged master in watchdogs
edwardalee Mar 25, 2023
e8a1b05
Deleted spurious empty files
edwardalee Mar 25, 2023
f9e9853
Merge remote-tracking branch 'origin/master' into watchdogs
edwardalee Mar 25, 2023
998787a
Merge remote-tracking branch 'origin/watchdogs' into watchdogs-eal
edwardalee Mar 25, 2023
534a003
Removed unused imports
edwardalee Mar 25, 2023
cb06dff
Group watchdog with action
edwardalee Mar 25, 2023
302f690
Removed unused imports
edwardalee Mar 25, 2023
7b05cd6
Removed non-substantive change
edwardalee Mar 25, 2023
673a7fc
Removed unused or redundant imports
edwardalee Mar 25, 2023
91086ad
Made this a real test
edwardalee Mar 25, 2023
c20e711
Made fields private and rearranged
edwardalee Mar 25, 2023
bb2a21d
Fixed hasWatchdogs, which was always returning true
edwardalee Mar 25, 2023
6d33efc
Regularized function pointer
edwardalee Mar 25, 2023
5e31d32
Align reactor-c
edwardalee Mar 25, 2023
60cf911
merged changes, fixed inconsistencies, implemented watchdog stop
Mar 31, 2023
7fb877b
threading error working
Mar 31, 2023
58da147
merged master
Mar 31, 2023
8b3b3e3
saving before pull again
Mar 31, 2023
e1c7046
Merge branch 'watchdogs' of github.com:lf-lang/lingua-franca into wat…
Mar 31, 2023
6c22729
fixed generator issue
Mar 31, 2023
7b6ea7a
got everything to merge from watchdogs-eal branch
Mar 31, 2023
a4740c3
saving before continuing changes
Apr 3, 2023
1af9922
added watchdog to body of itself, started making changes to treat wat…
Apr 3, 2023
b5d6d58
create triggers save progress
Benichiwa Apr 5, 2023
34f96e5
fixed watchdog test inconsistency? define watchdog trigger
Apr 5, 2023
f91883e
Merge branch 'master' of github.com:lf-lang/lingua-franca into watchdogs
Apr 10, 2023
a35208f
tried removing boolean from self-base_t struct, failed, everything wo…
Apr 10, 2023
5773b89
created check for runtime, and removed local one for each class
Apr 14, 2023
9e9aac7
saving changes before merging
Apr 14, 2023
755ff09
save before reattempting the merge
Apr 18, 2023
918c49a
hopefully succesfully resolved merge conflicts
Apr 20, 2023
b95830e
issues fixed w watchdog test, seems to be working as expected, not su…
Apr 20, 2023
3b8e0f7
removed fake python test
Apr 20, 2023
1f86008
updating reactor-c
Apr 21, 2023
1493800
fixed invocation of watchdog_stop in watchdog test
Apr 21, 2023
8aef4f7
fixed problem in recordWatchdogs (maybe temporary)
Apr 27, 2023
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
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
url = https://github.com/lf-lang/reactor-c-py.git
[submodule "org.lflang/src/lib/cpp/reactor-cpp"]
path = org.lflang/src/lib/cpp/reactor-cpp
url = https://github.com/lf-lang/reactor-cpp
url = https://github.com/lf-lang/reactor-cpp.git
[submodule "org.lflang/src/lib/rs/reactor-rs"]
path = org.lflang/src/lib/rs/reactor-rs
url = https://github.com/lf-lang/reactor-rs
url = https://github.com/lf-lang/reactor-rs.git
23 changes: 22 additions & 1 deletion org.lflang/src/org/lflang/ASTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
import org.lflang.lf.Type;
import org.lflang.lf.VarRef;
import org.lflang.lf.Variable;

//FIXME: modif4watchdogs
import org.lflang.lf.Watchdog;
import org.lflang.lf.WidthSpec;
import org.lflang.lf.WidthTerm;
import org.lflang.util.StringUtil;
Expand Down Expand Up @@ -122,13 +125,16 @@ public class ASTUtils {
/**
* A mapping from Reactor features to corresponding Mode features for collecting contained elements.
*/
//FIXME: modif4watchdogs
// added 'featurePackage.getReactor_Watchdogs'
private static final Map<EStructuralFeature, EStructuralFeature> reactorModeFeatureMap = Map.of(
featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(),
featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(),
featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(),
featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(),
featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(),
featurePackage.getReactor_Timers(), featurePackage.getMode_Timers()
featurePackage.getReactor_Timers(), featurePackage.getMode_Timers(),
featurePackage.getReactor_Watchdogs(), featurePackage.getMode_Watchdogs()
);


Expand Down Expand Up @@ -412,6 +418,16 @@ public static List<Reaction> allReactions(Reactor definition) {
return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions());
}

/**
* Given a reactor class, return a list of all its watchdogs.
* @param definition Reactor class definition
* @return List<Watchdog>
*/
// FIXME: modif4watchdogs
public static List<Watchdog> allWatchdogs(Reactor definition) {
return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs());
}

/**
* Given a reactor class, return a list of all its state variables,
* which includes state variables of base classes that it extends.
Expand Down Expand Up @@ -1059,6 +1075,11 @@ public static InferredType getInferredType(Port p) {
return getInferredType(p.getType(), null);
}

//FIXME: modif4watchdogs
Copy link
Member

Choose a reason for hiding this comment

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

According to the grammar, watchdogs don't have a value or type, so there appears to be nothing actionable here. Remove?

// public static InferredType getInferredType(Watchdog w) {
// return getInferredType(w.getType(), null);
// }



/**
Expand Down
15 changes: 11 additions & 4 deletions org.lflang/src/org/lflang/LinguaFranca.xtext
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Reactor:
| (connections+=Connection)
| (reactions+=Reaction)
| (modes+=Mode)
| (watchdogs+=Watchdog)
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this up, right after the actions?

)* '}';


Expand Down Expand Up @@ -176,7 +177,8 @@ Mode:
(actions+=Action) |
(instantiations+=Instantiation) |
(connections+=Connection) |
(reactions+=Reaction)
(reactions+=Reaction) |
(watchdogs+=Watchdog)
edwardalee marked this conversation as resolved.
Show resolved Hide resolved
)* '}';

// Action that has either a physical or logical origin.
Expand Down Expand Up @@ -213,6 +215,11 @@ BuiltinTriggerRef:

Deadline:
'deadline' '(' delay=Expression ')' code=Code;

Watchdog:
'watchdog' name=ID '(' timeout=Expression ')'
('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)?
code=Code;

STP:
'STP' '(' value=Expression ')' code=Code;
Expand Down Expand Up @@ -274,7 +281,7 @@ TypedVariable:
;

Variable:
TypedVariable | Timer | Mode;
TypedVariable | Timer | Mode | Watchdog;

VarRef:
variable=[Variable] | container=[Instantiation] '.' variable=[Variable]
Expand Down Expand Up @@ -449,7 +456,7 @@ SignedFloat:
// Just escaping with \ is not a good idea because then every \ has to be escaped \\.
// Perhaps the string EQUALS_BRACE could become '=}'?
Code:
//{Code} '{=' (tokens+=Token)* '=}'
// {Code} '{=' (tokens+=Token)* '=}'
{Code} '{=' body=Body '=}'
;

Expand Down Expand Up @@ -496,7 +503,7 @@ Token:
'mutable' | 'input' | 'output' | 'timer' | 'action' | 'reaction' |
'startup' | 'shutdown' | 'after' | 'deadline' | 'mutation' | 'preamble' |
'new' | 'federated' | 'at' | 'as' | 'from' | 'widthof' | 'const' | 'method' |
'interleaved' | 'mode' | 'initial' | 'reset' | 'history' |
'interleaved' | 'mode' | 'initial' | 'reset' | 'history' | 'watchdog' |
// Other terminals
NEGINT | TRUE | FALSE |
// Action origins
Expand Down
17 changes: 16 additions & 1 deletion org.lflang/src/org/lflang/ast/IsEqual.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
import org.lflang.lf.Variable;
import org.lflang.lf.WidthSpec;
import org.lflang.lf.WidthTerm;
//FIXME: modif4watchdogs
import org.lflang.lf.Watchdog;
import org.lflang.lf.util.LfSwitch;

/**
Expand Down Expand Up @@ -392,12 +394,14 @@ public Boolean caseElement(Element object) {

@Override
public Boolean caseTypedVariable(TypedVariable object) {
//FIXME: modif4watchdogs
throw thereIsAMoreSpecificCase(TypedVariable.class, Port.class, Action.class);
}

@Override
public Boolean caseVariable(Variable object) {
throw thereIsAMoreSpecificCase(Variable.class, TypedVariable.class, Timer.class, Mode.class);
//FIXME: modif4watchdogs
Benichiwa marked this conversation as resolved.
Show resolved Hide resolved
throw thereIsAMoreSpecificCase(Variable.class, TypedVariable.class, Timer.class, Mode.class, Watchdog.class);
}

@Override
Expand Down Expand Up @@ -487,6 +491,17 @@ public Boolean caseArraySpec(ArraySpec object) {
.conclusion;
}

//FIXME: modif4watchdogs
Benichiwa marked this conversation as resolved.
Show resolved Hide resolved
@Override
public Boolean caseWatchdog(Watchdog object) {
return new ComparisonMachine<>(object, Watchdog.class)
.equalAsObjects(Watchdog::getName)
.equivalent(Watchdog::getTimeout)
.listsEquivalent(Watchdog::getEffects)
.equivalent(Watchdog::getCode)
.conclusion;
}

@Override
public Boolean caseWidthSpec(WidthSpec object) {
return new ComparisonMachine<>(object, WidthSpec.class)
Expand Down
38 changes: 38 additions & 0 deletions org.lflang/src/org/lflang/ast/ToLf.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.lflang.lf.VarRef;
import org.lflang.lf.Variable;
import org.lflang.lf.Visibility;
import org.lflang.lf.Watchdog;
import org.lflang.lf.WidthSpec;
import org.lflang.lf.WidthTerm;
import org.lflang.lf.util.LfSwitch;
Expand Down Expand Up @@ -390,6 +391,7 @@ public MalleableString caseReactor(Reactor object) {
// | (outputs+=Output)
// | (timers+=Timer)
// | (actions+=Action)
// | (watchdogs+=Watchdog)
// | (instantiations+=Instantiation)
// | (connections+=Connection)
// | (reactions+=Reaction)
Expand All @@ -407,6 +409,7 @@ public MalleableString caseReactor(Reactor object) {
object.getOutputs(),
object.getTimers(),
object.getActions(),
object.getWatchdogs(),
object.getInstantiations(),
object.getConnections(),
object.getStateVars()),
Expand Down Expand Up @@ -653,6 +656,41 @@ public MalleableString caseDeadline(Deadline object) {
return handler(object, "deadline", Deadline::getDelay, Deadline::getCode);
}

//FIXME: modif4watchdogs
Benichiwa marked this conversation as resolved.
Show resolved Hide resolved
@Override
public MalleableString caseWatchdog(Watchdog object) {
// 'watchdog' name=ID '(' timeout=Expression ')'
// ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)?
// code=Code;

Builder msb = new Builder();
msb.append("watchdog ");
msb.append(object.getName());
msb.append(list(true, object.getTimeout()));

if (!object.getEffects().isEmpty()) {
List<Mode> allModes = ASTUtils.allModes(ASTUtils.getEnclosingReactor(object));
msb.append(" -> ", " ->\n")
.append(
object.getEffects().stream()
.map(
varRef ->
(allModes.stream()
.anyMatch(
m -> m.getName().equals(varRef.getVariable().getName())))
? new Builder()
.append(varRef.getTransition())
.append("(")
.append(doSwitch(varRef))
.append(")")
.get()
: doSwitch(varRef))
.collect(new Joiner(", ")));
}
msb.append(" ").append(doSwitch(object.getCode()));
return msb.get();
}

@Override
public MalleableString caseSTP(STP object) {
// 'STP' '(' value=Expression ')' code=Code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
import org.lflang.lf.TriggerRef;
import org.lflang.lf.VarRef;
import org.lflang.lf.Variable;
import org.lflang.lf.Watchdog;

import com.google.common.base.Objects;

Expand Down Expand Up @@ -461,9 +462,27 @@ private boolean contains(Timer timer) {
}
}
}

return false;
}

//FIXME:modif4watchdogs

// public boolean contains(Watchdog watchdog) {
// Reactor reactor = ASTUtils.getEnclosingReactor(watchdog);
// if (!reactor.isFederated() || this.isSingleton()) {
// return true;
// }

// if (!reactor.getWatchdogs().contains(watchdog)) {
// return false;
// }

// if (networkReactions.contains(watchdog)) {
// return true;
// }

// return false;
// }

/**
* Return true if the specified reactor instance or any parent
Expand Down
2 changes: 1 addition & 1 deletion org.lflang/src/org/lflang/generator/ReactionInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public ReactionInstance(
* Deadline for this reaction instance, if declared.
*/
public DeadlineInstance declaredDeadline;

/**
* Sadly, we have no way to mark reaction "unordered" in the AST,
* so instead, we use a magic comment at the start of the reaction body.
Expand Down
29 changes: 29 additions & 0 deletions org.lflang/src/org/lflang/generator/ReactorInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
import org.lflang.lf.Timer;
import org.lflang.lf.VarRef;
import org.lflang.lf.Variable;
import org.lflang.lf.Watchdog;
import org.lflang.lf.WidthSpec;
//FIXME: modif4watchdogs
import org.lflang.lf.Watchdog;


/**
Expand Down Expand Up @@ -144,6 +147,10 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re
/** List of reaction instances for this reactor instance. */
public final List<ReactionInstance> reactions = new ArrayList<>();

/** List of watchdog instances for this reactor instance. */
//FIXME: modif4watchdogs
public final List<WatchdogInstance> watchdogs = new ArrayList<>();

/** The timer instances belonging to this reactor instance. */
public final List<TimerInstance> timers = new ArrayList<>();

Expand Down Expand Up @@ -743,6 +750,24 @@ protected void createReactionInstances() {
}
}

/**
* Create all the watchdog instances of this reactor instance.
*/
// FIXME: modif4watchdogs
protected void createWatchdogInstances() {
List<Watchdog> watchdogs = ASTUtils.allWatchdogs(reactorDefinition);
if (watchdogs != null) {
for (Watchdog watchdog : watchdogs) {
// Create the watchdog instance.
var watchdogInstance = new WatchdogInstance(watchdog, this);

// Add the watchdog instance to the list of watchdogs for this
// reactor.
this.watchdogs.add(watchdogInstance);
}
}
}

/**
* Returns the built-in trigger or create a new one if none exists.
*/
Expand Down Expand Up @@ -849,6 +874,10 @@ private ReactorInstance(
// Note that this can only happen _after_ the children,
// port, action, and timer instances have been created.
createReactionInstances();

// Create the reaction instances in this reactor instance.
// FIXME: modif4watchdogs
createWatchdogInstances();

// Instantiate modes for this reactor instance
// This must come after the child elements (reactions, etc) of this reactor
Expand Down
Loading