Skip to content

Commit

Permalink
Change CanConnect logic: remove blanket direct feedthrough ban, and a…
Browse files Browse the repository at this point in the history
…lways check against the global precedence graph.
  • Loading branch information
Kagamihara Nadeshiko committed Dec 13, 2023
1 parent 8956aaa commit 286bc49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 0 additions & 5 deletions __tests__/InvalidMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ class R1 extends Reactor {
[this.in1],
[this.in1, this.in2, this.out1, this.out2],
function (this, __in1, __in2, __out1, __out2) {
test("expect error on creating creating direct feed through", () => {
expect(() => {
this.connect(__in2.asConnectable(), __out2.asConnectable());
}).toThrowError("New connection introduces direct feed through.");
});
test("expect error when creating connection outside container", () => {
expect(() => {
this.connect(__out2.asConnectable(), __in2.asConnectable());
Expand Down
21 changes: 19 additions & 2 deletions src/core/reactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,24 @@ export abstract class Reactor extends Component {
return CanConnectResult.RT_CONNECTION_OUTSIDE_CONTAINER;
}

// Take the local graph and merge in all the causality interfaces
/**
* TODO (axmmisaka): The following code is commented for multiple reasons:
* The causality interface check is not fully implemented so new checks are failing
* Second, direct feedthrough itself would not cause any problem *per se*.
* To ensure there is no cycle, the safest way is to check against the global dependency graph.
*/

let app = this as Reactor;
while (app._getContainer() !== app) {
app = app._getContainer();
}
const graph = app._getPrecedenceGraph();
graph.addEdge(src, dst);
if (graph.hasCycle()) {
return CanConnectResult.RT_CYCLE;
}

/* // Take the local graph and merge in all the causality interfaces
// of contained reactors. Then:
const graph = new PrecedenceGraph<Port<unknown> | Reaction<Variable[]>>();
graph.addAll(this._dependencyGraph);
Expand All @@ -1194,7 +1211,7 @@ export abstract class Reactor extends Component {
dst.getContainer() === src.getContainer()
) {
return CanConnectResult.RT_DIRECT_FEED_THROUGH;
}
} */

return CanConnectResult.SUCCESS;
}
Expand Down

0 comments on commit 286bc49

Please sign in to comment.