Problem with conditional expressions using constants non boolean values.
See original GitHub issueHello,
I found a code where CPython works and nuitka fails compiling.
python -m nuitka --standalone nuitka_test.py
Problem with <Node 'STATEMENT_CONDITIONAL'> at nuitka_test.py:2
Problem with <Node 'STATEMENT_TRY'> at nuitka_test.py:1
Nuitka:WARNING:Problem creating function code '__main__$$$function_1_test'.
Nuitka:WARNING:Problem creating code for module <Node 'PYTHON_MAIN_MODULE' with {'filename': 'nuitka_test.py', 'main_added': False, 'mode': 'compiled'}>.
Traceback (most recent call last):
File "C:\Python37-32\lib\site-packages\nuitka\__main__.py", line 184, in <module>
main()
File "C:\Python37-32\lib\site-packages\nuitka\__main__.py", line 177, in main
MainControl.main()
File "C:\Python37-32\lib\site-packages\nuitka\MainControl.py", line 756, in main
result, options = compileTree(main_module=main_module)
File "C:\Python37-32\lib\site-packages\nuitka\MainControl.py", line 649, in compileTree
makeSourceDirectory(main_module=main_module)
File "C:\Python37-32\lib\site-packages\nuitka\MainControl.py", line 377, in makeSourceDirectory
module_name=module.getFullName(),
File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeGeneration.py", line 413, in prepareModuleCode
function_body=function_body, context=context
File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeGeneration.py", line 352, in generateFunctionBodyCode
cross_module=function_body.isCrossModuleUsed()
File "C:\Python37-32\lib\site-packages\nuitka\codegen\FunctionCodes.py", line 535, in getFunctionCode
needs_exception_exit=needs_exception_exit,
File "C:\Python37-32\lib\site-packages\nuitka\codegen\FunctionCodes.py", line 572, in _getFunctionCode
context=context,
File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 246, in generateStatementSequenceCode
statement_sequence=statement_sequence, emit=emit, context=context
File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 217, in _generateStatementSequenceCode
statement=statement, emit=statement_codes, context=context
File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 173, in generateStatementCode
statement=statement, emit=emit, context=context
File "C:\Python37-32\lib\site-packages\nuitka\codegen\TryCodes.py", line 87, in generateTryCode
statement_sequence=tried_block, emit=emit, allow_none=False, context=context
File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 246, in generateStatementSequenceCode
statement_sequence=statement_sequence, emit=emit, context=context
File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 208, in _generateStatementSequenceCode
statement_sequence=statement, emit=emit, context=context
File "C:\Python37-32\lib\site-packages\nuitka\codegen\FrameCodes.py", line 128, in generateStatementsFrameCode
statement_sequence=statement_sequence, emit=local_emit, context=context
File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 217, in _generateStatementSequenceCode
statement=statement, emit=statement_codes, context=context
File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 177, in generateStatementCode
assert not context.getCleanupTempnames(), context.getCleanupTempnames()
AssertionError: [<VariableDeclaration PyObject * tmp_constant_value_1 = None>]
- Please check whether the bug was already reported or fixed. Does not seem to
- Please check out if the develop version of Nuitka works better for you. Running pre-release already 😃
If you want to post a problem/bug, to help us understand and resolve your issue please check that you have provided at least the information below, and discard up to here:
-
Nuitka version, full Python version and Platform (Windows, OSX, Linux …) 0.6.4rc3 Python: 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] Executable: C:\Python37-32\python.exe OS: Windows Arch: x86
-
How did you install Nuitka and Python (pip, anaconda, deb, rpm, from source, what is a virtualenv …), this is very important usually. Installed from pre-release msi file on windows.
-
If possible please supply a Short, Self Contained, Correct, Example that demonstrates the issue i.e a small piece of code which reproduces the issue and can be run with out any other (or as few as possible) external dependencies.
Smallest example I could make:
def test(somelist=None):
if 'element' in somelist if somelist is not None else []:
print('yes')
else:
print('no')
test(['some', 'element'])
test()
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Ok, turns out, that because this is roughly the only case where a constant value
PyObject *
used asnuitka_bool
is not yet optimized properly away, this ran into code that produced thenuitka_bool
from the constant object (which in case of the list, is actually created and needs a release), which then is complained about. This would have been reference leaking, which Nuitka caught itself doing.So we see this only because it’s in a conditional expression in a conditional statement with a constant value that takes a reference.
I am going to put this through my Buildbots, then on factory for the immanent next release.
Released as 0.6.4