-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Reactor::{connect, connectMulti, canConnect} #232
Conversation
0a40ff3
to
7570459
Compare
7570459
to
e165c8c
Compare
After discussion today with @lhstrh we discovered that the current logic of detecting causality interface/direct feedthrough is a bit problematic. I will keep as-is as of now (i.e. no change on enum type/return type) and add tests to make sure that the causality interface issue is resolved first. This is honestly something that needs to be done a long time ago but it is really seriously overdue...... |
83e015e
to
33fab10
Compare
@lhstrh : Or, should we NOT allow this do be done at all in one tag? This will be logically hard to achieve, I'm afraid, as this way we will need to record if a port is newly connected in the current tag.
this.addMutation(
[this.trig],
[this.writable(this.myport), this.myport.asConnectable(), this.destport.asConnectable()],
function (this, wport, cport, dest) {
this.connect(cport, dest);
wport.set(123);
}
);
this.addMutation(
[this.trig],
[this.writable(this.myport), this.destport.asConnectable()],
function (this, port, dest) {
this.connect(dest, cport);
port.getPort().asConnectable().set(123);
}
); Here are some approaches, but I'm still thinking about tradeoff/reason to allow only one:
|
14d18a3
to
a0dd502
Compare
a0dd502
to
3d33c61
Compare
3d33c61
to
3248225
Compare
One problem with the diff is that all of the logging stuff is in it too. I think |
Fixed! Sorry |
61237d7
to
286bc49
Compare
286bc49
to
0e1f736
Compare
0. `canConnect` doesn't experience situations where throwing Error is required. 1. `canConnect` is solely for testing and should not throw. 2. `connect` and `connectMulti` should throw. Simply return result from `canConnect` and throw in functions that calls them.
Most of them were achieved by a dirty hack: by changing `toBe(true)` to be `toBeFalsy()` and vice versa. The negation of truthiness is because if connection can be established, we return 0, which is falsy. Otherwise we return an error enum which is truthy. This is a bit C-esque and not JS-y, but let's keep it this way as of now. Throw-catch would technically work, but it's not technically an error because we are **testing** if a connection can be established. Returning an error would also technically work, and we can add some type matching to make it work more smoothly, but as of now I intend to keep it this way. One WIP would be to change `toBeTruthy` to the actual error code, but then some tests might break. We will need to investigate instead of coding tests based on the results.
1. Implemented ConnectablePort that can be used as `Variable` 2. Refactored ConnectablePort with function overloading at the same time to facilitate better type check (but due to TS limitation there's no type narrowing, see microsoft/TypeScript#22609) 3. Made tests conform to the new connection API
1. Adapt Sieve by simply using ConnectablePort 2. Adapt Online Facility Location by using ConnectablePort *and* making necessary changes to reflect the actual logic, as discussed with @lhstrh. In this case, two sources: an OutPort (port A), and a mutation, wants to write to an OutPort (port B), but at different times. The correct thing to do, then, will be to make the mutation have its own OutPort (port C) to write to, and when it wants to write to port B, it disconnects A->B, makes connection C->B, and write to C.
Specifically ones that are related to causality graph and `ConnectablePort` - that is, declaring `ConnectablePort` in a mutation should not create dependency between them, but connection between ports should.
…lways check against the global precedence graph.
0e1f736
to
d140fdc
Compare
While there may be some rough edges in the PR, it's generally a solid improvement, and the tests are running fine, so we should probably just go ahead and merge this... |
canConnect
doesn't experience situations where throwing Error is required.canConnect
is solely for testing and should not throw.connect
andconnectMulti
should throw. Simply return result fromcanConnect
and throw in functions that calls them.ConnectablePort
Note: this task ended up being a rather insane one - I told @lhstrh on Friday that I will make some slight restructuring to make it more sane, but it turns out that my attempts are rather futile and I will commit the rough and crazy one I made on Friday. The issue is thatConnectablePort
must still be able to be a validVariable
and cannot be a copy/wrapper that could be passed intoconnect
. After all,connect
taking anIOPort
is too big to be changed as of now. So my approach is to make a simple wrapper to bypass the causality interface update. I think a more radical solution (such as makingconnect
only takeConnectablePort
, and unwrap/get theIOPort
inside of it) deserves another branch/PR.Do not limit the scope on local check if causality interface has changedAlways do global check