Merge branch 'master' of git://factorcode.org/git/factor

db4
Joe Groff 2010-02-11 10:57:31 -08:00
commit 276db71ecd
7 changed files with 56 additions and 18 deletions

View File

@ -554,9 +554,6 @@ M: ulonglong-2-rep rep-component-type drop ulonglong ;
M: float-4-rep rep-component-type drop float ;
M: double-2-rep rep-component-type drop double ;
: rep-length ( rep -- n )
16 swap rep-component-type heap-size /i ; foldable
: (unsigned-interval) ( bytes -- from to ) [ 0 ] dip 8 * 2^ 1 - ; foldable
: unsigned-interval ( c-type -- from to ) heap-size (unsigned-interval) ; foldable
: (signed-interval) ( bytes -- from to ) 8 * 1 - 2^ [ neg ] [ 1 - ] bi ; foldable

View File

@ -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.
USING: kernel accessors sequences classes.tuple
classes.tuple.private arrays math math.private slots.private
@ -50,7 +50,10 @@ DEFER: record-literal-allocation
if* ;
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 -- )
[ in-d>> add-escaping-values ]

View File

@ -79,14 +79,6 @@ M: callable splicing-nodes splicing-body ;
: inline-math-method ( #call word -- ? )
dupd inlining-math-method eliminate-dispatch ;
: inlining-math-partial ( #call word -- class/f quot/f )
[ "derived-from" word-prop first inlining-math-method ]
[ nip 1quotation ] 2bi
[ = not ] [ drop ] 2bi and ;
: inline-math-partial ( #call word -- ? )
dupd inlining-math-partial eliminate-dispatch ;
! Method body inlining
SYMBOL: history

View File

@ -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.
USING: fry assocs arrays byte-arrays strings accessors sequences
kernel slots classes.algebra classes.tuple classes.tuple.private
words math math.private combinators sequences.private namespaces
slots.private classes compiler.tree.propagation.info ;
combinators.short-circuit words math math.private combinators
sequences.private namespaces slots.private classes
compiler.tree.propagation.info ;
IN: compiler.tree.propagation.slots
! Propagation of immutable slots and array lengths
@ -52,8 +53,18 @@ UNION: fixed-length-sequence array byte-array string ;
dup [ read-only>> ] when ;
: literal-info-slot ( slot object -- info/f )
2dup class read-only-slot?
[ swap slot <literal-info> ] [ 2drop f ] if ;
#! literal-info-slot makes an unsafe call to 'slot'.
#! 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 -- ? )
[ 1 = ] [ length>> ] bi* and ;

View File

@ -169,6 +169,19 @@ M: uint-scalar-rep rep-size drop 4 ;
M: longlong-scalar-rep rep-size drop 8 ;
M: ulonglong-scalar-rep rep-size drop 8 ;
GENERIC: rep-length ( rep -- n ) foldable
M: char-16-rep rep-length drop 16 ;
M: uchar-16-rep rep-length drop 16 ;
M: short-8-rep rep-length drop 8 ;
M: ushort-8-rep rep-length drop 8 ;
M: int-4-rep rep-length drop 4 ;
M: uint-4-rep rep-length drop 4 ;
M: longlong-2-rep rep-length drop 2 ;
M: ulonglong-2-rep rep-length drop 2 ;
M: float-4-rep rep-length drop 4 ;
M: double-2-rep rep-length drop 2 ;
GENERIC: rep-component-type ( rep -- n )
! Methods defined in alien.c-types

View File

@ -746,3 +746,21 @@ TUPLE: g < a-g ;
[ ] [ "IN: classes.tuple.tests MIXIN: a-g TUPLE: g ;" eval( -- ) ] 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

View File

@ -32,6 +32,10 @@ M: tuple class layout-of 2 slot { word } declare ; inline
: tuple-size ( tuple -- size )
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 )
dup tuple? [ not-a-tuple ] unless ; inline