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: Peephole breaks set unpacking
Type: compile error Stage:
Components: Interpreter Core Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Trundle, dmalcolm, eltoder, jcea, pitrou, python-dev, r.david.murray, rhettinger, santoso.wijaya
Priority: high Keywords: patch

Created on 2011-03-14 22:06 by eltoder, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
peep.diff rhettinger, 2011-03-15 07:42 Skip unpacking optimization for BUILD_SET
Messages (8)
msg130917 - (view) Author: Eugene Toder (eltoder) * Date: 2011-03-14 22:06
Since the time 'x in set' optimization was added to peephole it has the following bug with set unpacking:

>>> def foo(x,y):
	a,b = {x,y}
	return a,b

>>> dis(foo)
  2           0 LOAD_FAST                0 (x) 
              3 LOAD_FAST                1 (y) 
              6 ROT_TWO              
              7 STORE_FAST               2 (a) 
             10 STORE_FAST               3 (b) 

  3          13 LOAD_FAST                2 (a) 
             16 LOAD_FAST                3 (b) 
             19 BUILD_TUPLE              2 
             22 RETURN_VALUE         

That is, unpacking of literal set of sizes 2 and 3 is changed to ROT instructions. This, however, changes the semantics, as construction of set would eliminate duplicates.

The difference can be demonstrated like this:
Python 3.1
>>> foo(1,1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in foo
ValueError: need more than 1 value to unpack

Python 3.2
>>> foo(1,1)
(1, 1)
msg130934 - (view) Author: Santoso Wijaya (santoso.wijaya) * Date: 2011-03-15 00:26
Looks like changeset ed8b0ee1c531 (svn r77543) broke it.
msg130944 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-03-15 01:56
It looks like the steps for UNPACK_SEQUENCE should be skipped when following a BUILD_SET.  I'll post a patch tomorrow (probably a one-liner).
msg130960 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-03-15 07:42
See attached.
msg131045 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-15 21:50
New changeset 912eb87946e0 by Raymond Hettinger in branch '3.2':
Issue 11510: Fix BUILD_SET optimizer bug.
http://hg.python.org/cpython/rev/912eb87946e0
msg131049 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-15 22:07
New changeset db6997fb4c99 by Raymond Hettinger in branch 'default':
Issue 11510: Fix BUILD_SET optimizer bug.
http://hg.python.org/cpython/rev/db6997fb4c99
msg131050 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-03-15 22:09
Eugene, thanks for noticing and reporting this.
msg131054 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-03-15 22:13
Raymond, it looks like you committed this fix separately to the 3.2 branch and the default branch, instead of committing to 3.2 and then merging to default.  With svn, this wasn't a big deal, but with mercurial it will leave the 3.2 changeset unmerged, and the next person who wants to submit something will have to merge it.  (A dummy merge, since you already committed the fix to default).
History
Date User Action Args
2022-04-11 14:57:14adminsetgithub: 55719
2011-07-11 15:42:21jceasetnosy: + jcea
2011-03-15 22:13:16r.david.murraysetnosy: + r.david.murray
messages: + msg131054
2011-03-15 22:09:09rhettingersetstatus: open -> closed

messages: + msg131050
resolution: fixed
nosy: rhettinger, pitrou, Trundle, dmalcolm, santoso.wijaya, python-dev, eltoder
2011-03-15 22:07:56python-devsetnosy: rhettinger, pitrou, Trundle, dmalcolm, santoso.wijaya, python-dev, eltoder
messages: + msg131049
2011-03-15 21:50:34python-devsetnosy: + python-dev
messages: + msg131045
2011-03-15 07:42:49rhettingersetfiles: + peep.diff

messages: + msg130960
keywords: + patch
nosy: rhettinger, pitrou, Trundle, dmalcolm, santoso.wijaya, eltoder
2011-03-15 01:56:49rhettingersetnosy: rhettinger, pitrou, Trundle, dmalcolm, santoso.wijaya, eltoder
messages: + msg130944
2011-03-15 01:47:46rhettingersetpriority: normal -> high
assignee: rhettinger

nosy: + dmalcolm, pitrou, rhettinger
2011-03-15 00:26:15santoso.wijayasetnosy: + santoso.wijaya
messages: + msg130934
2011-03-14 22:46:35Trundlesetnosy: + Trundle
2011-03-14 22:06:03eltodercreate