Skip to content

Commit

Permalink
Merge branch 'master' into avi/partially-initialized-struct
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Aug 18, 2024
2 parents 500a380 + 4aa9dfa commit ff24278
Show file tree
Hide file tree
Showing 20 changed files with 188 additions and 118 deletions.
2 changes: 1 addition & 1 deletion base/Enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Base.print(io::IO, x::Enum) = print(io, _symbol(x))
function Base.show(io::IO, x::Enum)
sym = _symbol(x)
if !(get(io, :compact, false)::Bool)
from = get(io, :module, Base.active_module())
from = get(io, :module, Main)
def = parentmodule(typeof(x))
if from === nothing || !Base.isvisible(sym, def, from)
show(io, def)
Expand Down
7 changes: 4 additions & 3 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3532,24 +3532,25 @@ function push!(a::AbstractVector{T}, item) where T
itemT = item isa T ? item : convert(T, item)::T
new_length = length(a) + 1
resize!(a, new_length)
a[new_length] = itemT
a[end] = itemT
return a
end

# specialize and optimize the single argument case
function push!(a::AbstractVector{Any}, @nospecialize x)
new_length = length(a) + 1
resize!(a, new_length)
a[new_length] = x
a[end] = x
return a
end
function push!(a::AbstractVector{Any}, @nospecialize x...)
@_terminates_locally_meta
na = length(a)
nx = length(x)
resize!(a, na + nx)
e = lastindex(a) - nx
for i = 1:nx
a[na+i] = x[i]
a[e+i] = x[i]
end
return a
end
Expand Down
7 changes: 4 additions & 3 deletions base/precompilation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ function show_progress(io::IO, p::MiniProgressBar; termwidth=nothing, carriagere
to_print = sprint(; context=io) do io
print(io, " "^p.indent)
printstyled(io, p.header, color=p.color, bold=true)
print(io, " [")
print(io, "="^n_filled, ">")
print(io, " "^n_left, "] ", )
print(io, " ")
printstyled(io, ""^n_filled; color=p.color)
printstyled(io, perc >= 95 ? "" : ""; color=p.color)
printstyled(io, ""^n_left, " "; color=:light_black)
print(io, progress_text)
carriagereturn && print(io, "\r")
end
Expand Down
44 changes: 18 additions & 26 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,24 +514,16 @@ function _show_default(io::IO, @nospecialize(x))
end

function active_module()
REPL = REPL_MODULE_REF[]
REPL === Base && return Main
return invokelatest(REPL.active_module)::Module
if ccall(:jl_is_in_pure_context, Bool, ())
error("active_module() should not be called from a pure context")
end
if !@isdefined(active_repl) || active_repl === nothing
return Main
end
return invokelatest(active_module, active_repl)::Module
end

# Check if a particular symbol is exported from a standard library module
function is_exported_from_stdlib(name::Symbol, mod::Module)
!isdefined(mod, name) && return false
orig = getfield(mod, name)
while !(mod === Base || mod === Core)
activemod = active_module()
parent = parentmodule(mod)
if mod === activemod || mod === parent || parent === activemod
return false
end
mod = parent
end
return isexported(mod, name) && isdefined(mod, name) && !isdeprecated(mod, name) && getfield(mod, name) === orig
module UsesCoreAndBaseOnly
end

function show_function(io::IO, f::Function, compact::Bool, fallback::Function)
Expand All @@ -544,13 +536,13 @@ function show_function(io::IO, f::Function, compact::Bool, fallback::Function)
print(io, mt.name)
elseif isdefined(mt, :module) && isdefined(mt.module, mt.name) &&
getfield(mt.module, mt.name) === f
mod = active_module()
if is_exported_from_stdlib(mt.name, mt.module) || mt.module === mod
show_sym(io, mt.name)
else
# this used to call the removed internal function `is_exported_from_stdlib`, which effectively
# just checked for exports from Core and Base.
mod = get(io, :module, UsesCoreAndBaseOnly)
if !(isvisible(mt.name, mt.module, mod) || mt.module === mod)
print(io, mt.module, ".")
show_sym(io, mt.name)
end
show_sym(io, mt.name)
else
fallback(io, f)
end
Expand Down Expand Up @@ -737,9 +729,9 @@ end
function show_typealias(io::IO, name::GlobalRef, x::Type, env::SimpleVector, wheres::Vector)
if !(get(io, :compact, false)::Bool)
# Print module prefix unless alias is visible from module passed to
# IOContext. If :module is not set, default to Main (or current active module).
# IOContext. If :module is not set, default to Main.
# nothing can be used to force printing prefix.
from = get(io, :module, active_module())
from = get(io, :module, Main)
if (from === nothing || !isvisible(name.name, name.mod, from))
show(io, name.mod)
print(io, ".")
Expand Down Expand Up @@ -1053,9 +1045,9 @@ function show_type_name(io::IO, tn::Core.TypeName)
quo = false
if !(get(io, :compact, false)::Bool)
# Print module prefix unless type is visible from module passed to
# IOContext If :module is not set, default to Main (or current active module).
# IOContext If :module is not set, default to Main.
# nothing can be used to force printing prefix
from = get(io, :module, active_module())
from = get(io, :module, Main)
if isdefined(tn, :module) && (from === nothing || !isvisible(sym, tn.module, from::Module))
show(io, tn.module)
print(io, ".")
Expand Down Expand Up @@ -2535,7 +2527,7 @@ function show_signature_function(io::IO, @nospecialize(ft), demangle=false, farg
uw = unwrap_unionall(ft)
if ft <: Function && isa(uw, DataType) && isempty(uw.parameters) && _isself(uw)
uwmod = parentmodule(uw)
if qualified && !is_exported_from_stdlib(uw.name.mt.name, uwmod) && uwmod !== Main
if qualified && !isexported(uwmod, uw.name.mt.name) && uwmod !== Main
print_within_stacktrace(io, uwmod, '.', bold=true)
end
s = sprint(show_sym, (demangle ? demangle_function_name : identity)(uw.name.mt.name), context=io)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
725181b382adb22ad4f1f5e78db526ed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9ab56f368d5075a6f514ab8d2169239b439610c9bc9aca67a45a8a834b4d4ae7988910de3c78a687e40623fcd8bc9ba4aeee64ae7edf2cc84f1945b7e543a559
3 changes: 1 addition & 2 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1671,9 +1671,8 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
emit_gc_safepoint(ctx.builder, ctx.types().T_size, get_current_ptls(ctx), ctx.tbaa().tbaa_const);
return ghostValue(ctx, jl_nothing_type);
}
else if (is_libjulia_func("jl_get_ptls_states")) {
else if (is_libjulia_func(jl_get_ptls_states)) {
++CCALL_STAT(jl_get_ptls_states);
assert(lrt == ctx.types().T_size);
assert(!isVa && !llvmcall && nccallargs == 0);
JL_GC_POP();
return mark_or_box_ccall_result(ctx, get_current_ptls(ctx), retboxed, rt, unionall, static_rt);
Expand Down
3 changes: 0 additions & 3 deletions src/julia_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,7 @@ typedef struct _jl_tls_states_t {
#endif
} jl_tls_states_t;

#ifndef JL_LIBRARY_EXPORTS
// deprecated (only for external consumers)
JL_DLLEXPORT void *jl_get_ptls_states(void);
#endif

// Update codegen version in `ccall.cpp` after changing either `pause` or `wake`
#ifdef __MIC__
Expand Down
47 changes: 19 additions & 28 deletions src/llvm-demote-float16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,28 @@ extern JuliaOJIT *jl_ExecutionEngine;

namespace {

static bool have_fp16(Function &caller, const Triple &TT) {
Attribute FSAttr = caller.getFnAttribute("target-features");
StringRef FS = "";
if (FSAttr.isValid())
FS = FSAttr.getValueAsString();
else if (jl_ExecutionEngine)
FS = jl_ExecutionEngine->getTargetFeatureString();
// else probably called from opt, just do nothing
if (TT.isAArch64()) {
if (FS.find("+fp16fml") != llvm::StringRef::npos || FS.find("+fullfp16") != llvm::StringRef::npos){
return true;
}
} else if (TT.getArch() == Triple::x86_64) {
if (FS.find("+avx512fp16") != llvm::StringRef::npos){
return true;
}
}
if (caller.hasFnAttribute("julia.hasfp16")) {
return true;
}
return false;
static bool have_fp16(Function &F, const Triple &TT) {
// for testing purposes
Attribute Attr = F.getFnAttribute("julia.hasfp16");
if (Attr.isValid())
return Attr.getValueAsBool();

// llvm/llvm-project#97975: on some platforms, `half` uses excessive precision
if (TT.isPPC())
return false;

return true;
}

static bool have_bf16(Function &caller, const Triple &TT) {
if (caller.hasFnAttribute("julia.hasbf16")) {
return true;
}
static bool have_bf16(Function &F, const Triple &TT) {
// for testing purposes
Attribute Attr = F.getFnAttribute("julia.hasbf16");
if (Attr.isValid())
return Attr.getValueAsBool();

// there's no targets that fully support bfloat yet;,
// AVX512BF16 only provides conversion and dot product instructions.
return false;
// https://github.com/llvm/llvm-project/issues/97975#issuecomment-2218770199:
// on current versions of LLVM, bf16 always uses TypeSoftPromoteHalf
return true;
}

static bool demoteFloat16(Function &F)
Expand Down
12 changes: 6 additions & 6 deletions stdlib/LinearAlgebra/src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Symmetric{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
end
end
"""
Symmetric(A, uplo=:U)
Symmetric(A::AbstractMatrix, uplo::Symbol=:U)
Construct a `Symmetric` view of the upper (if `uplo = :U`) or lower (if `uplo = :L`)
triangle of the matrix `A`.
Expand Down Expand Up @@ -63,7 +63,7 @@ function Symmetric(A::AbstractMatrix, uplo::Symbol=:U)
end

"""
symmetric(A, uplo=:U)
symmetric(A, uplo::Symbol=:U)
Construct a symmetric view of `A`. If `A` is a matrix, `uplo` controls whether the upper
(if `uplo = :U`) or lower (if `uplo = :L`) triangle of `A` is used to implicitly fill the
Expand Down Expand Up @@ -105,7 +105,7 @@ struct Hermitian{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
end
end
"""
Hermitian(A, uplo=:U)
Hermitian(A::AbstractMatrix, uplo::Symbol=:U)
Construct a `Hermitian` view of the upper (if `uplo = :U`) or lower (if `uplo = :L`)
triangle of the matrix `A`.
Expand Down Expand Up @@ -153,7 +153,7 @@ function Hermitian(A::AbstractMatrix, uplo::Symbol=:U)
end

"""
hermitian(A, uplo=:U)
hermitian(A, uplo::Symbol=:U)
Construct a hermitian view of `A`. If `A` is a matrix, `uplo` controls whether the upper
(if `uplo = :U`) or lower (if `uplo = :L`) triangle of `A` is used to implicitly fill the
Expand Down Expand Up @@ -998,7 +998,7 @@ function cbrt(A::HermOrSym{<:Real})
end

"""
hermitianpart(A, uplo=:U) -> Hermitian
hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian
Return the Hermitian part of the square matrix `A`, defined as `(A + A') / 2`, as a
[`Hermitian`](@ref) matrix. For real matrices `A`, this is also known as the symmetric part
Expand All @@ -1014,7 +1014,7 @@ See also [`hermitianpart!`](@ref) for the corresponding in-place operation.
hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) = Hermitian(_hermitianpart(A), uplo)

"""
hermitianpart!(A, uplo=:U) -> Hermitian
hermitianpart!(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian
Overwrite the square matrix `A` in-place with its Hermitian part `(A + A') / 2`, and return
[`Hermitian(A, uplo)`](@ref). For real matrices `A`, this is also known as the symmetric
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PKG_BRANCH = master
PKG_SHA1 = 7aef1f044f3483e8b07d33fb4cfe918be554de69
PKG_SHA1 = d1d2fc986e7249909b450979acc4d359aacfc88e
PKG_GIT_URL := https://github.com/JuliaLang/Pkg.jl.git
PKG_TAR_URL = https://api.github.com/repos/JuliaLang/Pkg.jl/tarball/$1
21 changes: 8 additions & 13 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function warn_on_non_owning_accesses(current_mod, ast)
end
return ast
end
warn_on_non_owning_accesses(ast) = warn_on_non_owning_accesses(REPL.active_module(), ast)
warn_on_non_owning_accesses(ast) = warn_on_non_owning_accesses(Base.active_module(), ast)

const repl_ast_transforms = Any[softscope, warn_on_non_owning_accesses] # defaults for new REPL backends

Expand Down Expand Up @@ -497,7 +497,7 @@ end
function display(d::REPLDisplay, mime::MIME"text/plain", x)
x = Ref{Any}(x)
with_repl_linfo(d.repl) do io
io = IOContext(io, :limit => true, :module => active_module(d)::Module)
io = IOContext(io, :limit => true, :module => Base.active_module(d)::Module)
if d.repl isa LineEditREPL
mistate = d.repl.mistate
mode = LineEdit.mode(mistate)
Expand Down Expand Up @@ -527,7 +527,7 @@ show_repl(io::IO, ::MIME"text/plain", ex::Expr) =
function print_response(repl::AbstractREPL, response, show_value::Bool, have_color::Bool)
repl.waserror = response[2]
with_repl_linfo(repl) do io
io = IOContext(io, :module => active_module(repl)::Module)
io = IOContext(io, :module => Base.active_module(repl)::Module)
print_response(io, response, show_value, have_color, specialdisplay(repl))
end
return nothing
Expand Down Expand Up @@ -628,7 +628,7 @@ function run_repl(repl::AbstractREPL, @nospecialize(consumer = x -> nothing); ba
Core.println(Core.stderr, e)
Core.println(Core.stderr, catch_backtrace())
end
get_module = () -> active_module(repl)
get_module = () -> Base.active_module(repl)
if backend_on_current_task
t = @async run_frontend(repl, backend_ref)
errormonitor(t)
Expand Down Expand Up @@ -760,14 +760,9 @@ REPLCompletionProvider() = REPLCompletionProvider(LineEdit.Modifiers())
mutable struct ShellCompletionProvider <: CompletionProvider end
struct LatexCompletions <: CompletionProvider end

function active_module() # this method is also called from Base
isdefined(Base, :active_repl) || return Main
Base.active_repl === nothing && return Main
return active_module(Base.active_repl::AbstractREPL)
end
active_module((; mistate)::LineEditREPL) = mistate === nothing ? Main : mistate.active_module
active_module(::AbstractREPL) = Main
active_module(d::REPLDisplay) = active_module(d.repl)
Base.active_module((; mistate)::LineEditREPL) = mistate === nothing ? Main : mistate.active_module
Base.active_module(::AbstractREPL) = Main
Base.active_module(d::REPLDisplay) = Base.active_module(d.repl)

setmodifiers!(c::CompletionProvider, m::LineEdit.Modifiers) = nothing

Expand Down Expand Up @@ -1206,7 +1201,7 @@ enable_promptpaste(v::Bool) = JL_PROMPT_PASTE[] = v

function contextual_prompt(repl::LineEditREPL, prompt::Union{String,Function})
function ()
mod = active_module(repl)
mod = Base.active_module(repl)
prefix = mod == Main ? "" : string('(', mod, ") ")
pr = prompt isa String ? prompt : prompt()
prefix * pr
Expand Down
18 changes: 17 additions & 1 deletion test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1437,14 +1437,30 @@ using .Main.OffsetArrays
end

@testset "Check push!($a, $args...)" for
a in (["foo", "Bar"], SimpleArray(["foo", "Bar"]), OffsetVector(["foo", "Bar"], 0:1)),
a in (["foo", "Bar"], SimpleArray(["foo", "Bar"]), SimpleArray{Any}(["foo", "Bar"]), OffsetVector(["foo", "Bar"], 0:1)),
args in (("eenie",), ("eenie", "minie"), ("eenie", "minie", "mo"))
orig = copy(a)
push!(a, args...)
@test length(a) == length(orig) + length(args)
@test a[axes(orig,1)] == orig
@test all(a[end-length(args)+1:end] .== args)
end

@testset "Check append!($a, $args)" for
a in (["foo", "Bar"], SimpleArray(["foo", "Bar"]), SimpleArray{Any}(["foo", "Bar"]), OffsetVector(["foo", "Bar"], 0:1)),
args in (("eenie",), ("eenie", "minie"), ("eenie", "minie", "mo"))
orig = copy(a)
append!(a, args)
@test length(a) == length(orig) + length(args)
@test a[axes(orig,1)] == orig
@test all(a[end-length(args)+1:end] .== args)
end

@testset "Check sizehint!($a)" for
a in (["foo", "Bar"], SimpleArray(["foo", "Bar"]), SimpleArray{Any}(["foo", "Bar"]), OffsetVector(["foo", "Bar"], 0:1))
@test sizehint!(a, 10) === a
end

@testset "splatting into hvcat" begin
t = (1, 2)
@test [t...; 3 4] == [1 2; 3 4]
Expand Down
3 changes: 3 additions & 0 deletions test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -966,3 +966,6 @@ end
let x = Incomplete55396(55396)
@test x.x === (55396,)
end

# Core.getptls() special handling
@test !occursin("call ptr @jlplt", get_llvm(Core.getptls, Tuple{})) #It should lower to a direct load of the ptls and not a ccall
Loading

0 comments on commit ff24278

Please sign in to comment.