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: Move instruction code from ceval.c to a separate file
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: pdox, rhettinger
Priority: normal Keywords:

Created on 2017-10-13 23:58 by pdox, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg304370 - (view) Author: (pdox) * Date: 2017-10-13 23:58
I'd like to move all instruction code (the code inside a TARGET(NAME) block) from Python/ceval.c to a new file, Python/instructions.h. The new file will contain only instruction bodies (prefixed by related helper functions/macros).

Eval-context macros (e.g. TARGET, DISPATCH, TOP, PUSH, POP, etc) will not be moved to instructions.h, but will be expected to be available (defined by the #includer).

ceval.c will define the eval-context macros in the same way, and #include "instructions.h", inside the body of _PyEval_EvalFrameDefault. The code emitted should remain exactly the same.

The benefit of this change, is that it becomes easy to produce alternative implementations of EvalFrame which reuse the same instruction code, but with changes to the evaluation context or dispatch mechanism. In particular, after this change, I hope to experiment with adding a cross-platform subroutine-threading code evaluator. (for performance testing)
msg304378 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-10-14 06:05
While I can see the utility for experimentation, I think the proposed change would make our lives more difficult.  The body inside the instruction blocks is central to the understanding of ceval.c and somewhat tightly coupled with it.  I would find it more difficult to maintain that code, switching back and forth between ceval.c and instructions.h.   We've already hit a level of complexity that presents a challenge to newcomers.
msg304384 - (view) Author: (pdox) * Date: 2017-10-14 07:03
rhettinger, helper functions used by the instruction code would also be moved into instructions.h (e.g. call_function, do_call_core, cmp_outcome, etc). Done properly, there should be very little need to move between instructions.h and ceval.c to understand what is happening.

The contract between the two files has to be very explicit. The only dependencies instructions.h would have on ceval.c would be to receive the evaluator macros (for manipulating the stack & locals, flow control, triggering error condition, etc). A strict (non-leaky) abstraction interface is necessary for being able to re-use the instruction code in an alternate evaluator.
msg304401 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-10-14 20:57
> A strict (non-leaky) abstraction interface is necessary 
> for being able to re-use the instruction code in an
> alternate evaluator.

The problem is that we don't have a strict (non-leaky) abstraction and I don't think we should impose one.

> Done properly, there should be very little need to move
> between instructions.h and ceval.c to understand what is happening.

I believe that is just wishful thinking and the separation will make it harder to learn and reason ceval.c.   Also, I really don't like putting the essential core of instruction code in a .h file rather than a .c file.

FWIW, when I've done my own experiments with alternative evaluation techniques (such as subroutine threading), it always required changes to the instruction bodies (in part because interesting variants use different argument passing techniques and in part because of a need to change state external to the instruction body for tracing and whatnot).

Overall, I think the proposal would be a net detriment to future maintenance and would not have a recurring payoff beyond your present experiments.
msg304604 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-10-19 07:41
No one has spoken up for this feature request, so I'm marking it as closed.  Thank you for the suggestion, but I think it is prudent to decline.
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 75966
2017-10-19 07:41:38rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg304604

stage: resolved
2017-10-14 20:57:44rhettingersetmessages: + msg304401
2017-10-14 07:03:53pdoxsetmessages: + msg304384
2017-10-14 06:05:55rhettingersetnosy: + rhettinger
messages: + msg304378
2017-10-14 00:01:12pdoxsettitle: Move instruction code blocks to separate file -> Move instruction code from ceval.c to a separate file
2017-10-13 23:58:24pdoxcreate