Skip to content

Commit

Permalink
fix O(n^2) length calls in compact-ir lowering step (JuliaLang#50756)
Browse files Browse the repository at this point in the history
This can be a problem for very long function bodies.
  • Loading branch information
JeffBezanson committed Aug 2, 2023
1 parent 33e3d9f commit 3c64bc3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4980,6 +4980,7 @@ f(x) = yt(x)
(let ((code '(block))
(locs '(list))
(linetable '(list))
(linetablelen 0)
(labltable (table))
(ssavtable (table))
(current-loc 0)
Expand All @@ -4992,6 +4993,7 @@ f(x) = yt(x)
(if (and (null? (cdr linetable))
(not (and (pair? e) (eq? (car e) 'meta))))
(begin (set! linetable (cons (make-lineinfo name file line) linetable))
(set! linetablelen (+ linetablelen 1))
(set! current-loc 1)))
(set! code (cons e code))
(set! i (+ i 1))
Expand All @@ -5013,13 +5015,15 @@ f(x) = yt(x)
(make-lineinfo name current-file current-line)
(make-lineinfo name current-file current-line (caar locstack)))
linetable))
(set! current-loc (- (length linetable) 1)))))
(set! linetablelen (+ linetablelen 1))
(set! current-loc linetablelen))))
((and (length> e 2) (eq? (car e) 'meta) (eq? (cadr e) 'push_loc))
(set! locstack (cons (list current-loc current-line current-file) locstack))
(set! current-file (caddr e))
(set! current-line 0)
(set! linetable (cons (make-lineinfo name current-file current-line current-loc) linetable))
(set! current-loc (- (length linetable) 1)))
(set! linetablelen (+ linetablelen 1))
(set! current-loc linetablelen))
((and (length= e 2) (eq? (car e) 'meta) (eq? (cadr e) 'pop_loc))
(let ((l (car locstack)))
(set! locstack (cdr locstack))
Expand Down

0 comments on commit 3c64bc3

Please sign in to comment.