1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-11 22:31:12 +02:00

Limit impact of O(n^2) type analysis by imposing limit

* module/language/cps/types.scm (infer-types): Add #:max-label-count
  argument.

* module/language/cps/type-fold.scm (compute-folded, fold-constants*):
  Disable for big functions.  Perhaps we can relax this if we find an
  O(n log n) way to represent types.
This commit is contained in:
Andy Wingo 2014-05-14 21:42:09 +02:00
parent a77e3a7c8a
commit a7ee377dbe
2 changed files with 14 additions and 9 deletions

View file

@ -134,9 +134,11 @@
((eqv? type &nil) #nil)
((eqv? type &null) '())
(else (error "unhandled type" type val))))
(let* ((typev (infer-types fun dfg))
(folded? (make-bitvector (/ (vector-length typev) 2) #f))
(folded-values (make-vector (bitvector-length folded?) #f)))
(let* ((typev (infer-types fun dfg #:max-label-count 3000))
(folded? (and typev
(make-bitvector (/ (vector-length typev) 2) #f)))
(folded-values (and typev
(make-vector (bitvector-length folded?) #f))))
(define (label->idx label) (- label min-label))
(define (var->idx var) (- var min-var))
(define (maybe-fold-value! label name k def)
@ -201,9 +203,10 @@
(var->idx arg0) (var->idx arg1)))))
(_ #f)))
(_ #f)))
(match fun
(($ $cont kfun ($ $kfun src meta self tail clause))
(visit-cont clause)))
(when typev
(match fun
(($ $cont kfun ($ $kfun src meta self tail clause))
(visit-cont clause))))
(values folded? folded-values)))
(define (fold-constants* fun dfg)
@ -232,7 +235,8 @@
(($ $continue k src (and fun ($ $fun)))
($continue k src ,(visit-fun fun)))
(($ $continue k src (and primcall ($ $primcall)))
,(if (bitvector-ref folded? (label->idx label))
,(if (and folded?
(bitvector-ref folded? (label->idx label)))
(let ((val (vector-ref folded-values (label->idx label))))
;; Uncomment for debugging.
;; (pk 'folded src primcall val)

View file

@ -1381,7 +1381,7 @@ mapping symbols to types."
;; All done! Return the computed types.
(else typev)))))
(define (infer-types fun dfg)
(define* (infer-types fun dfg #:key (max-label-count +inf.0))
;; Fun must be renumbered.
(match fun
(($ $cont min-label ($ $kfun _ _ min-var))
@ -1412,7 +1412,8 @@ mapping symbols to types."
(values label-count var-count)))))
fun 0 0))
(lambda (label-count var-count)
(infer-types* dfg min-label label-count min-var var-count))))))
(and (< label-count max-label-count)
(infer-types* dfg min-label label-count min-var var-count)))))))
(define (lookup-pre-type typev label def)
(if (< def 0)