compiler.tree.propagation.*: new and fixed tests for the new propagation

behaviour for mod
db4
Björn Lindqvist 2015-06-25 18:24:20 +02:00
parent 2f835d3666
commit 0d02ff8e40
3 changed files with 85 additions and 64 deletions

View File

@ -0,0 +1,8 @@
USING: accessors compiler.tree.builder compiler.tree.propagation
compiler.tree.propagation.inlining kernel math sequences tools.test ;
IN: compiler.tree.propagation.inlining.tests
{ t } [
[ >bignum 10 mod ] build-tree propagate
fourth dup word>> do-inlining
] unit-test

View File

@ -0,0 +1,21 @@
USING: compiler.tree.propagation.known-words kernel math math.intervals
tools.test ;
IN: compiler.tree.propagation.known-words.tests
{
fixnum
T{ interval { from { -19 t } } { to { 19 t } } }
} [
integer
T{ interval { from { -19 t } } { to { 19 t } } }
maybe>fixnum
] unit-test
{
object
T{ interval { from { -19 t } } { to { 19 t } } }
} [
object
T{ interval { from { -19 t } } { to { 19 t } } }
maybe>fixnum
] unit-test

View File

@ -1,72 +1,39 @@
USING: accessors arrays assocs compiler.tree USING: accessors arrays assocs compiler.tree
compiler.tree.propagation.constraints compiler.tree.propagation.copy compiler.tree.propagation.constraints compiler.tree.propagation.copy
compiler.tree.propagation.info compiler.tree.propagation.simple kernel math compiler.tree.propagation.info compiler.tree.propagation.simple hashtables
math.intervals math.private namespaces sequences system tools.test words ; kernel math math.intervals math.private namespaces sequences system tools.test
words ;
IN: compiler.tree.propagation.simple.tests IN: compiler.tree.propagation.simple.tests
: make-value-infos ( classes intervals -- seq )
[ <class/interval-info> ] 2map ;
: fixnum-value-infos ( -- infos ) : fixnum-value-infos ( -- infos )
{ { fixnum fixnum } 56977 [a,a] 8098 [a,a] 2array make-value-infos ;
H{
{
1
T{ value-info-state
{ class fixnum }
{ interval
T{ interval
{ from { 56977 t } }
{ to { 56977 t } }
}
}
{ literal 56977 }
{ literal? t }
}
}
{
2
T{ value-info-state
{ class fixnum }
{ interval
T{ interval
{ from { 8098 t } }
{ to { 8098 t } }
}
}
{ literal 8098 }
{ literal? t }
}
}
}
} ;
: object-value-infos ( -- infos ) : object-value-infos ( -- infos )
{ { object object } { full-interval full-interval } make-value-infos ;
H{
{ : bignum-value-infos ( -- infos )
1 { bignum bignum } full-interval 20 [a,a] 2array
T{ value-info-state make-value-infos ;
{ class object }
{ interval full-interval } : full-interval-and-bignum-literal ( -- infos )
} { object bignum } full-interval 20 [a,a] 2array
} make-value-infos ;
{
2 : indexize ( seq -- assoc )
T{ value-info-state [ swap 2array ] map-index ;
{ class object }
{ interval full-interval }
}
}
}
} ;
: setup-value-infos ( value-infos -- ) : setup-value-infos ( value-infos -- )
value-infos set indexize >hashtable 1array value-infos set
H{ { 1 1 } { 2 2 } { 3 3 } } copies set ; H{ { 0 0 } { 1 1 } { 2 2 } } copies set ;
: #call-fixnum* ( -- node ) : #call-fixnum* ( -- node )
T{ #call { word fixnum* } { in-d V{ 1 2 } } { out-d { 3 } } } ; T{ #call { word fixnum* } { in-d V{ 0 1 } } { out-d { 3 } } } ;
: #call-fixnum/mod ( -- node ) : call-outputs-quot-of-word ( inputs outputs word -- value-infos )
T{ #call { word fixnum/mod } { in-d V{ 1 2 } } { out-d { 4 5 } } } ; <#call> dup word>> call-outputs-quot ;
{ } [ { } [
fixnum-value-infos setup-value-infos fixnum-value-infos setup-value-infos
@ -74,10 +41,6 @@ IN: compiler.tree.propagation.simple.tests
propagate-input-classes propagate-input-classes
] unit-test ] unit-test
{ t } [
fixnum-value-infos setup-value-infos 1 value-info literal?>>
] unit-test
{ {
{ {
T{ value-info-state T{ value-info-state
@ -97,7 +60,7 @@ IN: compiler.tree.propagation.simple.tests
} }
} [ } [
fixnum-value-infos setup-value-infos fixnum-value-infos setup-value-infos
#call-fixnum/mod dup word>> call-outputs-quot V{ 0 1 } V{ 2 3 } \ fixnum/mod call-outputs-quot-of-word
] unit-test ] unit-test
! The result of fixnum-mod should always be a fixnum. ! The result of fixnum-mod should always be a fixnum.
@ -116,7 +79,36 @@ cpu x86.64? [
} }
} [ } [
object-value-infos setup-value-infos object-value-infos setup-value-infos
T{ #call { word fixnum-mod } { in-d V{ 1 2 } } { out-d { 4 } } } V{ 0 1 } V{ 2 } \ fixnum-mod call-outputs-quot-of-word
dup word>> call-outputs-quot
] unit-test ] unit-test
] when ] when
! Downgrading should do its thing here.
{
{
T{ value-info-state
{ class fixnum }
{ interval
T{ interval { from { -19 t } } { to { 19 t } } }
}
}
}
} [
bignum-value-infos setup-value-infos
V{ 0 1 } V{ 2 } \ mod call-outputs-quot-of-word
] unit-test
! But not here because the argument to mod might be a real.
{
{
T{ value-info-state
{ class real }
{ interval
T{ interval { from { -20 f } } { to { 20 f } } }
}
}
}
} [
full-interval-and-bignum-literal setup-value-infos
V{ 0 1 } V{ 2 } \ mod call-outputs-quot-of-word
] unit-test