Skip to content

Commit

Permalink
remove "local in global scope" error for now
Browse files Browse the repository at this point in the history
add tests for timing macros
  • Loading branch information
JeffBezanson committed Jun 22, 2015
1 parent c367699 commit faae194
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ macro timed(ex)
local elapsedtime = time_ns()
local val = $(esc(ex))
elapsedtime = time_ns() - elapsedtime
diff = GC_Diff(gc_num(), stats)
local diff = GC_Diff(gc_num(), stats)
val, elapsedtime/1e9, diff.total_allocd + diff.allocd, diff.total_time/1e9, diff
end
end
Expand Down
4 changes: 1 addition & 3 deletions src/jlfrontend.scm
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@
;; vars assigned anywhere, if they have been defined as global
(filter defined-julia-global (find-possible-globals e))))
(append
(if (null? (find-decls 'local e))
'()
(error "local declaration in global scope"))
(find-decls 'local e)
(find-decls 'local! e))))

;; return a lambda expression representing a thunk for a top-level expression
Expand Down
25 changes: 25 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,28 @@ let l = ReentrantLock()
unlock(l)
@test_throws ErrorException unlock(l)
end

# timing macros

# test that they don't introduce global vars
global v11801, t11801, names_before_timing
names_before_timing = names(current_module(), true)

let t = @elapsed 1+1
@test isa(t, Real) && t >= 0
end

let
val, t = @timed sin(1)
@test val == sin(1)
@test isa(t, Real) && t >= 0
end

# problem after #11801 - at global scope
t11801 = @elapsed 1+1
@test isa(t11801,Real) && t11801 >= 0
v11801, t11801 = @timed sin(1)
@test v11801 == sin(1)
@test isa(t11801,Real) && t11801 >= 0

@test names(current_module(), true) == names_before_timing

0 comments on commit faae194

Please sign in to comment.