Skip to content

Commit e4a47f8

Browse files
make more cases of mapreduce trimmable (#59104)
add test for trimming with limited dynamic dispatch move mapreduce tests out of basic_jll test --------- Co-authored-by: Matt Bauman <[email protected]>
1 parent f345ee7 commit e4a47f8

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

base/reduce.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ mapreduce_empty(f::typeof(abs), ::typeof(max), T) = abs(zero(T))
374374
mapreduce_empty(f::typeof(abs2), ::typeof(max), T) = abs2(zero(T))
375375

376376
# For backward compatibility:
377-
mapreduce_empty_iter(f, op, itr, ItrEltype) =
377+
mapreduce_empty_iter(f::F, op::F2, itr, ItrEltype) where {F,F2} =
378378
reduce_empty_iter(MappingRF(f, op), itr, ItrEltype)
379379

380380
@inline reduce_empty_iter(op, itr) = reduce_empty_iter(op, itr, IteratorEltype(itr))

test/trimming/basic_jll.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,5 @@ function @main(args::Vector{String})::Cint
2424
cfunc = @cfunction(print_string, Cvoid, (Ptr{Cvoid},))
2525
fptr = dlsym(Zstd_jll.libzstd_handle, :ZSTD_versionString)
2626
ccall(cfunc, Cvoid, (Ptr{Cvoid},), fptr)
27-
28-
# map/mapreduce should work but relies on inlining and other optimizations
29-
arr = rand(10)
30-
sorted_arr = sort(arr)
31-
tot = sum(sorted_arr)
32-
tot = prod(sorted_arr)
33-
a = any(x -> x > 0, sorted_arr)
34-
b = all(x -> x >= 0, sorted_arr)
35-
c = map(x -> x^2, sorted_arr)
36-
# d = mapreduce(x -> x^2, +, sorted_arr) this doesn't work because of mapreduce_empty_iter having F specialized
37-
# e = reduce(xor, rand(Int, 10))
3827
return 0
3928
end

test/trimming/hello.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,34 @@ const str = OncePerProcess{String}() do
33
return "Hello, " * world
44
end
55

6+
abstract type Shape end
7+
struct Square <: Shape
8+
side::Float64
9+
end
10+
struct Circle <: Shape
11+
radius::Float64
12+
end
13+
area(s::Square) = s.side^2
14+
area(c::Circle) = pi*c.radius^2
15+
16+
sum_areas(v::Vector{Shape}) = sum(area, v)
17+
618
function @main(args::Vector{String})::Cint
719
println(Core.stdout, str())
820
foreach(x->println(Core.stdout, x), args)
21+
22+
# test map/mapreduce; should work but relies on inlining and other optimizations
23+
# test that you can dispatch to some number of concrete cases
24+
println(Core.stdout, sum_areas(Shape[Circle(1), Square(2)]))
25+
26+
arr = rand(10)
27+
sorted_arr = sort(arr)
28+
tot = sum(sorted_arr)
29+
tot = prod(sorted_arr)
30+
a = any(x -> x > 0, sorted_arr)
31+
b = all(x -> x >= 0, sorted_arr)
32+
c = map(x -> x^2, sorted_arr)
33+
d = mapreduce(x -> x^2, +, sorted_arr)
34+
# e = reduce(xor, rand(Int, 10))
935
return 0
1036
end

test/trimming/trimming.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ bindir = dirname(ARGS[1])
66
let exe_suffix = splitext(Base.julia_exename())[2]
77

88
hello_exe = joinpath(bindir, "hello" * exe_suffix)
9-
@test readchomp(`$hello_exe arg1 arg2`) == "Hello, world!\n$hello_exe\narg1\narg2"
10-
@test filesize(hello_exe) < 2_000_000
9+
@test readchomp(`$hello_exe arg1 arg2`) == "Hello, world!\n$hello_exe\narg1\narg2\n$(4.0+pi)"
10+
@test filesize(hello_exe) < 2_500_000
1111

1212
basic_jll_exe = joinpath(bindir, "basic_jll" * exe_suffix)
1313
lines = split(readchomp(`$basic_jll_exe`), "\n")

0 commit comments

Comments
 (0)