fix inference hang

cvs
Slava Pestov 2005-08-30 01:00:39 +00:00
parent 73c671ef24
commit 1bb4485a58
8 changed files with 75 additions and 55 deletions

View File

@ -32,7 +32,15 @@
<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>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>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>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> </ul>
</li> </li>

View File

@ -1,6 +1,6 @@
- reader syntax for arrays, byte arrays, displaced aliens - reader syntax for arrays, byte arrays, displaced aliens
- fix infer hang
- out of memory error when printing global namespace - out of memory error when printing global namespace
- decompile is broken
+ ui: + ui:

View File

@ -34,11 +34,7 @@ sequences vectors words ;
: partial-eval ( #call -- node ) : partial-eval ( #call -- node )
dup literal-in-d over node-param dup literal-in-d over node-param
[ with-datastack ] [ [ with-datastack ] [
[ [ 3drop t ] [ inline-literals ] ifte
3drop t
] [
inline-literals
] ifte
] catch ; ] catch ;
: flip-branches ( #ifte -- ) : flip-branches ( #ifte -- )

View File

@ -164,10 +164,18 @@ SYMBOL: current-node
: last-node ( node -- last ) : last-node ( node -- last )
dup node-successor [ last-node ] [ ] ?ifte ; 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 ) : drop-inputs ( node -- #drop )
node-in-d clone in-d-node <#drop> ; node-in-d clone in-d-node <#drop> ;
: each-node ( node quot -- ) : each-node ( node quot -- | quot: node -- )
over [ over [
[ call ] 2keep swap [ call ] 2keep swap
[ node-children [ swap each-node ] each-with ] 2keep [ node-children [ swap each-node ] each-with ] 2keep
@ -179,6 +187,26 @@ SYMBOL: current-node
: each-node-with ( obj node quot -- | quot: obj node -- ) : each-node-with ( obj node quot -- | quot: obj node -- )
swap [ with ] each-node 2drop ; inline 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 SYMBOL: substituted
DEFER: subst-value DEFER: subst-value

View File

@ -9,28 +9,13 @@ GENERIC: literals* ( node -- )
: literals ( node -- seq ) : literals ( node -- seq )
[ [ literals* ] each-node ] { } make ; [ [ literals* ] each-node ] { } make ;
GENERIC: can-kill* ( literal node -- ? ) 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 ;
: kill-set ( node -- list ) : kill-set ( node -- list )
#! Push a list of literals that may be killed in the IR. #! 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 -- ) : remove-values ( values node -- )
2dup [ node-in-d seq-diff ] keep set-node-in-d 2dup [ node-in-d seq-diff ] keep set-node-in-d
@ -48,19 +33,19 @@ M: node kill-node* ( literals node -- ) 2drop ;
! Generic nodes ! Generic nodes
M: node literals* ( node -- ) drop ; M: node literals* ( node -- ) drop ;
M: node can-kill* ( literal node -- ? ) uses-value? not ; M: node can-kill? ( literal node -- ? ) uses-value? not ;
! #push ! #push
M: #push literals* ( node -- ) M: #push literals* ( node -- )
node-out-d % ; 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 -- ) M: #push kill-node* ( literals node -- )
[ node-out-d seq-diff ] keep set-node-out-d ; [ node-out-d seq-diff ] keep set-node-out-d ;
! #drop ! #drop
M: #drop can-kill* ( literal node -- ? ) 2drop t ; M: #drop can-kill? ( literal node -- ? ) 2drop t ;
! #call ! #call
: (kill-shuffle) ( word -- map ) : (kill-shuffle) ( word -- map )
@ -84,8 +69,8 @@ M: #drop can-kill* ( literal node -- ? ) 2drop t ;
[[ r> {{ }} ]] [[ r> {{ }} ]]
}} hash ; }} hash ;
M: #call can-kill* ( literal node -- ? ) M: #call can-kill? ( literal node -- ? )
dup node-param (kill-shuffle) >r delegate can-kill* r> or ; dup node-param (kill-shuffle) >r delegate can-kill? r> or ;
: kill-mask ( killing node -- mask ) : kill-mask ( killing node -- mask )
dup node-param \ r> = [ node-in-r ] [ node-in-d ] ifte 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 ; [ kill-shuffle ] [ 2drop ] ifte ;
! #call-label ! #call-label
M: #call-label can-kill* ( literal node -- ? ) 2drop t ; M: #call-label can-kill? ( literal node -- ? ) 2drop t ;
! #values ! #values
M: #values can-kill* ( literal node -- ? ) 2drop t ; M: #values can-kill? ( literal node -- ? ) 2drop t ;
! #merge ! #merge
M: #merge can-kill* ( literal node -- ? ) 2drop t ; M: #merge can-kill? ( literal node -- ? ) 2drop t ;
! #entry ! #entry
M: #entry can-kill* ( literal node -- ? ) 2drop t ; M: #entry can-kill? ( literal node -- ? ) 2drop t ;

View File

@ -80,3 +80,22 @@ M: #values optimize-node* ( node -- node/t )
! #return ! #return
M: #return optimize-node* ( node -- node/t ) M: #return optimize-node* ( node -- node/t )
optimize-fold ; 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 ;

View File

@ -25,9 +25,6 @@ hashtables parser prettyprint ;
" was already attempted, and failed" append3 " was already attempted, and failed" append3
inference-error ; inference-error ;
: recursive? ( word -- ? )
f swap dup word-def [ = or ] tree-each-with ;
: with-block ( word [[ label quot ]] quot -- block-node ) : with-block ( word [[ label quot ]] quot -- block-node )
#! Execute a quotation with the word on the stack, and add #! Execute a quotation with the word on the stack, and add
#! its dataflow contribution to a new #label node in the IR. #! 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, #entry node, word-def infer-quot #return node,
] with-block ; ] 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-compound ( word base-case -- effect )
#! Infer a word's stack effect in a separate inferencer #! Infer a word's stack effect in a separate inferencer
#! instance. #! instance.
@ -137,11 +124,8 @@ M: compound apply-object ( word -- )
dup recursive-state get assoc [ dup recursive-state get assoc [
recursive-word recursive-word
] [ ] [
dup "inline" word-prop [ dup "inline" word-prop
inline-compound [ inline-block node, ] [ apply-default ] ifte
] [
apply-default
] ifte
] ifte* ; ] ifte* ;
: infer-shuffle ( word -- ) : infer-shuffle ( word -- )

View File

@ -151,7 +151,7 @@ M: real iterate drop ;
DEFER: agent DEFER: agent
: smith 1 + agent ; inline : 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 ] ] ] [ [ [ ] [ object object ] ] ]
[ [ [ drop ] 0 agent ] infer ] unit-test [ [ [ drop ] 0 agent ] infer ] unit-test