summaryrefslogtreecommitdiff
path: root/chapter14/src/main/java/com
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-09-19 10:30:13 -0700
committerCliff Click <cliffc@acm.org>2026-09-19 10:30:13 -0700
commitbf3e5632ddf21c109f7ef0f61bcc62e2ed0f9d49 (patch)
treebe2972819600b0a9790fceb882b5464c7c12857a /chapter14/src/main/java/com
parent200162345900136663027b6deae21d72cf30818c (diff)
downloadSimple-bf3e5632ddf21c109f7ef0f61bcc62e2ed0f9d49.tar.gz
Simple-bf3e5632ddf21c109f7ef0f61bcc62e2ed0f9d49.zip
Handle double-negation preserving not-null knowledge
Diffstat (limited to 'chapter14/src/main/java/com')
-rw-r--r--chapter14/src/main/java/com/seaofnodes/simple/node/ScopeNode.java7
1 files changed, 7 insertions, 0 deletions
diff --git a/chapter14/src/main/java/com/seaofnodes/simple/node/ScopeNode.java b/chapter14/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
index 843ce733..455f4b3a 100644
--- a/chapter14/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
+++ b/chapter14/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
@@ -254,6 +254,13 @@ public class ScopeNode extends Node {
// combinations, and replaces the variable with the upcast variant.
public Node upcast( Node ctrl, Node pred, boolean invert ) {
if( ctrl._type==Type.XCONTROL ) return null;
+ // A single negation is handled below. For !!p (including p != null),
+ // also refine the underlying p without changing the Boolean result.
+ if( pred instanceof NotNode not && not.in(1) instanceof NotNode ) {
+ pred.keep(); // Recursive peepholes may rediscover this Not.
+ upcast(ctrl,not.in(1),!invert);
+ pred.unkeep();
+ }
// Invert the If conditional
if( invert )
pred = pred instanceof NotNode not ? not.in(1) : IterPeeps.add(new NotNode(pred).peephole());