This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: compiler package: "global a; a=5"
Type: Stage:
Components: Interpreter Core Versions: Python 2.6, Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: arigo, nascheme, pitrou
Priority: normal Keywords: patch

Created on 2005-08-04 10:28 by arigo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
comp-scope.diff arigo, 2005-08-04 10:28 patch #1 (mwh)
compiler2.diff arigo, 2005-09-04 13:13 2.4/Lib/compiler package diff from PyPy (#2)
Messages (12)
msg48636 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2005-08-04 10:28
The stdlib compiler package produces wrong code for
"global a; a=5".  It produces a STORE_NAME instead of a
STORE_GLOBAL.

Quick patch from Michael attached.
msg48637 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2005-09-04 13:09
Logged In: YES 
user_id=4771

The compiler package contains several bugs along the lines
of the one reported here.  It doesn't seem to be that much
used; with PyPy it is probably the first time that this
package is tested in-depth, as we are trying to pass
CPython's own test suite by using only this compiler
package.  We had to make a few involved fixes.

Attached is a diff against the 2.4 maintenance head of
CPython (we based our changes on 2.4.1).  If there is
interest, I can extract individual parts of the big diff
and/or port them to 2.5 CVS HEAD.  For now I will only give
a quick overview of the diff.

* the more involved problem was related to scoping of
variables.  This turned out to be more difficult to fix than
mwh's patch (included in this tracker).  (Disclaimer:
Michael never pretended his patch was more than a quick
hack.)  For reference, see the following code snippets:
http://codespeak.net/svn/pypy/dist/pypy/interpreter/test/test_syntax.py


* we try to always raise SyntaxErrors with line number
information.  (Note sure if this has been done completely yet.)

* pyassem.py has some heavy changes that I cannot comment on
(don't know about them).  Other changes there are related to
scoping flags.

* a number of situations should raise a SyntaxError, but
were silently accepted (and generally produce weird bytecodes).

* fixed docstring handling.  Previously, in interactive
mode, entering "hello" produced no result at all -- because
the string was interpreted as a docstring!  Also, a genuine
docstring on the same line as a statement -- "docstring";
x=5 -- would result in the statement being ignored.

* we can pass future flags from outside now.

* lambda functions didn't get the official name <lambda>. 
(Yeah, I know it's a detail, but a CPython test fails
because of that.)

* added raising of SyntaxWarnings.

* the st->ast transformer 'single' mode now returns a Module
AST node instead of a Stmt.  This matches more closely what
the rest of the package expects.

* some minor changes in transformer.py are probably not
interesting to CPython (e.g. changing some () into []). 
Their goal was to make transformer.py statically typeable
for PyPy.
msg48638 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2005-09-04 22:52
Logged In: YES 
user_id=35752

These fixes should definitely go into  2.5, IMHO.  If you
need help porting the patch, let me know.
msg48639 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2005-09-12 09:09
Logged In: YES 
user_id=4771

The patch appears to apply as it is on the CVS HEAD, with at most offsets of 10 lines, and test_compiler.py passes afterwards.  I suppose that someone (else than me) needs to give the patch a quick review anyway, so feel free to consider it as a 2.4 + 2.5 patch.
msg64368 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-03-23 16:17
Armin, if you still care about the compiler package, could you (or some
other pypy coder) take a look at #2459? As part of the patch, it
rewrites the flow graph block ordering algorithm in a cleaner way (IMHO).
msg64409 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2008-03-24 10:22
Sorry, I don't think many PyPy coders care about microoptimizations in
the bytecode.  To be honest we've stopped worrying about the stdlib
compiler package because no one seemed to care.  I'm closing the present
patch as incomplete and outdated; if someone is interested in reviving
the stdlib compiler package, my offer to extract from PyPy an up-to-date
diff for the compiler package still stands.
msg64411 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-03-24 12:15
Armin, this is not about micro-optimizations per se, but about fixing
some parts of the compiler package. To make it easier, I've created a
separate entry for the fixing part in #2472 :)

This was the first time I was using the compiler package and I think it
can be useful in order to experiment with bytecode ideas (of course you
probably prefer to do that with PyPy). That's why I tried to fix what
was failing for me.
msg64452 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2008-03-25 02:50
On Sun, Mar 23, 2008 at 04:17:12PM +0000, Antoine Pitrou wrote:
> Armin, if you still care about the compiler package, could you (or some
> other pypy coder) take a look at #2459? As part of the patch, it
> rewrites the flow graph block ordering algorithm in a cleaner way (IMHO).

I'm interested to update the compiler package but I'm short of time
at the moment.  If you want to assign bugs and patches to me, I will
try to get to them.

  Neil
msg64470 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2008-03-25 09:18
Thanks Antoine for the clarification.

The situation is that by now PyPy has found many many more bugs in
trying to use the compiler package to run the whole stdlib and
real-world applications.  What I can propose is to extract what we have
got and put it back into CPython's stdlib, keeping the current
documented API.  This will require a little bit of work (e.g. first
finishing to add all new 2.5 and 2.6 features into PyPy's compiler)
but IMHO it's more worthwhile than going through the process of
rediscovering and fixing all the current bugs one by one.
msg64474 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-03-25 10:57
Armin, it would be nice to merge back your work indeed. If you submit a
patch I can take a look at it.
msg64496 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2008-03-25 16:37
On Tue, Mar 25, 2008 at 09:18:38AM +0000, Armin Rigo wrote:
> The situation is that by now PyPy has found many many more bugs in
> trying to use the compiler package to run the whole stdlib and
> real-world applications.  What I can propose is to extract what we have
> got and put it back into CPython's stdlib, keeping the current
> documented API.

I'm not sure it can go back into the stdlib since there doesn't seem
to be enough energy available to keep it up-to-date with the Python
release schedule.  I would like to make it available as an add-on
package.

> This will require a little bit of work (e.g. first
> finishing to add all new 2.5 and 2.6 features into PyPy's compiler)
> but IMHO it's more worthwhile than going through the process of
> rediscovering and fixing all the current bugs one by one.

Indeed it would make no sense to redo that work.  Can the version in
the PyPy tree be used as a direct replacement for the stdlib version
or does it need some changes?  You had mentioned being able to
produce a patch against the stdlib version.  Is that easy or would
it be better just to take the PyPy version and package it up.

  Neil
msg64507 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-03-25 19:27
It seems to me that releasing it as a third-party package would be a
little contradictory, since the compiler package is supposed to follow
the CPython core (compile.c etc.) evolutions.

In any case, whatever the decision (stdlib package or separate
releases), I think it would be nice if there was a slightly more
comprehensive test suite. :)

Something like running some selected non-controversial parts of the test
suite compiled with the compiler package (like PyPy does apparently)
could be a good start.
History
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42251
2008-03-25 19:27:27pitrousetmessages: + msg64507
2008-03-25 16:37:57naschemesetmessages: + msg64496
2008-03-25 10:57:18pitrousetmessages: + msg64474
2008-03-25 09:18:37arigosetmessages: + msg64470
2008-03-25 02:50:43naschemesetmessages: + msg64452
2008-03-24 12:15:53pitrousetmessages: + msg64411
2008-03-24 10:22:38arigosetstatus: open -> closed
resolution: wont fix
messages: + msg64409
2008-03-23 16:17:11pitrousetnosy: + pitrou
messages: + msg64368
2008-01-05 19:31:51christian.heimessetversions: + Python 2.6, Python 2.5
2005-08-04 10:28:57arigocreate