Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnesting Nested Subscripts and Attributes #1299

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion dace/frontend/python/newast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,9 @@ def __init__(self,
# Indirections
self.indirections = dict()

# Program variables
self.pvars = dict() # Dict[str, Any]

@classmethod
def progress_count(cls) -> int:
""" Returns the number of parsed SDFGs so far within this run. """
Expand Down Expand Up @@ -3120,6 +3123,12 @@ def visit_AnnAssign(self, node: ast.AnnAssign):
self._visit_assign(node, node.target, None, dtype=dtype)

def _visit_assign(self, node, node_target, op, dtype=None, is_return=False):

# NOTE: Assuming (for now) simple assignment with single target (LHS).
# NOTE: This should be enforced by the preprocessor.
# NOTE: There may be issues with implicit swaps (e.g., a, b = b, a).
assert isinstance(node_target, (ast.Name, ast.Subscript, ast.Attribute))

# Get targets (elts) and results
elts = None
results = None
Expand All @@ -3143,6 +3152,12 @@ def _visit_assign(self, node, node_target, op, dtype=None, is_return=False):

for target, (result, _) in zip(elts, results):

if not isinstance(result, (ast.Name, ast.Subscript, ast.Attribute)):
assert isinstance(target, ast.Name)
assert target.id not in self.pvars
self.pvars[target.id] = result
continue

name = rname(target)
true_name = None
if name in defined_vars:
Expand Down Expand Up @@ -4277,8 +4292,20 @@ def visit_Call(self, node: ast.Call, create_callbacks=False):
if self._has_sdfg(node.func.value):
func = node.func.value

# https://stackoverflow.com/a/2020083
def fullname(f):
module = f.__module__
if module == 'builtins':
return f.__qualname__ # avoid outputs like 'builtins.str'
return module + '.' + f.__qualname__

if isinstance(node.func, ast.Name) and node.func.id in self.pvars:
funcname = fullname(self.pvars[node.func.id])
print(funcname)

if func is None:
funcname = rname(node)
if funcname is None:
funcname = rname(node)
# Check if the function exists as an SDFG in a different module
modname = until(funcname, '.')
if ('.' in funcname and len(modname) > 0 and modname in self.globals
Expand Down
Loading
Loading