[pypy-dev] STM

Timothy Baldridge tbaldridge at gmail.com
Thu Jan 5 17:25:04 CET 2012


> I'm not sure how
> that plays into lexical structure, but intuitively it seems like the
> with-statement style plays nicely.

The lexical scoping method also helps with general sanity of the
programmer. The idea behind STM is that certain failed transactions
need to be re-startable. That is, if the transaction fails the code
needs to be re-run until it succeeds. Without lexical scoping, we can
do some really bizzare stuff like this:

def interator():
  for x in range(100:
    yield x

run_transactions()
for x in interator():
    run_transactions()
    yield x

Here things get super but I guess if we apply the same methodology
that the JIT uses to locate loops, it shouldn't be too bad. The
biggest thing is that in essence, all IO needs to be run only once,
and only when the transaction succeeds. This is why Clojure allows
functions to be marked with "io" tags that will throw exceptions if
executed inside a transaction. But what just gets really fun is when
you start looking at all this and say, "you can only run pure python
code instide a STM...no ctypes, no io, no nothing". Explaining that to
users will be a bit fun when the entire program is STM to start with.

That being said, I'm really excited about this, and can't wait to
start playing with it in my projects.

Timothy


More information about the pypy-dev mailing list