tensors.tensor-slice: make step-slice not extend slice.

This caused a small regression in compiler.tree.cleanup on this test:

{ t } [
    [ { array } declare 2 <groups> [ . . ] assoc-each ]
    \ nth-unsafe inlined?
] unit-test

I'm not entirely sure why it wasn't able to infer the slice that was created
for iteration stays a slice, and never becomes a step-slice, so perhaps there
is some improvement to be made in type inference here.
master
John Benediktsson 2020-01-08 09:05:06 -08:00
parent 655262af9a
commit d0fd75b208
1 changed files with 12 additions and 3 deletions

View File

@ -1,7 +1,12 @@
USING: accessors kernel locals math math.order sequences ; USING: accessors kernel locals math math.order sequences ;
IN: tensors.tensor-slice IN: tensors.tensor-slice
TUPLE: step-slice < slice { step integer read-only } ; TUPLE: step-slice
{ from integer read-only initial: 0 }
{ to integer read-only initial: 0 }
{ seq read-only }
{ step integer read-only } ;
:: <step-slice> ( from to step seq -- step-slice ) :: <step-slice> ( from to step seq -- step-slice )
step zero? [ "can't be zero" throw ] when step zero? [ "can't be zero" throw ] when
seq length :> len seq length :> len
@ -17,10 +22,14 @@ TUPLE: step-slice < slice { step integer read-only } ;
seq dup slice? [ collapse-slice ] when seq dup slice? [ collapse-slice ] when
step step-slice boa ; step step-slice boa ;
M: step-slice virtual-exemplar seq>> ; inline
M: step-slice virtual@ M: step-slice virtual@
[ step>> * ] [ from>> + ] [ seq>> ] tri ; [ step>> * ] [ from>> + ] [ seq>> ] tri ; inline
M: step-slice length M: step-slice length
[ to>> ] [ from>> - ] [ step>> ] tri [ to>> ] [ from>> - ] [ step>> ] tri
dup 0 < [ [ neg 0 max ] dip neg ] when /mod dup 0 < [ [ neg 0 max ] dip neg ] when /mod
zero? [ 1 + ] unless ; zero? [ 1 + ] unless ; inline
INSTANCE: step-slice virtual-sequence