copperhead
copperhead copied to clipboard
[FIXED] copperhead/compiler/rewrites.py seems not to handle nested argument lists
Hi
trying the samples/of_cg.py demo I have noticed that the rewriter is not able to correctly associate nested argument names to variables
The culprit seems to be lines 724-725 of file copperhead/compiler/rewrites.py
for (internal, external) in zip(functionArguments, instantiatedArguments):
env[internal.id] = external
which expect the argument list to be a flat list, while in of_gc.py there are 2 functions using nested argument lists
def of_spmv((du, dv), width, (m1, m2, m3, m4, m5, m6, m7)):
<body>
def precondition(u, v, (p1, p2, p3)):
<body>
By rewriting the initial part of the functions as follow all works fine
def precondition(u, v, p1_p3):
(p1, p2, p3) = p1_p3
<body>
def of_spmv(du_dv, width, m1_m7):
(du, dv) = du_dv
(m1, m2, m3, m4, m5, m6, m7) = m1_m7
<body>
[FIX]: I think I fixed the problem by moving the name_tuples step before the inline one in copperhead/compiler/passes.py
diff --git a/copperhead/compiler/passes.py b/copperhead/compiler/passes.py
index 6d5fa29..672e5bd 100644
--- a/copperhead/compiler/passes.py
+++ b/copperhead/compiler/passes.py
@@ -243,6 +243,7 @@ frontend = Pipeline('frontend', [gather_source,
procedure_flatten,
expression_flatten,
syntax_check,
+ name_tuples, # FIX: moved here to avoid inline errors with nested argument lists
inline,
cast_literals,