Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Compiler/src/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,13 @@ function abstract_eval_call(interp::AbstractInterpreter, e::Expr, sstate::Statem
end
end

function is_field_pointerfree(dt::DataType, fidx::Int)
dt.layout::Ptr{Cvoid} == C_NULL && return false
DataTypeFieldDesc(dt)[fidx].isptr && return false
ft = fieldtype(dt, fidx)
return ft isa DataType && datatype_pointerfree(ft)
end

function abstract_eval_new(interp::AbstractInterpreter, e::Expr, sstate::StatementState,
sv::AbsIntState)
𝕃ᵢ = typeinf_lattice(interp)
Expand All @@ -3089,9 +3096,8 @@ function abstract_eval_new(interp::AbstractInterpreter, e::Expr, sstate::Stateme
ismutable = ismutabletype(ut)
fcount = datatype_fieldcount(ut)
nargs = length(e.args) - 1
has_any_uninitialized = (fcount === nothing || (fcount > nargs && (let t = rt
any(i::Int -> !is_undefref_fieldtype(fieldtype(t, i)), (nargs+1):fcount)
end)))
has_any_uninitialized = fcount === nothing || (fcount > nargs &&
any(i::Int->is_field_pointerfree(ut, i), (nargs+1):fcount))
if has_any_uninitialized
# allocation with undefined field is inconsistent always
consistent = ALWAYS_FALSE
Expand Down
12 changes: 0 additions & 12 deletions Compiler/src/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1286,18 +1286,6 @@ end
return rewrap_unionall(R, s00)
end

# checks if a field of this type is guaranteed to be defined to a value
# and that access to an uninitialized field will cause an `UndefRefError` or return zero
# - is_undefref_fieldtype(String) === true
# - is_undefref_fieldtype(Integer) === true
# - is_undefref_fieldtype(Any) === true
# - is_undefref_fieldtype(Int) === false
# - is_undefref_fieldtype(Union{Int32,Int64}) === false
# - is_undefref_fieldtype(T) === false
function is_undefref_fieldtype(@nospecialize ftyp)
return !has_free_typevars(ftyp) && !allocatedinline(ftyp)
end

@nospecs function setfield!_tfunc(𝕃::AbstractLattice, o, f, v, order)
if !isvarargtype(order)
hasintersect(widenconst(order), Symbol) || return Bottom
Expand Down
3 changes: 3 additions & 0 deletions Compiler/test/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ end |> Compiler.is_consistent
@test Base.infer_effects() do
Maybe{String}()[]
end |> Compiler.is_consistent
@test Base.infer_effects() do
Maybe{Some{Base.RefValue{Int}}}()
end |> Compiler.is_consistent
let f() = Maybe{String}()[]
@test Base.return_types() do
f() # this call should be concrete evaluated
Expand Down
27 changes: 18 additions & 9 deletions JuliaLowering/src/syntax_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,20 @@ function ccall_macro_lower(ctx, ex, convention, func, rettype, types, args, gc_s
]
]
elseif kf == K"$"
check = @SyntaxTree quote
func = $(func[1])
if !isa(func, Ptr{Cvoid})
name = :($(func[1]))
throw(ArgumentError("interpolated function `$name` was not a `Ptr{Cvoid}`, but $(typeof(func))"))
end
end
fid = @ast ctx func[1] "func"::K"Identifier"
check = @ast ctx func [K"block"
[K"=" fid func[1]]
[K"if"
[K"call" (!isa)::K"Value" fid [K"curly" Ptr::K"Value" Cvoid::K"Value"]]
[K"block"
[K"=" "name"::K"Identifier" [K"quote" func[1]]]
[K"call" throw::K"Value"
[K"call" ArgumentError::K"Value"
[K"string"
"interpolated function `"::K"String"
"name"::K"Identifier"
"` was not a `Ptr{Cvoid}`, but "::K"String"
[K"call" typeof::K"Value" fid]]]]]]]
push!(statements, check)
lowered_func = check[1][1]
else
Expand All @@ -208,9 +215,11 @@ function ccall_macro_lower(ctx, ex, convention, func, rettype, types, args, gc_s
for (i, (type, arg)) in enumerate(zip(types, args))
argi = @ast ctx arg "arg$i"::K"Identifier"
# TODO: Does it help to emit ssavar() here for the `argi`?
push!(statements, @SyntaxTree :(local $argi = Base.cconvert($type, $arg)))
push!(statements,
@ast ctx arg [K"local"
[K"=" argi [K"call" Base.cconvert::K"Value" type arg]]])
push!(roots, argi)
push!(cargs, @SyntaxTree :(Base.unsafe_convert($type, $argi)))
push!(cargs, @ast ctx ex [K"call" Base.unsafe_convert::K"Value" type argi])
end
effect_flags = UInt16(0)
push!(statements, @ast ctx ex [K"foreigncall"
Expand Down
80 changes: 32 additions & 48 deletions JuliaLowering/test/misc_ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,59 +402,43 @@ end
# Basic @ccall lowering
@ccall foo(x::X, y::Y)::R
#---------------------
1 JuliaLowering.Base
2 (call top.getproperty %₁ :cconvert)
3 TestMod.X
4 TestMod.x
5 (= slot₁/arg1 (call %₂ %₃ %₄))
6 JuliaLowering.Base
7 (call top.getproperty %₆ :cconvert)
8 TestMod.Y
9 TestMod.y
10 (= slot₂/arg2 (call %₇ %₈ %₉))
11 JuliaLowering.Base
12 (call top.getproperty %₁₁ :unsafe_convert)
13 TestMod.X
14 slot₁/arg1
15 (call %₁₂ %₁₃ %₁₄)
16 JuliaLowering.Base
17 (call top.getproperty %₁₆ :unsafe_convert)
18 TestMod.Y
19 slot₂/arg2
20 (call %₁₇ %₁₈ %₁₉)
21 slot₁/arg1
22 slot₂/arg2
23 (foreigncall :foo (static_eval TestMod.R) (static_eval (call core.svec TestMod.X TestMod.Y)) 0 :($(QuoteNode((:ccall, 0x0000, false)))) %₁₅ %₂₀ %₂₁ %₂₂)
24 (return %₂₃)
1 TestMod.X
2 TestMod.x
3 (= slot₁/arg1 (call Base.cconvert %₁ %₂))
4 TestMod.Y
5 TestMod.y
6 (= slot₂/arg2 (call Base.cconvert %₄ %₅))
7 TestMod.X
8 slot₁/arg1
9 (call Base.unsafe_convert %₇ %₈)
10 TestMod.Y
11 slot₂/arg2
12 (call Base.unsafe_convert %₁₀ %₁₁)
13 slot₁/arg1
14 slot₂/arg2
15 (foreigncall :foo (static_eval TestMod.R) (static_eval (call core.svec TestMod.X TestMod.Y)) 0 :($(QuoteNode((:ccall, 0x0000, false)))) %₉ %₁₂ %₁₃ %₁₄)
16 (return %₁₅)

########################################
# @ccall lowering with gc_safe
@ccall foo(x::X; y::Y)::R gc_safe=true
#---------------------
1 JuliaLowering.Base
2 (call top.getproperty %₁ :cconvert)
3 TestMod.X
4 TestMod.x
5 (= slot₁/arg1 (call %₂ %₃ %₄))
6 JuliaLowering.Base
7 (call top.getproperty %₆ :cconvert)
8 TestMod.Y
9 TestMod.y
10 (= slot₂/arg2 (call %₇ %₈ %₉))
11 JuliaLowering.Base
12 (call top.getproperty %₁₁ :unsafe_convert)
13 TestMod.X
14 slot₁/arg1
15 (call %₁₂ %₁₃ %₁₄)
16 JuliaLowering.Base
17 (call top.getproperty %₁₆ :unsafe_convert)
18 TestMod.Y
19 slot₂/arg2
20 (call %₁₇ %₁₈ %₁₉)
21 slot₁/arg1
22 slot₂/arg2
23 (foreigncall :foo (static_eval TestMod.R) (static_eval (call core.svec TestMod.X TestMod.Y)) 1 :($(QuoteNode((:ccall, 0x0000, true)))) %₁₅ %₂₀ %₂₁ %₂₂)
24 (return %₂₃)
1 TestMod.X
2 TestMod.x
3 (= slot₁/arg1 (call Base.cconvert %₁ %₂))
4 TestMod.Y
5 TestMod.y
6 (= slot₂/arg2 (call Base.cconvert %₄ %₅))
7 TestMod.X
8 slot₁/arg1
9 (call Base.unsafe_convert %₇ %₈)
10 TestMod.Y
11 slot₂/arg2
12 (call Base.unsafe_convert %₁₀ %₁₁)
13 slot₁/arg1
14 slot₂/arg2
15 (foreigncall :foo (static_eval TestMod.R) (static_eval (call core.svec TestMod.X TestMod.Y)) 1 :($(QuoteNode((:ccall, 0x0000, true)))) %₉ %₁₂ %₁₃ %₁₄)
16 (return %₁₅)

########################################
# non-macro ccall with vararg in signature, but none provided
Expand Down
10 changes: 5 additions & 5 deletions deps/jlutilities/documenter/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ version = "0.9.5"

[[deps.Documenter]]
deps = ["ANSIColoredPrinters", "AbstractTrees", "Base64", "CodecZlib", "Dates", "DocStringExtensions", "Downloads", "Git", "IOCapture", "InteractiveUtils", "JSON", "Logging", "Markdown", "MarkdownAST", "Pkg", "PrecompileTools", "REPL", "RegistryInstances", "SHA", "TOML", "Test", "Unicode"]
git-tree-sha1 = "70c521ca3a23c576e12655d15963977c9766c26b"
git-tree-sha1 = "b37458ae37d8bdb643d763451585cd8d0e5b4a9e"
registries = "General"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "1.16.0"
version = "1.16.1"

[[deps.Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
Expand Down Expand Up @@ -116,10 +116,10 @@ version = "1.7.1"

[[deps.JSON]]
deps = ["Dates", "Logging", "Parsers", "PrecompileTools", "StructUtils", "UUIDs", "Unicode"]
git-tree-sha1 = "eb04df293213df64ddd720c86de3c431f5f8ccf1"
git-tree-sha1 = "5b6bb73f555bc753a6153deec3717b8904f5551c"
registries = "General"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "1.2.1"
version = "1.3.0"

[deps.JSON.extensions]
JSONArrowExt = ["ArrowTypes"]
Expand All @@ -146,7 +146,7 @@ version = "1.0.0"
[[deps.LibCURL_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "LibSSH2_jll", "Libdl", "OpenSSL_jll", "Zlib_jll", "Zstd_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
version = "8.16.0+0"
version = "8.17.0+0"

[[deps.LibGit2]]
deps = ["LibGit2_jll", "NetworkOptions", "Printf", "SHA"]
Expand Down
34 changes: 19 additions & 15 deletions stdlib/Base64/src/decode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ julia> String(read(iob64_decode))
"Hello!"
```
"""
struct Base64DecodePipe <: IO
io::IO
struct Base64DecodePipe{T <: IO} <: IO
io::T
buffer::Buffer
rest::Vector{UInt8}

function Base64DecodePipe(io::IO)
function Base64DecodePipe{T}(io::T) where {T <: IO}
buffer = Buffer(512)
return new(io, buffer, UInt8[])
return new{T}(io, buffer, UInt8[])
end
end

Base64DecodePipe(io::IO) = Base64DecodePipe{IO}(io)

Base.isreadable(pipe::Base64DecodePipe) = !isempty(pipe.rest) || isreadable(pipe.io)
Base.iswritable(::Base64DecodePipe) = false

Expand Down Expand Up @@ -172,21 +174,23 @@ function decode_slow(b1, b2, b3, b4, buffer, i, input, ptr, n, rest)
# Write output.
p::Ptr{UInt8} = ptr
p_end = ptr + n
function output(b)
if p < p_end
unsafe_store!(p, b)
p += 1
else
push!(rest, b)
end
end
k ≥ 1 && output(b1 << 2 | b2 >> 4)
k ≥ 2 && output(b2 << 4 | b3 >> 2)
k ≥ 3 && output(b3 << 6 | b4 )
k ≥ 1 && (p = _output(b1 << 2 | b2 >> 4, p, p_end, rest))
k ≥ 2 && (p = _output(b2 << 4 | b3 >> 2, p, p_end, rest))
k ≥ 3 && (p = _output(b3 << 6 | b4 , p, p_end, rest))

return i, p, k == 0
end

function _output(b, p, p_end, rest)
if p < p_end
unsafe_store!(p, b)
return p + 1
else
push!(rest, b)
return p
end
end

"""
base64decode(string)

Expand Down
10 changes: 6 additions & 4 deletions stdlib/Base64/src/encode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ julia> String(base64decode(str))
"Hello!"
```
"""
struct Base64EncodePipe <: IO
io::IO
struct Base64EncodePipe{T <: IO} <: IO
io::T
buffer::Buffer

function Base64EncodePipe(io::IO)
function Base64EncodePipe{T}(io::T) where {T <: IO}
# The buffer size must be at least 3.
buffer = Buffer(512)
pipe = new(io, buffer)
pipe = new{T}(io, buffer)
finalizer(_ -> close(pipe), buffer)
return pipe
end
end

Base64EncodePipe(io::IO) = Base64EncodePipe{IO}(io)

Base.isreadable(::Base64EncodePipe) = false
Base.iswritable(pipe::Base64EncodePipe) = iswritable(pipe.io)

Expand Down
Loading