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: RFE: introduce "enum Py_Opcode"
Type: Stage:
Components: Interpreter Core Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: dmalcolm, loewis, pitrou
Priority: normal Keywords: patch

Created on 2009-12-18 23:06 by dmalcolm, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fixup-opcode-header.py dmalcolm, 2009-12-18 23:07 Script to convert Include/opcode.h from a collection of numeric #defines to an enumeration
opcode.h dmalcolm, 2009-12-18 23:09 Result of running script against Include/opcode.h from trunk
opcode.h.patch dmalcolm, 2009-12-18 23:10 Difference between #define/enum opcode.h (for reference)
use-opcode-enum.patch dmalcolm, 2009-12-18 23:12 Patch to ceval.c and peephole.c to use enum Py_Opcode, rather than int
diff-in-generated-assembler-for-ceval.diff dmalcolm, 2009-12-18 23:50 Difference in generated assembler for Python/ceval.c before/after changing "int opcode" to "enum Py_Opcode opcode"
Messages (6)
msg96587 - (view) Author: Dave Malcolm (dmalcolm) (Python committer) Date: 2009-12-18 23:06
Currently, Python's opcodes are defined as preprocessor #defines.  This means that they are 
invisible to the debugger.

I'm attaching:
  (i) a simple script (fixup-opcode-header.py) which converts Include/opcode.h to use an 
anonymous enum for the values
  (ii) a diff containing the results of running the script on trunk's Include/opcode.h
  (iii) a patch that converts usage of "int opcode" to "enum Py_Opcode opcode" in a few 
places

(Is the usage of an anonymous enum acceptable on all compilers that Python supports?  Is it 
going to generate equal machinecode on all compilers, relative to an int?)

With this patch, if I break into PyEval_EvalFrameEx in gdb, the debugger is able to emit 
symbolic values for "opcode":
(gdb) p opcode
$2 = LOAD_CONST
msg96589 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-12-18 23:21
What do you mean with "anonymous enum"?
msg96591 - (view) Author: Dave Malcolm (dmalcolm) (Python committer) Date: 2009-12-18 23:30
Ooops, sorry; in an earlier version of this work, I was generating an 
enum of the form:
  enum {
  };
i.e. without an identifier (an anonymous enum) 

which I later changed to:
  enum Py_Opcode {
  };

Mea culpa; I forgot to update the text for this bug when I made that 
change.
Sorry about being confusing.
msg96612 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-12-19 16:33
The assembler diff shows that at one point the compiler produced
slightly less good code after the change. I don't know what the impact
is in terms of performance but it shows we should be cautious with this
change.

Are you doing anything specific which requires this change?
msg96622 - (view) Author: Dave Malcolm (dmalcolm) (Python committer) Date: 2009-12-19 17:39
> Are you doing anything specific which requires this change?
No.  I was looking for ways of making CPython easier to debug, and I experimented with 
this.  It didn't help with debuggability as much as I hoped.

Given that CPython's performance is known to be sensitive to changes in the opcode dispatch 
code, I'd be happy to drop this RFE; I haven't done actual performance measurements on it 
yet (if it shows no measurable impact, would it be acceptable?)

I wanted to at least capture the script and patch in the issue tracker for reference 
(perhaps of interest to unladen-swallow?)

Thanks; feel free to close it.
msg96652 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-12-19 21:33
Yes, I think when you debug CPython the biggest hurdle is not to lookup
the signification of opcodes :-)
Thanks, closing.
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51792
2009-12-19 21:33:29pitrousetstatus: open -> closed
resolution: rejected
messages: + msg96652
2009-12-19 17:39:17dmalcolmsetmessages: + msg96622
2009-12-19 16:33:53pitrousetnosy: + pitrou
messages: + msg96612
2009-12-18 23:50:14dmalcolmsetfiles: + diff-in-generated-assembler-for-ceval.diff
2009-12-18 23:30:20dmalcolmsetmessages: + msg96591
2009-12-18 23:21:10loewissetnosy: + loewis
messages: + msg96589
2009-12-18 23:12:38dmalcolmsetfiles: + use-opcode-enum.patch
2009-12-18 23:10:44dmalcolmsetfiles: + opcode.h.patch
keywords: + patch
2009-12-18 23:09:55dmalcolmsetfiles: + opcode.h
2009-12-18 23:07:58dmalcolmsetfiles: + fixup-opcode-header.py
2009-12-18 23:06:44dmalcolmcreate