]> gitweb.factorcode.org Git - factor.git/commitdiff
fix inference hang
authorSlava Pestov <slava@factorcode.org>
Tue, 30 Aug 2005 01:00:39 +0000 (01:00 +0000)
committerSlava Pestov <slava@factorcode.org>
Tue, 30 Aug 2005 01:00:39 +0000 (01:00 +0000)
CHANGES.html
TODO.FACTOR.txt
library/inference/call-optimizers.factor
library/inference/dataflow.factor
library/inference/kill-literals.factor
library/inference/optimizer.factor
library/inference/words.factor
library/test/inference.factor

index 72c326ec29d9a5a3fc1f2105f66490c6b0d8d615..015349216997ee28d9cfe4d402a67f7893aacd91 100644 (file)
 <li>The matrices library has been greatly simplified. Matrices are now represented as vectors of vectors, and matrix words have been moved to the <code>math</code> vocabulary.</li>
 <li>More descriptive "out of bounds" errors.</li>
 <li>New <code>make-hash ( quot -- namespace )</code> combinator executes quotation in a new namespace, which is then pushed on the stack.</li>
-<li>The <code>&lt;namespace&gt;</code> word is gone. It would create a hashtable with a default capacity. Now, just write <code>{{ }} clone</code>.
+<li>The <code>&lt;namespace&gt;</code> word is gone. It would create a hashtable with a default capacity. Now, just write <code>{{ }} clone</code>.</li>
+<li>Sequence construction words changed:
+<pre>
+make-list    ==&gt; [ ] make
+make-vector  ==&gt; { } make
+make-string  ==&gt; "" make
+make-rstring ==&gt; "" make reverse
+make-sbuf    ==&gt; SBUF" " make
+</pre></li>
 </ul>
 
 </li>
index c57fdf8988354f61ca05741bfd5e8d332d746bc3..5a84c7dc9b6af5a82c9327fe669d4711e52e5711 100644 (file)
@@ -1,6 +1,6 @@
 - reader syntax for arrays, byte arrays, displaced aliens\r
-- fix infer hang\r
 - out of memory error when printing global namespace\r
+- decompile is broken\r
 \r
 + ui:\r
 \r
