Skip to content

Commit

Permalink
Merge branch 'master' into rationalize_irrational
Browse files Browse the repository at this point in the history
  • Loading branch information
nsajko authored Feb 1, 2025
2 parents 8979e5a + 9a278a2 commit 381f888
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 144 deletions.
1 change: 1 addition & 0 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ julia> reinterpret(Tuple{UInt16, UInt8}, (0x01, 0x0203))
"""
function reinterpret(::Type{Out}, x) where {Out}
@inline
if isprimitivetype(Out) && isprimitivetype(typeof(x))
return bitcast(Out, x)
end
Expand Down
39 changes: 24 additions & 15 deletions base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -871,25 +871,34 @@ end
return out[]
else
# mismatched padding
GC.@preserve in out begin
ptr_in = unsafe_convert(Ptr{In}, in)
ptr_out = unsafe_convert(Ptr{Out}, out)
return _reinterpret_padding(Out, x)
end
end

if fieldcount(In) > 0 && ispacked(Out)
_copytopacked!(ptr_out, ptr_in)
elseif fieldcount(Out) > 0 && ispacked(In)
_copyfrompacked!(ptr_out, ptr_in)
else
packed = Ref{NTuple{inpackedsize, UInt8}}()
GC.@preserve packed begin
ptr_packed = unsafe_convert(Ptr{NTuple{inpackedsize, UInt8}}, packed)
_copytopacked!(ptr_packed, ptr_in)
_copyfrompacked!(ptr_out, ptr_packed)
end
# If the code reaches this part, it needs to handle padding and is unlikely
# to compile to a noop. Therefore, we don't forcibly inline it.
function _reinterpret_padding(::Type{Out}, x::In) where {Out, In}
inpackedsize = packedsize(In)
in = Ref{In}(x)
out = Ref{Out}()
GC.@preserve in out begin
ptr_in = unsafe_convert(Ptr{In}, in)
ptr_out = unsafe_convert(Ptr{Out}, out)

if fieldcount(In) > 0 && ispacked(Out)
_copytopacked!(ptr_out, ptr_in)
elseif fieldcount(Out) > 0 && ispacked(In)
_copyfrompacked!(ptr_out, ptr_in)
else
packed = Ref{NTuple{inpackedsize, UInt8}}()
GC.@preserve packed begin
ptr_packed = unsafe_convert(Ptr{NTuple{inpackedsize, UInt8}}, packed)
_copytopacked!(ptr_packed, ptr_in)
_copyfrompacked!(ptr_out, ptr_packed)
end
end
return out[]
end
return out[]
end


Expand Down
39 changes: 17 additions & 22 deletions base/staticdata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,16 @@ function _insert_backedges(edges::Vector{Any}, stack::Vector{CodeInstance}, visi
verify_method_graph(codeinst, stack, visiting)
minvalid = codeinst.min_world
maxvalid = codeinst.max_world
if maxvalid minvalid
if get_world_counter() == maxvalid
# if this callee is still valid, add all the backedges
Base.Compiler.store_backedges(codeinst, codeinst.edges)
end
if get_world_counter() == maxvalid
maxvalid = typemax(UInt)
@atomic :monotonic codeinst.max_world = maxvalid
end
if external
caller = get_ci_mi(codeinst)
@assert isdefined(codeinst, :inferred) # See #53586, #53109
inferred = @ccall jl_rettype_inferred(
codeinst.owner::Any, caller::Any, minvalid::UInt, maxvalid::UInt)::Any
if inferred !== nothing
# We already got a code instance for this world age range from
# somewhere else - we don't need this one.
else
@ccall jl_mi_cache_insert(caller::Any, codeinst::Any)::Cvoid
end
if maxvalid minvalid && external
caller = get_ci_mi(codeinst)
@assert isdefined(codeinst, :inferred) # See #53586, #53109
inferred = @ccall jl_rettype_inferred(
codeinst.owner::Any, caller::Any, minvalid::UInt, maxvalid::UInt)::Any
if inferred !== nothing
# We already got a code instance for this world age range from
# somewhere else - we don't need this one.
else
@ccall jl_mi_cache_insert(caller::Any, codeinst::Any)::Cvoid
end
end
end
Expand Down Expand Up @@ -196,9 +186,14 @@ function verify_method(codeinst::CodeInstance, stack::Vector{CodeInstance}, visi
while length(stack) depth
child = pop!(stack)
if maxworld 0
@atomic :monotonic child.min_world = minworld
@atomic :monotonic child.min_world = minworld
end
if maxworld == current_world
Base.Compiler.store_backedges(child, child.edges)
@atomic :monotonic child.max_world = typemax(UInt)
else
@atomic :monotonic child.max_world = maxworld
end
@atomic :monotonic child.max_world = maxworld
@assert visiting[child] == length(stack) + 1
delete!(visiting, child)
invalidations = _jl_debug_method_invalidation[]
Expand Down
57 changes: 34 additions & 23 deletions contrib/julia-config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function includeDir()
return abspath(Sys.BINDIR, Base.INCLUDEDIR, "julia")
end

function ldflags(doframework)
doframework && return "-F$(shell_escape(frameworkDir()))"
function ldflags(; framework::Bool=false)
framework && return "-F$(shell_escape(frameworkDir()))"
fl = "-L$(shell_escape(libDir()))"
if Sys.iswindows()
fl = fl * " -Wl,--stack,8388608"
Expand All @@ -56,27 +56,40 @@ function ldflags(doframework)
return fl
end

function ldlibs(doframework)
function ldrpath()
libname = if Base.isdebugbuild()
"julia-debug"
else
"julia"
end
return "-Wl,-rpath,$(shell_escape(private_libDir())) -Wl,-rpath,$(shell_escape(libDir())) -l$libname"
end

function ldlibs(; framework::Bool=false, rpath::Bool=true)
# Return "Julia" for the framework even if this is a debug build.
# If the user wants the debug framework, DYLD_IMAGE_SUFFIX=_debug
# should be used (refer to man 1 dyld).
doframework && return "-framework $(Base.DARWIN_FRAMEWORK_NAME)"
framework && return "-framework $(Base.DARWIN_FRAMEWORK_NAME)"
libname = if Base.isdebugbuild()
"julia-debug"
else
"julia"
end
if Sys.isunix()
return "-L$(shell_escape(private_libDir())) -Wl,-rpath,$(shell_escape(libDir())) -Wl,-rpath,$(shell_escape(private_libDir())) -l$libname"
if rpath
return "-L$(shell_escape(private_libDir())) $(ldrpath())"
else
return "-L$(shell_escape(private_libDir()))"
end
else
return "-l$libname -lopenlibm"
end
end

function cflags(doframework)
function cflags(; framework::Bool=false)
flags = IOBuffer()
print(flags, "-std=gnu11")
if doframework
if framework
include = shell_escape(frameworkDir())
print(flags, " -F", include)
else
Expand All @@ -89,8 +102,8 @@ function cflags(doframework)
return String(take!(flags))
end

function allflags(doframework)
return "$(cflags(doframework)) $(ldflags(doframework)) $(ldlibs(doframework))"
function allflags(; framework::Bool=false, rpath::Bool=true)
return "$(cflags(; framework)) $(ldflags(; framework)) $(ldlibs(; framework, rpath))"
end

function check_args(args)
Expand All @@ -102,31 +115,29 @@ function check_args(args)
end

function check_framework_flag(args)
doframework = "--framework" in args
if doframework && !Base.DARWIN_FRAMEWORK
framework = "--framework" in args
if framework && !Base.DARWIN_FRAMEWORK
println(stderr, "NOTICE: Ignoring --framework because Julia is not packaged as a framework.")
return false
elseif !doframework && Base.DARWIN_FRAMEWORK
elseif !framework && Base.DARWIN_FRAMEWORK
println(stderr, "NOTICE: Consider using --framework because Julia is packaged as a framework.")
return false
end
return doframework
return framework
end

function main()
check_args(ARGS)
doframework = check_framework_flag(ARGS)
for args in ARGS
function (@main)(args)
check_args(args)
framework = check_framework_flag(args)
for args in args
if args == "--ldflags"
println(ldflags(doframework))
println(ldflags(; framework))
elseif args == "--cflags"
println(cflags(doframework))
println(cflags(; framework))
elseif args == "--ldlibs"
println(ldlibs(doframework))
println(ldlibs(; framework))
elseif args == "--allflags"
println(allflags(doframework))
println(allflags(; framework))
end
end
end

main()
8 changes: 8 additions & 0 deletions contrib/juliac-buildscript.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ end
@inline function invokelatest(f::F, args...; kwargs...) where F
return f(args...; kwargs...)
end
@inline function invokelatest_gr(gr::GlobalRef, @nospecialize args...; kwargs...)
@inline
kwargs = merge(NamedTuple(), kwargs)
if isempty(kwargs)
return apply_gr(gr, args...)
end
return apply_gr_kw(kwargs, gr, args...)
end
function sprint(f::F, args::Vararg{Any,N}; context=nothing, sizehint::Integer=0) where {F<:Function,N}
s = IOBuffer(sizehint=sizehint)
if context isa Tuple
Expand Down
Loading

0 comments on commit 381f888

Please sign in to comment.