[pypy-issue] Issue #1963: Assertion failure in OptimizingVisitor.visit_Name (pypy/pypy)

Dave Watola issues-reply at bitbucket.org
Sat Jan 17 00:44:54 CET 2015


New issue 1963: Assertion failure in OptimizingVisitor.visit_Name
https://bitbucket.org/pypy/pypy/issue/1963/assertion-failure-in

Dave Watola:

Using version 2.4 of pypy, the very simple test case attached crashes with


```
#!

RPython traceback:
  File "pypy_interpreter_pycompiler.c", line 1567, in PythonAstCompiler__compile_ast
  File "pypy_interpreter_astcompiler_ast_1.c", line 20718, in Module_mutate_over
  File "pypy_interpreter_astcompiler_ast_2.c", line 10177, in ASTVisitor__mutate_sequence
  File "pypy_interpreter_astcompiler_ast_1.c", line 45287, in Assign_mutate_over
  File "pypy_interpreter_astcompiler_ast_2.c", line 10177, in ASTVisitor__mutate_sequence
  File "pypy_interpreter_astcompiler_ast_1.c", line 53781, in List_mutate_over
  File "pypy_interpreter_astcompiler_ast_2.c", line 10177, in ASTVisitor__mutate_sequence
  File "pypy_interpreter_astcompiler_optimize.c", line 252, in OptimizingVisitor_visit_Name
Fatal RPython error: AssertionError
Abort (core dumped)
```


This test case uses macropy, which adjusts AST representation using an import hook. 
The crash occurs during compilation -- there is no runtime code in this case.
Aside from this issue, macropy seems to work correctly with pypy.  All seems well with the proposed fix below.

It is not clear what is triggering this optimization, because the original and final ASTs involved do not use "None", I was able to eliminate the problem by editing OptimizingVisitor.visit_Name in pypy/interpreter/astcompiler/optimize.py and changing the guard condition on the "if" statement to include the assertion condition would provide a correct solution.  i.e.


```
#!python

  if name.id=="None" and name.ctx ==ast.Load
```


(and then eliminate the assertion).  

This appears to be a safe and correct change, but I have no familiarity with the pypy code base and thought that someone else should evaluate the situation.






More information about the pypy-issue mailing list