Fork me on GitHub
#core-async
<
2017-08-11
>
sophiago20:08:07

can anyone explain to me what a terminator is?

ghadi20:08:01

it's a term from LLVM

ghadi20:08:31

basically the last instruction in a basic block

ghadi20:08:45

so <! and >! and alt! are terminators

sophiago20:08:02

cool, thanks

ghadi20:08:05

because control flow is suspended there

sophiago20:08:58

i'm salvaging some code from core.async for a frankenstein's monster sort of thing

tbaldridge20:08:28

@sophiago have you seen the tests for core.async? They use the pluggable nature of the library to do tests on the macro without running async code. It's a good place to start if you want to hack on the macro a bit

sophiago20:08:18

Ooo, thanks. I'm going to take a look now. I'm working on an automatic differentiation library so need to do a lot of source transformation and so far only overrode defn to dump the ast into metadata, but then I was watching Aysylu Greenberg's talk on Loom from Conj I think three years ago and ended up rewatching (I think?) yours about analyzer and SSA in core.async. It seems it should do a lot of the work for me. Although I guess you never got to the point of writing a general SSA library since Clojure-in-Clojure never really happened?

sophiago20:08:02

Ha, thanks. That was not at all the directory I was looking in

tbaldridge20:08:04

The gist: 1) create a function with a signature you expect to use in the code pause in this case 2) create a terminator by adding extra parameters of state and block before the normal parameters. pause-run in this case 3) Wire it all up by copy/pasting the code you see in that test (`runner`) and replacing the terminator hash map with whatever functions you want to be replaced with termiantors

sophiago20:08:16

Oh, that's great. I had so far just commented out the terminator lines from parse-to-state-machine and wasn't sure what to do with the whole thing 😛

tbaldridge20:08:00

So now whenever pause is called, the code will instead call pause-run and expect you to tell it when to continue. If you need async functions you can look at these definitions to get some hints: https://github.com/clojure/core.async/blob/master/src/main/clojure/clojure/core/async/impl/ioc_macros.clj#L1007-L1011

sophiago20:08:07

So essentially by playing with this test macro I can get a sense of control flow and eventually start transforming it?

tbaldridge20:08:55

yep, that's a great place to start

sophiago20:08:32

I see. A lot of the hard problems in this sort of stuff are considered things like dealing with complex recursion and things you've seemingly already solved.

tbaldridge20:08:52

inside the terminators state is an array of all the locals and state of the state machine. And block is a pointer to the next block to jump into once you want to continue running the machine.

sophiago21:08:22

I'm going to have to play with it to understand how it works I think. Mainly I'm excited that it handles unrolling local control flow into a state machine because then I should be able to do whatever I want with it, not necessarily anything asynchronous.

sophiago21:08:20

I did have an idea to convert local control flow to using agents in order to maximize JVM thread pools, but that was sort of a whim.

sophiago21:08:43

Do you have any research you can point me to that helped when writing all this? I've been looking a lot into papers on analyzing control flow. For example I have this one open right now: https://pdfs.semanticscholar.org/853b/b1490af8f2d58c560bf9c4b32de880538d08.pdf