From c5ef4e52fd7d183861b33476db999fa04f777607 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 27 Sep 2026 08:52:12 -0700 Subject: Remove -disablePeephole --- chapter02/README.md | 3 ++- chapter02/src/main/java/com/seaofnodes/simple/node/Node.java | 9 --------- chapter02/src/test/java/com/seaofnodes/simple/Chapter02Test.java | 4 +--- 3 files changed, 3 insertions(+), 13 deletions(-) (limited to 'chapter02') diff --git a/chapter02/README.md b/chapter02/README.md index 8799863f..c670ea36 100644 --- a/chapter02/README.md +++ b/chapter02/README.md @@ -156,7 +156,8 @@ There are other important properties of the Lattice that we discuss in [Chapter ## Nodes Pre Peephole Optimization -The following visual shows how the graph looks like pre-peephole optimization: +The following schematic shows the operations before peephole folding. The parser +optimizes each node as it is built; it does not retain this entire intermediate graph: ![Example Visual](./docs/02-pre-peephole-ex1.svg) diff --git a/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java index 7e278173..acf6b236 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java @@ -177,12 +177,6 @@ public abstract class Node { // Mostly used for asserts and printing. public boolean isDead() { return isUnused() && nIns()==0 && _type==null; } - /** - * We allow disabling peephole opt so that we can observe the - * full graph, vs the optimized graph. - */ - public static boolean _disablePeephole = false; - /** * Try to peephole at this node and return a better replacement Node if * possible. We compute a {@link Type} and then check and replace: @@ -208,9 +202,6 @@ public abstract class Node { // Compute initial or improved Type Type type = _type = compute(); - if (_disablePeephole) - return null; // Peephole optimizations turned off - // Replace constant computations from non-constants with a constant node if (!(this instanceof ConstantNode) && type.isConstant()) { kill(); // Kill `this` because replacing with a Constant diff --git a/chapter02/src/test/java/com/seaofnodes/simple/Chapter02Test.java b/chapter02/src/test/java/com/seaofnodes/simple/Chapter02Test.java index ba9acea7..6c816a23 100644 --- a/chapter02/src/test/java/com/seaofnodes/simple/Chapter02Test.java +++ b/chapter02/src/test/java/com/seaofnodes/simple/Chapter02Test.java @@ -10,11 +10,9 @@ public class Chapter02Test { @Test public void testParseGrammar() { - Node._disablePeephole = true; // disable peephole so we can observe full graph Parser parser = new Parser("return 1+2*3+-5;"); ReturnNode ret = parser.parse(); - assertEquals("return (1+((2*3)+(-5)));", ret.print()); - Node._disablePeephole = false; + assertEquals("return 2;", ret.print()); } @Test -- cgit v1.2.3