Skip to content

Commit 0f6d9e5

Browse files
committed
Revert ""improve" allocations macro with more functions (#58057)"
This reverts commit a47b58f.
1 parent 0f93b24 commit 0f6d9e5

File tree

3 files changed

+16
-40
lines changed

3 files changed

+16
-40
lines changed

base/timing.jl

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -472,35 +472,6 @@ function gc_bytes()
472472
b[]
473473
end
474474

475-
function allocated(f, args::Vararg{Any,N}) where {N}
476-
b0 = Ref{Int64}(0)
477-
b1 = Ref{Int64}(0)
478-
Base.gc_bytes(b0)
479-
f(args...)
480-
Base.gc_bytes(b1)
481-
return b1[] - b0[]
482-
end
483-
only(methods(allocated)).called = 0xff
484-
485-
function allocations(f, args::Vararg{Any,N}) where {N}
486-
stats = Base.gc_num()
487-
f(args...)
488-
diff = Base.GC_Diff(Base.gc_num(), stats)
489-
return Base.gc_alloc_count(diff)
490-
end
491-
only(methods(allocations)).called = 0xff
492-
493-
function is_simply_call(@nospecialize ex)
494-
Meta.isexpr(ex, :call) || return false
495-
for a in ex.args
496-
a isa QuoteNode && continue
497-
a isa Symbol && continue
498-
isa_ast_node(a) || continue
499-
return false
500-
end
501-
return true
502-
end
503-
504475
"""
505476
@allocated
506477
@@ -516,11 +487,15 @@ julia> @allocated rand(10^6)
516487
```
517488
"""
518489
macro allocated(ex)
519-
if !is_simply_call(ex)
520-
ex = :((() -> $ex)())
490+
quote
491+
Experimental.@force_compile
492+
local b0 = Ref{Int64}(0)
493+
local b1 = Ref{Int64}(0)
494+
gc_bytes(b0)
495+
$(esc(ex))
496+
gc_bytes(b1)
497+
b1[] - b0[]
521498
end
522-
pushfirst!(ex.args, GlobalRef(Base, :allocated))
523-
return esc(ex)
524499
end
525500

526501
"""
@@ -541,14 +516,15 @@ julia> @allocations rand(10^6)
541516
This macro was added in Julia 1.9.
542517
"""
543518
macro allocations(ex)
544-
if !is_simply_call(ex)
545-
ex = :((() -> $ex)())
519+
quote
520+
Experimental.@force_compile
521+
local stats = Base.gc_num()
522+
$(esc(ex))
523+
local diff = Base.GC_Diff(Base.gc_num(), stats)
524+
Base.gc_alloc_count(diff)
546525
end
547-
pushfirst!(ex.args, GlobalRef(Base, :allocations))
548-
return esc(ex)
549526
end
550527

551-
552528
"""
553529
@lock_conflicts
554530

stdlib/Unicode/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ end
285285
@test_throws BoundsError graphemes("äöüx", 5:5)
286286
@test_throws ArgumentError graphemes("äöüx", 0:1)
287287

288-
@test @allocated(length(graphemes("äöüx"))) == 0
288+
@test (()->@allocated(length(graphemes("äöüx"))))() == 0
289289
end
290290

291291
@testset "#3721, #6939 up-to-date character widths" begin

test/boundscheck_exec.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ if bc_opt == bc_default
350350
m1 === m2
351351
end
352352
no_alias_prove(1)
353-
@test (@allocated no_alias_prove(5)) == 0
353+
@test_broken (@allocated no_alias_prove(5)) == 0
354354
end
355355

356356
@testset "automatic boundscheck elision for iteration on some important types" begin

0 commit comments

Comments
 (0)