compiler.crossref: changes the way in which dependencies are stored on words

Previosly, they were stored in three sequences in the properties
"conditional-dependencies" "effect-dependencies" and
"definition-dependencies". It seem to better to store all three
types in one big property called "dependencies".
char-rename
Björn Lindqvist 2016-11-28 06:33:58 +01:00
parent ef269c493c
commit e629f7b289
7 changed files with 63 additions and 60 deletions

View File

@ -1,13 +1,21 @@
USING: assocs help.markup help.syntax words ; USING: assocs help.markup help.syntax sequences words ;
IN: compiler.crossref IN: compiler.crossref
HELP: compiled-crossref HELP: compiled-crossref
{ $var-description "A hashtable that maps words to other words that depend on them. It also stores the types of the dependencies." } ; { $var-description "A hashtable that maps words to other words that depend on them and their dependency types." } ;
HELP: delete-compiled-xref
{ $values { "word" word } }
{ $description "Deletes cross-referencing data for a word. Used when the optimizing compiler forgets a word." } ;
HELP: load-dependencies HELP: load-dependencies
{ $values { "word" word } { "assoc" assoc } } { $values { "word" word } { "seq" sequence } }
{ $description "Creates an assoc where keys are the words the word depends on and values are the dependency type." } ; { $description "Outputs a sequence of the words dependencies." } ;
HELP: remove-xref
{ $values { "word" word } { "dependencies" sequence } { "crossref" assoc } }
{ $description "Removes a set of dependencies from the cross referencing table." } ;
HELP: store-dependencies HELP: store-dependencies
{ $values { "word" word } { "assoc" assoc } } { $values { "word" word } { "assoc" assoc } }
{ $description "Stores the dependencies in 'assoc' in the word attributes named \"effect-dependencies\", \"conditional-dependencies\" and \"definition-dependencies\"." } ; { $description "Stores the dependencies in 'assoc' in the word attribute \"dependencies\"." } ;

View File

@ -1,5 +1,5 @@
USING: accessors assocs compiler.crossref fry kernel namespaces USING: assocs compiler.crossref fry io kernel namespaces sequences
sequences stack-checker.dependencies tools.test vocabs words ; stack-checker.dependencies tools.test vocabs words ;
IN: compiler.crossref.tests IN: compiler.crossref.tests
! Dependencies of all words should always be satisfied unless we're ! Dependencies of all words should always be satisfied unless we're
@ -21,6 +21,19 @@ IN: compiler.crossref.tests
} }
} clone ; } clone ;
! compiled-unxref
SYMBOL: kolobi
{ f f } [
! Setup a fake dependency; kolobi -> print
+effect+ kolobi compiled-crossref get \ print of set-at
kolobi { print } "dependencies" set-word-prop
! Ensure it is being forgotten
kolobi compiled-unxref
kolobi "dependencies" word-prop
compiled-crossref get \ print of kolobi of
] unit-test
! dependencies-of ! dependencies-of
{ {
H{ { 20 +definition+ } } H{ { 20 +definition+ } }
@ -38,18 +51,15 @@ IN: compiler.crossref.tests
] with-variable ] with-variable
] unit-test ] unit-test
! join-dependencies ! remove-xref
SYMBOLS: foo1 bar ;
{ {
H{ H{ { foo1 H{ } } }
{ 1 +effect+ }
{ 2 +effect+ }
{ 3 +conditional+ }
{ 4 +conditional+ }
{ 5 +definition+ }
{ 6 +definition+ }
}
} [ } [
{ 1 2 } { 3 4 } { 5 6 } join-dependencies bar { foo1 }
H{
{ foo1 H{ { bar +definition+ } } }
} clone [ remove-xref ] keep
] unit-test ] unit-test
! store-dependencies ! store-dependencies
@ -63,10 +73,8 @@ IN: compiler.crossref.tests
SYMBOL: foo SYMBOL: foo
{ {
{ 20 } { 40 50 } { 30 } { 40 50 20 30 }
} [ } [
foo [ setup-deps store-dependencies ] keep props>> foo [ setup-deps store-dependencies ] keep "dependencies" word-prop
[ "definition-dependencies" of ] foo delete-compiled-xref
[ "effect-dependencies" of ]
[ "conditional-dependencies" of ] tri
] unit-test ] unit-test

View File

