Skip to content

Commit

Permalink
[squash][wip] add creatorkeychain
Browse files Browse the repository at this point in the history
  • Loading branch information
axmmisaka committed Aug 20, 2023
1 parent 10b8977 commit e046b40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/benchmark/Sieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class Sieve extends App {
fail?: () => void
) {
super(timeout, keepAlive, fast, success, fail, name);
this.source = new Ramp(this, 100000, TimeValue.nsec(1));
this.filter = new Filter(this, 2, 1000);
this.source = new Ramp(this, 1000, TimeValue.nsec(1));
this.filter = new Filter(this, 2, 10);
this._connect(this.source.value, this.filter.inp);
}
}
Expand Down
30 changes: 19 additions & 11 deletions src/core/reactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export abstract class Reactor extends Component {
*/
private readonly _keyChain = new Map<Component, symbol>();

// This is the keychain for creation, i.e. if Reactor R's mutation created reactor B,
// then R is B's creator, even if they are siblings. R should have access to B,
// at least semantically......?
private readonly _creatorKeyChain = new Map<Component, symbol>();

/**
* This graph has in it all the dependencies implied by this container's
* ports, reactions, and connections.
Expand Down Expand Up @@ -375,7 +380,7 @@ export abstract class Reactor extends Component {
* @param key The key that verifies the containment relation between this
* reactor and the component, with at most one level of indirection.
*/
public _getKey(component: Trigger, key?: symbol): symbol | undefined {
public _getKey(component: Trigger, key?: symbol, allowCreatorKey?: boolean): symbol | undefined {
if (component._isContainedBy(this) || this._key === key) {
return this._keyChain.get(component);
} else if (
Expand All @@ -386,6 +391,12 @@ export abstract class Reactor extends Component {
if (owner !== null) {
return owner._getKey(component, this._keyChain.get(owner));
}
} else if (allowCreatorKey ?? false) {
console.log("trying to get key......")
if (this._creatorKeyChain.get(component) != null) {
return this._creatorKeyChain.get(component);
}
return this._creatorKeyChain.get(component.getContainer());
}
}

Expand Down Expand Up @@ -436,7 +447,7 @@ export abstract class Reactor extends Component {
this.reactor._connectCall(src, dst);
} else if (src instanceof IOPort && dst instanceof IOPort) {
if (this.reactor.canConnect(src, dst) === 2) {
this.reactor._elevatedConnect(src, dst);
throw new Error("Connection will fail due to ");
} else {
this.reactor._connect(src, dst);
}
Expand Down Expand Up @@ -1117,12 +1128,6 @@ export abstract class Reactor extends Component {
throw Error("Destination port is already occupied.");
}

if (! (src.checkKey(this._key) && dst.checkKey(this._key) )) {
// FIXME: dirty hack here
// Scoping issue. Does not possess valid key for src/dst.
return 2;
}

if (!this._runtime.isRunning()) {
// console.log("Connecting before running")
// Validate connections between callers and callees.
Expand Down Expand Up @@ -1245,11 +1250,12 @@ export abstract class Reactor extends Component {
): void {
Log.debug(this, () => `connecting ${src} and ${dst}`);
// Register receiver for value propagation.
const writer = dst.asWritable(this._getKey(dst));
console.log(this._getKey(dst, undefined, true));
const writer = dst.asWritable(this._getKey(dst, undefined, true));
// Add dependency implied by connection to local graph.
this._dependencyGraph.addEdge(src, dst);
src
.getManager(this._getKey(src))
.getManager(this._getKey(src, undefined, true))
.addReceiver(writer as unknown as WritablePort<S>);
const val = src.get();
if (this._runtime.isRunning() && val !== undefined) {
Expand Down Expand Up @@ -1592,7 +1598,9 @@ export abstract class Reactor extends Component {
if (this._getContainer() === this) {
throw new Error(`Reactor ${this} is self-contained. Adding sibling creates logical issue.`);
}
return this._getContainer()._uncheckedAddChild(constructor, ...args);
const newReactor = this._getContainer()._uncheckedAddChild(constructor, ...args);
this._creatorKeyChain.set(newReactor, newReactor._key);
return newReactor;
}

public _elevatedConnect(...args: Parameters<Reactor["_connect"]>): ReturnType<Reactor["_connect"]> {
Expand Down

0 comments on commit e046b40

Please sign in to comment.