[pypy-dev] Annotating space status

Armin Rigo arigo at tunes.org
Sun Jul 6 14:37:26 MEST 2003


Hello Samuele,

On Sun, Jul 06, 2003 at 02:27:47PM +0200, Samuele Pedroni wrote:
> >>        r = self.codetest("def f(a):\n"
> >>                           "    x = [1,2]\n"
> >>                           "    if a:\n"
> >>                           "        x.append(3)\n"
> >>                           "    else:\n"
> >>                           "        x.append(3)\n"
> >>                           "    return x",
> >>                          'f',[W_Anything()])
> >>         print r
> 
> I agree, but then W_Constant should refuse to wrap mutable objects or raise 
> an exception when a mutating op is tried. I think the code should be 
> explicit about what is not able to do.
> 
> That means the above code should raise some exception complaining about the 
> wrapped list or about .append.

I agree about the exceptions. In the above example however the 'x' should 
simply not be wrapped in a W_Constant() at all, but instead it should be a 
W_List(W_Integer()), where the W_Integer() is obtained by the union of 
W_Constant(1) and W_Constant(2).

About .append, we should probably complain, just to emphasis the point that
this is not an efficient operation at all (a realloc()). If people really want
the same result in RPython, then "x += [3]" makes the point more clearly.


A bientôt,

Armin.


More information about the pypy-dev mailing list