Add specific scoping documentation

Adds information into the arguments and result
docs about how scoping lookup works and what it
implies.

Change-Id: I810874dce042ec43fe9e704d6689215e19d67c9c
This commit is contained in:
Joshua Harlow
2015-02-24 16:19:04 -08:00
parent 0a97fb96b5
commit 6da46b71d9
3 changed files with 66 additions and 30 deletions

View File

@@ -44,6 +44,8 @@ def _extract_atoms(node, idx=-1):
class ScopeWalker(object):
"""Walks through the scopes of a atom using a engines compilation.
NOTE(harlowja): for internal usage only.
This will walk the visible scopes that are accessible for the given
atom, which can be used by some external entity in some meaningful way,
for example to find dependent values...
@@ -63,29 +65,35 @@ class ScopeWalker(object):
How this works is the following:
We find all the possible predecessors of the given atom, this is useful
since we know they occurred before this atom but it doesn't tell us
the corresponding scope *level* that each predecessor was created in,
so we need to find this information.
We first grab all the predecessors of the given atom (lets call it
``Y``) by using the :py:class:`~.compiler.Compilation` execution
graph (and doing a reverse breadth-first expansion to gather its
predecessors), this is useful since we know they *always* will
exist (and execute) before this atom but it does not tell us the
corresponding scope *level* (flow, nested flow...) that each
predecessor was created in, so we need to find this information.
For that information we consult the location of the atom ``Y`` in the
node hierarchy. We lookup in a reverse order the parent ``X`` of ``Y``
and traverse backwards from the index in the parent where ``Y``
occurred, all children in ``X`` that we encounter in this backwards
search (if a child is a flow itself, its atom contents will be
expanded) will be assumed to be at the same scope. This is then a
*potential* single scope, to make an *actual* scope we remove the items
from the *potential* scope that are not predecessors of ``Y`` to form
the *actual* scope.
:py:class:`~.compiler.Compilation` hierarchy/tree. We lookup in a
reverse order the parent ``X`` of ``Y`` and traverse backwards from
the index in the parent where ``Y`` exists to all siblings (and
children of those siblings) in ``X`` that we encounter in this
backwards search (if a sibling is a flow itself, its atom(s)
will be recursively expanded and included). This collection will
then be assumed to be at the same scope. This is what is called
a *potential* single scope, to make an *actual* scope we remove the
items from the *potential* scope that are **not** predecessors
of ``Y`` to form the *actual* scope which we then yield back.
Then for additional scopes we continue up the tree, by finding the
parent of ``X`` (lets call it ``Z``) and perform the same operation,
going through the children in a reverse manner from the index in
parent ``Z`` where ``X`` was located. This forms another *potential*
scope which we provide back as an *actual* scope after reducing the
potential set by the predecessors of ``Y``. We then repeat this process
until we no longer have any parent nodes (aka have reached the top of
the tree) or we run out of predecessors.
potential set to only include predecessors previously gathered. We
then repeat this process until we no longer have any parent
nodes (aka we have reached the top of the tree) or we run out of
predecessors.
"""
predecessors = set(self._graph.bfs_predecessors_iter(self._atom))
last = self._node