@ -47,11 +47,7 @@ generic-call-site-crossref [ H{ } clone ] initialize
[ rot '[ nip _ = ] assoc-filter keys ] dip set-word-prop ; [ rot '[ nip _ = ] assoc-filter keys ] dip set-word-prop ;
: store-dependencies ( word assoc -- ) : store-dependencies ( word assoc -- )
{ keys "dependencies" set-word-prop ;
{ +effect+ "effect-dependencies" }
{ +conditional+ "conditional-dependencies" }
{ +definition+ "definition-dependencies" }
} [ store-dependencies-of-type ] 2with assoc-each ;
: add-xref ( word dependencies crossref -- ) : add-xref ( word dependencies crossref -- )
rot '[ rot '[
@ -59,7 +55,7 @@ generic-call-site-crossref [ H{ } clone ] initialize
] assoc-each ; ] assoc-each ;
: remove-xref ( word dependencies crossref -- ) : remove-xref ( word dependencies crossref -- )
[ keys ] dip '[ _ at delete-at ] with each ; '[ _ at delete-at ] with each ;
: (compiled-xref) ( word dependencies generic-dependencies -- ) : (compiled-xref) ( word dependencies generic-dependencies -- )
compiled-crossref generic-call-site-crossref compiled-crossref generic-call-site-crossref
@ -72,21 +68,8 @@ generic-call-site-crossref [ H{ } clone ] initialize
[ (compiled-xref) ] [ (compiled-xref) ]
3tri ; 3tri ;
: set-at-each ( keys assoc value -- ) : load-dependencies ( word -- seq )
'[ _ [ _ ] 2dip set-at ] each ; "dependencies" word-prop ;
: join-dependencies ( effect-deps cond-deps def-deps -- assoc )
H{ } clone [
[ +effect+ set-at-each ]
[ +conditional+ set-at-each ]
[ +definition+ set-at-each ] tri-curry tri*
] keep ;
: load-dependencies ( word -- assoc )
[ "effect-dependencies" word-prop ]
[ "conditional-dependencies" word-prop ]
[ "definition-dependencies" word-prop ] tri
join-dependencies ;
: (compiled-unxref) ( word dependencies variable -- ) : (compiled-unxref) ( word dependencies variable -- )
get remove-xref ; get remove-xref ;
@ -98,9 +81,7 @@ generic-call-site-crossref [ H{ } clone ] initialize
{ {
[ dup load-dependencies compiled-crossref (compiled-unxref) ] [ dup load-dependencies compiled-crossref (compiled-unxref) ]
[ dup generic-call-sites generic-call-site-crossref (compiled-unxref) ] [ dup generic-call-sites generic-call-site-crossref (compiled-unxref) ]
[ "effect-dependencies" remove-word-prop ] [ "dependencies" remove-word-prop ]
[ "conditional-dependencies" remove-word-prop ]
[ "definition-dependencies" remove-word-prop ]
[ "generic-call-sites" remove-word-prop ] [ "generic-call-sites" remove-word-prop ]
} cleave ; } cleave ;

View File

@ -1,6 +1,5 @@
USING: accessors compiler compiler.units tools.test math parser USING: arrays classes.mixin compiler.crossref compiler.units eval
kernel sequences sequences.private classes.mixin generic generic kernel sequences tools.test words ;
definitions arrays words assocs eval grouping ;
IN: compiler.tests.redefine3 IN: compiler.tests.redefine3
GENERIC: sheeple ( obj -- x ) GENERIC: sheeple ( obj -- x )
@ -14,7 +13,7 @@ M: empty-mixin sheeple drop "wake up" ; inline
: sheeple-test ( -- string ) { } sheeple ; : sheeple-test ( -- string ) { } sheeple ;
: compiled-use? ( key word -- ? ) : compiled-use? ( key word -- ? )
"definition-dependencies" word-prop member-eq? ; load-dependencies member-eq? ;
[ "sheeple" ] [ sheeple-test ] unit-test [ "sheeple" ] [ sheeple-test ] unit-test
[ t ] [ \ sheeple-test word-optimized? ] unit-test [ t ] [ \ sheeple-test word-optimized? ] unit-test

View File

@ -127,7 +127,6 @@ IN: tools.deploy.shaker
"boa-check" "boa-check"
"coercer" "coercer"
"combination" "combination"
"conditional-dependencies"
"constant" "constant"
"constraints" "constraints"
"custom-inlining" "custom-inlining"
@ -136,11 +135,10 @@ IN: tools.deploy.shaker
"default" "default"
"default-method" "default-method"
"default-output-classes" "default-output-classes"
"definition-dependencies" "dependencies"
"dependency-checks" "dependency-checks"
"derived-from" "derived-from"
"ebnf-parser" "ebnf-parser"
"effect-dependencies"
"engines" "engines"
"forgotten" "forgotten"

View File

@ -148,6 +148,17 @@ $nl
{ $snippet "\"specializer\"" } { $snippet "\"specializer\"" }
{ $link "hints" } { $link "hints" }
} }
{
{
{ $snippet "\"dependencies\"" } ", "
}
{ "Used by the optimizing compiler when forgetting words for fast dependency lookup. See " { $link "compilation-units" } "." }
}
{
{ $snippet "\"generic-call-sites\"" }
{ "Set on some generic words." }
}
} }
"Properties which are defined for classes only:" "Properties which are defined for classes only:"
{ $table { $table

View File

@ -1,6 +1,6 @@
USING: accessors arrays compiler.units definitions eval generic USING: accessors arrays compiler.crossref compiler.units definitions
io.streams.string kernel math namespaces parser sequences tools.test eval generic io.streams.string kernel math namespaces parser sequences
vocabs words words.private words.symbol ; tools.test vocabs words words.private words.symbol ;
IN: words.tests IN: words.tests
{ 4 } [ { 4 } [
@ -125,11 +125,9 @@ DEFER: deferred
{ { } } { { } }
[ [
! No word can have dependencies to forgotten words.
all-words [ all-words [
[ "effect-dependencies" word-prop ] load-dependencies [ "forgotten" word-prop ] filter
[ "definition-dependencies" word-prop ]
[ "conditional-dependencies" word-prop ] tri
3append [ "forgotten" word-prop ] filter
] map harvest ] map harvest
] unit-test ] unit-test