[Cython] CF based type inference
Robert Bradshaw
robertwb at gmail.com
Fri May 11 17:58:34 CEST 2012
On Fri, May 11, 2012 at 8:56 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Robert Bradshaw, 11.05.2012 17:48:
>> On Tue, May 8, 2012 at 11:22 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:
>>> Robert Bradshaw, 09.05.2012 00:12:
>>>> On Tue, May 8, 2012 at 6:47 AM, Vitja Makarov wrote:
>>>>> 2012/5/8 Stefan Behnel:
>>>>>> Vitja has rebased the type inference on the control flow, so I wonder if
>>>>>> this will enable us to properly infer this:
>>>>>>
>>>>>> def partial_validity():
>>>>>> """
>>>>>> >>> partial_validity()
>>>>>> ('Python object', 'double', 'str object')
>>>>>> """
>>>>>> a = 1.0
>>>>>> b = a + 2 # definitely double
>>>>>> a = 'test'
>>>>>> c = a + 'toast' # definitely str
>>>>>> return typeof(a), typeof(b), typeof(c)
>>>>>>
>>>>>> I think, what is mainly needed for this is that a NameNode with an
>>>>>> undeclared type should not report its own entry as dependency but that of
>>>>>> its own cf_assignments. Would this work?
>>>>>>
>>>>>> (Haven't got the time to try it out right now, so I'm dumping it here.)
>>>>>>
>>>>>
>>>>> Yeah, that might work. The other way to go is to split entries:
>>>>>
>>>>> def partial_validity():
>>>>> """
>>>>> >>> partial_validity()
>>>>> ('str object', 'double', 'str object')
>>>>> """
>>>>> a_1 = 1.0
>>>>> b = a_1 + 2 # definitely double
>>>>> a_2 = 'test'
>>>>> c = a_2 + 'toast' # definitely str
>>>>> return typeof(a_2), typeof(b), typeof(c)
>>>>>
>>>>> And this should work better because it allows to infer a_1 as a double
>>>>> and a_2 as a string.
>>>>
>>>> This already works, right?
>>>
>>> It would work if it was implemented. *wink*
>>
>> Well, we don't infer str
>
> Yes we do, there are even some optimisations for str. It's well defined for
> both Py2 and Py3, just not the same on both, so the final code to use for
> them is C compile time dependent.
>
> I meant to say that entry splitting isn't implemented.
Yeah, that isn't implemented yet.
- Robert
More information about the cython-devel
mailing list