From 8f1f18a773e8e0aacd7098a0a579c705bfee49d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Thu, 15 Sep 2022 16:07:06 +0200 Subject: [PATCH 1/5] Bump runtime --- org.lflang/src/lib/rs/reactor-rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/rs/reactor-rs b/org.lflang/src/lib/rs/reactor-rs index 2804556e68..1cb36535d3 160000 --- a/org.lflang/src/lib/rs/reactor-rs +++ b/org.lflang/src/lib/rs/reactor-rs @@ -1 +1 @@ -Subproject commit 2804556e68f928329169909e497ec92189c1f604 +Subproject commit 1cb36535d3da98712e6eca885001127ec7b98250 From f309cea888aad17a1fb25f013e243507f389d71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Thu, 15 Sep 2022 16:21:15 +0200 Subject: [PATCH 2/5] Support scheduling physical actions synchronously --- .../generator/rust/RustReactorEmitter.kt | 2 +- ...ysicalActionCanBeScheduledSynchronously.lf | 28 +++++++++++++++++++ test/Rust/src/README.md | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf diff --git a/org.lflang/src/org/lflang/generator/rust/RustReactorEmitter.kt b/org.lflang/src/org/lflang/generator/rust/RustReactorEmitter.kt index dd2156172b..ab21972bd1 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustReactorEmitter.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustReactorEmitter.kt @@ -390,7 +390,7 @@ ${" | "..declareChildConnections()} else -> "&$rsRuntime::ReadablePort<$dataType>" // note: a reference } is TimerData -> "&${toType()}" - is ActionData -> if (isLogical && kind == DepKind.Effects) "&mut ${toType()}" else "&${toType()}" + is ActionData -> if (kind == DepKind.Effects) "&mut ${toType()}" else "&${toType()}" } /** diff --git a/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf b/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf new file mode 100644 index 0000000000..d99bbf1a22 --- /dev/null +++ b/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf @@ -0,0 +1,28 @@ +// Tests that physical actions can be scheduled like logical actions within +// the body of reactions. +target Rust + +main reactor { + physical action act: u32 + + state count: u32 + + reaction(startup) -> act {= + ctx.schedule(act, Asap); + ctx.schedule(act, after!(20 ms)); + =} + + reaction(act) {= + println!("---- Invocation at {}", ctx.get_tag()); + self.count += 1; + + // If the physical time is used then it is unlikely to be + // exactly TO + 20 ms. + assert_ne!(ctx.get_elapsed_logical_time(), delay!(20 ms)); + =} + + reaction(shutdown) {= + assert_eq!(self.count, 2); + println!("success"); + =} +} diff --git a/test/Rust/src/README.md b/test/Rust/src/README.md index 5d09ad52eb..0d1f4d8933 100644 --- a/test/Rust/src/README.md +++ b/test/Rust/src/README.md @@ -55,6 +55,7 @@ This is not exhaustive. Ideally each of those bullet points would have a test ca - [x] `PhysicalActionWithKeepalive.lf`: keepalive option should keep the scheduler alive when there are async threads which can send notifications - [x] `PhysicalActionWakesSleepingScheduler.lf`: a physical action triggered during a period of idleness of the scheduler should wake it timely - [x] `PhysicalActionKeepaliveIsSmart.lf`: keepalive option doesn't keep the program alive if live threads do not have a reference to the scheduler + - [x] `PhysicalActionCanBeScheduledSynchronously.lf`: physical actions do not need to be carried by an asynchronous thread to be scheduled. When they are scheduled within a reaction, they still use physical time and not logical time. - [ ] todo does shutdown abort async threads or not? - [x] timers - [x] `TimerDefaults.lf`: timer with all params defaulted (`timer t;`) is non-periodic and has offset zero From f96e322e8ab72075a34bffdfbb8f76a1855e53aa Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 15 Sep 2022 21:19:35 -0700 Subject: [PATCH 3/5] Formatted new test --- org.lflang/src/lib/rs/reactor-rs | 2 +- test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/lib/rs/reactor-rs b/org.lflang/src/lib/rs/reactor-rs index 1cb36535d3..2804556e68 160000 --- a/org.lflang/src/lib/rs/reactor-rs +++ b/org.lflang/src/lib/rs/reactor-rs @@ -1 +1 @@ -Subproject commit 1cb36535d3da98712e6eca885001127ec7b98250 +Subproject commit 2804556e68f928329169909e497ec92189c1f604 diff --git a/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf b/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf index d99bbf1a22..206a3d7d1c 100644 --- a/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf +++ b/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf @@ -1,5 +1,5 @@ -// Tests that physical actions can be scheduled like logical actions within -// the body of reactions. +// Tests that physical actions can be scheduled like logical actions within the +// body of reactions. target Rust main reactor { From 770085ab9aab340a47cd20a1e432b62186108332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 16 Sep 2022 10:30:06 +0200 Subject: [PATCH 4/5] Bump runtime --- org.lflang/src/lib/rs/reactor-rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/rs/reactor-rs b/org.lflang/src/lib/rs/reactor-rs index 2804556e68..a7f47ce4ce 160000 --- a/org.lflang/src/lib/rs/reactor-rs +++ b/org.lflang/src/lib/rs/reactor-rs @@ -1 +1 @@ -Subproject commit 2804556e68f928329169909e497ec92189c1f604 +Subproject commit a7f47ce4ced7c6a214254e100c0392cb82d23f9a From 050fdb2a2e9374e4cf82a429df7149c620e23078 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 19 Sep 2022 06:42:27 +0200 Subject: [PATCH 5/5] update reactor-rs ref after merging https://github.com/lf-lang/reactor-rs/pull/30 --- org.lflang/src/lib/rs/reactor-rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/rs/reactor-rs b/org.lflang/src/lib/rs/reactor-rs index a7f47ce4ce..868c834f0d 160000 --- a/org.lflang/src/lib/rs/reactor-rs +++ b/org.lflang/src/lib/rs/reactor-rs @@ -1 +1 @@ -Subproject commit a7f47ce4ced7c6a214254e100c0392cb82d23f9a +Subproject commit 868c834f0de46b2cd633892ccafb7768357d3bd9