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