Comments (3)
On the subject of implementing output variables, I came up with what I think is a reasonable eager output implementation that doesn't rely on vtables or special output ref types, i.e., the type implementations and codegen remain entirely agnostic to whether a variable happens to affect the external environment.
Here's some pseudocode for what the tick
function looks, currently:
# start tick by performing all delayed assignments for current time
while event_queue.head().time is now:
let sv = event_queue.dequeue_head()
# perform update
sv.update() # virtual function
# wake up listening processes
for t in sv.triggers:
act_queue.enqueue(t.act)
# etc..
What we want is the value update to be "felt" by the external environment only if an event is an output variable, by calling out to some platform-specific output handler. So far, implementation suggestions have focused on pushing that into the sv
's update
function, or deferring the output handler to take place in a continuation (i.e., after # etc..
).
My suggestion is to add the output handler to a scheduled variable's trigger list, and then invoke that output handler while iterating through the trigger list:
# wake up listening processes
for t in sv.triggers:
case t:
Act (a) -> act_queue.enqueue(a)
OutputHandler (o) -> o()
This runs before any continuations during that instant, meaning it is still eager, but doesn't rely on update
being virtual. Notably, this means we can do the exact same thing during instantaneous assignment, without needing to make assign
virtual. In fact, this requires no modifications to the data type implementations. Also, it doesn't require any extra memory: with some careful bit hacking, we can union the struct act *
and the output handler function pointer in the same field in struct trigger
.
The cost we pay is an extra branch to check each trigger, though I think that can be optimized too (we should only need to check for an output handler once). We also still need to figure out from what interface we obtain these output references, since those will need to add this special trigger to the trigger list, but that's somewhat orthogonal to this discussion.
from scoria.
The solution you pose sounds cool, and I think it would be fun to see how such an implementation looks like, but I am thinking about the problem you initially posed.
In the example program, where m
forks functions f
& g
, is that really a compiler issue? I would think that that's an application error, i.e a poorly written program. All other programming languages surely have the same problem? Or maybe I am missing the point. It seems like we have been too careless with our resources, and now we have two processes that wish to modify the same resource at the same time.
from scoria.
Other "asynchronous" languages usually leave the behavior of data races undefined, or at least nondeterministic, but only because they don't have the total ordering between processes we have (which, to me, is the point of our programming model).
My worry is that, with an eager implementation, an external effect is duplicated, for the same logical time, since the output handler may be invoked multiple times. It just seems inconsistent to say that this behavior is somehow undefined when we give such strong guarantees about the behavior of "races" on variables that aren't output variables.
from scoria.
Related Issues (20)
- Implement unit type as SSMType HOT 4
- Even better shrinker! HOT 2
- Can't use references in operators HOT 6
- SSM time types for frontend HOT 9
- Lower deref from statement level to expression level HOT 1
- Profile interpreter to see if it's the culprit that makes the tests take longer than previously HOT 3
- Transpilation bug - names are duplicated HOT 4
- Ask Zephyr people about 64bit timers
- Refactor interpreter
- Connect standard streams to global references HOT 1
- Make expressions compile to ordinary types in C, not scheduled variables HOT 1
- Remove arguments to the entry point HOT 1
- Inefficient distribution of priorities HOT 1
- Propagate parse errors from trace parsers to testing framework
- Make core syntax more fine grained
- Examples wishlist HOT 2
- Don't assume long == 64-bit
- Add "escape hatch" in EDSL HOT 2
- Integer overflow in interpreter might be UB HOT 1
- [RFC] Output handlers HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scoria.