| 
									
										
										
										
											2010-01-20 10:23:20 -05:00
										 |  |  | ! Copyright (C) 2009, 2010 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2010-01-29 03:40:09 -05:00
										 |  |  | USING: arrays assocs classes.algebra compiler.units definitions | 
					
						
							|  |  |  | graphs grouping kernel namespaces sequences words fry | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  | stack-checker.dependencies combinators ;
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | IN: compiler.crossref | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SYMBOL: compiled-crossref | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | compiled-crossref [ H{ } clone ] initialize
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 23:20:08 -05:00
										 |  |  | SYMBOL: generic-call-site-crossref | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 23:20:08 -05:00
										 |  |  | generic-call-site-crossref [ H{ } clone ] initialize
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 11:28:55 -05:00
										 |  |  | : effect-dependencies-of ( word -- assoc )
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  |     compiled-crossref get at ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 11:28:55 -05:00
										 |  |  | : definition-dependencies-of ( word -- assoc )
 | 
					
						
							|  |  |  |     effect-dependencies-of [ nip definition-dependency dependency>= ] assoc-filter ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : conditional-dependencies-of ( word -- assoc )
 | 
					
						
							|  |  |  |     effect-dependencies-of [ nip conditional-dependency dependency>= ] assoc-filter ;
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-03 07:09:57 -05:00
										 |  |  | : outdated-definition-usages ( assoc -- assocs )
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  |     [ drop word? ] assoc-filter
 | 
					
						
							| 
									
										
										
										
											2010-02-03 07:09:57 -05:00
										 |  |  |     [ drop definition-dependencies-of ] { } assoc>map ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : outdated-effect-usages ( assoc -- assocs )
 | 
					
						
							|  |  |  |     [ drop word? ] assoc-filter
 | 
					
						
							|  |  |  |     [ drop effect-dependencies-of ] { } assoc>map ;
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 11:09:49 -05:00
										 |  |  | : dependencies-satisfied? ( word cache -- ? )
 | 
					
						
							|  |  |  |     [ "dependency-checks" word-prop ] dip
 | 
					
						
							|  |  |  |     '[ _ [ satisfied? ] cache ] all? ;
 | 
					
						
							| 
									
										
										
										
											2010-01-29 03:40:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 08:58:39 -05:00
										 |  |  | : outdated-conditional-usages ( assoc -- assocs )
 | 
					
						
							| 
									
										
										
										
											2010-01-29 11:09:49 -05:00
										 |  |  |     H{ } clone '[ | 
					
						
							| 
									
										
										
										
											2010-01-29 03:40:09 -05:00
										 |  |  |         drop
 | 
					
						
							| 
									
										
										
										
											2010-01-29 11:28:55 -05:00
										 |  |  |         conditional-dependencies-of | 
					
						
							| 
									
										
										
										
											2010-01-29 11:09:49 -05:00
										 |  |  |         [ drop _ dependencies-satisfied? not ] assoc-filter
 | 
					
						
							| 
									
										
										
										
											2010-01-29 03:40:09 -05:00
										 |  |  |     ] { } assoc>map ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 23:20:08 -05:00
										 |  |  | : generic-call-sites-of ( word -- assoc )
 | 
					
						
							|  |  |  |     generic-call-site-crossref get at ;
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  | : only-xref ( assoc -- assoc' )
 | 
					
						
							|  |  |  |     [ drop crossref? ] { } assoc-filter-as ;
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 23:20:08 -05:00
										 |  |  | : set-generic-call-sites ( word alist -- )
 | 
					
						
							|  |  |  |     concat f like "generic-call-sites" set-word-prop ;
 | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : split-dependencies ( assoc -- effect-deps cond-deps def-deps )
 | 
					
						
							|  |  |  |     [ nip effect-dependency eq? ] assoc-partition
 | 
					
						
							|  |  |  |     [ nip conditional-dependency eq? ] assoc-partition ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : (store-dependencies) ( word assoc prop -- )
 | 
					
						
							|  |  |  |     [ keys f like ] dip set-word-prop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : store-dependencies ( word assoc -- )
 | 
					
						
							|  |  |  |     split-dependencies | 
					
						
							| 
									
										
										
										
											2010-01-30 04:33:27 -05:00
										 |  |  |     "effect-dependencies" "conditional-dependencies" "definition-dependencies" | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  |     [ (store-dependencies) ] tri-curry@ tri-curry* tri ;
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  | : (compiled-xref) ( word dependencies generic-dependencies -- )
 | 
					
						
							| 
									
										
										
										
											2010-01-31 23:20:08 -05:00
										 |  |  |     compiled-crossref generic-call-site-crossref | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  |     [ get add-vertex* ] bi-curry@ bi-curry* bi ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : compiled-xref ( word dependencies generic-dependencies -- )
 | 
					
						
							|  |  |  |     [ only-xref ] bi@
 | 
					
						
							| 
									
										
										
										
											2010-01-31 23:20:08 -05:00
										 |  |  |     [ nip set-generic-call-sites ] | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  |     [ drop store-dependencies ] | 
					
						
							|  |  |  |     [ (compiled-xref) ] | 
					
						
							|  |  |  |     3tri ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : set-at-each ( keys assoc value -- )
 | 
					
						
							|  |  |  |     '[ _ [ _ ] 2dip set-at ] each ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : join-dependencies ( effect-deps cond-deps def-deps -- assoc )
 | 
					
						
							|  |  |  |     H{ } clone [ | 
					
						
							|  |  |  |         [ effect-dependency set-at-each ] | 
					
						
							|  |  |  |         [ conditional-dependency set-at-each ] | 
					
						
							|  |  |  |         [ definition-dependency set-at-each ] tri-curry tri*
 | 
					
						
							|  |  |  |     ] keep ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : load-dependencies ( word -- assoc )
 | 
					
						
							|  |  |  |     [ "effect-dependencies" word-prop ] | 
					
						
							| 
									
										
										
										
											2010-01-30 04:33:27 -05:00
										 |  |  |     [ "conditional-dependencies" word-prop ] | 
					
						
							|  |  |  |     [ "definition-dependencies" word-prop ] tri
 | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  |     join-dependencies ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : (compiled-unxref) ( word dependencies variable -- )
 | 
					
						
							|  |  |  |     get remove-vertex* ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 23:20:08 -05:00
										 |  |  | : generic-call-sites ( word -- alist )
 | 
					
						
							|  |  |  |     "generic-call-sites" word-prop 2 <groups> ;
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : compiled-unxref ( word -- )
 | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         [ dup load-dependencies compiled-crossref (compiled-unxref) ] | 
					
						
							| 
									
										
										
										
											2010-01-31 23:20:08 -05:00
										 |  |  |         [ dup generic-call-sites generic-call-site-crossref (compiled-unxref) ] | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  |         [ "effect-dependencies" remove-word-prop ] | 
					
						
							|  |  |  |         [ "conditional-dependencies" remove-word-prop ] | 
					
						
							| 
									
										
										
										
											2010-01-30 04:33:27 -05:00
										 |  |  |         [ "definition-dependencies" remove-word-prop ] | 
					
						
							| 
									
										
										
										
											2010-01-31 23:20:08 -05:00
										 |  |  |         [ "generic-call-sites" remove-word-prop ] | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  |     } cleave ;
 | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : delete-compiled-xref ( word -- )
 | 
					
						
							|  |  |  |     [ compiled-unxref ] | 
					
						
							|  |  |  |     [ compiled-crossref get delete-at ] | 
					
						
							| 
									
										
										
										
											2010-01-31 23:20:08 -05:00
										 |  |  |     [ generic-call-site-crossref get delete-at ] | 
					
						
							| 
									
										
										
										
											2009-11-08 07:08:04 -05:00
										 |  |  |     tri ;
 | 
					
						
							| 
									
										
										
										
											2010-01-29 03:40:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 16:58:00 -05:00
										 |  |  | : set-dependency-checks ( word deps -- )
 | 
					
						
							| 
									
										
										
										
											2010-01-29 15:28:33 -05:00
										 |  |  |     keys f like "dependency-checks" set-word-prop ;
 |