Skip to content

Commit 286bc49

Browse files
author
Kagamihara Nadeshiko
committed
Change CanConnect logic: remove blanket direct feedthrough ban, and always check against the global precedence graph.
1 parent 8956aaa commit 286bc49

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

__tests__/InvalidMutations.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ class R1 extends Reactor {
3838
[this.in1],
3939
[this.in1, this.in2, this.out1, this.out2],
4040
function (this, __in1, __in2, __out1, __out2) {
41-
test("expect error on creating creating direct feed through", () => {
42-
expect(() => {
43-
this.connect(__in2.asConnectable(), __out2.asConnectable());
44-
}).toThrowError("New connection introduces direct feed through.");
45-
});
4641
test("expect error when creating connection outside container", () => {
4742
expect(() => {
4843
this.connect(__out2.asConnectable(), __in2.asConnectable());

src/core/reactor.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,24 @@ export abstract class Reactor extends Component {
11681168
return CanConnectResult.RT_CONNECTION_OUTSIDE_CONTAINER;
11691169
}
11701170

1171-
// Take the local graph and merge in all the causality interfaces
1171+
/**
1172+
* TODO (axmmisaka): The following code is commented for multiple reasons:
1173+
* The causality interface check is not fully implemented so new checks are failing
1174+
* Second, direct feedthrough itself would not cause any problem *per se*.
1175+
* To ensure there is no cycle, the safest way is to check against the global dependency graph.
1176+
*/
1177+
1178+
let app = this as Reactor;
1179+
while (app._getContainer() !== app) {
1180+
app = app._getContainer();
1181+
}
1182+
const graph = app._getPrecedenceGraph();
1183+
graph.addEdge(src, dst);
1184+
if (graph.hasCycle()) {
1185+
return CanConnectResult.RT_CYCLE;
1186+
}
1187+
1188+
/* // Take the local graph and merge in all the causality interfaces
11721189
// of contained reactors. Then:
11731190
const graph = new PrecedenceGraph<Port<unknown> | Reaction<Variable[]>>();
11741191
graph.addAll(this._dependencyGraph);
@@ -1194,7 +1211,7 @@ export abstract class Reactor extends Component {
11941211
dst.getContainer() === src.getContainer()
11951212
) {
11961213
return CanConnectResult.RT_DIRECT_FEED_THROUGH;
1197-
}
1214+
} */
11981215

11991216
return CanConnectResult.SUCCESS;
12001217
}

0 commit comments

Comments
 (0)