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

Compiler error for reversed range with step parameter #3060

Open
nesanders opened this issue Jul 29, 2019 · 0 comments

Comments

@nesanders
Copy link

commented Jul 29, 2019

Hello,

I am encountering a compiler error in cython when compiling the following expression:

product(*[range(k) for k in reversed(range(1, N, 2))])

where N is a previously assigned integer.

The compiler error is:

 File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/UtilNodes.py", line 185, in result
    return self.result_code
AttributeError: 'ResultRefNode' object has no attribute 'result_code'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    ext_modules=cythonize("util.pyx", compiler_directives={'language_level' : "3"})) 
  File "/usr/local/lib/python3.6/dist-packages/Cython/Build/Dependencies.py", line 1096, in cythonize
    cythonize_one(*args)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Build/Dependencies.py", line 1202, in cythonize_one
    result = compile_single(pyx_file, options, full_module_name=full_module_name)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Main.py", line 727, in compile_single
    return run_pipeline(source, options, full_module_name)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Main.py", line 515, in run_pipeline
    err, enddata = Pipeline.run_pipeline(pipeline, source)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Pipeline.py", line 355, in run_pipeline
    data = run(phase, data)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Pipeline.py", line 335, in run
    return phase(data)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Pipeline.py", line 52, in generate_pyx_code_stage
    module_node.process_implementation(options, result)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ModuleNode.py", line 143, in process_implementation
    self.generate_c_code(env, options, result)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ModuleNode.py", line 384, in generate_c_code
    self.body.generate_function_definitions(env, code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Nodes.py", line 442, in generate_function_definitions
    stat.generate_function_definitions(env, code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Nodes.py", line 442, in generate_function_definitions
    stat.generate_function_definitions(env, code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Nodes.py", line 3176, in generate_function_definitions
    FuncDefNode.generate_function_definitions(self, env, code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Nodes.py", line 1983, in generate_function_definitions
    self.generate_function_body(env, code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Nodes.py", line 1745, in generate_function_body
    self.body.generate_execution_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Nodes.py", line 448, in generate_execution_code
    stat.generate_execution_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Nodes.py", line 5973, in generate_execution_code
    value.generate_evaluation_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 767, in generate_evaluation_code
    self.generate_subexpr_evaluation_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 782, in generate_subexpr_evaluation_code
    node.generate_evaluation_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 767, in generate_evaluation_code
    self.generate_subexpr_evaluation_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 782, in generate_subexpr_evaluation_code
    node.generate_evaluation_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 8236, in generate_evaluation_code
    generate_inner_evaluation_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 773, in generate_evaluation_code
    self.generate_result_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 8305, in generate_result_code
    self.generate_operation_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 8321, in generate_operation_code
    self.loop.generate_execution_code(code)
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Nodes.py", line 6901, in generate_execution_code
    self.bound1.result(), offset,
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 499, in result
    return self.calculate_result_code()
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 11321, in calculate_result_code
    result1, result2 = self.operand1.result(), self.operand2.result()
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 499, in result
    return self.calculate_result_code()
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 11321, in calculate_result_code
    result1, result2 = self.operand1.result(), self.operand2.result()
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/UtilNodes.py", line 188, in result
    self.result_code = self.expression.result()
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 499, in result
    return self.calculate_result_code()
  File "/usr/local/lib/python3.6/dist-packages/Cython/Compiler/ExprNodes.py", line 1377, in calculate_result_code
    return self.result_code
AttributeError: 'IntNode' object has no attribute 'result_code'

The following slightly simpler expressions do compile with no errors,

product(*[range(k) for k in (range(1, N, 2))])

^^ n.b no 'reversed' call

product(*[range(k) for k in reversed(range(1, N))])

^^ n.b no third argument to range function

The purpose of the code snippet I'm testing is similar to e.g. https://stackoverflow.com/a/13020502

I'm using compiler_directives={'language_level' : "3"} with Cython 0.29.13 for use in Python 3.6.8.

Thanks in advance for any suggestions for fixing this and thanks for all the developers' work on cython!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.