diff --git a/NEWS.md b/NEWS.md index 8f15022984476..cf9243ebbda8b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 -------------------- @@ -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 diff --git a/base/exports.jl b/base/exports.jl index 1571454875ed4..52e5786a37aef 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -946,7 +946,6 @@ export isbits, isequal, isimmutable, - isimmutabletype, isless, ifelse, lexless, diff --git a/base/reflection.jl b/base/reflection.jl index 6cafe3ffa76c5..c63ee030490ba 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -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) diff --git a/test/reflection.jl b/test/reflection.jl index 3894486ed20c0..aa73a47d6a799 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -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