viff

changeset 1215:f2fce145b9e1

Remove unused increment_pc decorator.
author Martin Geisler <mg@cs.au.dk>
date Fri, 18 Sep 2009 15:48:52 +0200
parents 34a7d23462a7
children d325a4ee6625
files doc/program-counters.txt doc/runtime.txt viff/runtime.py
diffstat 3 files changed, 27 insertions(+), 72 deletions(-) [+]
line diff
     1.1 --- a/doc/program-counters.txt	Fri Sep 18 14:43:01 2009 +0200
     1.2 +++ b/doc/program-counters.txt	Fri Sep 18 15:48:52 2009 +0200
     1.3 @@ -88,63 +88,41 @@
     1.4  point in the execution tree. The execution tree is never explicitly
     1.5  constructed in VIFF, so a simple static numbering is not possible.
     1.6  
     1.7 -Instead we mark methods that need to increment the program counter
     1.8 -with the :func:`viff.runtime.increment_pc` decorator. The program
     1.9 -counter starts at the value ``[0]`` and the decorated method will now
    1.10 -begin by doing::
    1.11 +The program counter starts at the value ``[0]``. It is changed in two
    1.12 +cases:
    1.13  
    1.14 -  self.program_counter[-1] += 1
    1.15 -  self.program_counter.append(0)
    1.16 +* when a callback is scheduled using
    1.17 +  :meth:`viff.runtime.BasicRuntime.schedule_callback`, a new
    1.18 +  sub-program counter is allocated. A sub-program counter is simply a
    1.19 +  program counter with another digit. Because of the asynchronous
    1.20 +  network, the callback will be invoked at an unknown later time. When
    1.21 +  invoked, it sees the sub-program counter. This ensures that that the
    1.22 +  parties agree on any network traffic produced in the callback.
    1.23  
    1.24 -before it executes its body. When the body is finished, the method
    1.25 -does::
    1.26 +  When a piece of code like this::
    1.27  
    1.28 -  self.program_counter.pop()
    1.29 +    def cb(ignored):
    1.30 +        print "callback:", self.program_counter
    1.31 +    d = Deferred()
    1.32  
    1.33 -before it returns. A method :meth:`foo` defined like this::
    1.34 +    print "main:", self.program_counter
    1.35 +    self.schedule_callback(d, cb)
    1.36 +    print "main:", self.program_counter
    1.37  
    1.38 -  @increment_pc
    1.39 -  def foo(self):
    1.40 -      print "foo:", self.program_counter
    1.41 +    d.callback(None)
    1.42  
    1.43 -is thus turned into this::
    1.44 +  is executed, one will see output like this:
    1.45  
    1.46 -  def foo(self):
    1.47 -      self.program_counter[-1] += 1
    1.48 -      self.program_counter.append(0)
    1.49 -      print "foo:", self.program_counter
    1.50 -      self.program_counter.pop()
    1.51 +  .. code-block:: none
    1.52  
    1.53 -and when executed starting from the initial program counter of ``[0]``
    1.54 -we see that it prints ``foo: [1, 0]`` and leaves the program counter
    1.55 -at ``[1]`` after it returns. It is very important that the program
    1.56 -counter is left changed like this, for this means that the next call
    1.57 -to :meth:`foo` will print ``foo: [2, 0]`` and increment the program
    1.58 -counter to ``[2]``.
    1.59 +     main: [0]
    1.60 +     main: [1]
    1.61 +     callback: [0, 0]
    1.62  
    1.63 -If we have a method :meth:`bar` which calls :meth:`foo` several times::
    1.64 +* some functions depend on a unique program counter. These functions
    1.65 +  simply increase the last digit in the current program counter::
    1.66  
    1.67 -  @increment_pc
    1.68 -  def bar(self):
    1.69 -      print "bar:", self.program_counter
    1.70 -      self.foo()
    1.71 -      print "bar:", self.program_counter
    1.72 -      self.foo()
    1.73 -      print "bar:", self.program_counter
    1.74 -
    1.75 -then the result of calling :meth:`bar` will be:
    1.76 -
    1.77 -.. code-block:: none
    1.78 -
    1.79 -   bar: [1, 0]
    1.80 -   foo: [1, 1, 0]
    1.81 -   bar: [1, 1]
    1.82 -   foo: [1, 2, 0]
    1.83 -   bar: [1, 2]
    1.84 -
    1.85 -Notice how each sub-call adds another digit to the counter and how it
    1.86 -increments the counter used at the level of the caller. This system
    1.87 -ensures that all program counters are unique.
    1.88 +    self.program_counter[-1] += 1
    1.89  
    1.90  
    1.91  Alternatives
     2.1 --- a/doc/runtime.txt	Fri Sep 18 14:43:01 2009 +0200
     2.2 +++ b/doc/runtime.txt	Fri Sep 18 15:48:52 2009 +0200
     2.3 @@ -31,8 +31,6 @@
     2.4        and other messages. They serve to distinguish messages sent with
     2.5        the same program counter from one another.
     2.6  
     2.7 -   .. autofunction:: increment_pc
     2.8 -
     2.9     .. autofunction:: preprocess
    2.10  
    2.11        See also :ref:`preprocessing` for more background information.
    2.12 @@ -88,9 +86,7 @@
    2.13           different parts of the program execution never reuses the
    2.14           same program counter for different variables.
    2.15  
    2.16 -         The :func:`increment_pc` decorator is responsible for
    2.17 -         dynamically building the tree as the execution unfolds and
    2.18 -         :meth:`schedule_callback` is responsible for scheduling
    2.19 -         callbacks with the correct program counter.
    2.20 +         The :meth:`schedule_callback` method is responsible for
    2.21 +         scheduling callbacks with the correct program counter.
    2.22  
    2.23           See :ref:`program-counters` for more background information.
     3.1 --- a/viff/runtime.py	Fri Sep 18 14:43:01 2009 +0200
     3.2 +++ b/viff/runtime.py	Fri Sep 18 15:48:52 2009 +0200
     3.3 @@ -401,25 +401,6 @@
     3.4          reason.trap(ConnectionDone)
     3.5  
     3.6  
     3.7 -def increment_pc(method):
     3.8 -    """Make *method* automatically increment the program counter.
     3.9 -
    3.10 -    Adding this decorator to a :class:`Runtime` method will ensure
    3.11 -    that the program counter is incremented correctly when entering
    3.12 -    the method.
    3.13 -    """
    3.14 -
    3.15 -    @wrapper(method)
    3.16 -    def inc_pc_wrapper(self, *args, **kwargs):
    3.17 -        try:
    3.18 -            self.program_counter[-1] += 1
    3.19 -            self.program_counter.append(0)
    3.20 -            return method(self, *args, **kwargs)
    3.21 -        finally:
    3.22 -            self.program_counter.pop()
    3.23 -    return inc_pc_wrapper
    3.24 -
    3.25 -
    3.26  def preprocess(generator):
    3.27      """Track calls to this method.
    3.28