Skip to content

Commit

Permalink
rename isimmutabletype to just a method of isimmutable
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Jan 26, 2017
1 parent 13859b7 commit 2656cdb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ This section lists changes that do not have deprecation warnings.
(since it is shorthand for `NTuple{N,T} where T`). To get the old behavior of matching
any tuple, use `NTuple{N,Any}` ([#18457]).

* `isimmutable(T::Type)` now checks whether `T` is an immutable type,
rather than checking whether `typeof(T)` is an immutable type ([#18168]).

Library improvements
--------------------

Expand Down Expand Up @@ -210,8 +213,6 @@ Library improvements

* New `iszero(x)` function to quickly check whether `x` is zero (or is all zeros, for an array) ([#19950]).

* New function `isimmutabletype(T)` ([#18168]).

* `notify` now returns a count of tasks woken up ([#19841]).

Compiler/Runtime improvements
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,6 @@ export
isbits,
isequal,
isimmutable,
isimmutabletype,
isless,
ifelse,
lexless,
Expand Down
19 changes: 6 additions & 13 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,25 +195,18 @@ datatype_fielddesc_type(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefErro
(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 30) & 3

"""
isimmutable(v)
isimmutable(x)
Return `true` iff value `v` is immutable. See [Immutable Composite Types](@ref)
for a discussion of immutability. Note that this function works on values, so if you give it
a type, it will tell you that a value of `DataType` is mutable.
Return `true` if the value `x` is immutable; if `x` is a type, then returns
whether `x` is an immutable type. See [Immutable Composite Types](@ref)
for a discussion of immutability.
"""
isimmutable(x::ANY) = (@_pure_meta; (isa(x,Tuple) || !typeof(x).mutable))
isimmutable(t::DataType) = (@_pure_meta; !t.mutable)
isimmutable(::Type) = (@_pure_meta; false)
isstructtype(t::DataType) = (@_pure_meta; nfields(t) != 0 || (t.size==0 && !t.abstract))
isstructtype(x) = (@_pure_meta; false)

"""
isimmutabletype(T)
Return `true` if the type `T` is immutable. See [manual](:ref:`man-immutable-composite-types`)
for a discussion of immutability. See also [`isimmutable`](:func:`isimmutable`)
for the corresponding function acting on values rather than types.
"""
isimmutabletype(t::ANY) = (@_pure_meta; isa(t, DataType) && !t.mutable)

"""
isbits(T)
Expand Down
8 changes: 4 additions & 4 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ not_const = 1
@test isimmutable([]) == false
@test isimmutable("abc") == true
@test isimmutable((3,4,5)) == true
@test isimmutabletype(Int) == true
@test isimmutabletype(Vector{Int}) == false
@test isimmutabletype(String) == true
@test isimmutabletype(Tuple{Int}) == true
@test isimmutable(Int) == true
@test isimmutable(Vector{Int}) == false
@test isimmutable(String) == true
@test isimmutable(Tuple{Int}) == true


## find bindings tests
Expand Down

0 comments on commit 2656cdb

Please sign in to comment.