Skip to content

Commit d493a97

Browse files
vtjnashgbaraldi
andauthored
remove excessive code from trim script (JuliaLang#58853)
Co-authored-by: gbaraldi <[email protected]>
1 parent 7634fdf commit d493a97

File tree

3 files changed

+16
-56
lines changed

3 files changed

+16
-56
lines changed

contrib/juliac/juliac-trim-base.jl

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -78,38 +78,12 @@ end
7878
end
7979
end
8080
show_type_name(io::IO, tn::Core.TypeName) = print(io, tn.name)
81-
82-
mapreduce(f::F, op::F2, A::AbstractArrayOrBroadcasted; dims=:, init=_InitialValue()) where {F, F2} =
83-
_mapreduce_dim(f, op, init, A, dims)
84-
mapreduce(f::F, op::F2, A::AbstractArrayOrBroadcasted...; kw...) where {F, F2} =
85-
reduce(op, map(f, A...); kw...)
86-
87-
_mapreduce_dim(f::F, op::F2, nt, A::AbstractArrayOrBroadcasted, ::Colon) where {F, F2} =
88-
mapfoldl_impl(f, op, nt, A)
89-
90-
_mapreduce_dim(f::F, op::F2, ::_InitialValue, A::AbstractArrayOrBroadcasted, ::Colon) where {F, F2} =
91-
_mapreduce(f, op, IndexStyle(A), A)
92-
93-
_mapreduce_dim(f::F, op::F2, nt, A::AbstractArrayOrBroadcasted, dims) where {F, F2} =
94-
mapreducedim!(f, op, reducedim_initarray(A, dims, nt), A)
95-
96-
_mapreduce_dim(f::F, op::F2, ::_InitialValue, A::AbstractArrayOrBroadcasted, dims) where {F,F2} =
97-
mapreducedim!(f, op, reducedim_init(f, op, A, dims), A)
98-
99-
mapreduce_empty_iter(f::F, op::F2, itr, ItrEltype) where {F, F2} =
100-
reduce_empty_iter(MappingRF(f, op), itr, ItrEltype)
101-
mapreduce_first(f::F, op::F2, x) where {F,F2} = reduce_first(op, f(x))
102-
103-
_mapreduce(f::F, op::F2, A::AbstractArrayOrBroadcasted) where {F,F2} = _mapreduce(f, op, IndexStyle(A), A)
104-
mapreduce_empty(::typeof(identity), op::F, T) where {F} = reduce_empty(op, T)
105-
mapreduce_empty(::typeof(abs), op::F, T) where {F} = abs(reduce_empty(op, T))
106-
mapreduce_empty(::typeof(abs2), op::F, T) where {F} = abs2(reduce_empty(op, T))
10781
end
10882
@eval Base.Sys begin
109-
__init_build() = nothing
83+
__init_build() = nothing # VersionNumber parsing is not supported yet
11084
end
11185
@eval Base.GMP begin
112-
function __init__()
86+
function __init__() # VersionNumber parsing is not supported yet
11387
try
11488
ccall((:__gmp_set_memory_functions, libgmp), Cvoid,
11589
(Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid}),
@@ -135,27 +109,3 @@ end
135109
end
136110
end
137111
end
138-
@eval Base.Sort begin
139-
issorted(itr;
140-
lt::T=isless, by::F=identity, rev::Union{Bool,Nothing}=nothing, order::Ordering=Forward) where {T,F} =
141-
issorted(itr, ord(lt,by,rev,order))
142-
end
143-
@eval Base.TOML begin
144-
function try_return_datetime(p, year, month, day, h, m, s, ms)
145-
return DateTime(year, month, day, h, m, s, ms)
146-
end
147-
function try_return_date(p, year, month, day)
148-
return Date(year, month, day)
149-
end
150-
function parse_local_time(l::Parser)
151-
h = @try parse_int(l, false)
152-
h in 0:23 || return ParserError(ErrParsingDateTime)
153-
_, m, s, ms = @try _parse_local_time(l, true)
154-
# TODO: Could potentially parse greater accuracy for the
155-
# fractional seconds here.
156-
return try_return_time(l, h, m, s, ms)
157-
end
158-
function try_return_time(p, h, m, s, ms)
159-
return Time(h, m, s, ms)
160-
end
161-
end

contrib/juliac/juliac-trim-stdlib.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,31 @@ let
5353
Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"))
5454
if Pkg !== nothing
5555
@eval Pkg begin
56-
__init__() = rand() #TODO, methods that do nothing don't get codegened
56+
__init__() = nothing # Assume the Pkg is not actually used
5757
end
5858
end
5959

6060
StyledStrings = find_loaded_root_module(Base.PkgId(
6161
Base.UUID("f489334b-da3d-4c2e-b8f0-e476e12c162b"), "StyledStrings"))
6262
if StyledStrings !== nothing
6363
@eval StyledStrings begin
64-
__init__() = rand()
64+
__init__() = nothing # Assume that StyledStrings are not actually used
6565
end
6666
end
6767

6868
Markdown = find_loaded_root_module(Base.PkgId(
6969
Base.UUID("d6f4376e-aef5-505a-96c1-9c027394607a"), "Markdown"))
7070
if Markdown !== nothing
7171
@eval Markdown begin
72-
__init__() = rand()
72+
__init__() = nothing # Assume that Markdown is not actually used with StyledStrings
7373
end
7474
end
7575

7676
JuliaSyntaxHighlighting = find_loaded_root_module(Base.PkgId(
7777
Base.UUID("ac6e5ff7-fb65-4e79-a425-ec3bc9c03011"), "JuliaSyntaxHighlighting"))
7878
if JuliaSyntaxHighlighting !== nothing
7979
@eval JuliaSyntaxHighlighting begin
80-
__init__() = rand()
80+
__init__() = nothing # Assume the JuliaSyntaxHighlighting is not actually used with StyledStrings
8181
end
8282
end
8383
end

test/trimming/basic_jll.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,15 @@ function @main(args::Vector{String})::Cint
2525
fptr = dlsym(Zstd_jll.libzstd_handle, :ZSTD_versionString)
2626
ccall(cfunc, Cvoid, (Ptr{Cvoid},), fptr)
2727

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))
2838
return 0
2939
end

0 commit comments

Comments
 (0)