index 02d12c9ab0f8c3fd74933587e869ba5bde9e4b2e..3d116a5d6f586614f2a2f819027c28a3fafa9257 100644 (file)
@@ -34,11 +34,7 @@ sequences vectors words ;
 : partial-eval ( #call -- node )
     dup literal-in-d over node-param
     [ with-datastack ] [
-        [
-            3drop t
-        ] [
-            inline-literals
-        ] ifte
+        [ 3drop t ] [ inline-literals ] ifte
     ] catch ;
 
 : flip-branches ( #ifte -- )
index d708abaae1509d10002d0e46ffa1c7ff0cc9c698..da77a273374dd9a19746c94b73c163de4b5ca135 100644 (file)
@@ -164,10 +164,18 @@ SYMBOL: current-node
 : last-node ( node -- last )
     dup node-successor [ last-node ] [ ] ?ifte ;
 
+: penultimate-node ( node -- penultimate )
+    dup node-successor dup [
+        dup node-successor
+        [ nip penultimate-node ] [ drop ] ifte
+    ] [
+        2drop f
+    ] ifte ;
+
 : drop-inputs ( node -- #drop )
     node-in-d clone in-d-node <#drop> ;
 
-: each-node ( node quot -- )
+: each-node ( node quot -- | quot: node -- )
     over [
         [ call ] 2keep swap
         [ node-children [ swap each-node ] each-with ] 2keep
@@ -179,6 +187,26 @@ SYMBOL: current-node
 : each-node-with ( obj node quot -- | quot: obj node -- )
     swap [ with ] each-node 2drop ; inline
 
+: all-nodes? ( node quot -- ? | quot: node -- ? )
+    over [
+        [ call ] 2keep rot [
+            [
+                swap node-children [ swap all-nodes? ] all-with?
+            ] 2keep rot [
+                >r node-successor r> all-nodes?
+            ] [
+                2drop f
+            ] ifte
+        ] [
+            2drop f
+        ] ifte
+    ] [
+        2drop t
+    ] ifte ; inline
+
+: all-nodes-with? ( obj node quot -- ? | quot: obj node -- ? )
+    swap [ with rot ] all-nodes? 2nip ; inline
+
 SYMBOL: substituted
 
 DEFER: subst-value
index 53509c8f73f06da64b49e9bbda147fc63ec522dd..61a0b1dcf77eccd41de093a348360a2d741ebfac 100644 (file)
@@ -9,28 +9,13 @@ GENERIC: literals* ( node -- )
 : literals ( node -- seq )
     [ [ literals* ] each-node ] { } make ;
 
-GENERIC: can-kill* ( literal node -- ? )
-
-: can-kill? ( literal node -- ? )
-    #! Return false if the literal appears in any node in the
-    #! list.
-    dup [
-        2dup can-kill* [
-            2dup node-children [ can-kill? ] all-with? [
-                node-successor can-kill?
-            ] [
-                2drop f
-            ] ifte
-        ] [
-            2drop f
-        ] ifte
-    ] [
-        2drop t
-    ] ifte ;
+GENERIC: can-kill? ( literal node -- ? )
 
 : kill-set ( node -- list )
     #! Push a list of literals that may be killed in the IR.
-    dup literals [ swap can-kill? ] subset-with ;
+    dup literals [
+        swap [ can-kill? ] all-nodes-with?
+    ] subset-with ;
 
 : remove-values ( values node -- )
     2dup [ node-in-d seq-diff ] keep set-node-in-d
@@ -48,19 +33,19 @@ M: node kill-node* ( literals node -- ) 2drop ;
 ! Generic nodes
 M: node literals* ( node -- ) drop ;
 
-M: node can-kill* ( literal node -- ? ) uses-value? not ;
+M: node can-kill? ( literal node -- ? ) uses-value? not ;
 
 ! #push
 M: #push literals* ( node -- )
     node-out-d % ;
 
-M: #push can-kill* ( literal node -- ? ) 2drop t ;
+M: #push can-kill? ( literal node -- ? ) 2drop t ;
 
 M: #push kill-node* ( literals node -- )
     [ node-out-d seq-diff ] keep set-node-out-d ;
 
 ! #drop
-M: #drop can-kill* ( literal node -- ? ) 2drop t ;
+M: #drop can-kill? ( literal node -- ? ) 2drop t ;
 
 ! #call
 : (kill-shuffle) ( word -- map )
@@ -84,8 +69,8 @@ M: #drop can-kill* ( literal node -- ? ) 2drop t ;
         [[ r> {{ }} ]]
     }} hash ;
 
-M: #call can-kill* ( literal node -- ? )
-    dup node-param (kill-shuffle) >r delegate can-kill* r> or ;
+M: #call can-kill? ( literal node -- ? )
+    dup node-param (kill-shuffle) >r delegate can-kill? r> or ;
 
 : kill-mask ( killing node -- mask )
     dup node-param \ r> = [ node-in-r ] [ node-in-d ] ifte
@@ -106,13 +91,13 @@ M: #call kill-node* ( literals node -- )
     [ kill-shuffle ] [ 2drop ] ifte ;
 
 ! #call-label
-M: #call-label can-kill* ( literal node -- ? ) 2drop t ;
+M: #call-label can-kill? ( literal node -- ? ) 2drop t ;
 
 ! #values
-M: #values can-kill* ( literal node -- ? ) 2drop t ;
+M: #values can-kill? ( literal node -- ? ) 2drop t ;
 
 ! #merge
-M: #merge can-kill* ( literal node -- ? ) 2drop t ;
+M: #merge can-kill? ( literal node -- ? ) 2drop t ;
 
 ! #entry
-M: #entry can-kill* ( literal node -- ? ) 2drop t ;
+M: #entry can-kill? ( literal node -- ? ) 2drop t ;
index b9250aee84723c7d569b6260c18d45a3413d2e8e..d0f250103feb3887e8fe982a641b611c38711607 100644 (file)
@@ -80,3 +80,22 @@ M: #values optimize-node* ( node -- node/t )
 ! #return
 M: #return optimize-node* ( node -- node/t )
     optimize-fold ;
+
+! #label
+GENERIC: calls-label? ( label node -- ? )
+
+M: node calls-label? 2drop f ;
+
+M: #call-label calls-label? node-param eq? ;
+
+M: #label optimize-node* ( node -- node/t )
+    dup node-param over node-children first calls-label? [
+        drop t
+    ] [
+        dup node-children first dup node-successor [
+            dup penultimate-node rot
+            node-successor swap set-node-successor
+        ] [
+            drop node-successor
+        ] ifte
+    ] ifte ;
index 1365cf74581cdc54cb18fc483a8dde95d8c57ae2..8182918f2905714e26335cbf41e08200276b8ae3 100644 (file)
@@ -25,9 +25,6 @@ hashtables parser prettyprint ;
     " was already attempted, and failed" append3
     inference-error ;
 
-: recursive? ( word -- ? )
-    f swap dup word-def [ = or ] tree-each-with ;
-
 : with-block ( word [[ label quot ]] quot -- block-node )
     #! Execute a quotation with the word on the stack, and add
     #! its dataflow contribution to a new #label node in the IR.
@@ -40,16 +37,6 @@ hashtables parser prettyprint ;
         #entry node,  word-def infer-quot  #return node,
     ] with-block ;
 
-: inline-compound ( word -- )
-    #! Infer the stack effect of a compound word in the current
-    #! inferencer instance. If the word in question is recursive
-    #! we infer its stack effect inside a new block.
-    dup recursive? [
-        inline-block node,
-    ] [
-        word-def infer-quot
-    ] ifte ;
-
 : infer-compound ( word base-case -- effect )
     #! Infer a word's stack effect in a separate inferencer
     #! instance.
@@ -137,11 +124,8 @@ M: compound apply-object ( word -- )
     dup recursive-state get assoc [
         recursive-word
     ] [
-        dup "inline" word-prop [
-            inline-compound
-        ] [
-            apply-default
-        ] ifte
+        dup "inline" word-prop
+        [ inline-block node, ] [ apply-default ] ifte
     ] ifte* ;
 
 : infer-shuffle ( word -- )
index 401d826da97476c6b943c6bba0c687c0bb049d37..ae2928cdc3a021256b6c424912e8138b4fc55607 100644 (file)
@@ -151,7 +151,7 @@ M: real iterate drop ;
 
 DEFER: agent
 : smith 1 + agent ; inline
-: agent dup 0 = [ [ swap call ] 2keep [ smith ] 2keep ] when ; inline
+: agent dup 0 = [ [ swap call ] 2keep smith ] when ; inline
 [ [ [ ] [ object object ] ] ]
 [ [ [ drop ] 0 agent ] infer ] unit-test