Hi Timothy,

On Tue, 4 Dec 2018 at 02:31, Timothy Baldridge <tbaldri...@gmail.com> wrote:
> I have the following code in my interpreter, and I'm getting an error message 
> I haven't seen before:
>
>     @specialize.call_location()
>     def assoc(self, *kws):
>         (...)
>         for idx in unrolling_iterable(range(0, len(kws), 2)):

The problem might be that the call to unrolling_iterable() should not
be seen in RPython code, as far as I know.  It should only occur
outside compiled functions.

It might be possible to rewrite your example to do that but it's not
completely obvious how.  Here's how I would do it instead.  Use the
fact that any function with ``*args`` is automatically specialized
based on the number of arguments (no @specialize needed):

    def assoc(self, *kws):
        new_dict = {}
        shape = self.get_shape()
        for k in shape.attr_list():
            new_dict[k] = shape.getter_for(k).get_value(self)
        _turn_to_dict(new_dict, kws)
        return DictStruct(new_dict)

    def _turn_to_dict(new_dict, *kws):
        if not kws: return   # done
        new_dict[kws[0]] = kws[1]
        _turn_to_dict(new_dict, *kws[2:])

This looks like a recursive call, but it isn't: the function
"_turn_to_dict_6" calls "_turn_to_dict_4", which calls
"_turn_to_dict_2", etc.  And at each level the tuple "kws" is replaced
with individual arguments: nobody is actually making and inspecting
any tuple at runtime.  Most or all of the levels of calls are inlined
because each function is small enough.


A bientôt,

Armin.
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to