Skip to content

Commit 040e5a6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into nushell-compat
2 parents 42a30a7 + 2bd37fb commit 040e5a6

File tree

34 files changed

+184
-76
lines changed

34 files changed

+184
-76
lines changed

Compiler/src/abstractlattice.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,10 @@ that should be forwarded along with constant propagation.
227227
end
228228
@nospecializeinfer function is_const_prop_profitable_arg(𝕃::ConstsLattice, @nospecialize t)
229229
if isa(t, Const)
230-
# don't consider mutable values useful constants
230+
# don't consider mutable values useful constants unless they have const fields
231231
val = t.val
232-
return isa(val, Symbol) || isa(val, Type) || isa(val, Method) || isa(val, CodeInstance) || !ismutable(val)
232+
return isa(val, Symbol) || isa(val, Type) || isa(val, Method) || isa(val, CodeInstance) ||
233+
!ismutable(val) || (typeof(val).name.constfields != C_NULL)
233234
end
234235
isa(t, PartialTypeVar) && return false # this isn't forwardable
235236
return is_const_prop_profitable_arg(widenlattice(𝕃), t)

Compiler/test/codegen.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,3 +1047,25 @@ f57872() = (Core.isdefinedglobal(@__MODULE__, Base.compilerbarrier(:const, :x578
10471047
@noinline f_mutateany(@nospecialize x) = x[] = 1
10481048
g_mutateany() = (y = Ref(0); f_mutateany(y); y[])
10491049
@test g_mutateany() === 1
1050+
1051+
# 58470 tbaa for unionselbyte of heap allocated mutables
1052+
mutable struct Wrapper58470
1053+
x::Union{Nothing,Int}
1054+
end
1055+
1056+
function findsomething58470(dict, inds)
1057+
default = Wrapper58470(nothing)
1058+
for i in inds
1059+
x = get(dict, i, default).x
1060+
if !isnothing(x)
1061+
return x
1062+
end
1063+
end
1064+
return nothing
1065+
end
1066+
1067+
let io = IOBuffer()
1068+
code_llvm(io, findsomething58470, Tuple{Dict{Int64, Wrapper58470}, Vector{Int}}, dump_module=true, raw=true, optimize=false)
1069+
str = String(take!(io))
1070+
@test !occursin("jtbaa_unionselbyte", str)
1071+
end

Compiler/test/irpasses.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,3 +2111,13 @@ let src = code_typed1(()) do
21112111
end
21122112
@test count(iscall((src, isdefined)), src.code) == 0
21132113
end
2114+
# We should successfully fold the default values of a ScopedValue
2115+
const svalconstprop = ScopedValue(1)
2116+
foosvalconstprop() = svalconstprop[]
2117+
2118+
let src = code_typed1(foosvalconstprop, ())
2119+
function is_constfield_load(expr)
2120+
iscall((src, getfield))(expr) && expr.args[3] in (:(:has_default), :(:default))
2121+
end
2122+
@test count(is_constfield_load, src.code) == 0
2123+
end

base/public.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public
111111
reseteof,
112112
link_pipe!,
113113
dup,
114+
showarg,
114115

115116
# filesystem operations
116117
rename,

base/range.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ julia> collect(LinRange(-0.1, 0.3, 5))
569569
0.3
570570
```
571571
572-
See also [`Logrange`](@ref Base.LogRange) for logarithmically spaced points.
572+
See also [`Base.LogRange`](@ref Base.LogRange) for logarithmically spaced points.
573573
"""
574574
struct LinRange{T,L<:Integer} <: AbstractRange{T}
575575
start::T

base/reduce.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The reduction operator used in `sum`. The main difference from [`+`](@ref) is th
1414
integers are promoted to `Int`/`UInt`.
1515
"""
1616
add_sum(x, y) = x + y
17-
add_sum(x::BitSignedSmall, y::BitSignedSmall) = Int(x) + Int(y)
17+
add_sum(x::Union{Bool,BitIntegerSmall}, y::Union{Bool,BitIntegerSmall}) = Int(x) + Int(y)
1818
add_sum(x::BitUnsignedSmall, y::BitUnsignedSmall) = UInt(x) + UInt(y)
1919
add_sum(x::Real, y::Real)::Real = x + y
2020

@@ -407,6 +407,8 @@ reduce_first(::typeof(add_sum), x::BitUnsignedSmall) = UInt(x)
407407
reduce_first(::typeof(mul_prod), x) = reduce_first(*, x)
408408
reduce_first(::typeof(mul_prod), x::BitSignedSmall) = Int(x)
409409
reduce_first(::typeof(mul_prod), x::BitUnsignedSmall) = UInt(x)
410+
reduce_first(::typeof(vcat), x) = vcat(x)
411+
reduce_first(::typeof(hcat), x) = hcat(x)
410412

411413
"""
412414
Base.mapreduce_first(f, op, x)
@@ -1073,8 +1075,8 @@ julia> count(i->(4<=i<=6), [2,3,4,5,6])
10731075
julia> count([true, false, true, true])
10741076
3
10751077
1076-
julia> count(>(3), 1:7, init=0x03)
1077-
0x07
1078+
julia> count(>(3), 1:7, init=UInt(0))
1079+
0x0000000000000004
10781080
```
10791081
"""
10801082
count(itr; init=0) = count(identity, itr; init)
@@ -1083,8 +1085,10 @@ count(f, itr; init=0) = _simple_count(f, itr, init)
10831085

10841086
_simple_count(pred, itr, init) = sum(_bool(pred), itr; init)
10851087

1086-
function _simple_count(::typeof(identity), x::Array{Bool}, init::T=0) where {T}
1087-
n::T = init
1088+
function _simple_count(::typeof(identity), x::Array{Bool}, init=0)
1089+
v0 = Base.add_sum(init, false)
1090+
T = typeof(v0)
1091+
n::T = v0
10881092
chunks = length(x) ÷ sizeof(UInt)
10891093
mask = 0x0101010101010101 % UInt
10901094
GC.@preserve x begin

contrib/juliac-buildscript.jl

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# Script to run in the process that generates juliac's object file output
22

3-
inputfile = ARGS[1]
4-
output_type = ARGS[2]
5-
add_ccallables = ARGS[3] == "true"
6-
73
# Run the verifier in the current world (before modifications), so that error
84
# messages and types print in their usual way.
95
Core.Compiler._verify_trim_world_age[] = Base.get_world_counter()
@@ -189,13 +185,37 @@ end
189185

190186
import Base.Experimental.entrypoint
191187

192-
let mod = Base.include(Base.__toplevel__, inputfile)
193-
if !isa(mod, Module)
194-
mod = Main
195-
end
188+
# for use as C main if needed
189+
function _main(argc::Cint, argv::Ptr{Ptr{Cchar}})::Cint
190+
args = ccall(:jl_set_ARGS, Any, (Cint, Ptr{Ptr{Cchar}}), argc, argv)::Vector{String}
191+
return Main.main(args)
192+
end
193+
194+
let mod = Base.include(Main, ARGS[1])
196195
Core.@latestworld
197-
if output_type == "--output-exe" && isdefined(mod, :main) && !add_ccallables
198-
entrypoint(mod.main, ())
196+
if ARGS[2] == "--output-exe"
197+
have_cmain = false
198+
if isdefined(Main, :main)
199+
for m in methods(Main.main)
200+
if isdefined(m, :ccallable)
201+
# TODO: possibly check signature and return type
202+
have_cmain = true
203+
break
204+
end
205+
end
206+
end
207+
if !have_cmain
208+
if Base.should_use_main_entrypoint()
209+
if hasmethod(Main.main, Tuple{Vector{String}})
210+
entrypoint(_main, (Cint, Ptr{Ptr{Cchar}}))
211+
Base._ccallable("main", Cint, Tuple{typeof(_main), Cint, Ptr{Ptr{Cchar}}})
212+
else
213+
error("`@main` must accept a `Vector{String}` argument.")
214+
end
215+
else
216+
error("To generate an executable a `@main` function must be defined.")
217+
end
218+
end
199219
end
200220
#entrypoint(join, (Base.GenericIOBuffer{Memory{UInt8}}, Array{Base.SubString{String}, 1}, String))
201221
#entrypoint(join, (Base.GenericIOBuffer{Memory{UInt8}}, Array{String, 1}, Char))
@@ -204,7 +224,7 @@ let mod = Base.include(Base.__toplevel__, inputfile)
204224
entrypoint(Base.wait_forever, ())
205225
entrypoint(Base.trypoptask, (Base.StickyWorkqueue,))
206226
entrypoint(Base.checktaskempty, ())
207-
if add_ccallables
227+
if ARGS[3] == "true"
208228
ccall(:jl_add_ccallable_entrypoints, Cvoid, ())
209229
end
210230
end

contrib/print_sorted_stdlibs.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ function check_flag(flag)
1212
end
1313

1414
if check_flag("--help") || check_flag("-h")
15-
println("Usage: julia print_sorted_stdlibs.jl [stdlib_dir] [--exclude-jlls] [--exclude-sysimage]")
15+
println("Usage: julia print_sorted_stdlibs.jl [stdlib_dir] [--exclude-jlls] [--exclude-sysimage] [--only-sysimg]")
1616
end
1717

1818
# Allow users to ask for JLL or no JLLs
1919
exclude_jlls = check_flag("--exclude-jlls")
2020
exclude_sysimage = check_flag("--exclude-sysimage")
21+
only_sysimage = check_flag("--only-sysimg")
2122

2223
# Default to the `stdlib/vX.Y` directory
2324
STDLIB_DIR = get(ARGS, 1, joinpath(@__DIR__, "..", "usr", "share", "julia", "stdlib"))
@@ -81,9 +82,19 @@ if exclude_jlls
8182
filter!(p -> !endswith(p, "_jll"), sorted_projects)
8283
end
8384

84-
if exclude_sysimage
85-
loaded_modules = Set(map(k->k.name, collect(keys(Base.loaded_modules))))
86-
filter!(p->!in(p, loaded_modules), sorted_projects)
85+
if only_sysimage && exclude_sysimage
86+
println(stderr, "Warning: --only-sysimg and --exclude-sysimage are mutually exclusive. Prioritizing --only-sysimg.")
87+
exclude_sysimage = false
88+
end
89+
90+
if only_sysimage || exclude_sysimage
91+
loaded_modules_set = Set(map(k->k.name, collect(keys(Base.loaded_modules))))
92+
93+
if only_sysimage
94+
filter!(p -> in(p, loaded_modules_set), sorted_projects)
95+
else
96+
filter!(p -> !in(p, loaded_modules_set), sorted_projects)
97+
end
8798
end
8899

89100
# Print out sorted projects, ready to be pasted into `sysimg.jl`
@@ -92,6 +103,9 @@ println(" # Stdlibs sorted in dependency, then alphabetical, order by contrib
92103
if exclude_jlls
93104
println(" # Run with the `--exclude-jlls` option to filter out all JLL packages")
94105
end
106+
if only_sysimage
107+
println(" # Run with the `--only-sysimg` option to filter for only packages included in the system image")
108+
end
95109
if exclude_sysimage
96110
println(" # Run with the `--exclude-sysimage` option to filter out all packages included in the system image")
97111
end

deps/checksums/Pkg-80d2e7505970b9f1a33b2a4e1c4c5bcea7a709b0.tar.gz/md5

Lines changed: 0 additions & 1 deletion
This file was deleted.

deps/checksums/Pkg-80d2e7505970b9f1a33b2a4e1c4c5bcea7a709b0.tar.gz/sha512

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)