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 0e1f736
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 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
35 changes: 12 additions & 23 deletions src/core/reactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,34 +1168,23 @@ export abstract class Reactor extends Component {
return CanConnectResult.RT_CONNECTION_OUTSIDE_CONTAINER;
}

// 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);

for (const r of this._getOwnReactors()) {
graph.addAll(r._getCausalityInterface());
/**
* 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();
}

// Add the new edge.
const graph = app._getPrecedenceGraph();
graph.addEdge(src, dst);

// 1) check for loops
const hasCycle = graph.hasCycle();
if (hasCycle) {
if (graph.hasCycle()) {
return CanConnectResult.RT_CYCLE;
}

// 2) check for direct feed through.
// FIXME: This doesn't handle while direct feed thorugh cases.
if (
src instanceof InPort &&
dst instanceof OutPort &&
dst.getContainer() === src.getContainer()
) {
return CanConnectResult.RT_DIRECT_FEED_THROUGH;
}

return CanConnectResult.SUCCESS;
}
}
Expand Down

0 comments on commit 0e1f736

Please sign in to comment.