Skip to content

Commit faae194

Browse files
committed
remove "local in global scope" error for now
add tests for timing macros
1 parent c367699 commit faae194

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

base/util.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ macro timed(ex)
227227
local elapsedtime = time_ns()
228228
local val = $(esc(ex))
229229
elapsedtime = time_ns() - elapsedtime
230-
diff = GC_Diff(gc_num(), stats)
230+
local diff = GC_Diff(gc_num(), stats)
231231
val, elapsedtime/1e9, diff.total_allocd + diff.allocd, diff.total_time/1e9, diff
232232
end
233233
end

src/jlfrontend.scm

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@
6565
;; vars assigned anywhere, if they have been defined as global
6666
(filter defined-julia-global (find-possible-globals e))))
6767
(append
68-
(if (null? (find-decls 'local e))
69-
'()
70-
(error "local declaration in global scope"))
68+
(find-decls 'local e)
7169
(find-decls 'local! e))))
7270

7371
;; return a lambda expression representing a thunk for a top-level expression

test/misc.jl

+25
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,28 @@ let l = ReentrantLock()
142142
unlock(l)
143143
@test_throws ErrorException unlock(l)
144144
end
145+
146+
# timing macros
147+
148+
# test that they don't introduce global vars
149+
global v11801, t11801, names_before_timing
150+
names_before_timing = names(current_module(), true)
151+
152+
let t = @elapsed 1+1
153+
@test isa(t, Real) && t >= 0
154+
end
155+
156+
let
157+
val, t = @timed sin(1)
158+
@test val == sin(1)
159+
@test isa(t, Real) && t >= 0
160+
end
161+
162+
# problem after #11801 - at global scope
163+
t11801 = @elapsed 1+1
164+
@test isa(t11801,Real) && t11801 >= 0
165+
v11801, t11801 = @timed sin(1)
166+
@test v11801 == sin(1)
167+
@test isa(t11801,Real) && t11801 >= 0
168+
169+
@test names(current_module(), true) == names_before_timing

0 commit comments

Comments
 (0)