Skip to content

Commit a58518f

Browse files
cfbolzmattip
andauthored
Apply suggestions from code review
thanks @mattip! Co-authored-by: Matti Picus <matti.picus@gmail.com>
1 parent 551b1e4 commit a58518f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

posts/2025/04/prospero-in-rpython.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ it becomes even more crucial.
189189

190190
## Writing a simple optimizer
191191

192-
To implement the quadtree recursion is straightforward. Since the program has
192+
Implementing the quadtree recursion is straightforward. Since the program has
193193
no control flow the optimizer is very simple to write. I've written a couple of
194194
blog posts on how to easily write optimizers for linear sequences of
195195
operations, and I'm using the approach described in these [Toy
@@ -291,7 +291,7 @@ class Optimizer(object):
291291

292292
The resulting optimized traces are then simply interpreted at the bottom of the
293293
quadtree recursion. Matt talks about also generating machine code from them,
294-
but when I tried to use PyPy's JIT for that it was simply way too slow at
294+
but when I tried to use PyPy's JIT for that it was way too slow at
295295
producing machine code.
296296

297297

@@ -300,9 +300,9 @@ producing machine code.
300300
To make sure that my interval computation in the optimizer is correct, I
301301
implemented a hypothesis-based property based test. It checks the abstract
302302
transfer functions of the interval domain for soundness. It does so by
303-
generating random concrete input values for an operation, random intervals that
303+
generating random concrete input values for an operation and random intervals that
304304
surround the random concrete values, then performs the concrete operation to
305-
get the concrete output, and checks that the abstract transfer function applied
305+
get the concrete output, and finally checks that the abstract transfer function applied
306306
to the input intervals gives an interval that contains the concrete output.
307307

308308
For example, the random test for the `square` operation would look like this:
@@ -425,7 +425,7 @@ implementation.
425425

426426
TODO Max: I am having a hard time understanding the demanded bits thing from your localized-to-prospero explanation. I think some of it is that I am wondering "what about the other uses of operation A that operation B only needs one bit from" and part of it is that the sign operations are implicit here
427427

428-
LLVM has an information called 'demanded bits'. It is a backwards analysis that
428+
LLVM has an static analysis pass called 'demanded bits'. It is a backwards analysis that
429429
allows you to determine which bits of a value are actually used in the final
430430
result. This information can then be used in peephole optimizations. For
431431
example, if you have an expression that computes a value, but only the last
@@ -609,7 +609,7 @@ didn't implement it because I wasn't too interested in that aspect.
609609

610610
## Random testing of the optimizer
611611

612-
To make sure I didn't break anything in the optimizer, I implemented a random
612+
To make sure I didn't break anything in the optimizer, I implemented a
613613
test that generates random input programs and checks that the output of the
614614
optimizer is equivalent to the input program. The test generates random
615615
operations, random intervals for the operations and a random input value within
@@ -716,5 +716,4 @@ The demanded info seem to help quite a bit, which was nice to see.
716716
## Conclusion
717717

718718
That's it! I had lots of fun with the challenge and have a whole bunch of other
719-
ideas I want to try out, but I should actually go back to working on my actual
720-
projects now ;-).
719+
ideas I want to try out, thanks Matt for this interesting puzzle.

0 commit comments

Comments
 (0)