Skip to content

Ch. 5.12 Python version comments #148

Open
@AndrewTolmach

Description

@AndrewTolmach

Maybe too late for this edition, but...

Section 5.12 is still not very convincing.

  • The optimization in 5.12.1. that gets rid of unused blocks via laziness is very hard to trigger: it requires a combination of a nested conditional and a constant boolean expression, e.g. as produced by shrinking
if (False and x > 4):
 print(1)
else:
 print(2)
  • Nearly all the benefit of the version of create_block on p. 87, including the block count reduction shown in Fig. 5.16, is due the first case that short-cuts Gotos. But this could have been done without involving laziness. Also, this case isn't discussed in the text at all.
  • The exercise in 5.12.2 becomes much more interesting if blocks can flow into one another, so that final Gotos can be removed altogether after suitable reordering. This is easy to support by allowing an alternative representation of x86 code as a list of blocks rather than an (unordered) dictionary. (Or the list representation can just replace the dictionary.) Doing a good job of reordering is non-trivial, but decent heuristics are not hard to find. And this also provides a great opportunity to remove unreachable blocks (without the complications of the lazy approach in 5.12.1.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions