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
4 changes: 2 additions & 2 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e),
end
elseif e.head === :new
t = instanceof_tfunc(abstract_eval_value(interp, e.args[1], vtypes, sv))[1]
if isconcretetype(t) && !t.mutable
if isconcretetype(t) && !t.name.mutable
args = Vector{Any}(undef, length(e.args)-1)
ats = Vector{Any}(undef, length(e.args)-1)
anyconst = false
Expand Down Expand Up @@ -1447,7 +1447,7 @@ function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e),
end
elseif e.head === :splatnew
t = instanceof_tfunc(abstract_eval_value(interp, e.args[1], vtypes, sv))[1]
if length(e.args) == 2 && isconcretetype(t) && !t.mutable
if length(e.args) == 2 && isconcretetype(t) && !t.name.mutable
at = abstract_eval_value(interp, e.args[2], vtypes, sv)
n = fieldcount(t)
if isa(at, Const) && isa(at.val, Tuple) && n == length(at.val) &&
Expand Down
10 changes: 5 additions & 5 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
if isa(typ, UnionAll)
typ = unwrap_unionall(typ)
end
(isa(typ, DataType) && (!typ.abstract)) || return nothing
@assert !typ.mutable
(isa(typ, DataType) && (!typ.name.abstract)) || return nothing
@assert !typ.name.mutable
if length(def.args) < 1 + field
if field > fieldcount(typ)
return nothing
Expand Down Expand Up @@ -625,7 +625,7 @@ function getfield_elim_pass!(ir::IRCode)
if isa(typ, UnionAll)
typ = unwrap_unionall(typ)
end
if typ isa DataType && !typ.mutable
if typ isa DataType && !typ.name.mutable
process_immutable_preserve(new_preserves, compact, def)
old_preserves[pidx] = nothing
continue
Expand Down Expand Up @@ -662,7 +662,7 @@ function getfield_elim_pass!(ir::IRCode)

def, typeconstraint = stmt.args[2], struct_typ

if struct_typ.mutable
if struct_typ.name.mutable
isa(def, SSAValue) || continue
let intermediaries = IdSet()
callback = function(@nospecialize(pi), ssa::AnySSAValue)
Expand Down Expand Up @@ -775,7 +775,7 @@ function getfield_elim_pass!(ir::IRCode)
end
# Could still end up here if we tried to setfield! and immutable, which would
# error at runtime, but is not illegal to have in the IR.
typ.mutable || continue
typ.name.mutable || continue
# Partition defuses by field
fielddefuse = SSADefUse[SSADefUse() for _ = 1:fieldcount(typ)]
ok = true
Expand Down
30 changes: 17 additions & 13 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ const DATATYPE_NAME_FIELDINDEX = fieldindex(DataType, :name)
const DATATYPE_PARAMETERS_FIELDINDEX = fieldindex(DataType, :parameters)
const DATATYPE_TYPES_FIELDINDEX = fieldindex(DataType, :types)
const DATATYPE_SUPER_FIELDINDEX = fieldindex(DataType, :super)
const DATATYPE_MUTABLE_FIELDINDEX = fieldindex(DataType, :mutable)
const DATATYPE_INSTANCE_FIELDINDEX = fieldindex(DataType, :instance)
const DATATYPE_ABSTRACT_FIELDINDEX = fieldindex(DataType, :abstract)
const DATATYPE_NAMES_FIELDINDEX = fieldindex(DataType, :names)
const DATATYPE_HASH_FIELDINDEX = fieldindex(DataType, :hash)

const TYPENAME_NAME_FIELDINDEX = fieldindex(Core.TypeName, :name)
const TYPENAME_MODULE_FIELDINDEX = fieldindex(Core.TypeName, :module)
const TYPENAME_NAMES_FIELDINDEX = fieldindex(Core.TypeName, :names)
const TYPENAME_WRAPPER_FIELDINDEX = fieldindex(Core.TypeName, :wrapper)
const TYPENAME_MUTABLE_FIELDINDEX = fieldindex(Core.TypeName, :mutable)
const TYPENAME_ABSTRACT_FIELDINDEX = fieldindex(Core.TypeName, :abstract)
const TYPENAME_HASH_FIELDINDEX = fieldindex(Core.TypeName, :hash)

##########
# tfuncs #
Expand Down Expand Up @@ -88,7 +90,7 @@ function instanceof_tfunc(@nospecialize(t))
# a real instance must be within the declared bounds of the type,
# so we can intersect with the original wrapper.
tr = typeintersect(tr, t′′.name.wrapper)
isconcrete = !t′′.abstract
isconcrete = !t′′.name.abstract
if tr === Union{}
# runtime unreachable (our inference Type{T} where S is
# uninhabited with any runtime T that exists)
Expand Down Expand Up @@ -271,7 +273,7 @@ function isdefined_tfunc(@nospecialize(arg1), @nospecialize(sym))
return Bool
end
a1 = unwrap_unionall(a1)
if isa(a1, DataType) && !a1.abstract
if isa(a1, DataType) && !a1.name.abstract
if a1 === Module
Symbol <: widenconst(sym) || return Bottom
if isa(sym, Const) && isa(sym.val, Symbol) && isa(arg1, Const) && isdefined(arg1.val, sym.val)
Expand Down Expand Up @@ -404,7 +406,7 @@ function nfields_tfunc(@nospecialize(x))
isa(x, Conditional) && return Const(0)
x = unwrap_unionall(widenconst(x))
isconstType(x) && return Const(nfields(x.parameters[1]))
if isa(x, DataType) && !x.abstract
if isa(x, DataType) && !x.name.abstract
if !(x.name === Tuple.name && isvatuple(x)) &&
!(x.name === _NAMEDTUPLE_NAME && !isconcretetype(x))
return Const(isdefined(x, :types) ? length(x.types) : length(x.name.names))
Expand Down Expand Up @@ -529,7 +531,7 @@ function typeof_tfunc(@nospecialize(t))
return typeof_tfunc(t.ub)
elseif isa(t, UnionAll)
u = unwrap_unionall(t)
if isa(u, DataType) && !u.abstract
if isa(u, DataType) && !u.name.abstract
if u.name === Tuple.name
uu = typeof_concrete_vararg(u)
if uu !== nothing
Expand Down Expand Up @@ -612,10 +614,9 @@ is_dt_const_field(fld::Int) = (
fld == DATATYPE_PARAMETERS_FIELDINDEX ||
fld == DATATYPE_TYPES_FIELDINDEX ||
fld == DATATYPE_SUPER_FIELDINDEX ||
fld == DATATYPE_MUTABLE_FIELDINDEX ||
fld == DATATYPE_INSTANCE_FIELDINDEX ||
fld == DATATYPE_NAMES_FIELDINDEX ||
fld == DATATYPE_ABSTRACT_FIELDINDEX
fld == DATATYPE_HASH_FIELDINDEX
)
function const_datatype_getfield_tfunc(@nospecialize(sv), fld::Int)
if fld == DATATYPE_INSTANCE_FIELDINDEX
Expand Down Expand Up @@ -649,7 +650,7 @@ function fieldcount_noerror(@nospecialize t)
end
abstr = true
else
abstr = t.abstract || (t.name === Tuple.name && isvatuple(t))
abstr = t.name.abstract || (t.name === Tuple.name && isvatuple(t))
end
if abstr
return nothing
Expand Down Expand Up @@ -717,7 +718,7 @@ function getfield_nothrow(@nospecialize(s00), @nospecialize(name), @nospecialize
getfield_nothrow(rewrap(s.b, s00), name, inbounds)
elseif isa(s, DataType)
# Can't say anything about abstract types
s.abstract && return false
s.name.abstract && return false
# If all fields are always initialized, and bounds check is disabled, we can assume
# we don't throw
if bounds_check_disabled && !isvatuple(s) && s.name !== NamedTuple.body.body.name && fieldcount(s) == s.ninitialized
Expand Down Expand Up @@ -775,6 +776,9 @@ function getfield_tfunc(@nospecialize(s00), @nospecialize(name))
if (fld == TYPENAME_NAME_FIELDINDEX ||
fld == TYPENAME_MODULE_FIELDINDEX ||
fld == TYPENAME_WRAPPER_FIELDINDEX ||
fld == TYPENAME_MUTABLE_FIELDINDEX ||
fld == TYPENAME_ABSTRACT_FIELDINDEX ||
fld == TYPENAME_HASH_FIELDINDEX ||
(fld == TYPENAME_NAMES_FIELDINDEX && isdefined(sv, fld)))
return Const(getfield(sv, fld))
end
Expand All @@ -799,7 +803,7 @@ function getfield_tfunc(@nospecialize(s00), @nospecialize(name))
end
s = widenconst(s)
end
if isType(s) || !isa(s, DataType) || s.abstract
if isType(s) || !isa(s, DataType) || s.name.abstract
return Any
end
s = s::DataType
Expand Down Expand Up @@ -925,7 +929,7 @@ function _fieldtype_nothrow(@nospecialize(s), exact::Bool, name::Const)
return exact ? (a || b) : (a && b)
end
u isa DataType || return false
u.abstract && return false
u.name.abstract && return false
if u.name === _NAMEDTUPLE_NAME && !isconcretetype(u)
# TODO: better approximate inference
return false
Expand Down Expand Up @@ -986,7 +990,7 @@ function _fieldtype_tfunc(@nospecialize(s), exact::Bool, @nospecialize(name))
_fieldtype_tfunc(rewrap(u.b, s), exact, name))
end
u isa DataType || return Union{Type, TypeVar}
if u.abstract
if u.name.abstract
# Abstract types have no fields
exact && return Bottom
# Type{...} without free typevars has no subtypes, so it is actually
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function type_more_complex(@nospecialize(t), @nospecialize(c), sources::SimpleVe
let tPi = unwrap_unionall(tPi),
cPi = unwrap_unionall(cPi)
if isa(tPi, DataType) && isa(cPi, DataType) &&
!tPi.abstract && !cPi.abstract &&
!tPi.name.abstract && !cPi.name.abstract &&
sym_isless(cPi.name.name, tPi.name.name)
# allow collect on (anonymous) Generators to nest, provided that their functions are appropriately ordered
# TODO: is there a better way?
Expand Down
2 changes: 1 addition & 1 deletion base/deepcopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ end
function deepcopy_internal(@nospecialize(x), stackdict::IdDict)
T = typeof(x)::DataType
nf = nfields(x)
if T.mutable
if T.name.mutable
if haskey(stackdict, x)
return stackdict[x]
end
Expand Down
2 changes: 1 addition & 1 deletion base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function showerror(io::IO, ex::MethodError)
if f === Base.convert && length(arg_types_param) == 2 && !is_arg_types
f_is_function = true
show_convert_error(io, ex, arg_types_param)
elseif isempty(methods(f)) && isa(f, DataType) && f.abstract
elseif isempty(methods(f)) && isa(f, DataType) && f.name.abstract
print(io, "no constructors have been defined for ", f)
elseif isempty(methods(f)) && !isa(f, Function) && !isa(f, Type)
print(io, "objects of type ", ft, " are not callable")
Expand Down
2 changes: 1 addition & 1 deletion base/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ See also: [`unsafe_pointer_to_objref`](@ref).
"""
function pointer_from_objref(@nospecialize(x))
@_inline_meta
typeof(x).mutable || error("pointer_from_objref cannot be used on immutable objects")
typeof(x).name.mutable || error("pointer_from_objref cannot be used on immutable objects")
ccall(:jl_value_ptr, Ptr{Cvoid}, (Any,), x)
end

Expand Down
14 changes: 7 additions & 7 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function fieldname(t::DataType, i::Integer)
end
throw_need_pos_int(i) = throw(ArgumentError("Field numbers must be positive integers. $i is invalid."))

t.abstract && throw_not_def_field()
t.name.abstract && throw_not_def_field()
names = _fieldnames(t)
n_fields = length(names)::Int
i > n_fields && throw_field_access(t, i, n_fields)
Expand Down Expand Up @@ -471,7 +471,7 @@ true
!!! compat "Julia 1.5"
This function requires at least Julia 1.5.
"""
ismutable(@nospecialize(x)) = (@_pure_meta; typeof(x).mutable)
ismutable(@nospecialize(x)) = (@_pure_meta; typeof(x).name.mutable)


"""
Expand All @@ -486,7 +486,7 @@ Determine whether type `T` was declared as a mutable type
function ismutabletype(@nospecialize(t::Type))
t = unwrap_unionall(t)
# TODO: what to do for `Union`?
return isa(t, DataType) && t.mutable
return isa(t, DataType) && t.name.mutable
end


Expand All @@ -502,7 +502,7 @@ function isstructtype(@nospecialize(t::Type))
# TODO: what to do for `Union`?
isa(t, DataType) || return false
hasfield = !isdefined(t, :types) || !isempty(t.types)
return hasfield || (t.size == 0 && !t.abstract)
return hasfield || (t.size == 0 && !t.name.abstract)
end

"""
Expand All @@ -517,7 +517,7 @@ function isprimitivetype(@nospecialize(t::Type))
# TODO: what to do for `Union`?
isa(t, DataType) || return false
hasfield = !isdefined(t, :types) || !isempty(t.types)
return !hasfield && t.size != 0 && !t.abstract
return !hasfield && t.size != 0 && !t.name.abstract
end

"""
Expand Down Expand Up @@ -623,7 +623,7 @@ function isabstracttype(@nospecialize(t))
@_pure_meta
t = unwrap_unionall(t)
# TODO: what to do for `Union`?
return isa(t, DataType) && t.abstract
return isa(t, DataType) && t.name.abstract
end

"""
Expand Down Expand Up @@ -757,7 +757,7 @@ function fieldcount(@nospecialize t)
end
abstr = true
else
abstr = t.abstract || (t.name === Tuple.name && isvatuple(t))
abstr = t.name.abstract || (t.name === Tuple.name && isvatuple(t))
end
if abstr
throw(ArgumentError("type does not have a definite number of fields"))
Expand Down
2 changes: 1 addition & 1 deletion base/refpointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ convert(::Type{Ref{T}}, x::AbstractArray{T}) where {T} = RefArray(x, 1)
function unsafe_convert(P::Union{Type{Ptr{T}},Type{Ptr{Cvoid}}}, b::RefArray{T})::P where T
if allocatedinline(T)
p = pointer(b.x, b.i)
elseif isconcretetype(T) && T.mutable
elseif isconcretetype(T) && T.name.mutable
p = pointer_from_objref(b.x[b.i])
else
# see comment on equivalent branch for RefValue
Expand Down
2 changes: 1 addition & 1 deletion base/refvalue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ isassigned(x::RefValue) = isdefined(x, :x)
function unsafe_convert(P::Union{Type{Ptr{T}},Type{Ptr{Cvoid}}}, b::RefValue{T})::P where T
if allocatedinline(T)
p = pointer_from_objref(b)
elseif isconcretetype(T) && T.mutable
elseif isconcretetype(T) && T.name.mutable
p = pointer_from_objref(b.x)
else
# If the slot is not leaf type, it could be either immutable or not.
Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2616,7 +2616,7 @@ function dump(io::IOContext, x::DataType, n::Int, indent)
if x !== Any
print(io, " <: ", supertype(x))
end
if n > 0 && !(x <: Tuple) && !x.abstract
if n > 0 && !(x <: Tuple) && !x.name.abstract
tvar_io::IOContext = io
for tparam in x.parameters
# approximately recapture the list of tvar parameterization
Expand Down
6 changes: 3 additions & 3 deletions src/abi_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct ABI_AArch64Layout : AbiLayout {
Type *get_llvm_vectype(jl_datatype_t *dt) const
{
// Assume jl_is_datatype(dt) && !jl_is_abstracttype(dt)
// `!dt->mutabl && dt->pointerfree && !dt->haspadding && dt->nfields > 0`
// `!dt->name->mutabl && dt->pointerfree && !dt->haspadding && dt->nfields > 0`
if (dt->layout == NULL || jl_is_layout_opaque(dt->layout))
return nullptr;
size_t nfields = dt->layout->nfields;
Expand Down Expand Up @@ -62,7 +62,7 @@ Type *get_llvm_vectype(jl_datatype_t *dt) const
Type *get_llvm_fptype(jl_datatype_t *dt) const
{
// Assume jl_is_datatype(dt) && !jl_is_abstracttype(dt)
// `!dt->mutabl && dt->pointerfree && !dt->haspadding && dt->nfields == 0`
// `!dt->name->mutabl && dt->pointerfree && !dt->haspadding && dt->nfields == 0`
Type *lltype;
// Check size first since it's cheaper.
switch (jl_datatype_size(dt)) {
Expand All @@ -88,7 +88,7 @@ Type *get_llvm_fptype(jl_datatype_t *dt) const
Type *get_llvm_fp_or_vectype(jl_datatype_t *dt) const
{
// Assume jl_is_datatype(dt) && !jl_is_abstracttype(dt)
if (dt->mutabl || dt->layout->npointers || dt->layout->haspadding)
if (dt->name->mutabl || dt->layout->npointers || dt->layout->haspadding)
return nullptr;
return dt->layout->nfields ? get_llvm_vectype(dt) : get_llvm_fptype(dt);
}
Expand Down
2 changes: 1 addition & 1 deletion src/abi_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool needPassByRef(jl_datatype_t *dt, AttrBuilder &ab) override
Type *get_llvm_fptype(jl_datatype_t *dt) const
{
// Assume jl_is_datatype(dt) && !jl_is_abstracttype(dt)
if (dt->mutabl || jl_datatype_nfields(dt) != 0)
if (dt->name->mutabl || jl_datatype_nfields(dt) != 0)
return NULL;
Type *lltype;
// Check size first since it's cheaper.
Expand Down
Loading