Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ch. 5.12 Python version comments #148

Open
AndrewTolmach opened this issue Dec 20, 2022 · 2 comments
Open

Ch. 5.12 Python version comments #148

AndrewTolmach opened this issue Dec 20, 2022 · 2 comments

Comments

@AndrewTolmach
Copy link

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.)
@jsiek
Copy link
Collaborator

jsiek commented Dec 20, 2022

Indeed, I noticed this too a couple days ago and edited to deal with it.

@jsiek
Copy link
Collaborator

jsiek commented Dec 20, 2022

I've pulled the short-cutting of Goto into the first version of create_block and then introduced an example along the lines of what you give above to motivate the lazy evaluation.

Those are neat thoughts regarding reordering blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants