Issue390

Title Error with handling locals() in nested functions
Priority bug Status resolved
Superseder Nosy List asovetnikov, kayhayen
Assigned To kayhayen Keywords compiler_crash

Created on 2017-12-15.14:37:41 by asovetnikov, last changed by kayhayen.

Messages
msg2349 (view) Author: kayhayen Date: 2018-03-27.10:37:28
Released as 0.5.29
msg2319 (view) Author: kayhayen Date: 2018-03-14.11:52:59
Turns out that the fix is causing regressions for at least Python 3.6, where 
dictionary order is preserved, failing tests, and making generally possible to 
behave differently if ran with Nuitka.

So instead a TODO is solved, and the order is separated from the dictionary, and 
values get only deleted in the dictionary, but not in the ordering list. That 
way the behavior is unchanged, but the crash won't happen, and the ordering dict 
is not used as it should be.
msg2312 (view) Author: kayhayen Date: 2018-03-13.19:14:43
So there is a fix on factory:

http://nuitka.net/doc/factory.html

Basically what happens is that the locals dictionary when code generation hits, 
does sort to become determinstic.

At the time though, unused closure variables have been removed from the list 
used as an index. Using that list is not necessary, new code sorts according to 
variable name for dictionary order. That is not a given anyway, so do not bother 
about fancy orders.

I am putting this to resolved immediately, as a new stable release is coming 
very soon.

Yours,
Kay
msg2311 (view) Author: kayhayen Date: 2018-03-13.18:46:21
I can confirm the crash. Tempted to look at special handling **locals() as an 
escape that won't modify locals.

Not sure yet, what happens here. Going to check.

Yours,
Kay
msg2296 (view) Author: asovetnikov Date: 2017-12-15.14:37:39
Just have a bug with nested functions and locals():

Steps to reproduce:
main.py:
def high():
    cad = 1
    # with atomic():
    def nested1():
        a = 2
        def nested2():
            o = {}
            o['cad'] = cad
        nested2()
        print('result'.format(**locals()))
    nested1()
high()

Run:
nuitka main.py

Output:
  File "C:\Python34\lib\site-packages\nuitka\codegen\GlobalsLocalsCodes.py", line 
206, in getLoadLocalsCode
    for local_var, version in _sorted(variables):
  File "C:\Python34\lib\site-packages\nuitka\codegen\GlobalsLocalsCodes.py", line 
158, in _sorted
    key = lambda variable_desc: all_variables.index(variable_desc[0]),
  File "C:\Python34\lib\site-packages\nuitka\codegen\GlobalsLocalsCodes.py", line 
158, in <lambda>
    key = lambda variable_desc: all_variables.index(variable_desc[0]),
ValueError: tuple.index(x): x not in tuple

nuitka --version
0.5.28.1

Seems cad variable is treated as local to nested2(), but it is not in local variables 
list when sorting.
History
Date User Action Args
2018-03-27 10:37:28kayhayensetstatus: chatting -> resolved
messages: + msg2349
2018-03-14 11:52:59kayhayensetstatus: resolved -> chatting
messages: + msg2319
2018-03-13 19:14:43kayhayensetstatus: chatting -> resolved
messages: + msg2312
keyword: + compiler_crash
2018-03-13 18:46:21kayhayensetstatus: unread -> chatting
assignedto: kayhayen
messages: + msg2311
nosy: + kayhayen
2017-12-15 14:37:41asovetnikovcreate