Vitja Makarov, 27.01.2011 10:02:
> 2011/1/27 Stefan Behnel:
>> Vitja Makarov, 27.01.2011 08:25:
>>>>> 2011/1/25 Stefan Behnel:
>>>>>> Vitja Makarov, 25.01.2011 10:01:
>>>>>>> 2011/1/25 Stefan Behnel:
>>>>>>>>        def x():
>>>>>>>>            do_some_stuff()
>>>>>>>>
>>>>>>>>            return # disable rest of code, e.g. during debugging
>>>>>>>>
>>>>>>>>            unreachable_code()
>>>>>>>>
>>>>>>>> Cython shouldn't bother generating dead code here (even if the C 
>>>>>>>> compiler
>>>>>>>> would drop it anyway).
>>>>>>>
>>>>>>> That should be rather easy to do: remove all the nodes in StatList
>>>>>>> after: break, continue, return, raise, something else?
>>>>>>
>>>>>> Careful, this may involve recursive propagation through helper nodes. The
>>>>>> tree isn't always as simple as that.
>>>>>>
>>>>>> I think an attribute "is_terminator" on Nodes might do the job. It's set 
>>>>>> to
>>>>>> False by default and to True on all nodes you mentioned above, and is
>>>>>> inherited by StatListNode if its last node is a terminator (while 
>>>>>> dropping
>>>>>> its remaining child nodes at the same time) and by all helper nodes that
>>>>>> contain StatListNodes. This could be done in analyse_types() (or maybe
>>>>>> earlier?).
>>>
>>> Ok. I've moved it into ParseTreeTransforms and created branch:
>>>
>>> https://github.com/vitek/cython/commit/a8e957ec29f0448ee7c43bd3969012772d09b236
>>
>> the StatListNode (and
>> other nodes) should inherit the flag from their last child.
>
> This could be done simply in RemoveUnreachableCode
>
> node.is_terminator = True

Sure.


> I don't actually understand where could be that used later?

Well, if you recursively propagate the flag through nodes that support it, 
you may end up in another StatListNode that strip its trailing dead code. 
Look through UtilNodes.py, there are a couple of nodes that can wrap 
Stat(List)Nodes. Maybe check Nodes.py also, not sure if there aren't any 
other nodes that can safely assume that a terminator at the end of their 
last child makes them a terminator as well.


>>> Some error tests do fail because nodes are removed and code generation
>>> time error is omited.
>>
>> That should be fixable in most cases. We could also use a compiler option
>> that disables dead code removal, and then use it in the error tests.
>
> Hmm, not sure here.
> I think it should be better to move checks outside code generation.

Ah, ok, I misunderstood you then. Yes, errors should no longer occur at 
code generation time.

Stefan
_______________________________________________
Cython-dev mailing list
Cython-dev@codespeak.net
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to