compiler.tree.modular-arithmetic: >fixnum elimination and value info annotations were too aggressive
							parent
							
								
									5297be3e19
								
							
						
					
					
						commit
						bf57d78b09
					
				| 
						 | 
				
			
			@ -249,3 +249,12 @@ cell {
 | 
			
		|||
    { fixnum+ >fixnum } inlined?
 | 
			
		||||
] unit-test
 | 
			
		||||
 | 
			
		||||
[ f ] [
 | 
			
		||||
    [ f >fixnum ]
 | 
			
		||||
    { >fixnum } inlined?
 | 
			
		||||
] unit-test
 | 
			
		||||
 | 
			
		||||
[ f ] [
 | 
			
		||||
    [ [ >fixnum ] 2dip set-alien-unsigned-1 ]
 | 
			
		||||
    { >fixnum } inlined?
 | 
			
		||||
] unit-test
 | 
			
		||||
| 
						 | 
				
			
			@ -124,22 +124,12 @@ SYMBOL: changed?
 | 
			
		|||
GENERIC: optimize-modular-arithmetic* ( node -- nodes )
 | 
			
		||||
 | 
			
		||||
M: #push optimize-modular-arithmetic*
 | 
			
		||||
    dup out-d>> first modular-value? [
 | 
			
		||||
        [ >fixnum ] change-literal
 | 
			
		||||
    ] when ;
 | 
			
		||||
 | 
			
		||||
: input-will-be-fixnum? ( #call -- ? )
 | 
			
		||||
    in-d>> first actually-defined-by
 | 
			
		||||
    [ value>> { [ modular-value? ] [ fixnum-value? ] } 1&& ] all? ;
 | 
			
		||||
 | 
			
		||||
: output-will-be-coerced? ( #call -- ? )
 | 
			
		||||
    out-d>> first modular-value? ;
 | 
			
		||||
    dup [ out-d>> first modular-value? ] [ literal>> real? ] bi and
 | 
			
		||||
    [ [ >fixnum ] change-literal ] when ;
 | 
			
		||||
 | 
			
		||||
: redundant->fixnum? ( #call -- ? )
 | 
			
		||||
    {
 | 
			
		||||
        [ input-will-be-fixnum? ]
 | 
			
		||||
        [ output-will-be-coerced? ]
 | 
			
		||||
    } 1|| ;
 | 
			
		||||
    in-d>> first actually-defined-by
 | 
			
		||||
    [ value>> { [ modular-value? ] [ fixnum-value? ] } 1&& ] all? ;
 | 
			
		||||
 | 
			
		||||
: optimize->fixnum ( #call -- nodes )
 | 
			
		||||
    dup redundant->fixnum? [ drop f ] when ;
 | 
			
		||||
| 
						 | 
				
			
			@ -172,7 +162,7 @@ MEMO: fixnum-coercion ( flags -- nodes )
 | 
			
		|||
    ] when ;
 | 
			
		||||
 | 
			
		||||
: optimize-low-order-op ( #call -- nodes )
 | 
			
		||||
    dup in-d>> first modular-value? [
 | 
			
		||||
    dup in-d>> first fixnum-value? [
 | 
			
		||||
        [ ] [ in-d>> first ] [ info>> ] tri
 | 
			
		||||
        [ drop fixnum <class-info> ] change-at
 | 
			
		||||
    ] when ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
USING: tools.test byte-arrays sequences kernel ;
 | 
			
		||||
USING: tools.test byte-arrays sequences kernel math ;
 | 
			
		||||
IN: byte-arrays.tests
 | 
			
		||||
 | 
			
		||||
[ 6 B{ 1 2 3 } ] [
 | 
			
		||||
| 
						 | 
				
			
			@ -11,3 +11,7 @@ IN: byte-arrays.tests
 | 
			
		|||
[ -10 B{ } resize-byte-array ] must-fail
 | 
			
		||||
 | 
			
		||||
[ B{ 123 } ] [ 123 1byte-array ] unit-test
 | 
			
		||||
 | 
			
		||||
[ B{ 123 } ] [ 123 0 B{ 0 } [ set-nth ] keep ] unit-test
 | 
			
		||||
 | 
			
		||||
[ B{ 123 } ] [ 123 >bignum 0 B{ 0 } [ set-nth ] keep ] unit-test
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
USING: tools.test io.streams.byte-array io.encodings.binary
 | 
			
		||||
io.encodings.utf8 io kernel arrays strings namespaces ;
 | 
			
		||||
io.encodings.utf8 io kernel arrays strings namespaces math ;
 | 
			
		||||
 | 
			
		||||
[ B{ } ] [ B{ } binary [ contents ] with-byte-reader ] unit-test
 | 
			
		||||
[ B{ 1 2 3 } ] [ binary [ B{ 1 2 3 } write ] with-byte-writer ] unit-test
 | 
			
		||||
| 
						 | 
				
			
			@ -28,3 +28,8 @@ io.encodings.utf8 io kernel arrays strings namespaces ;
 | 
			
		|||
        read1
 | 
			
		||||
    ] with-byte-reader
 | 
			
		||||
] unit-test
 | 
			
		||||
 | 
			
		||||
! Overly aggressive compiler optimizations
 | 
			
		||||
[ B{ 123 } ] [
 | 
			
		||||
    binary [ 123 >bignum write1 ] with-byte-writer
 | 
			
		||||
] unit-test
 | 
			
		||||
		Loading…
	
		Reference in New Issue