Skip to content

Commit

Permalink
fix #18408, closure lowering of captured, never-assigned locals
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Sep 13, 2016
1 parent 47ec910 commit 6f69ea9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,12 @@ f(x) = yt(x)
(if (eqv? (string.char (string name) 0) #\@)
(error "macro definition not allowed inside a local scope"))))
(if lam2
(lambda-optimize-vars! lam2))
(begin
;; mark all non-arguments as assigned, since locals that are never assigned
;; need to be handled the same as those that are (i.e., boxed).
(for-each (lambda (vi) (vinfo:set-asgn! vi #t))
(list-tail (car (lam:vinfo lam2)) (length (lam:args lam2))))
(lambda-optimize-vars! lam2)))
(if (not local) ;; not a local function; will not be closure converted to a new type
(cond (short e)
((null? cvs)
Expand Down Expand Up @@ -2992,6 +2997,8 @@ f(x) = yt(x)
'(null)
(convert-assignment name mk-closure fname lam interp)))))))
((lambda) ;; should only happen inside (thunk ...)
(for-each (lambda (vi) (vinfo:set-asgn! vi #t))
(car (lam:vinfo e)))
`(lambda ,(cadr e)
(,(clear-capture-bits (car (lam:vinfo e)))
() ,@(cddr (lam:vinfo e)))
Expand Down
8 changes: 8 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,14 @@ function capt_before_def()
end
@test capt_before_def()() == 2

function i18408()
local i
x->i
end
let f = i18408()
@test_throws UndefRefError f(0)
end

# variable scope, globals
glob_x = 23
function glotest()
Expand Down

2 comments on commit 6f69ea9

@vtjnash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nanosoldier runbenchmarks(ALL, vs="@47ec910d2db23ab96024569b5bd6bb75e8053251")

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

Please sign in to comment.