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.
flac
John Benediktsson 2020-01-08 09:05:06 -08:00 committed by Steve Ayerhart
parent a270b4797a
commit 3e428b1754
No known key found for this signature in database
GPG Key ID: 5BFD39C5359E967D
1 changed files with 12 additions and 3 deletions

View File

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