compiler.tree.propagation, compiler.tree.escape-analysis: make these passes handle constants in a more robust way in compilation units involving tuple reshaping
parent
a3b74d88c9
commit
a118f208dc
|
@ -1,4 +1,4 @@
|
||||||
! Copyright (C) 2008, 2009 Slava Pestov.
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel accessors sequences classes.tuple
|
USING: kernel accessors sequences classes.tuple
|
||||||
classes.tuple.private arrays math math.private slots.private
|
classes.tuple.private arrays math math.private slots.private
|
||||||
|
@ -50,7 +50,10 @@ DEFER: record-literal-allocation
|
||||||
if* ;
|
if* ;
|
||||||
|
|
||||||
M: #push escape-analysis*
|
M: #push escape-analysis*
|
||||||
[ out-d>> first ] [ literal>> ] bi record-literal-allocation ;
|
dup literal>> layout-up-to-date?
|
||||||
|
[ [ out-d>> first ] [ literal>> ] bi record-literal-allocation ]
|
||||||
|
[ out-d>> unknown-allocations ]
|
||||||
|
if ;
|
||||||
|
|
||||||
: record-unknown-allocation ( #call -- )
|
: record-unknown-allocation ( #call -- )
|
||||||
[ in-d>> add-escaping-values ]
|
[ in-d>> add-escaping-values ]
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
! Copyright (C) 2008, 2009 Slava Pestov.
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: fry assocs arrays byte-arrays strings accessors sequences
|
USING: fry assocs arrays byte-arrays strings accessors sequences
|
||||||
kernel slots classes.algebra classes.tuple classes.tuple.private
|
kernel slots classes.algebra classes.tuple classes.tuple.private
|
||||||
words math math.private combinators sequences.private namespaces
|
combinators.short-circuit words math math.private combinators
|
||||||
slots.private classes compiler.tree.propagation.info ;
|
sequences.private namespaces slots.private classes
|
||||||
|
compiler.tree.propagation.info ;
|
||||||
IN: compiler.tree.propagation.slots
|
IN: compiler.tree.propagation.slots
|
||||||
|
|
||||||
! Propagation of immutable slots and array lengths
|
! Propagation of immutable slots and array lengths
|
||||||
|
@ -52,8 +53,18 @@ UNION: fixed-length-sequence array byte-array string ;
|
||||||
dup [ read-only>> ] when ;
|
dup [ read-only>> ] when ;
|
||||||
|
|
||||||
: literal-info-slot ( slot object -- info/f )
|
: literal-info-slot ( slot object -- info/f )
|
||||||
2dup class read-only-slot?
|
#! literal-info-slot makes an unsafe call to 'slot'.
|
||||||
[ swap slot <literal-info> ] [ 2drop f ] if ;
|
#! Check that the layout is up to date to avoid accessing the
|
||||||
|
#! wrong slot during a compilation unit where reshaping took
|
||||||
|
#! place. This could happen otherwise because the "slots" word
|
||||||
|
#! property would reflect the new layout, but instances in the
|
||||||
|
#! heap would use the old layout since instances are updated
|
||||||
|
#! immediately after compilation.
|
||||||
|
{
|
||||||
|
[ class read-only-slot? ]
|
||||||
|
[ nip layout-up-to-date? ]
|
||||||
|
[ swap slot <literal-info> ]
|
||||||
|
} 2&& ;
|
||||||
|
|
||||||
: length-accessor? ( slot info -- ? )
|
: length-accessor? ( slot info -- ? )
|
||||||
[ 1 = ] [ length>> ] bi* and ;
|
[ 1 = ] [ length>> ] bi* and ;
|
||||||
|
|
|
@ -746,3 +746,21 @@ TUPLE: g < a-g ;
|
||||||
[ ] [ "IN: classes.tuple.tests MIXIN: a-g TUPLE: g ;" eval( -- ) ] unit-test
|
[ ] [ "IN: classes.tuple.tests MIXIN: a-g TUPLE: g ;" eval( -- ) ] unit-test
|
||||||
|
|
||||||
[ t ] [ g new layout-of "g" get layout-of eq? ] unit-test
|
[ t ] [ g new layout-of "g" get layout-of eq? ] unit-test
|
||||||
|
|
||||||
|
! Joe Groff discovered this bug
|
||||||
|
DEFER: factor-crashes-anymore
|
||||||
|
|
||||||
|
[ ] [
|
||||||
|
"IN: classes.tuple.tests
|
||||||
|
TUPLE: unsafe-slot-access ;
|
||||||
|
CONSTANT: unsafe-slot-access' T{ unsafe-slot-access }" eval( -- )
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ ] [
|
||||||
|
"IN: classes.tuple.tests
|
||||||
|
USE: accessors
|
||||||
|
TUPLE: unsafe-slot-access { x read-only initial: 31337 } ;
|
||||||
|
: factor-crashes-anymore ( -- x ) unsafe-slot-access' x>> ;" eval( -- )
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ 31337 ] [ factor-crashes-anymore ] unit-test
|
||||||
|
|
|
@ -32,6 +32,10 @@ M: tuple class layout-of 2 slot { word } declare ; inline
|
||||||
: tuple-size ( tuple -- size )
|
: tuple-size ( tuple -- size )
|
||||||
layout-of 3 slot { fixnum } declare ; inline
|
layout-of 3 slot { fixnum } declare ; inline
|
||||||
|
|
||||||
|
: layout-up-to-date? ( object -- ? )
|
||||||
|
dup tuple?
|
||||||
|
[ [ layout-of ] [ class tuple-layout ] bi eq? ] [ drop t ] if ;
|
||||||
|
|
||||||
: check-tuple ( object -- tuple )
|
: check-tuple ( object -- tuple )
|
||||||
dup tuple? [ not-a-tuple ] unless ; inline
|
dup tuple? [ not-a-tuple ] unless ; inline
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue