From 977e659fae94fe5def6eb9744e05589418f7333d Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 2 Feb 2017 17:03:56 -0500 Subject: [PATCH 1/3] rename type keywords to `abstract|primitive type`, `[mutable ]struct` --- NEWS.md | 8 + base/Enums.jl | 8 +- base/LineEdit.jl | 32 +-- base/REPL.jl | 22 +- base/REPLCompletions.jl | 9 +- base/Terminals.jl | 8 +- base/abstractarray.jl | 6 +- base/array.jl | 4 +- base/associative.jl | 6 +- base/asyncmap.jl | 8 +- base/atomics.jl | 4 +- base/base.jl | 28 +- base/base64.jl | 4 +- base/bitarray.jl | 2 +- base/boot.jl | 163 ++++++----- base/cartesian.jl | 2 +- base/channels.jl | 8 +- base/complex.jl | 2 +- base/coreio.jl | 2 +- base/dSFMT.jl | 2 +- base/datafmt.jl | 6 +- base/dates/adjusters.jl | 2 +- base/dates/io.jl | 10 +- base/dates/periods.jl | 2 +- base/dates/query.jl | 2 +- base/dates/types.jl | 32 +-- base/dft.jl | 4 +- base/dict.jl | 6 +- base/docs/Docs.jl | 12 +- base/docs/basedocs.jl | 57 ++-- base/docs/bindings.jl | 2 +- base/docs/helpdb/Base.jl | 2 +- base/docs/utils.jl | 12 +- base/env.jl | 2 +- base/error.jl | 2 +- base/essentials.jl | 8 +- base/event.jl | 6 +- base/fft/FFTW.jl | 8 +- base/fft/dct.jl | 2 +- base/file.jl | 2 +- base/filesystem.jl | 4 +- base/generator.jl | 18 +- base/gmp.jl | 2 +- base/grisu/bignums.jl | 2 +- base/grisu/float.jl | 2 +- base/inference.jl | 20 +- base/intset.jl | 2 +- base/io.jl | 4 +- base/iobuffer.jl | 2 +- base/iostream.jl | 2 +- base/irrationals.jl | 2 +- base/iterators.jl | 36 +-- base/libc.jl | 10 +- base/libdl.jl | 2 +- base/libgit2/error.jl | 4 +- base/libgit2/libgit2.jl | 2 +- base/libgit2/types.jl | 70 ++--- base/libuv.jl | 2 +- base/linalg/arnoldi.jl | 2 +- base/linalg/bidiag.jl | 2 +- base/linalg/bunchkaufman.jl | 2 +- base/linalg/cholesky.jl | 4 +- base/linalg/diagonal.jl | 2 +- base/linalg/eigen.jl | 4 +- base/linalg/exceptions.jl | 10 +- base/linalg/factorization.jl | 2 +- base/linalg/givens.jl | 6 +- base/linalg/hessenberg.jl | 4 +- base/linalg/ldlt.jl | 2 +- base/linalg/lq.jl | 4 +- base/linalg/lu.jl | 2 +- base/linalg/qr.jl | 10 +- base/linalg/rowvector.jl | 2 +- base/linalg/schur.jl | 4 +- base/linalg/svd.jl | 4 +- base/linalg/symmetric.jl | 4 +- base/linalg/triangular.jl | 4 +- base/linalg/tridiag.jl | 6 +- base/linalg/uniformscaling.jl | 2 +- base/loading.jl | 2 +- base/lock.jl | 4 +- base/locks.jl | 8 +- base/markdown/Common/block.jl | 16 +- base/markdown/Common/inline.jl | 10 +- base/markdown/GitHub/table.jl | 2 +- base/markdown/IPython/IPython.jl | 2 +- base/markdown/parse/config.jl | 2 +- base/markdown/parse/parse.jl | 2 +- base/mmap.jl | 2 +- base/mpfr.jl | 2 +- base/multidimensional.jl | 8 +- base/multimedia.jl | 6 +- base/multinverses.jl | 6 +- base/nullable.jl | 2 +- base/operators.jl | 4 +- base/options.jl | 2 +- base/ordering.jl | 14 +- base/parallel/cluster.jl | 12 +- base/parallel/clusterserialize.jl | 4 +- base/parallel/managers.jl | 6 +- base/parallel/messages.jl | 22 +- base/parallel/pmap.jl | 2 +- base/parallel/process_messages.jl | 4 +- base/parallel/remotecall.jl | 6 +- base/parallel/workerpool.jl | 6 +- base/permuteddimsarray.jl | 2 +- base/pkg/entry.jl | 2 +- base/pkg/pkg.jl | 2 +- base/pkg/reqs.jl | 6 +- base/pkg/resolve/fieldvalue.jl | 2 +- base/pkg/resolve/interface.jl | 2 +- base/pkg/resolve/maxsum.jl | 8 +- base/pkg/resolve/versionweight.jl | 8 +- base/pkg/types.jl | 8 +- base/poll.jl | 12 +- base/process.jl | 18 +- base/profile.jl | 2 +- base/random.jl | 24 +- base/range.jl | 16 +- base/rational.jl | 2 +- base/reflection.jl | 12 +- base/refpointer.jl | 12 +- base/regex.jl | 8 +- base/reshapedarray.jl | 6 +- base/rounding.jl | 2 +- base/serialize.jl | 6 +- base/set.jl | 2 +- base/sharedarray.jl | 6 +- base/show.jl | 14 +- base/simdloop.jl | 2 +- base/socket.jl | 16 +- base/sort.jl | 14 +- base/sparse/abstractsparse.jl | 2 +- base/sparse/cholmod.jl | 20 +- base/sparse/cholmod_h.jl | 2 +- base/sparse/higherorderfns.jl | 2 +- base/sparse/sparsematrix.jl | 4 +- base/sparse/sparsevector.jl | 2 +- base/sparse/spqr.jl | 4 +- base/sparse/umfpack.jl | 4 +- base/special/bessel.jl | 2 +- base/special/trig.jl | 4 +- base/stacktraces.jl | 2 +- base/stat.jl | 2 +- base/stream.jl | 16 +- base/strings/basic.jl | 2 +- base/strings/errors.jl | 2 +- base/strings/types.jl | 4 +- base/strings/utf8proc.jl | 2 +- base/subarray.jl | 4 +- base/summarysize.jl | 2 +- base/sysimg.jl | 2 +- base/sysinfo.jl | 4 +- base/task.jl | 4 +- base/test.jl | 28 +- base/traits.jl | 14 +- base/twiceprecision.jl | 2 +- base/util.jl | 10 +- base/version.jl | 2 +- base/version_git.sh | 2 +- base/weakkeydict.jl | 2 +- doc/src/manual/calling-c-and-fortran-code.md | 22 +- examples/ModInts.jl | 2 +- examples/bubblesort.jl | 2 +- examples/clustermanager/0mq/ZMQCM.jl | 2 +- .../clustermanager/simple/UnixDomainCM.jl | 2 +- examples/dictchannel.jl | 2 +- examples/juliatypes.jl | 20 +- examples/lru.jl | 8 +- examples/time.jl | 2 +- examples/typetree.jl | 4 +- src/abi_aarch64.cpp | 2 +- src/intrinsics.cpp | 4 +- src/julia-parser.scm | 67 ++++- src/runtime_intrinsics.c | 32 +-- test/TestHelpers.jl | 4 +- test/abstractarray.jl | 18 +- test/ambiguous.jl | 6 +- test/arrayops.jl | 14 +- test/broadcast.jl | 4 +- test/ccall.jl | 114 ++++---- test/compile.jl | 16 +- test/copy.jl | 4 +- test/core.jl | 264 +++++++++--------- test/dict.jl | 14 +- test/docs.jl | 50 ++-- test/inference.jl | 46 +-- test/int.jl | 2 +- test/intrinsics.jl | 6 +- test/keywordargs.jl | 2 +- test/linalg/arnoldi.jl | 2 +- test/linalg/generic.jl | 2 +- test/linalg/matmul.jl | 10 +- test/loading.jl | 2 +- test/markdown.jl | 2 +- test/misc.jl | 10 +- test/netload/memtest.jl | 2 +- test/nullable.jl | 4 +- test/offsetarray.jl | 2 +- test/operators.jl | 2 +- test/parallel_exec.jl | 8 +- test/parse.jl | 10 +- test/perf/array/indexing.jl | 12 +- test/perf/kernel/actor_centrality.jl | 2 +- test/perf/kernel/go_benchmark.jl | 4 +- test/perf/kernel/perf.jl | 6 +- test/perf/kernel/raytracer.jl | 12 +- test/perf/shootout/binary_trees.jl | 6 +- test/perf/shootout/k_nucleotide.jl | 2 +- test/perf/shootout/nbody.jl | 2 +- test/perf/shootout/nbody_vec.jl | 2 +- test/reduce.jl | 2 +- test/reflection.jl | 16 +- test/repl.jl | 4 +- test/replcompletions.jl | 6 +- test/replutil.jl | 20 +- test/serialize.jl | 32 +-- test/show.jl | 20 +- test/sorting.jl | 4 +- test/strings/basic.jl | 4 +- test/strings/io.jl | 2 +- test/subarray.jl | 2 +- test/subtype.jl | 24 +- test/test.jl | 6 +- test/threads.jl | 4 +- test/topology.jl | 2 +- test/tuple.jl | 6 +- test/vecelement.jl | 6 +- test/workspace.jl | 4 +- test/worlds.jl | 4 +- 230 files changed, 1179 insertions(+), 1125 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2d752f7bed7b3..454a2e59f1153 100644 --- a/NEWS.md +++ b/NEWS.md @@ -34,6 +34,14 @@ Language changes i.e. the case where the type parameters are specified. For clarity, this definition now must be written as `Foo{T,S}(x) where {T,S<:Real} = new(x)`. ([#11310]) + * The keywords used to define types have changed ([#19157], [#20418]). + + `immutable` changes to `struct` + + `type` changes to `mutable struct` + + `abstract` changes to `abstract type ... end` + + `bitstype 32 Char` changes to `primitive type Char 32 end` + In 0.6, `immutable` and `type` are still allowed as synonyms without a deprecation + warning. + * Multi-line and single-line nonstandard command literals have been added. A nonstandard command literal is like a nonstandard string literal, but the syntax uses backquotes (``` ` ```) instead of double quotes, and the diff --git a/base/Enums.jl b/base/Enums.jl index 4a4ceabf16049..48e9e63ecda60 100644 --- a/base/Enums.jl +++ b/base/Enums.jl @@ -7,7 +7,7 @@ export Enum, @enum function basetype end -abstract Enum{T<:Integer} +abstract type Enum{T<:Integer} end Base.convert{T<:Integer}(::Type{Integer}, x::Enum{T}) = bitcast(T, x) Base.convert{T<:Integer,T2<:Integer}(::Type{T}, x::Enum{T2}) = convert(T, bitcast(T2, x)) @@ -45,7 +45,7 @@ julia> f(apple) "I'm a Fruit with value: 1" ``` -`BaseType`, which defaults to `Int32`, must be a bitstype subtype of Integer. Member values can be converted between +`BaseType`, which defaults to `Int32`, must be a primitive subtype of Integer. Member values can be converted between the enum type and `BaseType`. `read` and `write` perform these conversions automatically. """ macro enum(T,syms...) @@ -58,7 +58,7 @@ macro enum(T,syms...) typename = T.args[1] basetype = eval(current_module(),T.args[2]) if !isa(basetype, DataType) || !(basetype <: Integer) || !isbits(basetype) - throw(ArgumentError("invalid base type for Enum $typename, $T=::$basetype; base type must be an integer bitstype")) + throw(ArgumentError("invalid base type for Enum $typename, $T=::$basetype; base type must be an integer primitive type")) end elseif !isa(T,Symbol) throw(ArgumentError("invalid type expression for enum $T")) @@ -103,7 +103,7 @@ macro enum(T,syms...) end blk = quote # enum definition - Base.@__doc__(bitstype $(sizeof(basetype) * 8) $(esc(typename)) <: Enum{$(basetype)}) + Base.@__doc__(primitive type $(esc(typename)) <: Enum{$(basetype)} $(sizeof(basetype) * 8) end) function Base.convert(::Type{$(esc(typename))}, x::Integer) $(membershiptest(:x, values)) || enum_argument_error($(Expr(:quote, typename)), x) return bitcast($(esc(typename)), convert($(basetype), x)) diff --git a/base/LineEdit.jl b/base/LineEdit.jl index 6a76f05f333ab..97d1ae38d060f 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -9,16 +9,16 @@ import ..Terminals: raw!, width, height, cmove, getX, import Base: ensureroom, peek, show, AnyDict -abstract TextInterface -abstract ModeState +abstract type TextInterface end +abstract type ModeState end export run_interface, Prompt, ModalInterface, transition, reset_state, edit_insert, keymap -immutable ModalInterface <: TextInterface +struct ModalInterface <: TextInterface modes end -type MIState +mutable struct MIState interface::ModalInterface current_mode aborted::Bool @@ -33,7 +33,7 @@ function show(io::IO, s::MIState) print(io, "MI State (", s.current_mode, " active)") end -type Prompt <: TextInterface +mutable struct Prompt <: TextInterface prompt # A string or function to be printed before the prompt. May not change the length of the prompt. # This may be used for changing the color, issuing other terminal escape codes, etc. @@ -51,12 +51,12 @@ end show(io::IO, x::Prompt) = show(io, string("Prompt(\"", x.prompt, "\",...)")) -immutable InputAreaState +struct InputAreaState num_rows::Int64 curs_row::Int64 end -type PromptState <: ModeState +mutable struct PromptState <: ModeState terminal p::Prompt input_buffer::IOBuffer @@ -74,13 +74,13 @@ function input_string_newlines_aftercursor(s::PromptState) return count(c->(c == '\n'), rest) end -abstract HistoryProvider -abstract CompletionProvider +abstract type HistoryProvider end +abstract type CompletionProvider end -type EmptyCompletionProvider <: CompletionProvider +mutable struct EmptyCompletionProvider <: CompletionProvider end -type EmptyHistoryProvider <: HistoryProvider +mutable struct EmptyHistoryProvider <: HistoryProvider end reset_state(::EmptyHistoryProvider) = nothing @@ -712,7 +712,7 @@ end # Redirect a key as if `seq` had been the keysequence instead in a lazy fashion. # This is different from the default eager redirect, which only looks at the current and lower # layers of the stack. -immutable KeyAlias +struct KeyAlias seq::String KeyAlias(seq) = new(normalize_key(seq)) end @@ -966,7 +966,7 @@ function write_response_buffer(s::PromptState, data) refresh_line(s) end -type SearchState <: ModeState +mutable struct SearchState <: ModeState terminal histprompt #rsearch (true) or ssearch (false) @@ -1010,7 +1010,7 @@ function reset_state(s::SearchState) reset_state(s.histprompt.hp) end -type HistoryPrompt{T<:HistoryProvider} <: TextInterface +mutable struct HistoryPrompt{T<:HistoryProvider} <: TextInterface hp::T complete keymap_dict::Dict{Char,Any} @@ -1020,7 +1020,7 @@ end HistoryPrompt(hp::T) where T<:HistoryProvider = HistoryPrompt{T}(hp) init_state(terminal, p::HistoryPrompt) = SearchState(terminal, p, true, IOBuffer(), IOBuffer()) -type PrefixSearchState <: ModeState +mutable struct PrefixSearchState <: ModeState terminal histprompt prefix::String @@ -1049,7 +1049,7 @@ input_string(s::PrefixSearchState) = String(s.response_buffer) # a meta-prompt that presents itself as parent_prompt, but which has an independent keymap # for prefix searching -type PrefixHistoryPrompt{T<:HistoryProvider} <: TextInterface +mutable struct PrefixHistoryPrompt{T<:HistoryProvider} <: TextInterface hp::T parent_prompt::Prompt complete diff --git a/base/REPL.jl b/base/REPL.jl index 866a3dde4dd44..c33c341de2e62 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -32,13 +32,13 @@ import ..LineEdit: accept_result, terminal -abstract AbstractREPL +abstract type AbstractREPL end answer_color(::AbstractREPL) = "" const JULIA_PROMPT = "julia> " -type REPLBackend +mutable struct REPLBackend "channel for AST" repl_channel::Channel "channel for results: (value, nothing) or (error, backtrace)" @@ -110,7 +110,7 @@ function ip_matches_func(ip, func::Symbol) return false end -immutable REPLDisplay{R<:AbstractREPL} <: Display +struct REPLDisplay{R<:AbstractREPL} <: Display repl::R end @@ -167,7 +167,7 @@ function print_response(errio::IO, val::ANY, bt, show_value::Bool, have_color::B end # A reference to a backend -immutable REPLBackendRef +struct REPLBackendRef repl_channel::Channel response_channel::Channel end @@ -183,7 +183,7 @@ end ## BasicREPL ## -type BasicREPL <: AbstractREPL +mutable struct BasicREPL <: AbstractREPL terminal::TextTerminal waserror::Bool BasicREPL(t) = new(t,false) @@ -241,7 +241,7 @@ end ## LineEditREPL ## -type LineEditREPL <: AbstractREPL +mutable struct LineEditREPL <: AbstractREPL t::TextTerminal hascolor::Bool prompt_color::String @@ -275,11 +275,11 @@ LineEditREPL(t::TextTerminal, envcolors = false) = LineEditREPL(t, Base.text_colors[:yellow], false, false, false, envcolors) -type REPLCompletionProvider <: CompletionProvider; end +mutable struct REPLCompletionProvider <: CompletionProvider; end -type ShellCompletionProvider <: CompletionProvider; end +mutable struct ShellCompletionProvider <: CompletionProvider; end -immutable LatexCompletions <: CompletionProvider; end +struct LatexCompletions <: CompletionProvider; end beforecursor(buf::IOBuffer) = String(buf.data[1:buf.ptr-1]) @@ -306,7 +306,7 @@ function complete_line(c::LatexCompletions, s) end -type REPLHistoryProvider <: HistoryProvider +mutable struct REPLHistoryProvider <: HistoryProvider history::Array{String,1} history_file start_idx::Int @@ -945,7 +945,7 @@ end ## StreamREPL ## -type StreamREPL <: AbstractREPL +mutable struct StreamREPL <: AbstractREPL stream::IO prompt_color::String input_color::String diff --git a/base/REPLCompletions.jl b/base/REPLCompletions.jl index 6a5369503334d..32dceecb5c2ad 100644 --- a/base/REPLCompletions.jl +++ b/base/REPLCompletions.jl @@ -84,11 +84,12 @@ end function complete_keyword(s::String) const sorted_keywords = [ - "abstract", "baremodule", "begin", "bitstype", "break", "catch", "ccall", + "abstract type", "baremodule", "begin", "break", "catch", "ccall", "const", "continue", "do", "else", "elseif", "end", "export", "false", - "finally", "for", "function", "global", "if", "immutable", "import", - "importall", "let", "local", "macro", "module", "quote", "return", - "true", "try", "type", "typealias", "using", "while"] + "finally", "for", "function", "global", "if", "import", + "importall", "let", "local", "macro", "module", "mutable struct", + "primitive type", "quote", "return", "struct", + "true", "try", "typealias", "using", "while"] r = searchsorted(sorted_keywords, s) i = first(r) n = length(sorted_keywords) diff --git a/base/Terminals.jl b/base/Terminals.jl index 14cd542616b25..071928972be28 100644 --- a/base/Terminals.jl +++ b/base/Terminals.jl @@ -35,7 +35,7 @@ import Base: ## TextTerminal ## -abstract TextTerminal <: Base.AbstractPipe +abstract type TextTerminal <: Base.AbstractPipe end # INTERFACE pipe_reader(::TextTerminal) = error("Unimplemented") @@ -89,16 +89,16 @@ disable_bracketed_paste(t::TextTerminal) = nothing ## UnixTerminal ## -abstract UnixTerminal <: TextTerminal +abstract type UnixTerminal <: TextTerminal end pipe_reader(t::UnixTerminal) = t.in_stream pipe_writer(t::UnixTerminal) = t.out_stream -type TerminalBuffer <: UnixTerminal +mutable struct TerminalBuffer <: UnixTerminal out_stream::Base.IO end -type TTYTerminal <: UnixTerminal +mutable struct TTYTerminal <: UnixTerminal term_type::String in_stream::Base.TTY out_stream::Base.TTY diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 5ca6ef34820f1..1f1cf9ef8c30f 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -245,9 +245,9 @@ end ## Traits for array types ## -abstract LinearIndexing -immutable LinearFast <: LinearIndexing end -immutable LinearSlow <: LinearIndexing end +abstract type LinearIndexing end +struct LinearFast <: LinearIndexing end +struct LinearSlow <: LinearIndexing end """ Base.linearindexing(A) diff --git a/base/array.jl b/base/array.jl index 355da7c2c71a7..e8ef8c22c0f59 100644 --- a/base/array.jl +++ b/base/array.jl @@ -117,10 +117,10 @@ end function reinterpret{T,S,N}(::Type{T}, a::Array{S}, dims::NTuple{N,Int}) if !isbits(T) - throw(ArgumentError("cannot reinterpret Array{$(S)} to ::Type{Array{$(T)}}, type $(T) is not a bitstype")) + throw(ArgumentError("cannot reinterpret Array{$(S)} to ::Type{Array{$(T)}}, type $(T) is not a bits type")) end if !isbits(S) - throw(ArgumentError("cannot reinterpret Array{$(S)} to ::Type{Array{$(T)}}, type $(S) is not a bitstype")) + throw(ArgumentError("cannot reinterpret Array{$(S)} to ::Type{Array{$(T)}}, type $(S) is not a bits type")) end nel = div(length(a)*sizeof(S),sizeof(T)) if prod(dims) != nel diff --git a/base/associative.jl b/base/associative.jl index 876b9607b2e3a..40ee1e2045b6d 100644 --- a/base/associative.jl +++ b/base/associative.jl @@ -25,10 +25,10 @@ function summary(t::Associative) return string(typeof(t), " with ", n, (n==1 ? " entry" : " entries")) end -immutable KeyIterator{T<:Associative} +struct KeyIterator{T<:Associative} dict::T end -immutable ValueIterator{T<:Associative} +struct ValueIterator{T<:Associative} dict::T end @@ -290,7 +290,7 @@ and value type and thus its `eltype` is always `Pair{Any,Any}`. See [`Dict`](@ref) for further help. """ -type ObjectIdDict <: Associative{Any,Any} +mutable struct ObjectIdDict <: Associative{Any,Any} ht::Vector{Any} ndel::Int ObjectIdDict() = new(Vector{Any}(32), 0) diff --git a/base/asyncmap.jl b/base/asyncmap.jl index 617927866d97d..f8a789a653fae 100644 --- a/base/asyncmap.jl +++ b/base/asyncmap.jl @@ -267,7 +267,7 @@ function asyncmap(f, s::AbstractSparseArray...; kwargs...) return sparse(asyncmap(f, sa...; kwargs...)) end -type AsyncCollector +mutable struct AsyncCollector f results enumerator::Enumerate @@ -302,7 +302,7 @@ function AsyncCollector(f, results, c...; ntasks=0, batch_size=nothing) AsyncCollector(f, results, enumerate(zip(c...)), ntasks, batch_size) end -type AsyncCollectorState +mutable struct AsyncCollectorState chnl::Channel worker_tasks::Array{Task,1} enum_state # enumerator state @@ -367,7 +367,7 @@ be a function which operates on an array of argument tuples. `collect(AsyncGenerator(f, c...; ntasks=1))` is equivalent to `map(f, c...)`. """ -type AsyncGenerator +mutable struct AsyncGenerator collector::AsyncCollector end @@ -375,7 +375,7 @@ function AsyncGenerator(f, c...; ntasks=0) AsyncGenerator(AsyncCollector(f, Dict{Int,Any}(), c...; ntasks=ntasks)) end -type AsyncGeneratorState +mutable struct AsyncGeneratorState i::Int collector_state::AsyncCollectorState end diff --git a/base/atomics.jl b/base/atomics.jl index 7df2e062dd0d0..b43ccd4f71047 100644 --- a/base/atomics.jl +++ b/base/atomics.jl @@ -39,7 +39,7 @@ Holds a reference to an object of type `T`, ensuring that it is only accessed atomically, i.e. in a thread-safe manner. Only certain "simple" types can be used atomically, namely the -bitstypes integer and float-point types. These are `Int8`...`Int128`, +primitive integer and float-point types. These are `Int8`...`Int128`, `UInt8`...`UInt128`, and `Float16`...`Float64`. New atomic objects can be created from a non-atomic values; if none is @@ -61,7 +61,7 @@ julia> x[] Atomic operations use an `atomic_` prefix, such as `atomic_add!`, `atomic_xchg!`, etc. """ -type Atomic{T<:AtomicTypes} +mutable struct Atomic{T<:AtomicTypes} value::T Atomic{T}() where T<:AtomicTypes = new(zero(T)) Atomic{T}(value) where T<:AtomicTypes = new(value) diff --git a/base/base.jl b/base/base.jl index af40b4b079e9a..652b9106a18c1 100644 --- a/base/base.jl +++ b/base/base.jl @@ -5,7 +5,7 @@ A system call failed with an error code (in the `errno` global variable). """ -type SystemError <: Exception +mutable struct SystemError <: Exception prefix::AbstractString errnum::Int32 extrainfo @@ -20,7 +20,7 @@ end The expression passed to the `parse` function could not be interpreted as a valid Julia expression. """ -type ParseError <: Exception +mutable struct ParseError <: Exception msg::AbstractString end @@ -30,21 +30,17 @@ end The parameters to a function call do not match a valid signature. Argument `msg` is a descriptive error string. """ -type ArgumentError <: Exception +mutable struct ArgumentError <: Exception msg::AbstractString end -#type UnboundError <: Exception -# var::Symbol -#end - """ KeyError(key) An indexing operation into an `Associative` (`Dict`) or `Set` like object tried to access or delete a non-existent element. """ -type KeyError <: Exception +mutable struct KeyError <: Exception key end @@ -54,7 +50,7 @@ end A method with the required type signature does not exist in the given generic function. Alternatively, there is no unique most-specific method. """ -type MethodError <: Exception +mutable struct MethodError <: Exception f args world::UInt @@ -67,7 +63,7 @@ MethodError(f::ANY, args::ANY) = MethodError(f, args, typemax(UInt)) No more data was available to read from a file or stream. """ -type EOFError <: Exception end +mutable struct EOFError <: Exception end """ DimensionMismatch([msg]) @@ -75,7 +71,7 @@ type EOFError <: Exception end The objects called do not have matching dimensionality. Optional argument `msg` is a descriptive error string. """ -type DimensionMismatch <: Exception +mutable struct DimensionMismatch <: Exception msg::AbstractString end DimensionMismatch() = DimensionMismatch("") @@ -86,7 +82,7 @@ DimensionMismatch() = DimensionMismatch("") The asserted condition did not evaluate to `true`. Optional argument `msg` is a descriptive error string. """ -type AssertionError <: Exception +mutable struct AssertionError <: Exception msg::AbstractString AssertionError() = new("") AssertionError(msg) = new(msg) @@ -94,7 +90,7 @@ end #Generic wrapping of arbitrary exceptions #Subtypes should put the exception in an 'error' field -abstract WrappedException <: Exception +abstract type WrappedException <: Exception end """ LoadError(file::AbstractString, line::Int, error) @@ -102,7 +98,7 @@ abstract WrappedException <: Exception An error occurred while `include`ing, `require`ing, or `using` a file. The error specifics should be available in the `.error` field. """ -type LoadError <: WrappedException +mutable struct LoadError <: WrappedException file::AbstractString line::Int error @@ -114,7 +110,7 @@ end An error occurred when running a module's `__init__` function. The actual error thrown is available in the `.error` field. """ -type InitError <: WrappedException +mutable struct InitError <: WrappedException mod::Symbol error end @@ -148,7 +144,7 @@ finalize(o::ANY) = ccall(:jl_finalize_th, Void, (Ptr{Void}, Any,), gc(full::Bool=true) = ccall(:jl_gc_collect, Void, (Int32,), full) gc_enable(on::Bool) = ccall(:jl_gc_enable, Int32, (Int32,), on) != 0 -immutable Nullable{T} +struct Nullable{T} hasvalue::Bool value::T diff --git a/base/base64.jl b/base/base64.jl index 2c42ef29cbe3d..9290a8bfb20f1 100644 --- a/base/base64.jl +++ b/base/base64.jl @@ -22,7 +22,7 @@ base64-encoded ASCII bytes written to `ostream`. Calling [`close`](@ref) on the `Base64EncodePipe` stream is necessary to complete the encoding (but does not close `ostream`). """ -type Base64EncodePipe <: IO +mutable struct Base64EncodePipe <: IO io::IO # writing works in groups of 3, so we need to cache last two bytes written b0::UInt8 @@ -188,7 +188,7 @@ base64encode(x...) = base64encode(write, x...) Returns a new read-only I/O stream, which decodes base64-encoded data read from `istream`. """ -type Base64DecodePipe <: IO +mutable struct Base64DecodePipe <: IO io::IO # reading works in blocks of 4 characters that are decoded into 3 bytes and 2 of them cached cache::Vector{UInt8} diff --git a/base/bitarray.jl b/base/bitarray.jl index 1356b702fd9af..5e9bf5962eb85 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -4,7 +4,7 @@ # notes: bits are stored in contiguous chunks # unused bits must always be set to 0 -type BitArray{N} <: DenseArray{Bool, N} +mutable struct BitArray{N} <: DenseArray{Bool, N} chunks::Vector{UInt64} len::Int dims::NTuple{N,Int} diff --git a/base/boot.jl b/base/boot.jl index b052017593fd7..dbbdb112fcbac 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -2,21 +2,20 @@ # commented-out definitions are implemented in C -#abstract Any <: Any -#abstract Type{T} +#abstract type Any <: Any end +#abstract type Type{T} end -#abstract Vararg{T} -#Tuple = (Any...) +#abstract type Vararg{T} end -#type Symbol +#mutable struct Symbol # #opaque #end -#type TypeName +#mutable struct TypeName # name::Symbol #end -#type DataType <: Type +#mutable struct DataType <: Type # name::TypeName # super::Type # parameters::Tuple @@ -30,91 +29,91 @@ # pointerfree::Bool #end -#type Union <: Type +#struct Union <: Type # a # b #end -#type TypeVar +#mutable struct TypeVar # name::Symbol # lb::Type # ub::Type #end -#type UnionAll +#struct UnionAll # var::TypeVar # body #end -#immutable Void +#struct Void #end #const nothing = Void() -#abstract AbstractArray{T,N} -#abstract DenseArray{T,N} <: AbstractArray{T,N} +#abstract type AbstractArray{T,N} end +#abstract type DenseArray{T,N} <: AbstractArray{T,N} end -#type Array{T,N} <: DenseArray{T,N} +#mutable struct Array{T,N} <: DenseArray{T,N} #end -#type Module +#mutable struct Module # name::Symbol #end -#type Method +#mutable struct Method #end -#type MethodInstance +#mutable struct MethodInstance #end -#type CodeInfo +#mutable struct CodeInfo #end -#type TypeMapLevel +#mutable struct TypeMapLevel #end -#type TypeMapEntry +#mutable struct TypeMapEntry #end -#abstract Ref{T} -#bitstype {32|64} Ptr{T} <: Ref{T} +#abstract type Ref{T} end +#primitive type Ptr{T} <: Ref{T} {32|64} end # types for the front end -#type Expr +#mutable struct Expr # head::Symbol # args::Array{Any,1} # typ::Any #end -#immutable LineNumberNode +#struct LineNumberNode # line::Int #end -#immutable LabelNode +#struct LabelNode # label::Int #end -#immutable GotoNode +#struct GotoNode # label::Int #end -#immutable QuoteNode +#struct QuoteNode # value #end -#immutable GlobalRef +#struct GlobalRef # mod::Module # name::Symbol #end -# type Task -# parent::Task -# storage::Any -# consumers -# started::Bool -# done::Bool -# runnable::Bool -# end +#mutable struct Task +# parent::Task +# storage::Any +# consumers +# started::Bool +# done::Bool +# runnable::Bool +#end export # key types @@ -150,30 +149,30 @@ export typealias AnyVector Array{Any,1} -abstract Number -abstract Real <: Number -abstract AbstractFloat <: Real -abstract Integer <: Real -abstract Signed <: Integer -abstract Unsigned <: Integer - -bitstype 16 Float16 <: AbstractFloat -bitstype 32 Float32 <: AbstractFloat -bitstype 64 Float64 <: AbstractFloat - -bitstype 8 Bool <: Integer -bitstype 32 Char - -bitstype 8 Int8 <: Signed -bitstype 8 UInt8 <: Unsigned -bitstype 16 Int16 <: Signed -bitstype 16 UInt16 <: Unsigned -bitstype 32 Int32 <: Signed -bitstype 32 UInt32 <: Unsigned -bitstype 64 Int64 <: Signed -bitstype 64 UInt64 <: Unsigned -bitstype 128 Int128 <: Signed -bitstype 128 UInt128 <: Unsigned +abstract type Number end +abstract type Real <: Number end +abstract type AbstractFloat <: Real end +abstract type Integer <: Real end +abstract type Signed <: Integer end +abstract type Unsigned <: Integer end + +primitive type Float16 <: AbstractFloat 16 end +primitive type Float32 <: AbstractFloat 32 end +primitive type Float64 <: AbstractFloat 64 end + +primitive type Bool <: Integer 8 end +primitive type Char 32 end + +primitive type Int8 <: Signed 8 end +primitive type UInt8 <: Unsigned 8 end +primitive type Int16 <: Signed 16 end +primitive type UInt16 <: Unsigned 16 end +primitive type Int32 <: Signed 32 end +primitive type UInt32 <: Unsigned 32 end +primitive type Int64 <: Signed 64 end +primitive type UInt64 <: Unsigned 64 end +primitive type Int128 <: Signed 128 end +primitive type UInt128 <: Unsigned 128 end if Int === Int64 typealias UInt UInt64 @@ -184,8 +183,8 @@ end function Typeof end (f::typeof(Typeof))(x::ANY) = isa(x,Type) ? Type{x} : typeof(x) -abstract Exception -type ErrorException <: Exception +abstract type Exception end +mutable struct ErrorException <: Exception msg::AbstractString ErrorException(msg::AbstractString) = new(msg) end @@ -196,34 +195,34 @@ macro _noinline_meta() Expr(:meta, :noinline) end -immutable BoundsError <: Exception +struct BoundsError <: Exception a::Any i::Any BoundsError() = new() BoundsError(a::ANY) = (@_noinline_meta; new(a)) BoundsError(a::ANY, i) = (@_noinline_meta; new(a,i)) end -immutable DivideError <: Exception end -immutable DomainError <: Exception end -immutable OverflowError <: Exception end -immutable InexactError <: Exception end -immutable OutOfMemoryError <: Exception end -immutable ReadOnlyMemoryError<: Exception end -immutable SegmentationFault <: Exception end -immutable StackOverflowError <: Exception end -immutable UndefRefError <: Exception end -immutable UndefVarError <: Exception +struct DivideError <: Exception end +struct DomainError <: Exception end +struct OverflowError <: Exception end +struct InexactError <: Exception end +struct OutOfMemoryError <: Exception end +struct ReadOnlyMemoryError<: Exception end +struct SegmentationFault <: Exception end +struct StackOverflowError <: Exception end +struct UndefRefError <: Exception end +struct UndefVarError <: Exception var::Symbol end -immutable InterruptException <: Exception end -type TypeError <: Exception +struct InterruptException <: Exception end +mutable struct TypeError <: Exception func::Symbol context::AbstractString expected::Type got end -abstract DirectIndexString <: AbstractString +abstract type DirectIndexString <: AbstractString end String(s::String) = s # no constructor yet @@ -239,7 +238,7 @@ kwfunc(f::ANY) = ccall(:jl_get_keyword_sorter, Any, (Any,), f) kwftype(t::ANY) = typeof(ccall(:jl_get_kwsorter, Any, (Any,), t.name)) -type Box +mutable struct Box contents::Any Box(x::ANY) = new(x) Box() = new() @@ -247,7 +246,7 @@ end # constructors for built-in types -type WeakRef +mutable struct WeakRef value WeakRef() = WeakRef(nothing) WeakRef(v::ANY) = ccall(:jl_gc_new_weakref_th, Ref{WeakRef}, @@ -267,7 +266,7 @@ Void() = nothing (::Type{Tuple{}})() = () -immutable VecElement{T} +struct VecElement{T} value::T VecElement{T}(value::T) where {T} = new(value) # disable converting constructor in Core end @@ -350,9 +349,9 @@ atdoc!(λ) = global atdoc = λ # simple stand-alone print definitions for debugging -abstract IO -type CoreSTDOUT <: IO end -type CoreSTDERR <: IO end +abstract type IO end +mutable struct CoreSTDOUT <: IO end +mutable struct CoreSTDERR <: IO end const STDOUT = CoreSTDOUT() const STDERR = CoreSTDERR() io_pointer(::CoreSTDOUT) = Intrinsics.pointerref(Intrinsics.cglobal(:jl_uv_stdout, Ptr{Void}), 1, 1) diff --git a/base/cartesian.jl b/base/cartesian.jl index 334fed12d68df..fe1f8ad44c548 100644 --- a/base/cartesian.jl +++ b/base/cartesian.jl @@ -281,7 +281,7 @@ inlineanonymous(base::Symbol, ext) = Symbol(base,'_',ext) # lreplace(:i_d, :d, 3) -> :i_3 # lreplace(:i_{d-1}, :d, 3) -> :i_2 # This follows LaTeX notation. -immutable LReplace{S<:AbstractString} +struct LReplace{S<:AbstractString} pat_sym::Symbol pat_str::S val::Int diff --git a/base/channels.jl b/base/channels.jl index 05bd379e60faf..56b4d4bfcc2d2 100644 --- a/base/channels.jl +++ b/base/channels.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -abstract AbstractChannel +abstract type AbstractChannel end """ Channel{T}(sz::Int) @@ -17,7 +17,7 @@ Other constructors: * `Channel(Inf)`: equivalent to `Channel{Any}(typemax(Int))` * `Channel(sz)`: equivalent to `Channel{Any}(sz)` """ -type Channel{T} <: AbstractChannel +mutable struct Channel{T} <: AbstractChannel cond_take::Condition # waiting for data to become available cond_put::Condition # waiting for a writeable slot state::Symbol @@ -239,7 +239,7 @@ function close_chnl_on_taskdone(t::Task, ref::WeakRef) end end -type InvalidStateException <: Exception +mutable struct InvalidStateException <: Exception msg::AbstractString state::Symbol end @@ -361,7 +361,7 @@ eltype{T}(::Type{Channel{T}}) = T show(io::IO, c::Channel) = print(io, "$(typeof(c))(sz_max:$(c.sz_max),sz_curr:$(n_avail(c)))") -type ChannelIterState{T} +mutable struct ChannelIterState{T} hasval::Bool val::T ChannelIterState{T}(has::Bool) where {T} = new(has) diff --git a/base/complex.jl b/base/complex.jl index 038d610d20cdd..8a17eff2823f1 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -immutable Complex{T<:Real} <: Number +struct Complex{T<:Real} <: Number re::T im::T end diff --git a/base/coreio.jl b/base/coreio.jl index 8e89c7fab4724..2035aae97abe9 100644 --- a/base/coreio.jl +++ b/base/coreio.jl @@ -5,7 +5,7 @@ print(xs...) = print(STDOUT::IO, xs...) println(xs...) = println(STDOUT::IO, xs...) println(io::IO) = print(io, '\n') -immutable DevNullStream <: IO end +struct DevNullStream <: IO end const DevNull = DevNullStream() isreadable(::DevNullStream) = false iswritable(::DevNullStream) = true diff --git a/base/dSFMT.jl b/base/dSFMT.jl index 5236c8def9cf3..77c7d95c8ec9a 100644 --- a/base/dSFMT.jl +++ b/base/dSFMT.jl @@ -21,7 +21,7 @@ const JN32 = (N+1)*4+1+1 "Jump polynomial for 10^20 steps for dSFMT with exponent 19937" const JPOLY1e21 = "e172e20c5d2de26b567c0cace9e7c6cc4407bd5ffcd22ca59d37b73d54fdbd937cd3abc6f502e8c186dbd4f1a06b9e2b894f31be77424f94dddfd5a45888a84ca66eeeb242eefe6764ed859dafccae7a6a635b3a63fe9dfbbd5f2d3f2610d39388f53060e84edae75be4f4f2272c0f1f26d1231836ad040ab091550f8a3a5423fb3ab83e068fe2684057f15691c4dc757a3aee4bca8595bf1ad03500d9620a5dbe3b2d64380694895d2f379ca928238293ea267ce14236d5be816a61f018fe4f6bc3c9865f5d4d4186e320ab653d1f3c035ae83e2ad725648a67d3480331e763a1dcdfb5711b56796170b124f5febd723a664a2deefbfa9999d922a108b0e683582ae8d3baacb5bb56683405ea9e6e0d71ddb24b2229c72bb9d07061f2d1fa097ade823b607a2029d6e121ae09d93de01a154199e8e6a6e77c970bda72ba8079b2b3a15dd494a3188b1d94a25ae108a8a5bd0b050e6ce64a365a21420e07fdeebecae02eb68a4304b59283055d22c27d680ea35952834d828c9b9b9dd1a886b4f7fe82fe8f2a962e1e5390e563dc281c799aee2a441b7a813facb6ff5e94c059710dcfe7e6b1635e21ae0dc878dd5f7cc0e1101a74452495a67d23a2672c939f32c81d4a2611073990e92a084cc3a62fd42ee566f29d963a9cc5100ccd0a200f49ce0a74fa891efa1b974d342b7fedf9269e40d9b34e3c59c3d37201aecd5a04f4ae3d0c9a68c7ab78c662390e4cf36cb63ea3539c442efd0bf4aace4b8c8bde93c3d84b4d6290adfae1c5e3fcd457b6f3159e501f17b72ff6bc13d6bf61fbdafabefd16ac1dae0bca667e4e16a2b800732f1d0a9274c8a4c6cccd2db62fc275dc308c31c11cd6fda78de2f81f0e542b76b42b2cc09ed8f965d94c714c9918064f53af5379cfbbc31edf9cbce694f63a75f122048de6e57b094908f749661456813a908027f5d8397ab7962bf75ac779a3e1b7ae3fbc93397a67b486bb849befff1de6162ef2819715a88f41881e366ace692a900796a2806393898dd1750ac2b4ca3d34ca48942322fb6375f0c9a00c9701048ee8d7d7a17e11739177a7ad5027556e85835daf8594d84a97fe6621c0fce1495ae6ab8676cdc992d247acf5a4e5ec8c4755fde28117228d2c3ecf89edb91e93d949e2174924572265e36d176d082ed1be884e51d885ba3cda175c51edcee5042eaf519d292aa05aa4185b03858d710a9d0880b3d4e5111f858a52fe352cbe0a24f06a3d977ae2eb85e2a03a68131d0ab91dac4941067cf90ecd0fce156bcd40b8968cd4aa11e0b4353b14508d79d13ac00af4a4d452496b7f2393699889aa1e508427dbf0be3db91d955feb51e559af57640c6b3f9d5f95609852c28f9462a9869dd93acbdb1aafb2381ebb886a0b3fcec278f8bb0f62c23e157e49b89245b0881268ce594acbddd3605b9eaa77c9ff513e0dbad514914136d96fe2843fe2b4e886a0b718a9b8d1132132110618d0d3595da284cd2a4c9d09386199e4f4d7723983d3a374b51cf20dac5cabb4ff7e7197c2ebd9318463409baa583d6a6115c1b768282ff37b0fe152c97671e400d5ccba7d6875df0bf95c5d91257fedb124de393f31908d0e36251326aa29dd5be86291c80b4bf78f419ec151eeaeff643a58b48ab35ad2cd2c0b77b1965966ef3db6b6373cb2c4b590cef2f16f4d6f62f13a6cbf1a481565b5935edd4e76f7b6a8fd0d74bc336b40a803aec38125c006c877dfdcdb9ba2b7aecab5cafe6076e024c73e3567adf97f607a71d180402c22a20a8388f517484cc4198f97c2fe4f3407e0dc577e61f0f71354aa601cf4e3e42e1edd8722d50f5af3441f68caa568cc1c3a19956c1233f265bb47236afab24ee42b27b0042b90693d77c1923147360ae6503f6ba6abbc9dd52a7b4c36a3b6b55f6a80cfa7f101dd9f1bfc7d7eaf09a5d636b510228f245bfb37b4625025d2c911435cdf6f878113753e0804ab8ecab870ad733b9728d7636b17578b41239393e7de47cbce871137d2b61729dda67b2b84cd3363aad64c5dd5bd172f1f091305b1ff78982abe7dab1588036d097cf497e300e6c78a926048febd1b9462c07f5868928357b74297c87f503056b89f786d22a538b6702e290bca04639a0f1d0939b67f409e5e58e472a6a07fa543e2531c2567ec73c41f6769b6ba94c5aa0a030d006f5b6b1c5fb218b86a8f63a48bc867466f20f699859e87956f48a182d26ed451861dd21201ecc7239037ada67319bdf0849c387c73a110af798b4c5f9018bc97993e060ea2a2937fa2eb095d65ec07009fc407a350f1d6fb3c98a0a5f204be985b0cb6962f0eb7844a179c4598a92ea32d2d706c800034d2e960ded5b476d77073316b933fb3e6ba2f4f24a3b73a1e4d8ed1491d757ecf56fd72465dac0000736744d28d29073091587c8bccad302f7054e8a32bb8724974d9f3e449fc70b2a41f0008b548f717ac0a2c3a6580bfb50774933a578ad6acdcb89940bb406ea540893f097d8a88d1609ed605f25499de939083a0c8a7c6db462df5dfa06c298dd233e249433a54267d5cdc22e5524705b7d6b16b96bb2cb83e00cef62e21d91528a74cf95bfd1d391590c93f4058e9bb02656fd087a5b63d738d1c3b5cf533fd59c81cf9136bfcd3e955c19daf9906ef175791fde6a1d98155d7881e241c3522551cf9fcae42e1e46929ea39fd00943446823f9755085ccc8456a3090b73a3031a201d9c704a4ad4868dd9b6d06205560013973f60d637de2f18354bf4523d9d81dc2a7e78cd42c586364bbe0ed86fde0f081f801c1a4abb830839b7796d9a01f141bec8bd93144104c6dc59170162c0a5a639eb63a0a164970de50eb2e04f027394b26ed48d341f7851994df79d7cd663672a556f25e5e16a3adbe1003d631de938fabfed234df12b5ff3027f4a2da823834cb098e0f977a4eb9614579d5c7a1d400a1a933a657aef8ea1a66743d73b0cf37a7d64e9a63e4c7b09945f0db750b311b39783fb5ea216616751967d480a630d3da7c89d1c7beae20369137e96734a4cfedca56a7887f076fe4fe97534ad3e4f74d1a81750581a5ea214b440c7f30331ab86c257534c71175d1e731303a48b01c589fda4fb0d4368b4dd63d91204cb6fc389b2202aa94391907bfb72902a4031f5589ed5f391c2ce92aa998c200ba3c77d8bd747b9d0a29fa85cda3949a6d2bd0c3402e68f98fd451aa27b6c2dfd170e004577cbdb25e3a1b9852e9f66a370789c47bfce722446dade1b32ceae71ee0e1d96edf7ed08a93e3690056f46c3d8e63f88e53673ee71d72cfedbeba493ee91333120e09e9ce9f9c9a7a400f814ea618b1de48f9805e092f4e20f301fbb65caa83735a2a5c89befe4bce4116dca3688e1e14c6f09a945671dedbb5c0ba526842b6cae31d8b5ff978bae928a17a75c134630dd9de988f6ad3d89a071b33775a9660a40b48ec61ad3f93ac81cb1c65d8b0bab5c214786abd13cc10a8ea2e2a370e86e2fa1a372d83c9697b5e37b281e51507685f714fdaebe49ffc93a5582e1936eaee8e4140a4b72" -type DSFMT_state +mutable struct DSFMT_state val::Vector{Int32} DSFMT_state(val::Vector{Int32} = zeros(Int32, JN32)) = diff --git a/base/datafmt.jl b/base/datafmt.jl index 55ec222e6f8b3..36948df35936b 100644 --- a/base/datafmt.jl +++ b/base/datafmt.jl @@ -141,9 +141,9 @@ end # # DLMOffsets: Keep offsets (when result dimensions are not known) # DLMStore: Store values directly into a result store (when result dimensions are known) -abstract DLMHandler +abstract type DLMHandler end -type DLMOffsets <: DLMHandler +mutable struct DLMOffsets <: DLMHandler oarr::Vector{Vector{Int}} offidx::Int thresh::Int @@ -194,7 +194,7 @@ function result(dlmoffsets::DLMOffsets) dlmoffsets.oarr end -type DLMStore{T} <: DLMHandler +mutable struct DLMStore{T} <: DLMHandler hdr::Array{AbstractString, 2} data::Array{T, 2} diff --git a/base/dates/adjusters.jl b/base/dates/adjusters.jl index ddc44711c119f..eebc68b59b5ad 100644 --- a/base/dates/adjusters.jl +++ b/base/dates/adjusters.jl @@ -124,7 +124,7 @@ end lastdayofquarter(dt::DateTime) = DateTime(lastdayofquarter(Date(dt))) # Temporal Adjusters -immutable DateFunction +struct DateFunction f::Function # validate boolean, single-arg inner constructor function DateFunction(f::ANY, dt::TimeType) diff --git a/base/dates/io.jl b/base/dates/io.jl index 5dcdafa8de3ca..fd91696e7e5c5 100644 --- a/base/dates/io.jl +++ b/base/dates/io.jl @@ -7,7 +7,7 @@ A token used in parsing or formatting a date time string. Each subtype must define the tryparsenext and format methods. """ -abstract AbstractDateToken +abstract type AbstractDateToken end """ tryparsenext(tok::AbstractDateToken, str::String, i::Int, len::Int, locale::DateLocale) @@ -59,14 +59,14 @@ Base.show(io::IO, x::Time) = print(io, string(x)) end # Information for parsing and formatting date time values. -immutable DateFormat{S, T<:Tuple} +struct DateFormat{S, T<:Tuple} tokens::T locale::DateLocale end ### Token types ### -immutable DatePart{letter} <: AbstractDateToken +struct DatePart{letter} <: AbstractDateToken width::Int fixed::Bool end @@ -167,7 +167,7 @@ end ### Delimiters -immutable Delim{T, length} <: AbstractDateToken +struct Delim{T, length} <: AbstractDateToken d::T end @@ -234,7 +234,7 @@ end ### DateFormat construction -abstract DayOfWeekToken # special addition to Period types +abstract type DayOfWeekToken end # special addition to Period types # mapping format specifiers to period types const SLOT_RULE = Dict{Char, Type}( diff --git a/base/dates/periods.jl b/base/dates/periods.jl index b1074e67e80b0..75eef1331d1e4 100644 --- a/base/dates/periods.jl +++ b/base/dates/periods.jl @@ -156,7 +156,7 @@ be expressed using a `CompoundPeriod`. In fact, a `CompoundPeriod` is automatica generated by addition of different period types, e.g. `Year(1) + Day(1)` produces a `CompoundPeriod` result. """ -type CompoundPeriod <: AbstractTime +mutable struct CompoundPeriod <: AbstractTime periods::Array{Period, 1} function CompoundPeriod(p::Vector{Period}) n = length(p) diff --git a/base/dates/query.jl b/base/dates/query.jl index 64ae360a7b275..71072b8afe6f6 100644 --- a/base/dates/query.jl +++ b/base/dates/query.jl @@ -2,7 +2,7 @@ # Date Locales -immutable DateLocale +struct DateLocale months::Vector{String} months_abbr::Vector{String} days_of_week::Vector{String} diff --git a/base/dates/types.jl b/base/dates/types.jl index 605b79595edab..f0cf5ebb45fa2 100644 --- a/base/dates/types.jl +++ b/base/dates/types.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -abstract AbstractTime +abstract type AbstractTime end """ Period @@ -17,18 +17,18 @@ abstract AbstractTime `Period` types represent discrete, human representations of time. """ -abstract Period <: AbstractTime -abstract DatePeriod <: Period -abstract TimePeriod <: Period +abstract type Period <: AbstractTime end +abstract type DatePeriod <: Period end +abstract type TimePeriod <: Period end for T in (:Year, :Month, :Week, :Day) - @eval immutable $T <: DatePeriod + @eval struct $T <: DatePeriod value::Int64 $T(v::Number) = new(v) end end for T in (:Hour, :Minute, :Second, :Millisecond, :Microsecond, :Nanosecond) - @eval immutable $T <: TimePeriod + @eval struct $T <: TimePeriod value::Int64 $T(v::Number) = new(v) end @@ -57,7 +57,7 @@ Period(v) `Instant` types represent integer-based, machine representations of time as continuous timelines starting from an epoch. """ -abstract Instant <: AbstractTime +abstract type Instant <: AbstractTime end """ UTInstant{T} @@ -66,7 +66,7 @@ The `UTInstant` represents a machine timeline based on UT time (1 day = one revo the earth). The `T` is a `Period` parameter that indicates the resolution or precision of the instant. """ -immutable UTInstant{P<:Period} <: Instant +struct UTInstant{P<:Period} <: Instant periods::P end @@ -76,15 +76,15 @@ UTD(x) = UTInstant(Day(x)) # Calendar types provide rules for interpretating instant # timelines in human-readable form. -abstract Calendar <: AbstractTime +abstract type Calendar <: AbstractTime end # ISOCalendar implements the ISO 8601 standard (en.wikipedia.org/wiki/ISO_8601) # Notably based on the proleptic Gregorian calendar # ISOCalendar provides interpretation rules for UTInstants to civil date and time parts -immutable ISOCalendar <: Calendar end +struct ISOCalendar <: Calendar end -abstract TimeZone -immutable UTC <: TimeZone end +abstract type TimeZone end +struct UTC <: TimeZone end """ TimeType @@ -92,7 +92,7 @@ immutable UTC <: TimeZone end `TimeType` types wrap `Instant` machine instances to provide human representations of the machine instant. Both `DateTime` and `Date` are subtypes of `TimeType`. """ -abstract TimeType <: AbstractTime +abstract type TimeType <: AbstractTime end """ DateTime @@ -100,7 +100,7 @@ abstract TimeType <: AbstractTime `DateTime` wraps a `UTInstant{Millisecond}` and interprets it according to the proleptic Gregorian calendar. """ -immutable DateTime <: TimeType +struct DateTime <: TimeType instant::UTInstant{Millisecond} DateTime(instant::UTInstant{Millisecond}) = new(instant) end @@ -110,7 +110,7 @@ end `Date` wraps a `UTInstant{Day}` and interprets it according to the proleptic Gregorian calendar. """ -immutable Date <: TimeType +struct Date <: TimeType instant::UTInstant{Day} Date(instant::UTInstant{Day}) = new(instant) end @@ -120,7 +120,7 @@ end `Time` wraps a `Nanosecond` and represents a specific moment in a 24-hour day. """ -immutable Time <: TimeType +struct Time <: TimeType instant::Nanosecond Time(instant::Nanosecond) = new(instant) end diff --git a/base/dft.jl b/base/dft.jl index 21cf0023a0674..41d8eef064414 100644 --- a/base/dft.jl +++ b/base/dft.jl @@ -3,7 +3,7 @@ module DFT # DFT plan where the inputs are an array of eltype T -abstract Plan{T} +abstract type Plan{T} end import Base: show, summary, size, ndims, length, eltype, *, A_mul_B!, inv, \, A_ldiv_B! @@ -237,7 +237,7 @@ A_ldiv_B!(y::AbstractArray, p::Plan, x::AbstractArray) = A_mul_B!(y, inv(p), x) # implementations only need to provide the unnormalized backwards FFT, # similar to FFTW, and we do the scaling generically to get the ifft: -type ScaledPlan{T,P,N} <: Plan{T} +mutable struct ScaledPlan{T,P,N} <: Plan{T} p::P scale::N # not T, to avoid unnecessary promotion to Complex pinv::Plan diff --git a/base/dict.jl b/base/dict.jl index 229de51ef4050..e548ab7678e6e 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -55,7 +55,7 @@ function show{K,V}(io::IO, t::Associative{K,V}) end end -abstract AbstractSerializer +abstract type AbstractSerializer end # Dict @@ -89,7 +89,7 @@ Dict{String,Int64} with 2 entries: "A" => 1 ``` """ -type Dict{K,V} <: Associative{K,V} +mutable struct Dict{K,V} <: Associative{K,V} slots::Array{UInt8,1} keys::Array{K,1} vals::Array{V,1} @@ -595,7 +595,7 @@ function filter!(f, d::Union{ObjectIdDict,Dict}) return d end -immutable ImmutableDict{K, V} <: Associative{K,V} +struct ImmutableDict{K, V} <: Associative{K,V} parent::ImmutableDict{K, V} key::K value::V diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl index 76db2ee306a8c..f067851664368 100644 --- a/base/docs/Docs.jl +++ b/base/docs/Docs.jl @@ -127,7 +127,7 @@ which helps to reduce total precompiled image size. The `.data` fields stores several values related to the docstring, such as: path, linenumber, source code, and fielddocs. """ -type DocStr +mutable struct DocStr text :: Core.SimpleVector object :: Nullable data :: Dict{Symbol, Any} @@ -199,7 +199,7 @@ is stored as `Union{Tuple{T}, Tuple{T, Any}}`. Note: The `Function`/`DataType` object's signature is always `Union{}`. """ -type MultiDoc +mutable struct MultiDoc "Ordered (via definition order) vector of object signatures." order::Vector{Type} "Documentation for each object. Keys are signatures." @@ -370,9 +370,11 @@ function summarize(io::IO, T::DataType, binding) println(io, "**Summary:**") println(io, "```") println(io, - T.abstract ? "abstract" : T.mutable ? "type" : "immutable", - " ", T, " <: ", supertype(T) - ) + T.abstract ? "abstract type" : + T.mutable ? "mutable struct" : + Base.isstructtype(T) ? "struct" : "primitive type", + " ", T, " <: ", supertype(T) + ) println(io, "```") if !isempty(fieldnames(T)) println(io, "**Fields:**") diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index cc75293a2ca02..002d8846e8091 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -2,7 +2,7 @@ module BaseDocs -immutable Keyword +struct Keyword name :: Symbol end macro kw_str(text) Keyword(Symbol(text)) end @@ -76,17 +76,17 @@ made available to the user. For example: kw"export" """ -`abstract` declares a type that cannot be instantiated, and serves only as a node in the +`abstract type` declares a type that cannot be instantiated, and serves only as a node in the type graph, thereby describing sets of related concrete types: those concrete types which are their descendants. Abstract types form the conceptual hierarchy which makes Julia’s type system more than just a collection of object implementations. For example: - abstract Number - abstract Real <: Number + abstract type Number end + abstract type Real <: Number end -`abstract Number` has no supertype, whereas `abstract Real` is an abstract subtype of `Number`. +`Number` has no supertype, whereas `Real` is an abstract subtype of `Number`. """ -kw"abstract" +kw"abstract type" """ `module` declares a Module, which is a separate global variable workspace. Within a @@ -118,19 +118,19 @@ or a definition of `eval`. It does still import `Core`. kw"baremodule" """ -`bitstype` declares a concrete type whose data consists of plain old bits. Classic -examples of bits types are integers and floating-point values. Some example built-in -bits type declarations: +`primitive type` declares a concrete type whose data consists only of a series of bits. Classic +examples of primitive types are integers and floating-point values. Some example built-in +primitive type declarations: - bitstype 32 Char - bitstype 8 Bool <: Integer + primitive type Char 32 end + primitive type Bool <: Integer 8 end -The first parameter indicates how many bits of storage the type requires. Currently, -only sizes that are multiples of 8 bits are supported. The second parameter gives the -name of the type. The `Bool` declaration shows how a bits type can be optionally +The number after the name indicates how many bits of storage the type requires. Currently, +only sizes that are multiples of 8 bits are supported. +The `Bool` declaration shows how a primitive type can be optionally declared to be a subtype of some supertype. """ -kw"bitstype" +kw"primitive type" """ `macro` defines a method to include generated code in the final body of a program. A @@ -613,28 +613,33 @@ implicitly begin blocks of code. See also `;`. kw"begin" """ -At their most basic, Julia types are specified as a name and a set of fields. +The most commonly used kind of type in Julia is a struct, specified as a name and a +set of fields. - type Point + struct Point x y end -Fields can have type restrictions, which may be parametrised: +Fields can have type restrictions, which may be parameterized: - type Point{X} + struct Point{X} x::X y::Float64 end -Type can also declare an abstract super type via `<:` syntax: +A struct can also declare an abstract super type via `<:` syntax: - type Point <: AbstractPoint + struct Point <: AbstractPoint ... -See the manual for more details, such as information on inner constructors. +Structs are immutable by default; an instance of one of these types cannot +be modified after construction. Use `mutable struct` instead to declare a +type whose instances can be modified. + +See the manual for more details, such as how to define constructors. """ -kw"type" +kw"struct" """ Introduce a new name for an already expressible type. For example, in `base/boot.jl`, @@ -655,10 +660,10 @@ some parameter choices are fixed. In `base` for example: kw"typealias" """ -`immutable` acts in the same way as `type`, but declares that the fields of the type may -not be set after construction. See `type` and the manual for more information. +`mutable struct` is similar to `struct`, but additionally allows the fields of the type +to be set after construction. See `struct` and the manual for more information. """ -kw"immutable" +kw"mutable struct" """ @__LINE__ -> Int diff --git a/base/docs/bindings.jl b/base/docs/bindings.jl index 045b62b3bc4e4..40ca52cd09e0a 100644 --- a/base/docs/bindings.jl +++ b/base/docs/bindings.jl @@ -2,7 +2,7 @@ export @var -immutable Binding +struct Binding mod::Module var::Symbol diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index b79496acbfee0..ff06ebd8473a6 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -342,7 +342,7 @@ julia> sizeof(Complex128) 16 ``` -If `T` is not a bitstype, an error is thrown. +If `T` does not have a specific size, an error is thrown. ```jldoctest julia> sizeof(Base.LinAlg.LU) diff --git a/base/docs/utils.jl b/base/docs/utils.jl index 173a22f8ec60a..97052991c8ff9 100644 --- a/base/docs/utils.jl +++ b/base/docs/utils.jl @@ -19,7 +19,7 @@ You can also use a stream for large amounts of data: println(io, "
foo
") end """ -type HTML{T} +mutable struct HTML{T} content::T end @@ -64,7 +64,7 @@ You can also use a stream for large amounts of data: println(io, "foo") end """ -type Text{T} +mutable struct Text{T} content::T end @@ -348,12 +348,12 @@ print_correction(word) = print_correction(STDOUT, word) # Completion data -const builtins = ["abstract", "baremodule", "begin", "bitstype", "break", +const builtins = ["abstract type", "baremodule", "begin", "break", "catch", "ccall", "const", "continue", "do", "else", "elseif", "end", "export", "finally", "for", "function", - "global", "if", "immutable", "import", "importall", "let", - "local", "macro", "module", "quote", "return", "try", "type", - "typealias", "using", "while"] + "global", "if", "import", "importall", "let", + "local", "macro", "module", "mutable struct", "primitive type", + "quote", "return", "struct", "try", "typealias", "using", "while"] moduleusings(mod) = ccall(:jl_module_usings, Any, (Any,), mod) diff --git a/base/env.jl b/base/env.jl index cca18315941bc..e4bc18e39df8e 100644 --- a/base/env.jl +++ b/base/env.jl @@ -63,7 +63,7 @@ end # os test A singleton of this type provides a hash table interface to environment variables. """ -type EnvHash <: Associative{String,String}; end +mutable struct EnvHash <: Associative{String,String}; end """ ENV diff --git a/base/error.jl b/base/error.jl index e05d0ecdead42..e5d1cb36a7f59 100644 --- a/base/error.jl +++ b/base/error.jl @@ -82,7 +82,7 @@ macro assert(ex, msgs...) return :($(esc(ex)) ? $(nothing) : throw(Main.Base.AssertionError($msg))) end -immutable ExponentialBackOff +struct ExponentialBackOff n::Int first_delay::Float64 max_delay::Float64 diff --git a/base/essentials.jl b/base/essentials.jl index 30d5fea5e3692..702f8af163b2f 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -6,8 +6,8 @@ typealias Callable Union{Function,Type} const Bottom = Union{} -abstract AbstractSet{T} -abstract Associative{K,V} +abstract type AbstractSet{T} end +abstract type Associative{K,V} end # The real @inline macro is not available until after array.jl, so this # internal macro splices the meta Expr directly into the function body. @@ -286,12 +286,12 @@ Very few operations are defined on Colons directly; instead they are converted by `to_indices` to an internal vector type (`Base.Slice`) to represent the collection of indices they span before being used. """ -immutable Colon +struct Colon end const (:) = Colon() # For passing constants through type inference -immutable Val{T} +struct Val{T} end # used by interpolating quote and some other things in the front end diff --git a/base/event.jl b/base/event.jl index 2b671aaa1d826..0d455ebf18195 100644 --- a/base/event.jl +++ b/base/event.jl @@ -12,7 +12,7 @@ called can be woken up. For level-triggered notifications, you must keep extra s track of whether a notification has happened. The [`Channel`](@ref) type does this, and so can be used for level-triggered events. """ -type Condition +mutable struct Condition waitq::Vector{Any} Condition() = new([]) @@ -235,7 +235,7 @@ when notified from C by a call to `uv_async_send`. Waiting tasks are woken with an error when the object is closed (by [`close`](@ref). Use [`isopen`](@ref) to check whether it is still active. """ -type AsyncCondition +mutable struct AsyncCondition handle::Ptr{Void} cond::Condition @@ -308,7 +308,7 @@ Create a timer that wakes up tasks waiting for it (by calling [`wait`](@ref) on a specified interval. Times are in seconds. Waiting tasks are woken with an error when the timer is closed (by [`close`](@ref). Use [`isopen`](@ref) to check whether a timer is still active. """ -type Timer +mutable struct Timer handle::Ptr{Void} cond::Condition isopen::Bool diff --git a/base/fft/FFTW.jl b/base/fft/FFTW.jl index 4a595e2e937bf..950021cf20045 100644 --- a/base/fft/FFTW.jl +++ b/base/fft/FFTW.jl @@ -73,7 +73,7 @@ typealias fftwTypeSingle Union{Type{Float32},Type{Complex64}} # since it is not written to. Hence, it is convenient to create an # array-like type that carries a size and a stride like a "real" array # but which is converted to C_NULL as a pointer. -immutable FakeArray{T, N} <: DenseArray{T, N} +struct FakeArray{T, N} <: DenseArray{T, N} sz::NTuple{N, Int} st::NTuple{N, Int} end @@ -154,7 +154,7 @@ end # pointer type for fftw_plan (opaque pointer) -immutable fftw_plan_struct end +struct fftw_plan_struct end typealias PlanPtr Ptr{fftw_plan_struct} # Planner timelimits @@ -197,10 +197,10 @@ end # this into a type to support a finalizer on the fftw_plan. # K is FORWARD/BACKWARD for forward/backward or r2c/c2r plans, respectively. # For r2r plans, K is a tuple of the transform kinds along each dimension. -abstract FFTWPlan{T<:fftwNumber,K,inplace} <: Plan{T} +abstract type FFTWPlan{T<:fftwNumber,K,inplace} <: Plan{T} end for P in (:cFFTWPlan, :rFFTWPlan, :r2rFFTWPlan) # complex, r2c/c2r, and r2r @eval begin - type $P{T<:fftwNumber,K,inplace,N} <: FFTWPlan{T,K,inplace} + mutable struct $P{T<:fftwNumber,K,inplace,N} <: FFTWPlan{T,K,inplace} plan::PlanPtr sz::NTuple{N, Int} # size of array on which plan operates (Int tuple) osz::NTuple{N, Int} # size of output array (Int tuple) diff --git a/base/fft/dct.jl b/base/fft/dct.jl index f97f52ee3be0f..ef73687eff988 100644 --- a/base/fft/dct.jl +++ b/base/fft/dct.jl @@ -9,7 +9,7 @@ export dct, idct, dct!, idct!, plan_dct, plan_idct, plan_dct!, plan_idct! # Unlike Matlab we compute the multidimensional transform by default, # similar to the Julia fft functions. -type DCTPlan{T<:fftwNumber,K,inplace} <: Plan{T} +mutable struct DCTPlan{T<:fftwNumber,K,inplace} <: Plan{T} plan::r2rFFTWPlan{T} r::Array{UnitRange{Int}} # array of indices for rescaling nrm::Float64 # normalization factor diff --git a/base/file.jl b/base/file.jl index 1cc1829c33d4f..30eb9696de249 100644 --- a/base/file.jl +++ b/base/file.jl @@ -389,7 +389,7 @@ function mktempdir(fn::Function, parent=tempdir()) end end -immutable uv_dirent_t +struct uv_dirent_t name::Ptr{UInt8} typ::Cint end diff --git a/base/filesystem.jl b/base/filesystem.jl index e90a1b821050e..f66bbfd5a0df5 100644 --- a/base/filesystem.jl +++ b/base/filesystem.jl @@ -57,9 +57,9 @@ include(string(length(Core.ARGS)>=2?Core.ARGS[2]:"","file_constants.jl")) # inc ## Operations with File (fd) objects ## -abstract AbstractFile <: IO +abstract type AbstractFile <: IO end -type File <: AbstractFile +mutable struct File <: AbstractFile open::Bool handle::RawFD File(fd::RawFD) = new(true, fd) diff --git a/base/generator.jl b/base/generator.jl index 2708d65148d30..c3a4c9bf974c8 100644 --- a/base/generator.jl +++ b/base/generator.jl @@ -28,7 +28,7 @@ julia> collect(g) 25 ``` """ -immutable Generator{I,F} +struct Generator{I,F} f::F iter::I end @@ -48,11 +48,11 @@ end ## iterator traits -abstract IteratorSize -immutable SizeUnknown <: IteratorSize end -immutable HasLength <: IteratorSize end -immutable HasShape <: IteratorSize end -immutable IsInfinite <: IteratorSize end +abstract type IteratorSize end +struct SizeUnknown <: IteratorSize end +struct HasLength <: IteratorSize end +struct HasShape <: IteratorSize end +struct IsInfinite <: IteratorSize end """ iteratorsize(itertype::Type) -> IteratorSize @@ -82,9 +82,9 @@ Base.HasLength() iteratorsize(x) = iteratorsize(typeof(x)) iteratorsize(::Type) = HasLength() # HasLength is the default -abstract IteratorEltype -immutable EltypeUnknown <: IteratorEltype end -immutable HasEltype <: IteratorEltype end +abstract type IteratorEltype end +struct EltypeUnknown <: IteratorEltype end +struct HasEltype <: IteratorEltype end """ iteratoreltype(itertype::Type) -> IteratorEltype diff --git a/base/gmp.jl b/base/gmp.jl index 3cdf65b6fcdec..03a61e3ae7252 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -38,7 +38,7 @@ else end -type BigInt <: Integer +mutable struct BigInt <: Integer alloc::Cint size::Cint d::Ptr{Limb} diff --git a/base/grisu/bignums.jl b/base/grisu/bignums.jl index 6dfb917d50460..db65740cfd848 100644 --- a/base/grisu/bignums.jl +++ b/base/grisu/bignums.jl @@ -49,7 +49,7 @@ const kBigitMask = Chunk((1 << kBigitSize) - 1) # grow. There are no checks if the stack-allocated space is sufficient. const kBigitCapacity = div(kMaxSignificantBits,kBigitSize) -type Bignum +mutable struct Bignum bigits::Array{UInt32,1} used_digits::Int32 exponent::Int32 diff --git a/base/grisu/float.jl b/base/grisu/float.jl index 70de682f97d73..c545b8c10d216 100644 --- a/base/grisu/float.jl +++ b/base/grisu/float.jl @@ -28,7 +28,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -immutable Float +struct Float s::UInt64 e::Int32 de::Int32 diff --git a/base/inference.jl b/base/inference.jl index 5670a6edbdede..7cbd5758041d3 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -6,7 +6,7 @@ import Core: _apply, svec, apply_type, Builtin, IntrinsicFunction, MethodInstanc const MAX_TYPEUNION_LEN = 3 const MAX_TYPE_DEPTH = 8 -immutable InferenceParams +struct InferenceParams world::UInt # optimization @@ -47,20 +47,20 @@ const Slot_UsedUndef = 32 #### inference state types #### -immutable NotFound end +struct NotFound end const NF = NotFound() typealias LineNum Int typealias VarTable Array{Any,1} # The type of a variable load is either a value or an UndefVarError -type VarState +mutable struct VarState typ undef::Bool VarState(typ::ANY, undef::Bool) = new(typ, undef) end # The type of a value might be constant -immutable Const +struct Const val Const(v::ANY) = new(v) end @@ -70,7 +70,7 @@ end # limit the type of some other variable # The Conditional type tracks the set of branches on variable type info # that was used to create the boolean condition -type Conditional +mutable struct Conditional var::Union{Slot,SSAValue} vtype elsetype @@ -82,7 +82,7 @@ type Conditional end end -immutable PartialTypeVar +struct PartialTypeVar tv::TypeVar # N.B.: Currently unused, but would allow turning something back # into Const, if the bounds are pulled out of this TypeVar @@ -97,7 +97,7 @@ function rewrap(t::ANY, u::ANY) return rewrap_unionall(t, u) end -type InferenceState +mutable struct InferenceState sp::SimpleVector # static parameters label_counter::Int # index of the current highest label for this function mod::Module @@ -1929,7 +1929,7 @@ end #### handling for statement-position expressions #### -type StateUpdate +mutable struct StateUpdate var::Union{Slot,SSAValue} vtype state::VarTable @@ -3309,7 +3309,7 @@ end #### post-inference optimizations #### -immutable InvokeData +struct InvokeData mt::MethodTable entry::TypeMapEntry types0 @@ -4891,7 +4891,7 @@ function alloc_elim_pass!(sv::InferenceState) nv, field_names = alloc tup = rhs.args # This makes sure the value doesn't escape so we can elide - # allocation of mutable types too + # allocation of mutable structs too if (var !== nothing && occurs_outside_getfield(bexpr, var, sv, nv, field_names)) i += 1 diff --git a/base/intset.jl b/base/intset.jl index cecbb0f2a365d..1bb2016d0a11a 100644 --- a/base/intset.jl +++ b/base/intset.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -immutable IntSet <: AbstractSet{Int} +struct IntSet <: AbstractSet{Int} bits::BitVector IntSet() = new(falses(256)) end diff --git a/base/io.jl b/base/io.jl index 7db13a6f8c8e3..58d443371db4c 100644 --- a/base/io.jl +++ b/base/io.jl @@ -101,7 +101,7 @@ end # Generic wrappers around other IO objects -abstract AbstractPipe <: IO +abstract type AbstractPipe <: IO end function pipe_reader end function pipe_writer end @@ -538,7 +538,7 @@ readstring(filename::AbstractString) = open(readstring, filename) ## high-level iterator interfaces ## -type EachLine +mutable struct EachLine stream::IO ondone::Function chomp::Bool diff --git a/base/iobuffer.jl b/base/iobuffer.jl index 72af09462d340..af58ba1a5b1e2 100644 --- a/base/iobuffer.jl +++ b/base/iobuffer.jl @@ -3,7 +3,7 @@ ## work with AbstractVector{UInt8} via I/O primitives ## # Stateful string -type AbstractIOBuffer{T<:AbstractVector{UInt8}} <: IO +mutable struct AbstractIOBuffer{T<:AbstractVector{UInt8}} <: IO data::T # T should support: getindex, setindex!, length, copy!, resize!, and T() readable::Bool writable::Bool diff --git a/base/iostream.jl b/base/iostream.jl index a2050119b78fb..dc0b0ac2f8618 100644 --- a/base/iostream.jl +++ b/base/iostream.jl @@ -4,7 +4,7 @@ const sizeof_ios_t = Int(ccall(:jl_sizeof_ios_t, Cint, ())) -type IOStream <: IO +mutable struct IOStream <: IO handle::Ptr{Void} ios::Array{UInt8,1} name::AbstractString diff --git a/base/irrationals.jl b/base/irrationals.jl index d17111f500154..ae8f4d4af3f3c 100644 --- a/base/irrationals.jl +++ b/base/irrationals.jl @@ -2,7 +2,7 @@ ## general machinery for irrational mathematical constants -immutable Irrational{sym} <: Real end +struct Irrational{sym} <: Real end show{sym}(io::IO, x::Irrational{sym}) = print(io, "$sym = $(string(float(x))[1:15])...") diff --git a/base/iterators.jl b/base/iterators.jl index 30a864ce2a990..eb52006852af1 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -28,7 +28,7 @@ and_iteratoreltype(a, b) = EltypeUnknown() # enumerate -immutable Enumerate{I} +struct Enumerate{I} itr::I end @@ -71,7 +71,7 @@ iteratoreltype{I}(::Type{Enumerate{I}}) = iteratoreltype(I) # zip -abstract AbstractZipIterator +abstract type AbstractZipIterator end zip_iteratorsize(a, b) = and_iteratorsize(a,b) # as `and_iteratorsize` but inherit `Union{HasLength,IsInfinite}` of the shorter iterator zip_iteratorsize(::HasLength, ::IsInfinite) = HasLength() @@ -80,7 +80,7 @@ zip_iteratorsize(a::IsInfinite, b) = zip_iteratorsize(b,a) zip_iteratorsize(a::IsInfinite, b::IsInfinite) = IsInfinite() -immutable Zip1{I} <: AbstractZipIterator +struct Zip1{I} <: AbstractZipIterator a::I end zip(a) = Zip1(a) @@ -98,7 +98,7 @@ end iteratorsize{I}(::Type{Zip1{I}}) = iteratorsize(I) iteratoreltype{I}(::Type{Zip1{I}}) = iteratoreltype(I) -immutable Zip2{I1, I2} <: AbstractZipIterator +struct Zip2{I1, I2} <: AbstractZipIterator a::I1 b::I2 end @@ -118,7 +118,7 @@ end iteratorsize{I1,I2}(::Type{Zip2{I1,I2}}) = zip_iteratorsize(iteratorsize(I1),iteratorsize(I2)) iteratoreltype{I1,I2}(::Type{Zip2{I1,I2}}) = and_iteratoreltype(iteratoreltype(I1),iteratoreltype(I2)) -immutable Zip{I, Z<:AbstractZipIterator} <: AbstractZipIterator +struct Zip{I, Z<:AbstractZipIterator} <: AbstractZipIterator a::I z::Z end @@ -171,7 +171,7 @@ iteratoreltype{I1,I2}(::Type{Zip{I1,I2}}) = and_iteratoreltype(iteratoreltype(I1 # filter -immutable Filter{F,I} +struct Filter{F,I} flt::F itr::I end @@ -212,7 +212,7 @@ iteratorsize{T<:Filter}(::Type{T}) = SizeUnknown() # Rest -- iterate starting at the given state -immutable Rest{I,S} +struct Rest{I,S} itr::I st::S end @@ -237,7 +237,7 @@ iteratorsize{I,S}(::Type{Rest{I,S}}) = rest_iteratorsize(iteratorsize(I)) # Count -- infinite counting -immutable Count{S<:Number} +struct Count{S<:Number} start::S step::S end @@ -261,7 +261,7 @@ iteratorsize{S}(::Type{Count{S}}) = IsInfinite() # Take -- iterate through the first n elements -immutable Take{I} +struct Take{I} xs::I n::Int end @@ -316,7 +316,7 @@ end # Drop -- iterator through all but the first n elements -immutable Drop{I} +struct Drop{I} xs::I n::Int end @@ -374,7 +374,7 @@ done(it::Drop, state) = done(it.xs, state) # Cycle an iterator forever -immutable Cycle{I} +struct Cycle{I} xs::I end @@ -408,7 +408,7 @@ done(it::Cycle, state) = state[2] # Repeated - repeat an object infinitely many times -immutable Repeated{O} +struct Repeated{O} x::O end repeated(x) = Repeated(x) @@ -444,7 +444,7 @@ iteratoreltype{O}(::Type{Repeated{O}}) = HasEltype() # Product -- cartesian product of iterators -abstract AbstractProdIterator +abstract type AbstractProdIterator end length(p::AbstractProdIterator) = prod(size(p)) _length(p::AbstractProdIterator) = prod(map(unsafe_length, indices(p))) @@ -476,7 +476,7 @@ _prod_indices(a, b, A, B) = throw(ArgumentError("Cannot construct indices for objects of types $(typeof(a)) and $(typeof(b))")) # one iterator -immutable Prod1{I} <: AbstractProdIterator +struct Prod1{I} <: AbstractProdIterator a::I end product(a) = Prod1(a) @@ -496,7 +496,7 @@ iteratoreltype{I}(::Type{Prod1{I}}) = iteratoreltype(I) iteratorsize{I}(::Type{Prod1{I}}) = iteratorsize(I) # two iterators -immutable Prod2{I1, I2} <: AbstractProdIterator +struct Prod2{I1, I2} <: AbstractProdIterator a::I1 b::I2 end @@ -548,7 +548,7 @@ end @inline done(p::AbstractProdIterator, st) = st[4] # n iterators -immutable Prod{I1, I2<:AbstractProdIterator} <: AbstractProdIterator +struct Prod{I1, I2<:AbstractProdIterator} <: AbstractProdIterator a::I1 b::I2 end @@ -574,7 +574,7 @@ prod_iteratorsize(a, b) = SizeUnknown() # flatten an iterator of iterators -immutable Flatten{I} +struct Flatten{I} it::I end @@ -649,7 +649,7 @@ julia> collect(Iterators.partition([1,2,3,4,5], 2)) partition{T}(c::T, n::Integer) = PartitionIterator{T}(c, Int(n)) -type PartitionIterator{T} +mutable struct PartitionIterator{T} c::T n::Int end diff --git a/base/libc.jl b/base/libc.jl index ea0e4b3698348..d811c79aae6d9 100644 --- a/base/libc.jl +++ b/base/libc.jl @@ -15,7 +15,7 @@ include(string(length(Core.ARGS)>=2?Core.ARGS[2]:"","errno_h.jl")) # include($B ## RawFD ## # Wrapper for an OS file descriptor (on both Unix and Windows) -immutable RawFD +struct RawFD fd::Int32 RawFD(fd::Integer) = new(fd) RawFD(fd::RawFD) = fd @@ -30,7 +30,7 @@ dup(src::RawFD, target::RawFD) = systemerror("dup", -1 == # Wrapper for an OS file descriptor (for Windows) if is_windows() - immutable WindowsRawSocket + struct WindowsRawSocket handle::Ptr{Void} # On Windows file descriptors are HANDLE's and 64-bit on 64-bit Windows end Base.cconvert(::Type{Ptr{Void}}, fd::WindowsRawSocket) = fd.handle @@ -42,7 +42,7 @@ end ## FILE (not auto-finalized) ## -immutable FILE +struct FILE ptr::Ptr{Void} end @@ -96,7 +96,7 @@ else error("systemsleep undefined for this OS") end -immutable TimeVal +struct TimeVal sec::Int64 usec::Int64 end @@ -114,7 +114,7 @@ end Convert a number of seconds since the epoch to broken-down format, with fields `sec`, `min`, `hour`, `mday`, `month`, `year`, `wday`, `yday`, and `isdst`. """ -type TmStruct +mutable struct TmStruct sec::Int32 min::Int32 hour::Int32 diff --git a/base/libdl.jl b/base/libdl.jl index 5f2b696d35853..a9e65684700c3 100644 --- a/base/libdl.jl +++ b/base/libdl.jl @@ -180,7 +180,7 @@ File extension for dynamic libraries (e.g. dll, dylib, so) on the current platfo dlext if is_linux() - immutable dl_phdr_info + struct dl_phdr_info # Base address of object addr::Cuint diff --git a/base/libgit2/error.jl b/base/libgit2/error.jl index 1d6c904a62e57..8e91bec65821c 100644 --- a/base/libgit2/error.jl +++ b/base/libgit2/error.jl @@ -58,12 +58,12 @@ export GitError Describe, Rebase) -immutable ErrorStruct +struct ErrorStruct message::Ptr{UInt8} class::Cint end -immutable GitError <: Exception +struct GitError <: Exception class::Class code::Code msg::AbstractString diff --git a/base/libgit2/libgit2.jl b/base/libgit2/libgit2.jl index 0ccfc2298158a..0df0561181124 100644 --- a/base/libgit2/libgit2.jl +++ b/base/libgit2/libgit2.jl @@ -36,7 +36,7 @@ include("callbacks.jl") using .Error -immutable State +struct State head::GitHash index::GitHash work::GitHash diff --git a/base/libgit2/types.jl b/base/libgit2/types.jl index 0c978783bd35f..10423af8e0952 100644 --- a/base/libgit2/types.jl +++ b/base/libgit2/types.jl @@ -6,7 +6,7 @@ const OID_RAWSZ = 20 const OID_HEXSZ = OID_RAWSZ * 2 const OID_MINPREFIXLEN = 4 -abstract AbstractGitHash +abstract type AbstractGitHash end """ GitHash @@ -14,7 +14,7 @@ abstract AbstractGitHash A git object identifier, based on the sha-1 hash. It is a $OID_RAWSZ byte string ($OID_HEXSZ hex digits) used to identify a `GitObject` in a repository. """ -immutable GitHash <: AbstractGitHash +struct GitHash <: AbstractGitHash val::NTuple{OID_RAWSZ, UInt8} GitHash(val::NTuple{OID_RAWSZ, UInt8}) = new(val) end @@ -29,7 +29,7 @@ is unique. Internally it is stored as two fields: a full-size `GitHash` (`hash`) and a length (`len`). Only the initial `len` hex digits of `hash` are used. """ -immutable GitShortHash <: AbstractGitHash +struct GitShortHash <: AbstractGitHash hash::GitHash # underlying hash: unused digits are ignored len::Csize_t # length in hex digits end @@ -41,7 +41,7 @@ end Time in a signature. Matches the [`git_time`](https://libgit2.github.com/libgit2/#HEAD/type/git_time) struct. """ -immutable TimeStruct +struct TimeStruct time::Int64 # time in seconds from epoch offset::Cint # timezone offset in minutes end @@ -52,7 +52,7 @@ end An action signature (e.g. for committers, taggers, etc). Matches the [`git_signature`](https://libgit2.github.com/libgit2/#HEAD/type/git_signature) struct. """ -immutable SignatureStruct +struct SignatureStruct name::Ptr{UInt8} # full name of the author email::Ptr{UInt8} # email of the author when::TimeStruct # time when the action happened @@ -81,7 +81,7 @@ strs = String[...] ``` Note that no call to `free` is required as the data is allocated by Julia. """ -immutable StrArrayStruct +struct StrArrayStruct strings::Ptr{Cstring} count::Csize_t end @@ -106,7 +106,7 @@ free(buf_ref) ``` In particular, note that `LibGit2.free` should be called afterward on the `Ref` object. """ -immutable Buffer +struct Buffer ptr::Ptr{Cchar} asize::Csize_t size::Csize_t @@ -118,7 +118,7 @@ function free(buf_ref::Base.Ref{Buffer}) end "Abstract credentials payload" -abstract AbstractCredentials +abstract type AbstractCredentials end "Checks if credentials were used" checkused!(p::AbstractCredentials) = true @@ -131,7 +131,7 @@ reset!(p::AbstractCredentials, cnt::Int=3) = nothing Matches the [`git_checkout_options`](https://libgit2.github.com/libgit2/#HEAD/type/git_checkout_options) struct. """ -@kwdef immutable CheckoutOptions +@kwdef struct CheckoutOptions version::Cuint = 1 checkout_strategy::Cuint = Consts.CHECKOUT_SAFE @@ -168,7 +168,7 @@ end Callback settings. Matches the [`git_remote_callbacks`](https://libgit2.github.com/libgit2/#HEAD/type/git_remote_callbacks) struct. """ -@kwdef immutable RemoteCallbacks +@kwdef struct RemoteCallbacks version::Cuint = 1 sideband_progress::Ptr{Void} completion::Ptr{Void} @@ -195,7 +195,7 @@ Options for connecting through a proxy. Matches the [`git_proxy_options`](https://libgit2.github.com/libgit2/#HEAD/type/git_proxy_options) struct. """ -@kwdef immutable ProxyOptions +@kwdef struct ProxyOptions version::Cuint = 1 proxytype::Cint url::Cstring @@ -210,7 +210,7 @@ end Matches the [`git_fetch_options`](https://libgit2.github.com/libgit2/#HEAD/type/git_fetch_options) struct. """ -@kwdef immutable FetchOptions +@kwdef struct FetchOptions version::Cuint = 1 callbacks::RemoteCallbacks prune::Cint = Consts.FETCH_PRUNE_UNSPECIFIED @@ -229,7 +229,7 @@ end Matches the [`git_clone_options`](https://libgit2.github.com/libgit2/#HEAD/type/git_clone_options) struct. """ -@kwdef immutable CloneOptions +@kwdef struct CloneOptions version::Cuint = 1 checkout_opts::CheckoutOptions fetch_opts::FetchOptions @@ -247,7 +247,7 @@ end Matches the [`git_diff_options`](https://libgit2.github.com/libgit2/#HEAD/type/git_diff_options) struct. """ -@kwdef immutable DiffOptionsStruct +@kwdef struct DiffOptionsStruct version::Cuint = Consts.DIFF_OPTIONS_VERSION flags::UInt32 = Consts.DIFF_NORMAL @@ -275,7 +275,7 @@ end Description of one side of a delta. Matches the [`git_diff_file`](https://libgit2.github.com/libgit2/#HEAD/type/git_diff_file) struct. """ -immutable DiffFile +struct DiffFile id::GitHash path::Cstring size::Int64 @@ -292,7 +292,7 @@ end Description of changes to one entry. Matches the [`git_diff_file`](https://libgit2.github.com/libgit2/#HEAD/type/git_diff_file) struct. """ -immutable DiffDelta +struct DiffDelta status::Cint flags::UInt32 similarity::UInt16 @@ -306,7 +306,7 @@ end Matches the [`git_merge_options`](https://libgit2.github.com/libgit2/#HEAD/type/git_merge_options) struct. """ -@kwdef immutable MergeOptions +@kwdef struct MergeOptions version::Cuint = 1 flags::Cint rename_threshold::Cuint = 50 @@ -327,7 +327,7 @@ end Matches the [`git_push_options`](https://libgit2.github.com/libgit2/#HEAD/type/git_push_options) struct. """ -@kwdef immutable PushOptions +@kwdef struct PushOptions version::Cuint = 1 parallelism::Cint = 1 callbacks::RemoteCallbacks @@ -344,7 +344,7 @@ end Matches the [`git_index_time`](https://libgit2.github.com/libgit2/#HEAD/type/git_index_time) struct. """ -immutable IndexTime +struct IndexTime seconds::Int64 nanoseconds::Cuint end @@ -355,7 +355,7 @@ end In-memory representation of a file entry in the index. Matches the [`git_index_entry`](https://libgit2.github.com/libgit2/#HEAD/type/git_index_entry) struct. """ -immutable IndexEntry +struct IndexEntry ctime::IndexTime mtime::IndexTime @@ -380,7 +380,7 @@ Base.show(io::IO, ie::IndexEntry) = print(io, "IndexEntry($(string(ie.id)))") Matches the `git_rebase_options` struct. """ -@kwdef immutable RebaseOptions +@kwdef struct RebaseOptions version::Cuint = 1 quiet::Cint = 1 @static if LibGit2.VERSION >= v"0.24.0" @@ -399,7 +399,7 @@ end Describes a single instruction/operation to be performed during the rebase. Matches the [`git_rebase_operation`](https://libgit2.github.com/libgit2/#HEAD/type/git_rebase_operation_t) struct. """ -immutable RebaseOperation +struct RebaseOperation optype::Cint id::GitHash exec::Cstring @@ -412,7 +412,7 @@ Base.show(io::IO, rbo::RebaseOperation) = print(io, "RebaseOperation($(string(rb Options to control how `git_status_foreach_ext()` will issue callbacks. Matches the [`git_status_opt_t`](https://libgit2.github.com/libgit2/#HEAD/type/git_status_opt_t) struct. """ -@kwdef immutable StatusOptions +@kwdef struct StatusOptions version::Cuint = 1 show::Cint = Consts.STATUS_SHOW_INDEX_AND_WORKDIR flags::Cuint = Consts.STATUS_OPT_INCLUDE_UNTRACKED | @@ -429,7 +429,7 @@ Providing the differences between the file as it exists in HEAD and the index, a providing the differences between the index and the working directory. Matches the `git_status_entry` struct. """ -immutable StatusEntry +struct StatusEntry status::Cuint head_to_index::Ptr{DiffDelta} index_to_workdir::Ptr{DiffDelta} @@ -442,7 +442,7 @@ Contains the information about HEAD during a fetch, including the name and URL of the branch fetched from, the oid of the HEAD, and whether the fetched HEAD has been merged locally. """ -immutable FetchHead +struct FetchHead name::String url::String oid::GitHash @@ -450,10 +450,10 @@ immutable FetchHead end # Abstract object types -abstract AbstractGitObject +abstract type AbstractGitObject end Base.isempty(obj::AbstractGitObject) = (obj.ptr == C_NULL) -abstract GitObject <: AbstractGitObject +abstract type GitObject <: AbstractGitObject end for (typ, reporef, sup, cname) in [ (:GitRepo, nothing, :AbstractGitObject, :git_repository), @@ -475,7 +475,7 @@ for (typ, reporef, sup, cname) in [ (:GitTag, :GitRepo, :GitObject, :git_tag)] if reporef === nothing - @eval type $typ <: $sup + @eval mutable struct $typ <: $sup ptr::Ptr{Void} function $typ(ptr::Ptr{Void},fin=true) # fin=false should only be used when the pointer should not be free'd @@ -490,7 +490,7 @@ for (typ, reporef, sup, cname) in [ end end elseif reporef == :Nullable - @eval type $typ <: $sup + @eval mutable struct $typ <: $sup nrepo::Nullable{GitRepo} ptr::Ptr{Void} function $typ(repo::GitRepo, ptr::Ptr{Void}) @@ -509,7 +509,7 @@ for (typ, reporef, sup, cname) in [ end end elseif reporef == :GitRepo - @eval type $typ <: $sup + @eval mutable struct $typ <: $sup repo::GitRepo ptr::Ptr{Void} function $typ(repo::GitRepo, ptr::Ptr{Void}) @@ -545,7 +545,7 @@ end This is a Julia wrapper around a pointer to a [`git_signature`](https://libgit2.github.com/libgit2/#HEAD/type/git_signature) object. """ -type GitSignature <: AbstractGitObject +mutable struct GitSignature <: AbstractGitObject ptr::Ptr{SignatureStruct} function GitSignature(ptr::Ptr{SignatureStruct}) @assert ptr != C_NULL @@ -562,7 +562,7 @@ function Base.close(obj::GitSignature) end # Structure has the same layout as SignatureStruct -type Signature +mutable struct Signature name::String email::String time::Int64 @@ -629,7 +629,7 @@ end import Base.securezero! "Credentials that support only `user` and `password` parameters" -type UserPasswordCredentials <: AbstractCredentials +mutable struct UserPasswordCredentials <: AbstractCredentials user::String pass::String prompt_if_incorrect::Bool # Whether to allow interactive prompting if the credentials are incorrect @@ -650,7 +650,7 @@ function securezero!(cred::UserPasswordCredentials) end "SSH credentials type" -type SSHCredentials <: AbstractCredentials +mutable struct SSHCredentials <: AbstractCredentials user::String pass::String pubkey::String @@ -676,7 +676,7 @@ function securezero!(cred::SSHCredentials) end "Credentials that support caching" -type CachedCredentials <: AbstractCredentials +mutable struct CachedCredentials <: AbstractCredentials cred::Dict{String,AbstractCredentials} count::Int # authentication failure protection count CachedCredentials() = new(Dict{String,AbstractCredentials}(),3) diff --git a/base/libuv.jl b/base/libuv.jl index 27e2d2cd392fa..1037e7ce03d9c 100644 --- a/base/libuv.jl +++ b/base/libuv.jl @@ -54,7 +54,7 @@ unpreserve_handle(x) = (v = uvhandles[x]::Int; v == 1 ? pop!(uvhandles,x) : (uvh ## Libuv error handling ## -type UVError <: Exception +mutable struct UVError <: Exception prefix::AbstractString code::Int32 UVError(p::AbstractString,code::Integer)=new(p,code) diff --git a/base/linalg/arnoldi.jl b/base/linalg/arnoldi.jl index ff73a7c8e7a3a..f5b7cc362ae58 100644 --- a/base/linalg/arnoldi.jl +++ b/base/linalg/arnoldi.jl @@ -302,7 +302,7 @@ end ## svds ### Restrict operator to BlasFloat because ARPACK only supports that. Loosen restriction ### when we switch to our own implementation -type SVDOperator{T<:BlasFloat,S} <: AbstractArray{T, 2} +mutable struct SVDOperator{T<:BlasFloat,S} <: AbstractArray{T, 2} X::S m::Int n::Int diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index 230948e39c362..e5e306d2013cd 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -1,7 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license # Bidiagonal matrices -type Bidiagonal{T} <: AbstractMatrix{T} +mutable struct Bidiagonal{T} <: AbstractMatrix{T} dv::Vector{T} # diagonal ev::Vector{T} # sub/super diagonal isupper::Bool # is upper bidiagonal (true) or lower (false) diff --git a/base/linalg/bunchkaufman.jl b/base/linalg/bunchkaufman.jl index ac155f1c3ed5f..8bc09855f614c 100644 --- a/base/linalg/bunchkaufman.jl +++ b/base/linalg/bunchkaufman.jl @@ -4,7 +4,7 @@ ## LD for BunchKaufman, UL for CholeskyDense, LU for LUDense and ## define size methods for Factorization types using it. -immutable BunchKaufman{T,S<:AbstractMatrix} <: Factorization{T} +struct BunchKaufman{T,S<:AbstractMatrix} <: Factorization{T} LD::S ipiv::Vector{BlasInt} uplo::Char diff --git a/base/linalg/cholesky.jl b/base/linalg/cholesky.jl index f01d07d9f2fa9..fa435ff564bbf 100644 --- a/base/linalg/cholesky.jl +++ b/base/linalg/cholesky.jl @@ -27,14 +27,14 @@ # checks of those fields before calls to LAPACK to check which version of the Cholesky # factorization the type represents. -immutable Cholesky{T,S<:AbstractMatrix} <: Factorization{T} +struct Cholesky{T,S<:AbstractMatrix} <: Factorization{T} factors::S uplo::Char end Cholesky{T}(A::AbstractMatrix{T}, uplo::Symbol) = Cholesky{T,typeof(A)}(A, char_uplo(uplo)) Cholesky{T}(A::AbstractMatrix{T}, uplo::Char) = Cholesky{T,typeof(A)}(A, uplo) -immutable CholeskyPivoted{T,S<:AbstractMatrix} <: Factorization{T} +struct CholeskyPivoted{T,S<:AbstractMatrix} <: Factorization{T} factors::S uplo::Char piv::Vector{BlasInt} diff --git a/base/linalg/diagonal.jl b/base/linalg/diagonal.jl index 7ef09ad1508a7..c115680ffc082 100644 --- a/base/linalg/diagonal.jl +++ b/base/linalg/diagonal.jl @@ -2,7 +2,7 @@ ## Diagonal matrices -immutable Diagonal{T} <: AbstractMatrix{T} +struct Diagonal{T} <: AbstractMatrix{T} diag::Vector{T} end """ diff --git a/base/linalg/eigen.jl b/base/linalg/eigen.jl index 87ff0da9804cb..b07894732beaf 100644 --- a/base/linalg/eigen.jl +++ b/base/linalg/eigen.jl @@ -1,7 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license # Eigendecomposition -immutable Eigen{T,V,S<:AbstractMatrix,U<:AbstractVector} <: Factorization{T} +struct Eigen{T,V,S<:AbstractMatrix,U<:AbstractVector} <: Factorization{T} values::U vectors::S Eigen{T,V,S,U}(values::AbstractVector{V}, vectors::AbstractMatrix{T}) where {T,V,S,U} = @@ -11,7 +11,7 @@ Eigen(values::AbstractVector{V}, vectors::AbstractMatrix{T}) where {T,V} = Eigen{T,V,typeof(vectors),typeof(values)}(values, vectors) # Generalized eigenvalue problem. -immutable GeneralizedEigen{T,V,S<:AbstractMatrix,U<:AbstractVector} <: Factorization{T} +struct GeneralizedEigen{T,V,S<:AbstractMatrix,U<:AbstractVector} <: Factorization{T} values::U vectors::S GeneralizedEigen{T,V,S,U}(values::AbstractVector{V}, vectors::AbstractMatrix{T}) where {T,V,S,U} = diff --git a/base/linalg/exceptions.jl b/base/linalg/exceptions.jl index 89dfee2e657ed..40320246f420b 100644 --- a/base/linalg/exceptions.jl +++ b/base/linalg/exceptions.jl @@ -6,11 +6,11 @@ export LAPACKException, PosDefException, RankDeficientException -type LAPACKException <: Exception +mutable struct LAPACKException <: Exception info::BlasInt end -type ARPACKException <: Exception +mutable struct ARPACKException <: Exception info::String end @@ -25,14 +25,14 @@ function ARPACKException(i::Integer) return ARPACKException("unspecified ARPACK error: $i") end -type SingularException <: Exception +mutable struct SingularException <: Exception info::BlasInt end -type PosDefException <: Exception +mutable struct PosDefException <: Exception info::BlasInt end -type RankDeficientException <: Exception +mutable struct RankDeficientException <: Exception info::BlasInt end diff --git a/base/linalg/factorization.jl b/base/linalg/factorization.jl index ac581f5466a47..872ae195a99d1 100644 --- a/base/linalg/factorization.jl +++ b/base/linalg/factorization.jl @@ -2,7 +2,7 @@ ## Matrix factorizations and decompositions -abstract Factorization{T} +abstract type Factorization{T} end eltype{T}(::Type{Factorization{T}}) = T transpose(F::Factorization) = error("transpose not implemented for $(typeof(F))") diff --git a/base/linalg/givens.jl b/base/linalg/givens.jl index 7471df3a8c19c..9100331761e5b 100644 --- a/base/linalg/givens.jl +++ b/base/linalg/givens.jl @@ -1,7 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license # givensAlgorithm functions are derived from LAPACK, see below -abstract AbstractRotation{T} +abstract type AbstractRotation{T} end transpose(R::AbstractRotation) = error("transpose not implemented for $(typeof(R)). Consider using conjugate transpose (') instead of transpose (.').") @@ -24,13 +24,13 @@ therefore be multiplied with matrices of arbitrary size as long as `i2<=size(A,2 See also: [`givens`](@ref) """ -immutable Givens{T} <: AbstractRotation{T} +struct Givens{T} <: AbstractRotation{T} i1::Int i2::Int c::T s::T end -type Rotation{T} <: AbstractRotation{T} +mutable struct Rotation{T} <: AbstractRotation{T} rotations::Vector{Givens{T}} end diff --git a/base/linalg/hessenberg.jl b/base/linalg/hessenberg.jl index 28cdcd2187194..e84dcedf62f7e 100644 --- a/base/linalg/hessenberg.jl +++ b/base/linalg/hessenberg.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -immutable Hessenberg{T,S<:AbstractMatrix} <: Factorization{T} +struct Hessenberg{T,S<:AbstractMatrix} <: Factorization{T} factors::S τ::Vector{T} Hessenberg{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} = @@ -53,7 +53,7 @@ function hessfact{T}(A::StridedMatrix{T}) return hessfact!(copy_oftype(A, S)) end -immutable HessenbergQ{T,S<:AbstractMatrix} <: AbstractMatrix{T} +struct HessenbergQ{T,S<:AbstractMatrix} <: AbstractMatrix{T} factors::S τ::Vector{T} HessenbergQ{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} = new(factors, τ) diff --git a/base/linalg/ldlt.jl b/base/linalg/ldlt.jl index 27989efb18436..55260cc46142e 100644 --- a/base/linalg/ldlt.jl +++ b/base/linalg/ldlt.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -immutable LDLt{T,S<:AbstractMatrix} <: Factorization{T} +struct LDLt{T,S<:AbstractMatrix} <: Factorization{T} data::S end diff --git a/base/linalg/lq.jl b/base/linalg/lq.jl index 8df48e9ddc6ed..a72aded3031b8 100644 --- a/base/linalg/lq.jl +++ b/base/linalg/lq.jl @@ -2,13 +2,13 @@ # LQ Factorizations -immutable LQ{T,S<:AbstractMatrix} <: Factorization{T} +struct LQ{T,S<:AbstractMatrix} <: Factorization{T} factors::S τ::Vector{T} LQ{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} = new(factors, τ) end -immutable LQPackedQ{T,S<:AbstractMatrix} <: AbstractMatrix{T} +struct LQPackedQ{T,S<:AbstractMatrix} <: AbstractMatrix{T} factors::Matrix{T} τ::Vector{T} LQPackedQ{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} = new(factors, τ) diff --git a/base/linalg/lu.jl b/base/linalg/lu.jl index a53795fdbc1fc..fa3e9d312b1d1 100644 --- a/base/linalg/lu.jl +++ b/base/linalg/lu.jl @@ -3,7 +3,7 @@ #################### # LU Factorization # #################### -immutable LU{T,S<:AbstractMatrix} <: Factorization{T} +struct LU{T,S<:AbstractMatrix} <: Factorization{T} factors::S ipiv::Vector{BlasInt} info::BlasInt diff --git a/base/linalg/qr.jl b/base/linalg/qr.jl index f4fade51b3680..d75abad392910 100644 --- a/base/linalg/qr.jl +++ b/base/linalg/qr.jl @@ -2,21 +2,21 @@ # QR and Hessenberg Factorizations -immutable QR{T,S<:AbstractMatrix} <: Factorization{T} +struct QR{T,S<:AbstractMatrix} <: Factorization{T} factors::S τ::Vector{T} QR{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} = new(factors, τ) end QR(factors::AbstractMatrix{T}, τ::Vector{T}) where {T} = QR{T,typeof(factors)}(factors, τ) # Note. For QRCompactWY factorization without pivoting, the WY representation based method introduced in LAPACK 3.4 -immutable QRCompactWY{S,M<:AbstractMatrix} <: Factorization{S} +struct QRCompactWY{S,M<:AbstractMatrix} <: Factorization{S} factors::M T::Matrix{S} QRCompactWY{S,M}(factors::AbstractMatrix{S}, T::AbstractMatrix{S}) where {S,M<:AbstractMatrix} = new(factors, T) end QRCompactWY(factors::AbstractMatrix{S}, T::AbstractMatrix{S}) where {S} = QRCompactWY{S,typeof(factors)}(factors, T) -immutable QRPivoted{T,S<:AbstractMatrix} <: Factorization{T} +struct QRPivoted{T,S<:AbstractMatrix} <: Factorization{T} factors::S τ::Vector{T} jpvt::Vector{BlasInt} @@ -343,14 +343,14 @@ end getq(A::QRCompactWY) = QRCompactWYQ(A.factors,A.T) getq(A::Union{QR, QRPivoted}) = QRPackedQ(A.factors,A.τ) -immutable QRPackedQ{T,S<:AbstractMatrix} <: AbstractMatrix{T} +struct QRPackedQ{T,S<:AbstractMatrix} <: AbstractMatrix{T} factors::S τ::Vector{T} QRPackedQ{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} = new(factors, τ) end QRPackedQ(factors::AbstractMatrix{T}, τ::Vector{T}) where {T} = QRPackedQ{T,typeof(factors)}(factors, τ) -immutable QRCompactWYQ{S, M<:AbstractMatrix} <: AbstractMatrix{S} +struct QRCompactWYQ{S, M<:AbstractMatrix} <: AbstractMatrix{S} factors::M T::Matrix{S} QRCompactWYQ{S,M}(factors::AbstractMatrix{S}, T::Matrix{S}) where {S,M<:AbstractMatrix} = new(factors, T) diff --git a/base/linalg/rowvector.jl b/base/linalg/rowvector.jl index b8d49eabc077b..3d8ad33b3a051 100644 --- a/base/linalg/rowvector.jl +++ b/base/linalg/rowvector.jl @@ -11,7 +11,7 @@ vector can be multiplied by a matrix on its right (such that `v.' * A = (A.' * v differs from a `1×n`-sized matrix by the facts that its transpose returns a vector and the inner product `v1.' * v2` returns a scalar, but will otherwise behave similarly. """ -immutable RowVector{T,V<:AbstractVector} <: AbstractMatrix{T} +struct RowVector{T,V<:AbstractVector} <: AbstractMatrix{T} vec::V function RowVector{T,V}(v::V) where V<:AbstractVector where T check_types(T,v) diff --git a/base/linalg/schur.jl b/base/linalg/schur.jl index 5d8a41193f21c..15cda0efbf18d 100644 --- a/base/linalg/schur.jl +++ b/base/linalg/schur.jl @@ -1,7 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license # Schur decomposition -immutable Schur{Ty,S<:AbstractMatrix} <: Factorization{Ty} +struct Schur{Ty,S<:AbstractMatrix} <: Factorization{Ty} T::S Z::S values::Vector @@ -139,7 +139,7 @@ either both included or both excluded via `select`. ordschur{Ty<:BlasFloat}(T::StridedMatrix{Ty}, Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) = ordschur!(copy(T), copy(Z), select) -immutable GeneralizedSchur{Ty,M<:AbstractMatrix} <: Factorization{Ty} +struct GeneralizedSchur{Ty,M<:AbstractMatrix} <: Factorization{Ty} S::M T::M alpha::Vector diff --git a/base/linalg/svd.jl b/base/linalg/svd.jl index 4c4dca7ce6f35..6854cbe99a19e 100644 --- a/base/linalg/svd.jl +++ b/base/linalg/svd.jl @@ -1,7 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license # Singular Value Decomposition -immutable SVD{T,Tr,M<:AbstractArray} <: Factorization{T} +struct SVD{T,Tr,M<:AbstractArray} <: Factorization{T} U::M S::Vector{Tr} Vt::M @@ -170,7 +170,7 @@ function A_ldiv_B!{Ta,Tb}(A::SVD{Ta}, B::StridedVecOrMat{Tb}) end # Generalized svd -immutable GeneralizedSVD{T,S} <: Factorization{T} +struct GeneralizedSVD{T,S} <: Factorization{T} U::S V::S Q::S diff --git a/base/linalg/symmetric.jl b/base/linalg/symmetric.jl index 51edfa0e3757a..1b7b7c6317a07 100644 --- a/base/linalg/symmetric.jl +++ b/base/linalg/symmetric.jl @@ -1,7 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license #Symmetric and Hermitian matrices -immutable Symmetric{T,S<:AbstractMatrix} <: AbstractMatrix{T} +struct Symmetric{T,S<:AbstractMatrix} <: AbstractMatrix{T} data::S uplo::Char end @@ -41,7 +41,7 @@ julia> Slower = Symmetric(A, :L) Note that `Supper` will not be equal to `Slower` unless `A` is itself symmetric (e.g. if `A == A.'`). """ Symmetric(A::AbstractMatrix, uplo::Symbol=:U) = (checksquare(A);Symmetric{eltype(A),typeof(A)}(A, char_uplo(uplo))) -immutable Hermitian{T,S<:AbstractMatrix} <: AbstractMatrix{T} +struct Hermitian{T,S<:AbstractMatrix} <: AbstractMatrix{T} data::S uplo::Char end diff --git a/base/linalg/triangular.jl b/base/linalg/triangular.jl index 10446edbe908a..45208cd4a822c 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -3,13 +3,13 @@ ## Triangular # could be renamed to Triangular when that name has been fully deprecated -abstract AbstractTriangular{T,S<:AbstractMatrix} <: AbstractMatrix{T} +abstract type AbstractTriangular{T,S<:AbstractMatrix} <: AbstractMatrix{T} end # First loop through all methods that don't need special care for upper/lower and unit diagonal for t in (:LowerTriangular, :UnitLowerTriangular, :UpperTriangular, :UnitUpperTriangular) @eval begin - immutable $t{T,S<:AbstractMatrix} <: AbstractTriangular{T,S} + struct $t{T,S<:AbstractMatrix} <: AbstractTriangular{T,S} data::S end $t(A::$t) = A diff --git a/base/linalg/tridiag.jl b/base/linalg/tridiag.jl index bb00136bc8cb2..9662501d0942d 100644 --- a/base/linalg/tridiag.jl +++ b/base/linalg/tridiag.jl @@ -3,7 +3,7 @@ #### Specialized matrix types #### ## (complex) symmetric tridiagonal matrices -immutable SymTridiagonal{T} <: AbstractMatrix{T} +struct SymTridiagonal{T} <: AbstractMatrix{T} dv::Vector{T} # diagonal ev::Vector{T} # subdiagonal function SymTridiagonal{T}(dv::Vector{T}, ev::Vector{T}) where T @@ -294,7 +294,7 @@ end ################### #Needed for inv_usmani() -type ZeroOffsetVector +mutable struct ZeroOffsetVector data::Vector end getindex( a::ZeroOffsetVector, i) = a.data[i+1] @@ -385,7 +385,7 @@ function setindex!(A::SymTridiagonal, x, i::Integer, j::Integer) end ## Tridiagonal matrices ## -immutable Tridiagonal{T} <: AbstractMatrix{T} +struct Tridiagonal{T} <: AbstractMatrix{T} dl::Vector{T} # sub-diagonal d::Vector{T} # diagonal du::Vector{T} # sup-diagonal diff --git a/base/linalg/uniformscaling.jl b/base/linalg/uniformscaling.jl index bad9ddff58a5b..be0a4f92562e4 100644 --- a/base/linalg/uniformscaling.jl +++ b/base/linalg/uniformscaling.jl @@ -4,7 +4,7 @@ import Base: copy, ctranspose, getindex, show, transpose, one, zero, inv, @_pure_meta, hcat, vcat, hvcat import Base.LinAlg: SingularException -immutable UniformScaling{T<:Number} +struct UniformScaling{T<:Number} λ::T end diff --git a/base/loading.jl b/base/loading.jl index 0e62463bc738b..aa746cdb01820 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -277,7 +277,7 @@ end # We throw PrecompilableError(true) when a module wants to be precompiled but isn't, # and PrecompilableError(false) when a module doesn't want to be precompiled but is -immutable PrecompilableError <: Exception +struct PrecompilableError <: Exception isprecompilable::Bool end function show(io::IO, ex::PrecompilableError) diff --git a/base/lock.jl b/base/lock.jl index e0bd86dfeff81..00d0fb9a93d95 100644 --- a/base/lock.jl +++ b/base/lock.jl @@ -10,7 +10,7 @@ Each `lock` must be matched with an `unlock`. This lock is NOT threadsafe. See `Threads.Mutex` for a threadsafe lock. """ -type ReentrantLock +mutable struct ReentrantLock locked_by::Nullable{Task} cond_wait::Condition reentrancy_cnt::Int @@ -124,7 +124,7 @@ Each acquire must be mached with a release. This construct is NOT threadsafe. """ -type Semaphore +mutable struct Semaphore sem_size::Int curr_cnt::Int cond_wait::Condition diff --git a/base/locks.jl b/base/locks.jl index 5f699c3f7507c..7ece049fe989b 100644 --- a/base/locks.jl +++ b/base/locks.jl @@ -17,7 +17,7 @@ Abstract supertype describing types that implement the thread-safe synchronization primitives: `lock`, `trylock`, `unlock`, and `islocked` """ -abstract AbstractLock +abstract type AbstractLock end # Test-and-test-and-set spin locks are quickest up to about 30ish # contending threads. If you have more contention than that, perhaps @@ -27,7 +27,7 @@ abstract AbstractLock See SpinLock. """ -immutable TatasLock <: AbstractLock +struct TatasLock <: AbstractLock handle::Atomic{Int} TatasLock() = new(Atomic{Int}(0)) end @@ -86,7 +86,7 @@ end See RecursiveSpinLock. """ -immutable RecursiveTatasLock <: AbstractLock +struct RecursiveTatasLock <: AbstractLock ownertid::Atomic{Int16} handle::Atomic{Int} RecursiveTatasLock() = new(Atomic{Int16}(0), Atomic{Int}(0)) @@ -179,7 +179,7 @@ on pthreads, this is a `pthread_mutex_t`. See also SpinLock for a lighter-weight lock. """ -type Mutex <: AbstractLock +mutable struct Mutex <: AbstractLock ownertid::Int16 handle::Ptr{Void} function Mutex() diff --git a/base/markdown/Common/block.jl b/base/markdown/Common/block.jl index 9a8aed8de78f6..0594ffe48fabc 100644 --- a/base/markdown/Common/block.jl +++ b/base/markdown/Common/block.jl @@ -4,7 +4,7 @@ # Paragraphs # –––––––––– -type Paragraph +mutable struct Paragraph content end @@ -40,7 +40,7 @@ end # Headers # ––––––– -type Header{level} +mutable struct Header{level} text end @@ -96,7 +96,7 @@ end # Code # –––– -type Code +mutable struct Code language::String code::String end @@ -125,7 +125,7 @@ end # Footnote # -------- -type Footnote +mutable struct Footnote id::String text end @@ -160,7 +160,7 @@ end # Quotes # –––––– -type BlockQuote +mutable struct BlockQuote content end @@ -189,7 +189,7 @@ end # Admonitions # ----------- -type Admonition +mutable struct Admonition category::String title::String content::Vector @@ -247,7 +247,7 @@ end # Lists # ––––– -type List +mutable struct List items::Vector{Any} ordered::Int # `-1` is unordered, `>= 0` is ordered. @@ -332,7 +332,7 @@ pushitem!(list, buffer) = push!(list.items, parse(String(take!(buffer))).content # HorizontalRule # –––––––––––––– -type HorizontalRule +mutable struct HorizontalRule end function horizontalrule(stream::IO, block::MD) diff --git a/base/markdown/Common/inline.jl b/base/markdown/Common/inline.jl index 46f94264d4761..1ef1171a9f647 100644 --- a/base/markdown/Common/inline.jl +++ b/base/markdown/Common/inline.jl @@ -4,7 +4,7 @@ # Emphasis # –––––––– -type Italic +mutable struct Italic text end @@ -14,7 +14,7 @@ function asterisk_italic(stream::IO, md::MD) return result === nothing ? nothing : Italic(parseinline(result, md)) end -type Bold +mutable struct Bold text end @@ -54,7 +54,7 @@ end # Images & Links # –––––––––––––– -type Image +mutable struct Image url::String alt::String end @@ -73,7 +73,7 @@ function image(stream::IO, md::MD) end end -type Link +mutable struct Link text url::String end @@ -147,7 +147,7 @@ end # Punctuation # ––––––––––– -type LineBreak end +mutable struct LineBreak end @trigger '\\' -> function linebreak(stream::IO, md::MD) diff --git a/base/markdown/GitHub/table.jl b/base/markdown/GitHub/table.jl index 04485669dc936..dc31fad954143 100644 --- a/base/markdown/GitHub/table.jl +++ b/base/markdown/GitHub/table.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -type Table +mutable struct Table rows::Vector{Vector{Any}} align::Vector{Symbol} end diff --git a/base/markdown/IPython/IPython.jl b/base/markdown/IPython/IPython.jl index 47d564b2df21d..1cceb3e616d4d 100644 --- a/base/markdown/IPython/IPython.jl +++ b/base/markdown/IPython/IPython.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -type LaTeX +mutable struct LaTeX formula::String end diff --git a/base/markdown/parse/config.jl b/base/markdown/parse/config.jl index d004a82009bdd..eba41283e5377 100644 --- a/base/markdown/parse/config.jl +++ b/base/markdown/parse/config.jl @@ -2,7 +2,7 @@ typealias InnerConfig Dict{Char, Vector{Function}} -type Config +mutable struct Config breaking::Vector{Function} regular::Vector{Function} inner::InnerConfig diff --git a/base/markdown/parse/parse.jl b/base/markdown/parse/parse.jl index 0b22c8306e8ea..c061ee6d10ee8 100644 --- a/base/markdown/parse/parse.jl +++ b/base/markdown/parse/parse.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -type MD +mutable struct MD content::Vector{Any} meta::Dict{Any, Any} diff --git a/base/mmap.jl b/base/mmap.jl index 96ba008e1d6e7..e9402b39442de 100644 --- a/base/mmap.jl +++ b/base/mmap.jl @@ -5,7 +5,7 @@ module Mmap const PAGESIZE = Int(is_unix() ? ccall(:jl_getpagesize, Clong, ()) : ccall(:jl_getallocationgranularity, Clong, ())) # for mmaps not backed by files -type Anonymous <: IO +mutable struct Anonymous <: IO name::AbstractString readonly::Bool create::Bool diff --git a/base/mpfr.jl b/base/mpfr.jl index 024860ef1ef39..214367a811616 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -61,7 +61,7 @@ julia> big"2.1" 2.099999999999999999999999999999999999999999999999999999999999999999999999999986 ``` """ -type BigFloat <: AbstractFloat +mutable struct BigFloat <: AbstractFloat prec::Clong sign::Cint exp::Clong diff --git a/base/multidimensional.jl b/base/multidimensional.jl index b99e4002f1132..a074afbc70ff7 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -13,7 +13,7 @@ module IteratorsMD export CartesianIndex, CartesianRange # CartesianIndex - immutable CartesianIndex{N} <: AbstractCartesianIndex{N} + struct CartesianIndex{N} <: AbstractCartesianIndex{N} I::NTuple{N,Int} CartesianIndex{N}(index::NTuple{N,Integer}) where {N} = new(index) end @@ -77,7 +77,7 @@ module IteratorsMD icmp(a, b) = ifelse(isless(a,b), 1, ifelse(a==b, 0, -1)) # Iteration - immutable CartesianRange{I<:CartesianIndex} + struct CartesianRange{I<:CartesianIndex} start::I stop::I end @@ -273,7 +273,7 @@ where `mask[I]` is true. This specialized type does not support indexing directly as doing so would require O(n) lookup time. `AbstractArray{Bool}` are wrapped with `LogicalIndex` upon calling `to_indices`. """ -immutable LogicalIndex{T, A<:AbstractArray{Bool}} <: AbstractVector{T} +struct LogicalIndex{T, A<:AbstractArray{Bool}} <: AbstractVector{T} mask::A sum::Int LogicalIndex{T,A}(mask::A) where {T,A<:AbstractArray{Bool}} = new(mask, countnz(mask)) @@ -1149,7 +1149,7 @@ end # TODO: this doesn't fit into the new hashing scheme in any obvious way -immutable Prehashed +struct Prehashed hash::UInt end hash(x::Prehashed) = x.hash diff --git a/base/multimedia.jl b/base/multimedia.jl index c364dedebef10..377874407ab36 100644 --- a/base/multimedia.jl +++ b/base/multimedia.jl @@ -12,7 +12,7 @@ export Display, display, pushdisplay, popdisplay, displayable, redisplay, # dispatch show and to add conversions for new types. # defined in sysimg.jl for bootstrapping: -# immutable MIME{mime} end +# struct MIME{mime} end # macro MIME_str(s) import Base: MIME, @MIME_str @@ -119,7 +119,7 @@ end # cannot be displayed. The return value of display(...) is up to the # Display type. -abstract Display +abstract type Display end # it is convenient to accept strings instead of ::MIME display(d::Display, mime::AbstractString, x) = display(d, MIME(mime), x) @@ -145,7 +145,7 @@ Returns a `TextDisplay <: Display`, which displays any object as the text/plain (by default), writing the text representation to the given I/O stream. (This is how objects are printed in the Julia REPL.) """ -immutable TextDisplay <: Display +struct TextDisplay <: Display io::IO end display(d::TextDisplay, M::MIME"text/plain", x) = show(d.io, M, x) diff --git a/base/multinverses.jl b/base/multinverses.jl index c1a72ec84ecde..765d5a55f0804 100644 --- a/base/multinverses.jl +++ b/base/multinverses.jl @@ -13,7 +13,7 @@ unsigned(::Type{Int64}) = UInt64 unsigned(::Type{Int128}) = UInt128 unsigned{T<:Unsigned}(::Type{T}) = T -abstract MultiplicativeInverse{T} +abstract type MultiplicativeInverse{T} end # Computes integer division by a constant using multiply, add, and bitshift. @@ -43,7 +43,7 @@ abstract MultiplicativeInverse{T} # # Further details can be found in Hacker's Delight, Chapter 10. -immutable SignedMultiplicativeInverse{T<:Signed} <: MultiplicativeInverse{T} +struct SignedMultiplicativeInverse{T<:Signed} <: MultiplicativeInverse{T} divisor::T multiplier::T addmul::Int8 @@ -88,7 +88,7 @@ immutable SignedMultiplicativeInverse{T<:Signed} <: MultiplicativeInverse{T} end SignedMultiplicativeInverse(x::Signed) = SignedMultiplicativeInverse{typeof(x)}(x) -immutable UnsignedMultiplicativeInverse{T<:Unsigned} <: MultiplicativeInverse{T} +struct UnsignedMultiplicativeInverse{T<:Unsigned} <: MultiplicativeInverse{T} divisor::T multiplier::T add::Bool diff --git a/base/nullable.jl b/base/nullable.jl index f249d1ab712ce..1b301f7c0e396 100644 --- a/base/nullable.jl +++ b/base/nullable.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -immutable NullException <: Exception +struct NullException <: Exception end """ diff --git a/base/operators.jl b/base/operators.jl index ebf140ca0e599..091c3f71feb5c 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -1138,7 +1138,7 @@ ranges with the same indices as those they wrap. This means that indexing into Slice objects with an integer always returns that exact integer, and they iterate over all the wrapped indices, even supporting offset indices. """ -immutable Slice{T<:AbstractUnitRange} <: AbstractUnitRange{Int} +struct Slice{T<:AbstractUnitRange} <: AbstractUnitRange{Int} indices::T end indices(S::Slice) = (S.indices,) @@ -1191,7 +1191,7 @@ end # Pair -immutable Pair{A,B} +struct Pair{A,B} first::A second::B end diff --git a/base/options.jl b/base/options.jl index f3ef8d1a7cd24..ac8d7643680d5 100644 --- a/base/options.jl +++ b/base/options.jl @@ -1,7 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license # NOTE: This type needs to be kept in sync with jl_options in src/julia.h -immutable JLOptions +struct JLOptions quiet::Int8 julia_home::Ptr{UInt8} julia_bin::Ptr{UInt8} diff --git a/base/ordering.jl b/base/ordering.jl index c3015f76315f8..7bfd85f8facb6 100644 --- a/base/ordering.jl +++ b/base/ordering.jl @@ -11,10 +11,10 @@ export # not exported by Base DirectOrdering, lt, ord, ordtype -abstract Ordering +abstract type Ordering end -immutable ForwardOrdering <: Ordering end -immutable ReverseOrdering{Fwd<:Ordering} <: Ordering +struct ForwardOrdering <: Ordering end +struct ReverseOrdering{Fwd<:Ordering} <: Ordering fwd::Fwd end @@ -26,18 +26,18 @@ typealias DirectOrdering Union{ForwardOrdering,ReverseOrdering{ForwardOrdering}} const Forward = ForwardOrdering() const Reverse = ReverseOrdering(Forward) -immutable LexicographicOrdering <: Ordering end +struct LexicographicOrdering <: Ordering end const Lexicographic = LexicographicOrdering() -immutable By{T} <: Ordering +struct By{T} <: Ordering by::T end -immutable Lt{T} <: Ordering +struct Lt{T} <: Ordering lt::T end -immutable Perm{O<:Ordering,V<:AbstractVector} <: Ordering +struct Perm{O<:Ordering,V<:AbstractVector} <: Ordering order::O data::V end diff --git a/base/parallel/cluster.jl b/base/parallel/cluster.jl index 847a8270f3979..5225b33edb507 100644 --- a/base/parallel/cluster.jl +++ b/base/parallel/cluster.jl @@ -1,8 +1,8 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -abstract ClusterManager +abstract type ClusterManager end -type WorkerConfig +mutable struct WorkerConfig # Common fields relevant to all cluster managers io::Nullable{IO} host::Nullable{AbstractString} @@ -51,7 +51,7 @@ type WorkerConfig end @enum WorkerState W_CREATED W_CONNECTED W_TERMINATING W_TERMINATED -type Worker +mutable struct Worker id::Int del_msgs::Array{Any,1} add_msgs::Array{Any,1} @@ -119,7 +119,7 @@ end ## process group creation ## -type LocalProcess +mutable struct LocalProcess id::Int bind_addr::AbstractString bind_port::UInt16 @@ -557,7 +557,7 @@ let next_pid = 2 # 1 is reserved for the client (always) end end -type ProcessGroup +mutable struct ProcessGroup name::AbstractString workers::Array{Any,1} refs::Dict # global references @@ -736,7 +736,7 @@ After a client Julia process has exited, further attempts to reference the dead throw this exception. """ ProcessExitedException() -type ProcessExitedException <: Exception end +mutable struct ProcessExitedException <: Exception end worker_from_id(i) = worker_from_id(PGRP, i) function worker_from_id(pg::ProcessGroup, i) diff --git a/base/parallel/clusterserialize.jl b/base/parallel/clusterserialize.jl index 5aed58c648152..f89d7992a5aff 100644 --- a/base/parallel/clusterserialize.jl +++ b/base/parallel/clusterserialize.jl @@ -4,7 +4,7 @@ using Base.Serializer: known_object_data, object_number, serialize_cycle, deseri __deserialized_types__, serialize_typename, deserialize_typename, TYPENAME_TAG, object_numbers, reset_state, serialize_type -type ClusterSerializer{I<:IO} <: AbstractSerializer +mutable struct ClusterSerializer{I<:IO} <: AbstractSerializer io::I counter::Int table::ObjectIdDict @@ -86,7 +86,7 @@ end # Send/resend a global object if # a) has not been sent previously, i.e., we are seeing this object_id for the first time, or, # b) hash value has changed or -# c) is a bitstype +# c) is a bits type function syms_2b_sent(s::ClusterSerializer, identifier) lst = Symbol[] check_syms = get(s.glbs_in_tnobj, identifier, []) diff --git a/base/parallel/managers.jl b/base/parallel/managers.jl index c270183c40587..f06d3fa0245ed 100644 --- a/base/parallel/managers.jl +++ b/base/parallel/managers.jl @@ -2,7 +2,7 @@ # Built-in SSH and Local Managers -immutable SSHManager <: ClusterManager +struct SSHManager <: ClusterManager machines::Dict function SSHManager(machines) @@ -282,7 +282,7 @@ end # LocalManager -immutable LocalManager <: ClusterManager +struct LocalManager <: ClusterManager np::Integer restrict::Bool # Restrict binding to 127.0.0.1 only end @@ -365,7 +365,7 @@ manage # DefaultClusterManager for the default TCP transport - used by both SSHManager and LocalManager -immutable DefaultClusterManager <: ClusterManager +struct DefaultClusterManager <: ClusterManager end const tunnel_hosts_map = Dict{AbstractString, Semaphore}() diff --git a/base/parallel/messages.jl b/base/parallel/messages.jl index 39c2d1c49f2b3..dc95b032e2efa 100644 --- a/base/parallel/messages.jl +++ b/base/parallel/messages.jl @@ -1,13 +1,13 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -abstract AbstractMsg +abstract type AbstractMsg end let REF_ID::Int = 1 global next_ref_id next_ref_id() = (id = REF_ID; REF_ID += 1; id) end -immutable RRID +struct RRID whence::Int id::Int @@ -26,7 +26,7 @@ hash(r::RRID, h::UInt) = hash(r.whence, hash(r.id, h)) # Message header stored separately from body to be able to send back errors if # a deserialization error occurs when reading the message body. -immutable MsgHeader +struct MsgHeader response_oid::RRID notify_oid::RRID MsgHeader(respond_oid=RRID(0,0), notify_oid=RRID(0,0)) = @@ -37,41 +37,41 @@ end # Used instead of Nullable to decrease wire size of header. null_id(id) = id == RRID(0, 0) -immutable CallMsg{Mode} <: AbstractMsg +struct CallMsg{Mode} <: AbstractMsg f::Function args::Tuple kwargs::Array end -immutable CallWaitMsg <: AbstractMsg +struct CallWaitMsg <: AbstractMsg f::Function args::Tuple kwargs::Array end -immutable RemoteDoMsg <: AbstractMsg +struct RemoteDoMsg <: AbstractMsg f::Function args::Tuple kwargs::Array end -immutable ResultMsg <: AbstractMsg +struct ResultMsg <: AbstractMsg value::Any end # Worker initialization messages -immutable IdentifySocketMsg <: AbstractMsg +struct IdentifySocketMsg <: AbstractMsg from_pid::Int end -immutable IdentifySocketAckMsg <: AbstractMsg +struct IdentifySocketAckMsg <: AbstractMsg end -immutable JoinPGRPMsg <: AbstractMsg +struct JoinPGRPMsg <: AbstractMsg self_pid::Int other_workers::Array topology::Symbol enable_threaded_blas::Bool end -immutable JoinCompleteMsg <: AbstractMsg +struct JoinCompleteMsg <: AbstractMsg cpu_cores::Int ospid::Int end diff --git a/base/parallel/pmap.jl b/base/parallel/pmap.jl index 926f4f776549a..9e8c6530796f1 100644 --- a/base/parallel/pmap.jl +++ b/base/parallel/pmap.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -type BatchProcessingError <: Exception +mutable struct BatchProcessingError <: Exception data ex end diff --git a/base/parallel/process_messages.jl b/base/parallel/process_messages.jl index e0c8cf5f0e7ac..d9bac73f9545e 100644 --- a/base/parallel/process_messages.jl +++ b/base/parallel/process_messages.jl @@ -2,7 +2,7 @@ # data stored by the owner of a remote reference def_rv_channel() = Channel(1) -type RemoteValue +mutable struct RemoteValue c::AbstractChannel clientset::IntSet # Set of workerids that have a reference to this channel. # Keeping ids instead of a count aids in cleaning up upon @@ -16,7 +16,7 @@ end wait(rv::RemoteValue) = wait(rv.c) ## core messages: do, call, fetch, wait, ref, put! ## -type RemoteException <: Exception +mutable struct RemoteException <: Exception pid::Int captured::CapturedException end diff --git a/base/parallel/remotecall.jl b/base/parallel/remotecall.jl index 0cbef021603a5..eed3fa2eeba24 100644 --- a/base/parallel/remotecall.jl +++ b/base/parallel/remotecall.jl @@ -10,9 +10,9 @@ The `client_refs` lock is also used to synchronize access to `.refs` and associa """ const client_refs = WeakKeyDict{Any, Void}() # used as a WeakKeySet -abstract AbstractRemoteRef +abstract type AbstractRemoteRef end -type Future <: AbstractRemoteRef +mutable struct Future <: AbstractRemoteRef where::Int whence::Int id::Int @@ -22,7 +22,7 @@ type Future <: AbstractRemoteRef Future(w::Int, rrid::RRID, v) = (r = new(w,rrid.whence,rrid.id,v); return test_existing_ref(r)) end -type RemoteChannel{T<:AbstractChannel} <: AbstractRemoteRef +mutable struct RemoteChannel{T<:AbstractChannel} <: AbstractRemoteRef where::Int whence::Int id::Int diff --git a/base/parallel/workerpool.jl b/base/parallel/workerpool.jl index bb390c8b94c7a..2c5f772f706a0 100644 --- a/base/parallel/workerpool.jl +++ b/base/parallel/workerpool.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -abstract AbstractWorkerPool +abstract type AbstractWorkerPool end # An AbstractWorkerPool should implement # @@ -15,7 +15,7 @@ abstract AbstractWorkerPool # workers::Set{Int} # -type WorkerPool <: AbstractWorkerPool +mutable struct WorkerPool <: AbstractWorkerPool channel::Channel{Int} workers::Set{Int} ref::RemoteChannel @@ -214,7 +214,7 @@ using [`remotecall_fetch`](@ref). remote(f) = (args...; kwargs...)->remotecall_fetch(f, default_worker_pool(), args...; kwargs...) remote(p::AbstractWorkerPool, f) = (args...; kwargs...)->remotecall_fetch(f, p, args...; kwargs...) -type CachingPool <: AbstractWorkerPool +mutable struct CachingPool <: AbstractWorkerPool channel::Channel{Int} workers::Set{Int} diff --git a/base/permuteddimsarray.jl b/base/permuteddimsarray.jl index 133ad971871b1..591298551caab 100644 --- a/base/permuteddimsarray.jl +++ b/base/permuteddimsarray.jl @@ -5,7 +5,7 @@ module PermutedDimsArrays export permutedims, PermutedDimsArray # Some day we will want storage-order-aware iteration, so put perm in the parameters -immutable PermutedDimsArray{T,N,perm,iperm,AA<:AbstractArray} <: AbstractArray{T,N} +struct PermutedDimsArray{T,N,perm,iperm,AA<:AbstractArray} <: AbstractArray{T,N} parent::AA function PermutedDimsArray{T,N,perm,iperm,AA}(data::AA) where {T,N,perm,iperm,AA<:AbstractArray} diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index 13eb492f1f785..0d53268f96d5a 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -732,7 +732,7 @@ function test!(pkg::AbstractString, isfile(reqs_path) && resolve() end -type PkgTestError <: Exception +mutable struct PkgTestError <: Exception msg::String end diff --git a/base/pkg/pkg.jl b/base/pkg/pkg.jl index edb3a03a010f9..c5d9836a0b949 100644 --- a/base/pkg/pkg.jl +++ b/base/pkg/pkg.jl @@ -9,7 +9,7 @@ export dir, init, rm, add, available, installed, status, clone, checkout, const DEFAULT_META = "https://github.com/JuliaLang/METADATA.jl" const META_BRANCH = "metadata-v2" -type PkgError <: Exception +mutable struct PkgError <: Exception msg::AbstractString ex::Nullable{Exception} end diff --git a/base/pkg/reqs.jl b/base/pkg/reqs.jl index 003b82496e3c9..131cf06a40d7d 100644 --- a/base/pkg/reqs.jl +++ b/base/pkg/reqs.jl @@ -8,11 +8,11 @@ using ..Types # representing lines of REQUIRE files -abstract Line -immutable Comment <: Line +abstract type Line end +struct Comment <: Line content::AbstractString end -immutable Requirement <: Line +struct Requirement <: Line content::AbstractString package::AbstractString versions::VersionSet diff --git a/base/pkg/resolve/fieldvalue.jl b/base/pkg/resolve/fieldvalue.jl index 701c1a26f252c..20a79b44f9591 100644 --- a/base/pkg/resolve/fieldvalue.jl +++ b/base/pkg/resolve/fieldvalue.jl @@ -19,7 +19,7 @@ export FieldValue, Field, validmax, secondmax # l4 : for favoring dependants over dependencies # l5 : for symmetry-breaking random noise # -immutable FieldValue +struct FieldValue l0::Int l1::VersionWeight l2::VersionWeight diff --git a/base/pkg/resolve/interface.jl b/base/pkg/resolve/interface.jl index a9b8f35ab7313..67eda62e39ddc 100644 --- a/base/pkg/resolve/interface.jl +++ b/base/pkg/resolve/interface.jl @@ -9,7 +9,7 @@ export Interface, compute_output_dict, greedysolver, # A collection of objects which allow interfacing external (Pkg) and # internal (MaxSum) representation -type Interface +mutable struct Interface # requirements and dependencies, in external representation reqs::Requires deps::Dict{String,Dict{VersionNumber,Available}} diff --git a/base/pkg/resolve/maxsum.jl b/base/pkg/resolve/maxsum.jl index acc172fc23782..55c02a2925a9c 100644 --- a/base/pkg/resolve/maxsum.jl +++ b/base/pkg/resolve/maxsum.jl @@ -10,12 +10,12 @@ export UnsatError, Graph, Messages, maxsum # An exception type used internally to signal that an unsatisfiable # constraint was detected -type UnsatError <: Exception +mutable struct UnsatError <: Exception info end # Some parameters to drive the decimation process -type MaxSumParams +mutable struct MaxSumParams nondec_iterations # number of initial iterations before starting # decimation dec_interval # number of iterations between decimations @@ -36,7 +36,7 @@ end # Graph holds the graph structure onto which max-sum is run, in # sparse format -type Graph +mutable struct Graph # adjacency matrix: # for each package, has the list of neighbors # indices (both dependencies and dependants) @@ -158,7 +158,7 @@ end # Messages has the cavity messages and the total fields, and # gets updated iteratively (and occasionally decimated) until # convergence -type Messages +mutable struct Messages # cavity incoming messages: for each package p0, # for each neighbor p1 of p0, # msg[p0][p1] is a vector of length spp[p0] diff --git a/base/pkg/resolve/versionweight.jl b/base/pkg/resolve/versionweight.jl index 0593544a05ee6..faa16874d59d1 100644 --- a/base/pkg/resolve/versionweight.jl +++ b/base/pkg/resolve/versionweight.jl @@ -6,7 +6,7 @@ importall ....Base.Operators export VersionWeight -immutable HierarchicalValue{T} +struct HierarchicalValue{T} v::Vector{T} rest::T end @@ -68,7 +68,7 @@ Base.:(==){T}(a::HierarchicalValue{T}, b::HierarchicalValue{T}) = cmp(a,b) == 0 Base.abs{T}(a::HierarchicalValue{T}) = HierarchicalValue(T[abs(x) for x in a.v], abs(a.rest)) -immutable VWPreBuildItem +struct VWPreBuildItem nonempty::Int s::HierarchicalValue{Int} i::Int @@ -96,7 +96,7 @@ Base.:(==)(a::VWPreBuildItem, b::VWPreBuildItem) = cmp(a,b) == 0 Base.abs(a::VWPreBuildItem) = VWPreBuildItem(abs(a.nonempty), abs(a.s), abs(a.i)) -immutable VWPreBuild +struct VWPreBuild nonempty::Int w::HierarchicalValue{VWPreBuildItem} end @@ -153,7 +153,7 @@ end # The numeric type used to determine how the different # versions of a package should be weighed -immutable VersionWeight +struct VersionWeight major::Int minor::Int patch::Int diff --git a/base/pkg/types.jl b/base/pkg/types.jl index 1c05659f380b4..6ca8a0f389a98 100644 --- a/base/pkg/types.jl +++ b/base/pkg/types.jl @@ -6,7 +6,7 @@ export VersionInterval, VersionSet, Requires, Available, Fixed, merge_requires!, ResolveBacktraceItem, ResolveBacktrace import Base: show, isempty, in, intersect, union!, union, ==, hash, copy, deepcopy_internal, push! -immutable VersionInterval +struct VersionInterval lower::VersionNumber upper::VersionNumber end @@ -20,7 +20,7 @@ intersect(a::VersionInterval, b::VersionInterval) = VersionInterval(max(a.lower, ==(a::VersionInterval, b::VersionInterval) = a.lower == b.lower && a.upper == b.upper hash(i::VersionInterval, h::UInt) = hash((i.lower, i.upper), h + (0x0f870a92db508386 % UInt)) -immutable VersionSet +struct VersionSet intervals::Vector{VersionInterval} end function VersionSet(versions::Vector{VersionNumber}) @@ -121,7 +121,7 @@ end satisfies(pkg::AbstractString, ver::VersionNumber, reqs::Requires) = !haskey(reqs, pkg) || in(ver, reqs[pkg]) -immutable Available +struct Available sha1::String requires::Requires end @@ -134,7 +134,7 @@ show(io::IO, a::Available) = isempty(a.requires) ? print(io, "Available(", repr(a.sha1), ")") : print(io, "Available(", repr(a.sha1), ",", a.requires, ")") -immutable Fixed +struct Fixed version::VersionNumber requires::Requires end diff --git a/base/poll.jl b/base/poll.jl index 9fa13085bda2d..6cda7fa4ad8ca 100644 --- a/base/poll.jl +++ b/base/poll.jl @@ -20,7 +20,7 @@ end # libuv file watching event flags const UV_RENAME = 1 const UV_CHANGE = 2 -immutable FileEvent +struct FileEvent renamed::Bool changed::Bool timedout::Bool @@ -31,7 +31,7 @@ FileEvent(flags::Integer) = FileEvent((flags & UV_RENAME) != 0, (flags & FD_TIMEDOUT) != 0) fetimeout() = FileEvent(false, false, true) -immutable FDEvent +struct FDEvent readable::Bool writable::Bool disconnect::Bool @@ -57,7 +57,7 @@ fdtimeout() = FDEvent(false, false, false, true) a.disconnect | b.disconnect, a.timedout | b.timedout) -type FileMonitor +mutable struct FileMonitor handle::Ptr{Void} file::String notify::Condition @@ -76,7 +76,7 @@ type FileMonitor end end -type PollingFileWatcher +mutable struct PollingFileWatcher handle::Ptr{Void} file::String interval::UInt32 @@ -96,7 +96,7 @@ type PollingFileWatcher end end -type _FDWatcher +mutable struct _FDWatcher handle::Ptr{Void} fdnum::Int # this is NOT the file descriptor refcount::Tuple{Int, Int} @@ -195,7 +195,7 @@ type _FDWatcher end end -type FDWatcher +mutable struct FDWatcher watcher::_FDWatcher readable::Bool writable::Bool diff --git a/base/process.jl b/base/process.jl index cb8859cb60183..09f45f466b0dd 100644 --- a/base/process.jl +++ b/base/process.jl @@ -1,13 +1,13 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -abstract AbstractCmd +abstract type AbstractCmd end # libuv process option flags const UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS = UInt8(1 << 2) const UV_PROCESS_DETACHED = UInt8(1 << 3) const UV_PROCESS_WINDOWS_HIDE = UInt8(1 << 4) -immutable Cmd <: AbstractCmd +struct Cmd <: AbstractCmd exec::Vector{String} ignorestatus::Bool flags::UInt32 # libuv process flags @@ -76,19 +76,19 @@ hash(x::Cmd, h::UInt) = hash(x.exec, hash(x.env, hash(x.ignorestatus, hash(x.dir ==(x::Cmd, y::Cmd) = x.exec == y.exec && x.env == y.env && x.ignorestatus == y.ignorestatus && x.dir == y.dir && isequal(x.flags, y.flags) -immutable OrCmds <: AbstractCmd +struct OrCmds <: AbstractCmd a::AbstractCmd b::AbstractCmd OrCmds(a::AbstractCmd, b::AbstractCmd) = new(a, b) end -immutable ErrOrCmds <: AbstractCmd +struct ErrOrCmds <: AbstractCmd a::AbstractCmd b::AbstractCmd ErrOrCmds(a::AbstractCmd, b::AbstractCmd) = new(a, b) end -immutable AndCmds <: AbstractCmd +struct AndCmds <: AbstractCmd a::AbstractCmd b::AbstractCmd AndCmds(a::AbstractCmd, b::AbstractCmd) = new(a, b) @@ -137,7 +137,7 @@ const STDIN_NO = 0 const STDOUT_NO = 1 const STDERR_NO = 2 -immutable FileRedirect +struct FileRedirect filename::AbstractString append::Bool function FileRedirect(filename, append) @@ -161,7 +161,7 @@ uvtype(x::RawFD) = UV_RAW_FD typealias Redirectable Union{IO, FileRedirect, RawFD} typealias StdIOSet NTuple{3, Union{Redirectable, Ptr{Void}}} # XXX: remove Ptr{Void} once libuv is refactored to use upstream release -immutable CmdRedirect <: AbstractCmd +struct CmdRedirect <: AbstractCmd cmd::AbstractCmd handle::Redirectable stream_no::Int @@ -305,7 +305,7 @@ run(pipeline("out.txt", `grep xyz`)) """ pipeline(a, b, c, d...) = pipeline(pipeline(a,b), c, d...) -type Process <: AbstractPipe +mutable struct Process <: AbstractPipe cmd::Cmd handle::Ptr{Void} in::IO @@ -339,7 +339,7 @@ end pipe_reader(p::Process) = p.out pipe_writer(p::Process) = p.in -immutable ProcessChain <: AbstractPipe +struct ProcessChain <: AbstractPipe processes::Vector{Process} in::Redirectable out::Redirectable diff --git a/base/profile.jl b/base/profile.jl index bda1c761f1b95..325d8693c4151 100644 --- a/base/profile.jl +++ b/base/profile.jl @@ -76,7 +76,7 @@ clear() = ccall(:jl_profile_clear_data, Void, ()) typealias LineInfoDict Dict{UInt64, Vector{StackFrame}} typealias LineInfoFlatDict Dict{UInt64, StackFrame} -immutable ProfileFormat +struct ProfileFormat maxdepth::Int mincount::Int noisefloor::Float64 diff --git a/base/random.jl b/base/random.jl index ed7cd3174567e..1e731d750fee0 100644 --- a/base/random.jl +++ b/base/random.jl @@ -19,18 +19,18 @@ export srand, GLOBAL_RNG, randjump -abstract AbstractRNG +abstract type AbstractRNG end -abstract FloatInterval -type CloseOpen <: FloatInterval end -type Close1Open2 <: FloatInterval end +abstract type FloatInterval end +mutable struct CloseOpen <: FloatInterval end +mutable struct Close1Open2 <: FloatInterval end ## RandomDevice if is_windows() - immutable RandomDevice <: AbstractRNG + struct RandomDevice <: AbstractRNG buffer::Vector{UInt128} RandomDevice() = new(Array{UInt128}(1)) @@ -43,7 +43,7 @@ if is_windows() rand!{T<:Union{Bool, Base.BitInteger}}(rd::RandomDevice, A::Array{T}) = (win32_SystemFunction036!(A); A) else # !windows - immutable RandomDevice <: AbstractRNG + struct RandomDevice <: AbstractRNG file::IOStream unlimited::Bool @@ -73,7 +73,7 @@ rand(rng::RandomDevice, ::Type{CloseOpen}) = rand(rng, Close1Open2) - 1.0 const MTCacheLength = dsfmt_get_min_array_size() -type MersenneTwister <: AbstractRNG +mutable struct MersenneTwister <: AbstractRNG seed::Vector{UInt32} state::DSFMT_state vals::Vector{Float64} @@ -528,9 +528,9 @@ maxmultiple{T<:Unsigned}(k::T) = (div(typemax(T) - k + oneunit(k), k + (k == 0)) # maximum multiple of k within 1:2^32 or 1:2^64 decremented by one, depending on size maxmultiplemix(k::UInt64) = if k >> 32 != 0; maxmultiple(k); else (div(0x0000000100000000, k + (k == 0))*k - oneunit(k))::UInt64; end -abstract RangeGenerator +abstract type RangeGenerator end -immutable RangeGeneratorInt{T<:Integer, U<:Unsigned} <: RangeGenerator +struct RangeGeneratorInt{T<:Integer, U<:Unsigned} <: RangeGenerator a::T # first element of the range k::U # range length or zero for full range u::U # rejection threshold @@ -561,7 +561,7 @@ for (T, U) in [(UInt8, UInt32), (UInt16, UInt32), end if GMP_VERSION.major >= 6 - immutable RangeGeneratorBigInt <: RangeGenerator + struct RangeGeneratorBigInt <: RangeGenerator a::BigInt # first m::BigInt # range length - 1 nlimbs::Int # number of limbs in generated BigInt's @@ -569,7 +569,7 @@ if GMP_VERSION.major >= 6 end else - immutable RangeGeneratorBigInt <: RangeGenerator + struct RangeGeneratorBigInt <: RangeGenerator a::BigInt # first m::BigInt # range length - 1 limbs::Vector{Limb} # buffer to be copied into generated BigInt's @@ -1302,7 +1302,7 @@ end ## random UUID generation -immutable UUID +struct UUID value::UInt128 UUID(u::UInt128) = new(u) diff --git a/base/range.jl b/base/range.jl index 6089c32c8e982..e195bf1efbcd6 100644 --- a/base/range.jl +++ b/base/range.jl @@ -58,14 +58,14 @@ range(a::AbstractFloat, st::Real, len::Integer) = range(a, float(st), len) ## 1-dimensional ranges ## -abstract Range{T} <: AbstractArray{T,1} +abstract type Range{T} <: AbstractArray{T,1} end ## ordinal ranges -abstract OrdinalRange{T,S} <: Range{T} -abstract AbstractUnitRange{T} <: OrdinalRange{T,Int} +abstract type OrdinalRange{T,S} <: Range{T} end +abstract type AbstractUnitRange{T} <: OrdinalRange{T,Int} end -immutable StepRange{T,S} <: OrdinalRange{T,S} +struct StepRange{T,S} <: OrdinalRange{T,S} start::T step::S stop::T @@ -125,7 +125,7 @@ steprem(start,stop,step) = (stop-start) % step StepRange(start::T, step::S, stop::T) where {T,S} = StepRange{T,S}(start, step, stop) -immutable UnitRange{T<:Real} <: AbstractUnitRange{T} +struct UnitRange{T<:Real} <: AbstractUnitRange{T} start::T stop::T UnitRange{T}(start, stop) where T<:Real = new(start, unitrange_last(start,stop)) @@ -146,7 +146,7 @@ Define an `AbstractUnitRange` that behaves like `1:n`, with the added distinction that the lower limit is guaranteed (by the type system) to be 1. """ -immutable OneTo{T<:Integer} <: AbstractUnitRange{T} +struct OneTo{T<:Integer} <: AbstractUnitRange{T} stop::T OneTo{T}(stop) where T<:Integer = new(max(zero(T), stop)) end @@ -164,7 +164,7 @@ value of `r[offset]` for some other index `1 <= offset <= len`. In conjunction with `TwicePrecision` this can be used to implement ranges that are free of roundoff error. """ -immutable StepRangeLen{T,R,S} <: Range{T} +struct StepRangeLen{T,R,S} <: Range{T} ref::R # reference value (might be smallest-magnitude value in the range) step::S # step value len::Int # length of the range @@ -182,7 +182,7 @@ StepRangeLen(ref::R, step::S, len::Integer, offset::Integer = 1) where {R,S} = ## linspace and logspace -immutable LinSpace{T} <: Range{T} +struct LinSpace{T} <: Range{T} start::T stop::T len::Int diff --git a/base/rational.jl b/base/rational.jl index 6c5df9f117344..5b26062155281 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -immutable Rational{T<:Integer} <: Real +struct Rational{T<:Integer} <: Real num::T den::T diff --git a/base/reflection.jl b/base/reflection.jl index 41c15cee63b7b..c5eefc9b661f1 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -172,7 +172,7 @@ isconst(m::Module, s::Symbol) = # return an integer such that object_id(x)==object_id(y) if x===y object_id(x::ANY) = ccall(:jl_object_id, UInt, (Any,), x) -immutable DataTypeLayout +struct DataTypeLayout nfields::UInt32 alignment::UInt32 # alignment : 28; @@ -250,7 +250,7 @@ end Determine the upper bound of a type parameter in the underlying type. E.g.: ```jldoctest -julia> immutable Foo{T<:AbstractFloat, N} +julia> struct Foo{T<:AbstractFloat, N} x::Tuple{T, N} end @@ -279,7 +279,7 @@ typeseq(a::ANY,b::ANY) = (@_pure_meta; a<:b && b<:a) fieldoffset(type, i) The byte offset of field `i` of a type relative to the data start. For example, we could -use it in the following manner to summarize information about a struct type: +use it in the following manner to summarize information about a struct: ```jldoctest julia> structinfo(T) = [(fieldoffset(T,i), fieldname(T,i), fieldtype(T,i)) for i = 1:nfields(T)]; @@ -484,7 +484,7 @@ end # high-level, more convenient method lookup functions # type for reflecting and pretty-printing a subset of methods -type MethodList +mutable struct MethodList ms::Array{Method,1} mt::MethodTable end @@ -583,7 +583,7 @@ function uncompressed_ast(m::Method, s::CodeInfo) end # this type mirrors jl_cghooks_t (documented in julia.h) -immutable CodegenHooks +struct CodegenHooks module_setup::Ptr{Void} module_activation::Ptr{Void} raise_exception::Ptr{Void} @@ -595,7 +595,7 @@ immutable CodegenHooks end # this type mirrors jl_cgparams_t (documented in julia.h) -immutable CodegenParams +struct CodegenParams cached::Cint runtime::Cint diff --git a/base/refpointer.jl b/base/refpointer.jl index e12ebbf284520..8941a83c01c4a 100644 --- a/base/refpointer.jl +++ b/base/refpointer.jl @@ -18,11 +18,11 @@ Ref # instead of Ptr{Cchar} and Ptr{Cwchar_t}, respectively, to enforce # a check for embedded NUL chars in the string (to avoid silent truncation). if Int === Int64 - bitstype 64 Cstring - bitstype 64 Cwstring + primitive type Cstring 64 end + primitive type Cwstring 64 end else - bitstype 32 Cstring - bitstype 32 Cwstring + primitive type Cstring 32 end + primitive type Cwstring 32 end end ### General Methods for Ref{T} type @@ -35,7 +35,7 @@ unsafe_convert{T}(::Type{Ref{T}}, x) = unsafe_convert(Ptr{T}, x) ### Methods for a Ref object that can store a single value of any type -type RefValue{T} <: Ref{T} +mutable struct RefValue{T} <: Ref{T} x::T RefValue{T}() where {T} = new() RefValue{T}(x) where {T} = new(x) @@ -64,7 +64,7 @@ end unsafe_convert{T}(::Type{Ptr{Void}}, b::RefValue{T}) = convert(Ptr{Void}, unsafe_convert(Ptr{T}, b)) ### Methods for a Ref object that is backed by an array at index i -immutable RefArray{T, A<:AbstractArray{T}, R} <: Ref{T} +struct RefArray{T, A<:AbstractArray{T}, R} <: Ref{T} x::A i::Int roots::R # should be either ::Void or ::Any diff --git a/base/regex.jl b/base/regex.jl index 16926728d0402..e2161c90874f3 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -7,7 +7,7 @@ include("pcre.jl") const DEFAULT_COMPILER_OPTS = PCRE.UTF | PCRE.NO_UTF_CHECK | PCRE.ALT_BSUX const DEFAULT_MATCH_OPTS = PCRE.NO_UTF_CHECK -type Regex +mutable struct Regex pattern::String compile_options::UInt32 match_options::UInt32 @@ -104,7 +104,7 @@ end # TODO: map offsets into strings in other encodings back to original indices. # or maybe it's better to just fail since that would be quite slow -immutable RegexMatch +struct RegexMatch match::SubString{String} captures::Vector{Union{Void,SubString{String}}} offset::Int @@ -226,7 +226,7 @@ search(s::AbstractString, r::Regex, idx::Integer) = throw(ArgumentError( )) search(s::AbstractString, r::Regex) = search(s,r,start(s)) -immutable SubstitutionString{T<:AbstractString} <: AbstractString +struct SubstitutionString{T<:AbstractString} <: AbstractString string::T end @@ -309,7 +309,7 @@ function _replace(io, repl_s::SubstitutionString, str, r, re) end end -immutable RegexMatchIterator +struct RegexMatchIterator regex::Regex string::String overlap::Bool diff --git a/base/reshapedarray.jl b/base/reshapedarray.jl index 7f1308a16718c..1f94977c35c9a 100644 --- a/base/reshapedarray.jl +++ b/base/reshapedarray.jl @@ -2,7 +2,7 @@ using Base.MultiplicativeInverses: SignedMultiplicativeInverse -immutable ReshapedArray{T,N,P<:AbstractArray,MI<:Tuple{Vararg{SignedMultiplicativeInverse{Int}}}} <: AbstractArray{T,N} +struct ReshapedArray{T,N,P<:AbstractArray,MI<:Tuple{Vararg{SignedMultiplicativeInverse{Int}}}} <: AbstractArray{T,N} parent::P dims::NTuple{N,Int} mi::MI @@ -13,7 +13,7 @@ ReshapedArray{T,N}(parent::AbstractArray{T}, dims::NTuple{N,Int}, mi) = Reshaped typealias ReshapedArrayLF{T,N,P<:AbstractArray} ReshapedArray{T,N,P,Tuple{}} # Fast iteration on ReshapedArrays: use the parent iterator -immutable ReshapedArrayIterator{I,M} +struct ReshapedArrayIterator{I,M} iter::I mi::NTuple{M,SignedMultiplicativeInverse{Int}} end @@ -23,7 +23,7 @@ function _rs_iterator{M}(P, mi::NTuple{M}) ReshapedArrayIterator{typeof(iter),M}(iter, mi) end -immutable ReshapedIndex{T} +struct ReshapedIndex{T} parentindex::T end diff --git a/base/rounding.jl b/base/rounding.jl index 3e9342a781f76..96bad342c2bf3 100644 --- a/base/rounding.jl +++ b/base/rounding.jl @@ -41,7 +41,7 @@ Currently supported rounding modes are: - [`RoundUp`](@ref) - [`RoundDown`](@ref) """ -immutable RoundingMode{T} end +struct RoundingMode{T} end """ RoundNearest diff --git a/base/serialize.jl b/base/serialize.jl index ee40289720394..9e8b835e9b5b6 100644 --- a/base/serialize.jl +++ b/base/serialize.jl @@ -8,7 +8,7 @@ using Base: ViewIndex, Slice, index_lengths, unwrap_unionall export serialize, deserialize, SerializationState -type SerializationState{I<:IO} <: AbstractSerializer +mutable struct SerializationState{I<:IO} <: AbstractSerializer io::I counter::Int table::ObjectIdDict @@ -784,7 +784,7 @@ function deserialize_typename(s::AbstractSerializer, number) types = deserialize(s)::SimpleVector has_instance = deserialize(s)::Bool abstr = deserialize(s)::Bool - mutable = deserialize(s)::Bool + mutabl = deserialize(s)::Bool ninitialized = deserialize(s)::Int32 if makenew @@ -794,7 +794,7 @@ function deserialize_typename(s::AbstractSerializer, number) # tn.wrapper and throw UndefRefException before we get to this point ndt = ccall(:jl_new_datatype, Any, (Any, Any, Any, Any, Any, Cint, Cint, Cint), tn, super, parameters, names, types, - abstr, mutable, ninitialized) + abstr, mutabl, ninitialized) tn.wrapper = ndt.name.wrapper ccall(:jl_set_const, Void, (Any, Any, Any), tn.module, tn.name, tn.wrapper) ty = tn.wrapper diff --git a/base/set.jl b/base/set.jl index c3210bdbed0f6..d2f61c2a0aac2 100644 --- a/base/set.jl +++ b/base/set.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -type Set{T} <: AbstractSet{T} +mutable struct Set{T} <: AbstractSet{T} dict::Dict{T,Void} Set{T}() where {T} = new(Dict{T,Void}()) diff --git a/base/sharedarray.jl b/base/sharedarray.jl index 823eb715134f9..c6aeaee945f88 100644 --- a/base/sharedarray.jl +++ b/base/sharedarray.jl @@ -2,7 +2,7 @@ import .Serializer: serialize_cycle_header, serialize_type, writetag, UNDEFREF_TAG -type SharedArray{T,N} <: DenseArray{T,N} +mutable struct SharedArray{T,N} <: DenseArray{T,N} dims::NTuple{N,Int} pids::Vector{Int} refs::Vector @@ -32,7 +32,7 @@ end SharedArray{T}(dims::NTuple; init=false, pids=Int[]) SharedArray{T,N}(...) -Construct a `SharedArray` of a bitstype `T` and size `dims` across the +Construct a `SharedArray` of a bits type `T` and size `dims` across the processes specified by `pids` - all of which have to be on the same host. If `N` is specified by calling `SharedArray{T,N}(dims)`, then `N` must match the length of `dims`. @@ -49,7 +49,7 @@ the participating workers. SharedArray{T,N}(...) Construct a `SharedArray` backed by the file `filename`, with element -type `T` (must be a `bitstype`) and size `dims`, across the processes +type `T` (must be a bits type) and size `dims`, across the processes specified by `pids` - all of which have to be on the same host. This file is mmapped into the host memory, with the following consequences: diff --git a/base/show.jl b/base/show.jl index 928bbe53acb35..e0a0d2bb76359 100644 --- a/base/show.jl +++ b/base/show.jl @@ -10,7 +10,7 @@ print(io::IO, s::Symbol) = (write(io,s); nothing) In short, it is an immutable dictionary that is a subclass of `IO`. It supports standard dictionary operations such as [`getindex`](@ref), and can also be used as an I/O stream. """ -immutable IOContext{IO_t <: IO} <: AbstractPipe +struct IOContext{IO_t <: IO} <: AbstractPipe io::IO_t dict::ImmutableDict{Symbol, Any} @@ -851,12 +851,18 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) # type declaration elseif head === :type && nargs==3 - show_block(io, args[1] ? :type : :immutable, args[2], args[3], indent) + show_block(io, args[1] ? Symbol("mutable struct") : Symbol("struct"), args[2], args[3], indent) print(io, "end") elseif head === :bitstype && nargs == 2 - print(io, "bitstype ") + print(io, "primitive type ") + show_list(io, reverse(args), ' ', indent) + print(io, " end") + + elseif head === :abstract && nargs == 1 + print(io, "abstract type ") show_list(io, args, ' ', indent) + print(io, " end") # empty return (i.e. "function f() return end") elseif head === :return && nargs == 1 && args[1] === nothing @@ -876,7 +882,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) elseif (nargs == 0 && head in (:break, :continue)) print(io, head) - elseif (nargs == 1 && head in (:return, :abstract, :const)) || + elseif (nargs == 1 && head in (:return, :const)) || head in (:local, :global, :export) print(io, head, ' ') show_list(io, args, ", ", indent) diff --git a/base/simdloop.jl b/base/simdloop.jl index e20fe75d994ae..9f1946e35ee15 100644 --- a/base/simdloop.jl +++ b/base/simdloop.jl @@ -7,7 +7,7 @@ module SimdLoop export @simd, simd_outer_range, simd_inner_length, simd_index # Error thrown from ill-formed uses of @simd -type SimdError <: Exception +mutable struct SimdError <: Exception msg::String end diff --git a/base/socket.jl b/base/socket.jl index b4598efca6d81..fee666b71c0c3 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -1,12 +1,12 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license ## IP ADDRESS HANDLING ## -abstract IPAddr +abstract type IPAddr end Base.isless{T<:IPAddr}(a::T, b::T) = isless(a.host, b.host) Base.convert{T<:Integer}(dt::Type{T}, ip::IPAddr) = dt(ip.host) -immutable IPv4 <: IPAddr +struct IPv4 <: IPAddr host::UInt32 IPv4(host::UInt32) = new(host) IPv4(a::UInt8,b::UInt8,c::UInt8,d::UInt8) = new(UInt32(a)<<24| @@ -45,7 +45,7 @@ print(io::IO,ip::IPv4) = print(io,dec((ip.host&(0xFF000000))>>24),".", dec((ip.host&(0xFF00))>>8),".", dec(ip.host&0xFF)) -immutable IPv6 <: IPAddr +struct IPv6 <: IPAddr host::UInt128 IPv6(host::UInt128) = new(host) IPv6(a::UInt16,b::UInt16,c::UInt16,d::UInt16, @@ -236,7 +236,7 @@ macro ip_str(str) return parse(IPAddr, str) end -immutable InetAddr{T<:IPAddr} +struct InetAddr{T<:IPAddr} host::T port::UInt16 end @@ -245,7 +245,7 @@ InetAddr(ip::IPAddr, port) = InetAddr{typeof(ip)}(ip, port) ## SOCKETS ## -type TCPSocket <: LibuvStream +mutable struct TCPSocket <: LibuvStream handle::Ptr{Void} status::Int buffer::IOBuffer @@ -281,7 +281,7 @@ function TCPSocket() return tcp end -type TCPServer <: LibuvServer +mutable struct TCPServer <: LibuvServer handle::Ptr{Void} status::Int connectnotify::Condition @@ -329,7 +329,7 @@ accept(server::PipeServer) = accept(server, init_pipe!(PipeEndpoint(); # UDP -type UDPSocket <: LibuvStream +mutable struct UDPSocket <: LibuvStream handle::Ptr{Void} status::Int recvnotify::Condition @@ -561,7 +561,7 @@ end ## -type DNSError <: Exception +mutable struct DNSError <: Exception host::AbstractString code::Int32 end diff --git a/base/sort.jl b/base/sort.jl index 61bef81914c28..864b37cd525d3 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -206,13 +206,13 @@ end ## sorting algorithms ## -abstract Algorithm +abstract type Algorithm end -immutable InsertionSortAlg <: Algorithm end -immutable QuickSortAlg <: Algorithm end -immutable MergeSortAlg <: Algorithm end +struct InsertionSortAlg <: Algorithm end +struct QuickSortAlg <: Algorithm end +struct MergeSortAlg <: Algorithm end -immutable PartialQuickSort{T <: Union{Int,OrdinalRange}} <: Algorithm +struct PartialQuickSort{T <: Union{Int,OrdinalRange}} <: Algorithm k::T end @@ -690,8 +690,8 @@ import ...Order: lt, DirectOrdering typealias Floats Union{Float32,Float64} -immutable Left <: Ordering end -immutable Right <: Ordering end +struct Left <: Ordering end +struct Right <: Ordering end left(::DirectOrdering) = Left() right(::DirectOrdering) = Right() diff --git a/base/sparse/abstractsparse.jl b/base/sparse/abstractsparse.jl index 60d70f97cc9f6..ace29a16677f5 100644 --- a/base/sparse/abstractsparse.jl +++ b/base/sparse/abstractsparse.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -abstract AbstractSparseArray{Tv,Ti,N} <: AbstractArray{Tv,N} +abstract type AbstractSparseArray{Tv,Ti,N} <: AbstractArray{Tv,N} end typealias AbstractSparseVector{Tv,Ti} AbstractSparseArray{Tv,Ti,1} typealias AbstractSparseMatrix{Tv,Ti} AbstractSparseArray{Tv,Ti,2} diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index e26b07143aafd..0827b4e444788 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -175,7 +175,7 @@ end # Type definitions # #################### -abstract SuiteSparseStruct +abstract type SuiteSparseStruct end # The three core data types for CHOLMOD: Dense, Sparse and Factor. # CHOLMOD manages the memory, so the Julia versions only wrap a @@ -183,7 +183,7 @@ abstract SuiteSparseStruct # time a pointer is returned from CHOLMOD. # Dense -immutable C_Dense{T<:VTypes} <: SuiteSparseStruct +struct C_Dense{T<:VTypes} <: SuiteSparseStruct nrow::Csize_t ncol::Csize_t nzmax::Csize_t @@ -194,12 +194,12 @@ immutable C_Dense{T<:VTypes} <: SuiteSparseStruct dtype::Cint end -type Dense{T<:VTypes} <: DenseMatrix{T} +mutable struct Dense{T<:VTypes} <: DenseMatrix{T} p::Ptr{C_Dense{T}} end # Sparse -immutable C_Sparse{Tv<:VTypes} <: SuiteSparseStruct +struct C_Sparse{Tv<:VTypes} <: SuiteSparseStruct nrow::Csize_t ncol::Csize_t nzmax::Csize_t @@ -219,7 +219,7 @@ end # Corresponds to the exact definition of cholmod_sparse_struct in the library. # Useful when reading matrices of unknown type from files as in # cholmod_read_sparse -immutable C_SparseVoid <: SuiteSparseStruct +struct C_SparseVoid <: SuiteSparseStruct nrow::Csize_t ncol::Csize_t nzmax::Csize_t @@ -236,7 +236,7 @@ immutable C_SparseVoid <: SuiteSparseStruct packed::Cint end -type Sparse{Tv<:VTypes} <: AbstractSparseMatrix{Tv,SuiteSparse_long} +mutable struct Sparse{Tv<:VTypes} <: AbstractSparseMatrix{Tv,SuiteSparse_long} p::Ptr{C_Sparse{Tv}} function Sparse{Tv}(p::Ptr{C_Sparse{Tv}}) where Tv<:VTypes if p == C_NULL @@ -251,7 +251,7 @@ Sparse(p::Ptr{C_Sparse{Tv}}) where Tv<:VTypes = Sparse{Tv}(p) # Factor if build_version >= v"2.1.0" # CHOLMOD version 2.1.0 or later - immutable C_Factor{Tv<:VTypes} <: SuiteSparseStruct + struct C_Factor{Tv<:VTypes} <: SuiteSparseStruct n::Csize_t minor::Csize_t Perm::Ptr{SuiteSparse_long} @@ -283,7 +283,7 @@ if build_version >= v"2.1.0" # CHOLMOD version 2.1.0 or later dtype::Cint end else - immutable C_Factor{Tv<:VTypes} <: SuiteSparseStruct + struct C_Factor{Tv<:VTypes} <: SuiteSparseStruct n::Csize_t minor::Csize_t Perm::Ptr{SuiteSparse_long} @@ -315,7 +315,7 @@ else end end -type Factor{Tv} <: Factorization{Tv} +mutable struct Factor{Tv} <: Factorization{Tv} p::Ptr{C_Factor{Tv}} function Factor{Tv}(p::Ptr{C_Factor{Tv}}) where Tv if p == C_NULL @@ -341,7 +341,7 @@ function get{T<:SuiteSparseStruct}(p::Ptr{T}) end # FactorComponent, for encoding particular factors from a factorization -type FactorComponent{Tv,S} <: AbstractMatrix{Tv} +mutable struct FactorComponent{Tv,S} <: AbstractMatrix{Tv} F::Factor{Tv} function FactorComponent{Tv,S}(F::Factor{Tv}) where {Tv,S} diff --git a/base/sparse/cholmod_h.jl b/base/sparse/cholmod_h.jl index 922b3b772b7cc..7be23f78e4074 100644 --- a/base/sparse/cholmod_h.jl +++ b/base/sparse/cholmod_h.jl @@ -70,7 +70,7 @@ end typealias VTypes Union{Complex128, Float64} typealias VRealTypes Union{Float64} -type CHOLMODException <: Exception +mutable struct CHOLMODException <: Exception msg::AbstractString end diff --git a/base/sparse/higherorderfns.jl b/base/sparse/higherorderfns.jl index ea947b9336eba..cfe312bb52bbf 100644 --- a/base/sparse/higherorderfns.jl +++ b/base/sparse/higherorderfns.jl @@ -1002,7 +1002,7 @@ broadcast{Tf,T}(f::Tf, A::SparseMatrixCSC, ::Type{T}) = broadcast(x -> f(x, T), # first (Broadcast containertype) dispatch layer's promotion logic -immutable PromoteToSparse end +struct PromoteToSparse end # broadcast containertype definitions for structured matrices StructuredMatrix = Union{Diagonal,Bidiagonal,Tridiagonal,SymTridiagonal} diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index 7ebaae7c0b5fd..f1d74c97ecb7e 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -5,7 +5,7 @@ # Assumes that row values in rowval for each column are sorted # issorted(rowval[colptr[i]:(colptr[i+1]-1)]) == true -immutable SparseMatrixCSC{Tv,Ti<:Integer} <: AbstractSparseMatrix{Tv,Ti} +struct SparseMatrixCSC{Tv,Ti<:Integer} <: AbstractSparseMatrix{Tv,Ti} m::Int # Number of rows n::Int # Number of columns colptr::Vector{Ti} # Column i is in colptr[i]:(colptr[i+1]-1) @@ -3178,7 +3178,7 @@ end ## diag and related using an iterator -type SpDiagIterator{Tv,Ti} +mutable struct SpDiagIterator{Tv,Ti} A::SparseMatrixCSC{Tv,Ti} n::Int end diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index f9478910d66f7..593dc1281231b 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -9,7 +9,7 @@ import Base.LinAlg: promote_to_array_type, promote_to_arrays_ ### Types -immutable SparseVector{Tv,Ti<:Integer} <: AbstractSparseVector{Tv,Ti} +struct SparseVector{Tv,Ti<:Integer} <: AbstractSparseVector{Tv,Ti} n::Int # the number of elements nzind::Vector{Ti} # the indices of nonzeros nzval::Vector{Tv} # the values of nonzeros diff --git a/base/sparse/spqr.jl b/base/sparse/spqr.jl index 435a87f1dd195..66deb05e5d320 100644 --- a/base/sparse/spqr.jl +++ b/base/sparse/spqr.jl @@ -45,12 +45,12 @@ import Base: size import Base.LinAlg: qrfact import ..SparseArrays.CHOLMOD: convert, free! -immutable C_Factorization{Tv<:VTypes} <: SuiteSparseStruct +struct C_Factorization{Tv<:VTypes} <: SuiteSparseStruct xtype::Cint factors::Ptr{Tv} end -type Factorization{Tv<:VTypes} <: Base.LinAlg.Factorization{Tv} +mutable struct Factorization{Tv<:VTypes} <: Base.LinAlg.Factorization{Tv} m::Int n::Int p::Ptr{C_Factorization{Tv}} diff --git a/base/sparse/umfpack.jl b/base/sparse/umfpack.jl index 496faf5552d89..f4cc9b4217ea5 100644 --- a/base/sparse/umfpack.jl +++ b/base/sparse/umfpack.jl @@ -11,7 +11,7 @@ importall ..SparseArrays import ..SparseArrays: increment, increment!, decrement, decrement!, nnz include("umfpack_h.jl") -type MatrixIllConditionedException <: Exception +mutable struct MatrixIllConditionedException <: Exception message::AbstractString end @@ -91,7 +91,7 @@ function show_umf_info(level::Real = 2.0) end ## Should this type be immutable? -type UmfpackLU{Tv<:UMFVTypes,Ti<:UMFITypes} <: Factorization{Tv} +mutable struct UmfpackLU{Tv<:UMFVTypes,Ti<:UMFITypes} <: Factorization{Tv} symbolic::Ptr{Void} numeric::Ptr{Void} m::Int diff --git a/base/special/bessel.jl b/base/special/bessel.jl index 17e9b905af534..1c3636f8cd796 100644 --- a/base/special/bessel.jl +++ b/base/special/bessel.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -type AmosException <: Exception +mutable struct AmosException <: Exception info::Int32 end diff --git a/base/special/trig.jl b/base/special/trig.jl index 291503aec000c..80a0d9073bf61 100644 --- a/base/special/trig.jl +++ b/base/special/trig.jl @@ -1,11 +1,11 @@ # This file is a part of Julia. Except for the *_kernel functions (see below), # license is MIT: http://julialang.org/license -immutable DoubleFloat64 +struct DoubleFloat64 hi::Float64 lo::Float64 end -immutable DoubleFloat32 +struct DoubleFloat32 hi::Float64 end diff --git a/base/stacktraces.jl b/base/stacktraces.jl index 612f127e55e05..8dc816096008d 100644 --- a/base/stacktraces.jl +++ b/base/stacktraces.jl @@ -42,7 +42,7 @@ Stack information representing execution context, with the following fields: Representation of the pointer to the execution context as returned by `backtrace`. """ -immutable StackFrame # this type should be kept platform-agnostic so that profiles can be dumped on one machine and read on another +struct StackFrame # this type should be kept platform-agnostic so that profiles can be dumped on one machine and read on another "the name of the function containing the execution context" func::Symbol "the path to the file containing the execution context" diff --git a/base/stat.jl b/base/stat.jl index 7e102c57fc3b2..d6922fc626572 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -25,7 +25,7 @@ export stat, uperm -immutable StatStruct +struct StatStruct device :: UInt inode :: UInt mode :: UInt diff --git a/base/stream.jl b/base/stream.jl index 80514c305bace..04b05d6bf5e63 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -6,9 +6,9 @@ if is_windows() end ## types ## -abstract IOServer -abstract LibuvServer <: IOServer -abstract LibuvStream <: IO +abstract type IOServer end +abstract type LibuvServer <: IOServer end +abstract type LibuvStream <: IO end # IO # +- AbstractIOBuffer{T<:AbstractArray{UInt8,1}} (not exported) @@ -99,7 +99,7 @@ function uv_status_string(x) return "invalid status" end -type PipeEndpoint <: LibuvStream +mutable struct PipeEndpoint <: LibuvStream handle::Ptr{Void} status::Int buffer::IOBuffer @@ -127,7 +127,7 @@ type PipeEndpoint <: LibuvStream end end -type PipeServer <: LibuvServer +mutable struct PipeServer <: LibuvServer handle::Ptr{Void} status::Int connectnotify::Condition @@ -150,7 +150,7 @@ function PipeServer() return init_pipe!(p; readable=true) end -type TTY <: LibuvStream +mutable struct TTY <: LibuvStream handle::Ptr{Void} status::Int buffer::IOBuffer @@ -529,7 +529,7 @@ end # (composed of two half-pipes: .in and .out) ########################################## -type Pipe <: AbstractPipe +mutable struct Pipe <: AbstractPipe in::PipeEndpoint # writable out::PipeEndpoint # readable end @@ -1103,7 +1103,7 @@ reset(x::LibuvStream) = reset(x.buffer) ismarked(x::LibuvStream) = ismarked(x.buffer) # BufferStream's are non-OS streams, backed by a regular IOBuffer -type BufferStream <: LibuvStream +mutable struct BufferStream <: LibuvStream buffer::IOBuffer r_c::Condition close_c::Condition diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 2305ab422950f..48a29d5db0a18 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -310,7 +310,7 @@ function chr2ind(s::AbstractString, i::Integer) end end -immutable EachStringIndex{T<:AbstractString} +struct EachStringIndex{T<:AbstractString} s::T end eachindex(s::AbstractString) = EachStringIndex(s) diff --git a/base/strings/errors.jl b/base/strings/errors.jl index c0ca38ff28db2..8f80e5b1f8c30 100644 --- a/base/strings/errors.jl +++ b/base/strings/errors.jl @@ -5,7 +5,7 @@ const UTF_ERR_SHORT = "invalid UTF-8 sequence starting at index <<1>> (0x<<2>> missing one or more continuation bytes)" const UTF_ERR_INVALID_INDEX = "invalid character index" -type UnicodeError <: Exception +mutable struct UnicodeError <: Exception errmsg::AbstractString ##< A UTF_ERR_ message errpos::Int32 ##< Position of invalid character errchr::UInt32 ##< Invalid character diff --git a/base/strings/types.jl b/base/strings/types.jl index 5442d14346f78..d3f56d707404a 100644 --- a/base/strings/types.jl +++ b/base/strings/types.jl @@ -4,7 +4,7 @@ ## substrings reference original strings ## -immutable SubString{T<:AbstractString} <: AbstractString +struct SubString{T<:AbstractString} <: AbstractString string::T offset::Int endof::Int @@ -100,7 +100,7 @@ end ## reversed strings without data movement ## -immutable RevString{T<:AbstractString} <: AbstractString +struct RevString{T<:AbstractString} <: AbstractString string::T end diff --git a/base/strings/utf8proc.jl b/base/strings/utf8proc.jl index 27683d1d4defb..591d0b5793dd8 100644 --- a/base/strings/utf8proc.jl +++ b/base/strings/utf8proc.jl @@ -338,7 +338,7 @@ isgraphemebreak(c1::Char, c2::Char) = isgraphemebreak!(state::Ref{Int32}, c1::Char, c2::Char) = ccall(:utf8proc_grapheme_break_stateful, Bool, (UInt32, UInt32, Ref{Int32}), c1, c2, state) -immutable GraphemeIterator{S<:AbstractString} +struct GraphemeIterator{S<:AbstractString} s::S # original string (for generation of SubStrings) end diff --git a/base/subarray.jl b/base/subarray.jl index 334f5e59ddcc3..23fab73ddbb1f 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -1,11 +1,11 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -abstract AbstractCartesianIndex{N} # This is a hacky forward declaration for CartesianIndex +abstract type AbstractCartesianIndex{N} end # This is a hacky forward declaration for CartesianIndex typealias ViewIndex Union{Real, AbstractArray} typealias ScalarIndex Real # L is true if the view itself supports fast linear indexing -immutable SubArray{T,N,P,I,L} <: AbstractArray{T,N} +struct SubArray{T,N,P,I,L} <: AbstractArray{T,N} parent::P indexes::I offset1::Int # for linear indexing and pointer, only valid when L==true diff --git a/base/summarysize.jl b/base/summarysize.jl index 25b7679795e48..174f18f3cf8fc 100644 --- a/base/summarysize.jl +++ b/base/summarysize.jl @@ -1,4 +1,4 @@ -immutable SummarySize +struct SummarySize seen::ObjectIdDict frontier_x::Vector{Any} frontier_i::Vector{Int} diff --git a/base/sysimg.jl b/base/sysimg.jl index 4d5fd140c73f8..bddd182a77f34 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -112,7 +112,7 @@ include("abstractarraymath.jl") include("arraymath.jl") # define MIME"foo/bar" early so that we can overload 3-arg show -immutable MIME{mime} end +struct MIME{mime} end macro MIME_str(s) :(MIME{$(Expr(:quote, Symbol(s)))}) end diff --git a/base/sysinfo.jl b/base/sysinfo.jl index d96af3366c5c7..d23f709a140f4 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -67,7 +67,7 @@ function __init__() global JIT = ccall(:jl_get_JIT, Ref{String}, ()) end -type UV_cpu_info_t +mutable struct UV_cpu_info_t model::Ptr{UInt8} speed::Int32 cpu_times!user::UInt64 @@ -76,7 +76,7 @@ type UV_cpu_info_t cpu_times!idle::UInt64 cpu_times!irq::UInt64 end -type CPUinfo +mutable struct CPUinfo model::String speed::Int32 cpu_times!user::UInt64 diff --git a/base/task.jl b/base/task.jl index 94901a8754a54..a25bc78cd65b6 100644 --- a/base/task.jl +++ b/base/task.jl @@ -3,7 +3,7 @@ ## basic task functions and TLS # Container for a captured exception and its backtrace. Can be serialized. -type CapturedException <: Exception +mutable struct CapturedException <: Exception ex::Any processed_bt::Vector{Any} @@ -26,7 +26,7 @@ function showerror(io::IO, ce::CapturedException) showerror(io, ce.ex, ce.processed_bt, backtrace=true) end -type CompositeException <: Exception +mutable struct CompositeException <: Exception exceptions::Vector{Any} CompositeException() = new(Any[]) CompositeException(exceptions) = new(exceptions) diff --git a/base/test.jl b/base/test.jl index 23eff2c191f9a..f460b97a73989 100644 --- a/base/test.jl +++ b/base/test.jl @@ -52,7 +52,7 @@ end All tests produce a result object. This object may or may not be stored, depending on whether the test is part of a test set. """ -abstract Result +abstract type Result end """ Pass @@ -60,7 +60,7 @@ abstract Result The test condition was true, i.e. the expression evaluated to true or the correct exception was thrown. """ -immutable Pass <: Result +struct Pass <: Result test_type::Symbol orig_expr data @@ -87,7 +87,7 @@ end The test condition was false, i.e. the expression evaluated to false or the correct exception was not thrown. """ -type Fail <: Result +mutable struct Fail <: Result test_type::Symbol orig_expr data @@ -119,7 +119,7 @@ it evaluated to something other than a `Bool`. In the case of `@test_broken` it is used to indicate that an unexpected `Pass` `Result` occurred. """ -type Error <: Result +mutable struct Error <: Result test_type::Symbol orig_expr value @@ -159,7 +159,7 @@ end The test condition is the expected (failed) result of a broken test, or was explicitly skipped with `@test_skip`. """ -type Broken <: Result +mutable struct Broken <: Result test_type::Symbol orig_expr end @@ -174,14 +174,14 @@ end #----------------------------------------------------------------------- -abstract ExecutionResult +abstract type ExecutionResult end -immutable Returned <: ExecutionResult +struct Returned <: ExecutionResult value data end -immutable Threw <: ExecutionResult +struct Threw <: ExecutionResult exception backtrace end @@ -455,7 +455,7 @@ end # Called by do_test after a test is evaluated # finish(AbstractTestSet) # Called after the test set has been popped from the test set stack -abstract AbstractTestSet +abstract type AbstractTestSet end """ record(ts::AbstractTestSet, res::Result) @@ -482,7 +482,7 @@ function finish end Thrown when a test set finishes and not all tests passed. """ -type TestSetException <: Exception +mutable struct TestSetException <: Exception pass::Int fail::Int error::Int @@ -509,11 +509,11 @@ end A simple fallback test set that throws immediately on a failure. """ -immutable FallbackTestSet <: AbstractTestSet +struct FallbackTestSet <: AbstractTestSet end fallback_testset = FallbackTestSet() -type FallbackTestSetException <: Exception +mutable struct FallbackTestSetException <: Exception msg::String end @@ -540,7 +540,7 @@ If using the DefaultTestSet, the test results will be recorded. If there are any `Fail`s or `Error`s, an exception will be thrown only at the end, along with a summary of the test results. """ -type DefaultTestSet <: AbstractTestSet +mutable struct DefaultTestSet <: AbstractTestSet description::AbstractString results::Vector n_passed::Int @@ -1163,7 +1163,7 @@ The `GenericString` can be used to test generic string APIs that program to the `AbstractString` interface, in order to ensure that functions can work with string types besides the standard `String` type. """ -immutable GenericString <: AbstractString +struct GenericString <: AbstractString string::AbstractString end Base.convert(::Type{GenericString}, s::AbstractString) = GenericString(s) diff --git a/base/traits.jl b/base/traits.jl index 62bc9ecb4d6da..e22d87d0b4530 100644 --- a/base/traits.jl +++ b/base/traits.jl @@ -2,19 +2,19 @@ ## numeric/object traits # trait for objects that have an ordering -abstract TypeOrder -immutable HasOrder <: TypeOrder end -immutable Unordered <: TypeOrder end +abstract type TypeOrder end +struct HasOrder <: TypeOrder end +struct Unordered <: TypeOrder end (::Type{TypeOrder})(instance) = TypeOrder(typeof(instance)) (::Type{TypeOrder}){T<:Real}(::Type{T}) = HasOrder() (::Type{TypeOrder}){T}(::Type{T}) = Unordered() # trait for objects that support arithmetic -abstract TypeArithmetic -immutable ArithmeticRounds <: TypeArithmetic end # least significant bits can be lost -immutable ArithmeticOverflows <: TypeArithmetic end # most significant bits can be lost -immutable ArithmeticUnknown <: TypeArithmetic end +abstract type TypeArithmetic end +struct ArithmeticRounds <: TypeArithmetic end # least significant bits can be lost +struct ArithmeticOverflows <: TypeArithmetic end # most significant bits can be lost +struct ArithmeticUnknown <: TypeArithmetic end (::Type{TypeArithmetic})(instance) = TypeArithmetic(typeof(instance)) (::Type{TypeArithmetic}){T<:AbstractFloat}(::Type{T}) = ArithmeticRounds() diff --git a/base/twiceprecision.jl b/base/twiceprecision.jl index 3eea580df5f3c..9f1259e7d25ce 100644 --- a/base/twiceprecision.jl +++ b/base/twiceprecision.jl @@ -30,7 +30,7 @@ roundoff error). If `step` has an exact rational representation where `nb` is the number of trailing zero bits of `step.hi`. For ranges, you can set `nb = ceil(Int, log2(len-1))`. """ -immutable TwicePrecision{T} +struct TwicePrecision{T} hi::T # most significant bits lo::T # least significant bits end diff --git a/base/util.jl b/base/util.jl index d3945fc32df33..f92360bc124ac 100644 --- a/base/util.jl +++ b/base/util.jl @@ -14,7 +14,7 @@ Get the time in nanoseconds. The time corresponding to 0 is undefined, and wraps time_ns() = ccall(:jl_hrtime, UInt64, ()) # This type must be kept in sync with the C struct in src/gc.h -immutable GC_Num +struct GC_Num allocd ::Int64 # GC internal deferred_alloc::Int64 # GC internal freed ::Int64 # GC internal @@ -34,7 +34,7 @@ end gc_num() = ccall(:jl_gc_num, GC_Num, ()) # This type is to represent differences in the counters, so fields may be negative -immutable GC_Diff +struct GC_Diff allocd ::Int64 # Bytes allocated malloc ::Int64 # Number of GC aware malloc() realloc ::Int64 # Number of GC aware realloc() @@ -670,7 +670,7 @@ end # Windows authentication prompt if is_windows() - immutable CREDUI_INFO + struct CREDUI_INFO cbSize::UInt32 parent::Ptr{Void} pszMessageText::Ptr{UInt16} @@ -771,13 +771,13 @@ crc32c(a::Union{Array{UInt8},String}, crc::UInt32=0x00000000) = @kwdef typedef This is a helper macro that automatically defines a keyword-based constructor for the type -declared in the expression `typedef`, which must be a `type` or `immutable` +declared in the expression `typedef`, which must be a `struct` or `mutable struct` expression. The default argument is supplied by declaring fields of the form `field::T = default`. If no default is provided then the default is provided by the `kwdef_val(T)` function. ```julia -@kwdef immutable Foo +@kwdef struct Foo a::Cint # implied default Cint(0) b::Cint = 1 # specified default z::Cstring # implied default Cstring(C_NULL) diff --git a/base/version.jl b/base/version.jl index 9d7bf3a8198f0..956763ce27344 100644 --- a/base/version.jl +++ b/base/version.jl @@ -2,7 +2,7 @@ ## semantic version numbers (http://semver.org) -immutable VersionNumber +struct VersionNumber major::Int minor::Int patch::Int diff --git a/base/version_git.sh b/base/version_git.sh index 110ef86ee0d9b..35f54e92bf177 100644 --- a/base/version_git.sh +++ b/base/version_git.sh @@ -4,7 +4,7 @@ # This file collects git info and create a julia file with the GIT_VERSION_INFO struct echo "# This file was autogenerated in base/version_git.sh" -echo "immutable GitVersionInfo" +echo "struct GitVersionInfo" echo " commit::AbstractString" echo " commit_short::AbstractString" echo " branch::AbstractString" diff --git a/base/weakkeydict.jl b/base/weakkeydict.jl index ea28c9805f0ba..a20be01394a26 100644 --- a/base/weakkeydict.jl +++ b/base/weakkeydict.jl @@ -9,7 +9,7 @@ referenced in a hash table. See [`Dict`](@ref) for further help. """ -type WeakKeyDict{K,V} <: Associative{K,V} +mutable struct WeakKeyDict{K,V} <: Associative{K,V} ht::Dict{WeakRef,V} lock::Threads.RecursiveSpinLock finalizer::Function diff --git a/doc/src/manual/calling-c-and-fortran-code.md b/doc/src/manual/calling-c-and-fortran-code.md index 2ca50b7c996b5..d0e8c920ffa09 100644 --- a/doc/src/manual/calling-c-and-fortran-code.md +++ b/doc/src/manual/calling-c-and-fortran-code.md @@ -264,15 +264,15 @@ First, a review of some relevant Julia type terminology: | Syntax / Keyword | Example | Description | |:----------------------------- |:------------------------------------------- |:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `type` | `String` | "Leaf Type" :: A group of related data that includes a type-tag, is managed by the Julia GC, and is defined by object-identity. The type parameters of a leaf type must be fully defined (no `TypeVars` are allowed) in order for the instance to be constructed. | +| `mutable` | `String` | "Leaf Type" :: A group of related data that includes a type-tag, is managed by the Julia GC, and is defined by object-identity. The type parameters of a leaf type must be fully defined (no `TypeVars` are allowed) in order for the instance to be constructed. | | `abstract` | `Any`, `AbstractArray{T, N}`, `Complex{T}` | "Super Type" :: A super-type (not a leaf-type) that cannot be instantiated, but can be used to describe a group of types. | | `{T}` | `Vector{Int}` | "Type Parameter" :: A specialization of a type (typically used for dispatch or storage optimization). | | | | "TypeVar" :: The `T` in the type parameter declaration is referred to as a TypeVar (short for type variable). | | `bitstype` | `Int`, `Float64` | "Bits Type" :: A type with no fields, but a size. It is stored and defined by-value. | -| `immutable` | `Pair{Int, Int}` | "Immutable" :: A type with all fields defined to be constant. It is defined by-value. And may be stored with a type-tag. | -| | `Complex128` (`isbits`) | "Is-Bits" :: A `bitstype`, or an `immutable` type where all fields are other `isbits` types. It is defined by-value, and is stored without a type-tag. | -| `type ...; end` | `nothing` | "Singleton" :: a Leaf Type or Immutable with no fields. | -| `(...)` or `tuple(...)` | `(1, 2, 3)` | "Tuple" :: an immutable data-structure similar to an anonymous immutable type, or a constant array. Represented as either an array or a struct. | +| `struct` | `Pair{Int, Int}` | "Struct" :: A type with all fields defined to be constant. It is defined by-value. And may be stored with a type-tag. | +| | `Complex128` (`isbits`) | "Is-Bits" :: A `bitstype`, or a `struct` type where all fields are other `isbits` types. It is defined by-value, and is stored without a type-tag. | +| `struct ...; end` | `nothing` | "Singleton" :: a Leaf Type or Struct with no fields. | +| `(...)` or `tuple(...)` | `(1, 2, 3)` | "Tuple" :: an immutable data-structure similar to an anonymous struct type, or a constant array. Represented as either an array or a struct. | | `typealias` | Not applicable here | Type aliases, and other similar mechanisms of doing type indirection, are resolved to their base type (this includes assigning a type to another name, or getting the type out of a function call). | ### Bits Types: @@ -427,13 +427,13 @@ checks and is only meant to improve readability of the call. ### Struct Type correspondences Composite types, aka `struct` in C or `TYPE` in Fortran90 (or `STRUCTURE` / `RECORD` in some variants -of F77), can be mirrored in Julia by creating a `type` or `immutable` definition with the same +of F77), can be mirrored in Julia by creating a `struct` definition with the same field layout. When used recursively, `isbits` types are stored inline. All other types are stored as a pointer to the data. When mirroring a struct used by-value inside another struct in C, it is imperative that you do not attempt to manually copy the fields over, as this will not preserve the correct -field alignment. Instead, declare an immutable `isbits` type and use that instead. Unnamed structs +field alignment. Instead, declare an `isbits` struct type and use that instead. Unnamed structs are not possible in the translation to Julia. Packed structs and union declarations are not supported by Julia. @@ -554,7 +554,7 @@ pointers, `Ref{T}` should generally be used for the types of input arguments, al of pointers to memory managed by either Julia or C through the implicit call to [`Base.cconvert()`](@ref). In contrast, pointers returned by the C function called should be declared to be of output type `Ptr{T}`, reflecting that the memory pointed to is managed by C only. Pointers contained in C -structs should be represented as fields of type `Ptr{T}` within the corresponding Julia immutable +structs should be represented as fields of type `Ptr{T}` within the corresponding Julia struct types designed to mimic the internal structure of corresponding C structs. In Julia code wrapping calls to external Fortran routines, all input arguments should be declared @@ -691,7 +691,7 @@ end The meaning of prefix `&` is not quite the same as in C. In particular, any changes to the referenced variables will not be visible in Julia unless the type is mutable (declared via `type`). However, -even for immutable types it will not cause any harm for called functions to attempt such modifications +even for immutable structs it will not cause any harm for called functions to attempt such modifications (that is, writing through the passed pointers). Moreover, `&` may be used with any expression, such as `&0` or `&f(x)`. @@ -937,12 +937,12 @@ back to a Julia object reference by [`unsafe_pointer_to_objref(ptr)`](@ref). (Ju can be converted to `jl_value_t*` pointers, as `Ptr{Void}`, by calling [`pointer_from_objref(v)`](@ref).) The reverse operation (writing data to a `Ptr{T}`), can be performed using [`unsafe_store!(ptr, value, [index])`](@ref). - Currently, this is only supported for bitstypes or other pointer-free (`isbits`) immutable types. + Currently, this is only supported for bitstypes or other pointer-free (`isbits`) immutable struct types. Any operation that throws an error is probably currently unimplemented and should be posted as a bug so that it can be resolved. -If the pointer of interest is a plain-data array (bitstype or immutable), the function [`unsafe_wrap(Array, ptr,dims,[own])`](@ref) +If the pointer of interest is a plain-data array (bitstype or immutable struct), the function [`unsafe_wrap(Array, ptr,dims,[own])`](@ref) may be more useful. The final parameter should be true if Julia should "take ownership" of the underlying buffer and call `free(ptr)` when the returned `Array` object is finalized. If the `own` parameter is omitted or false, the caller must ensure the buffer remains in existence until diff --git a/examples/ModInts.jl b/examples/ModInts.jl index 0effca60b1c0d..d811722814843 100644 --- a/examples/ModInts.jl +++ b/examples/ModInts.jl @@ -5,7 +5,7 @@ export ModInt import Base: +, -, *, /, inv -immutable ModInt{n} <: Integer +struct ModInt{n} <: Integer k::Int ModInt{n}(k) where n = new(mod(k,n)) end diff --git a/examples/bubblesort.jl b/examples/bubblesort.jl index e1b215b9bc5b7..8b39e6793ded4 100644 --- a/examples/bubblesort.jl +++ b/examples/bubblesort.jl @@ -1,7 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license import Base.Sort -immutable BubbleSortAlg <: Sort.Algorithm end +struct BubbleSortAlg <: Sort.Algorithm end const BubbleSort = BubbleSortAlg() function Base.sort!(v::AbstractVector, lo::Int, hi::Int, ::BubbleSortAlg, o::Sort.Ordering) diff --git a/examples/clustermanager/0mq/ZMQCM.jl b/examples/clustermanager/0mq/ZMQCM.jl index 1fd7fad73c0df..4d89de0ed029c 100644 --- a/examples/clustermanager/0mq/ZMQCM.jl +++ b/examples/clustermanager/0mq/ZMQCM.jl @@ -17,7 +17,7 @@ const REQUEST_ACK = "R" const ACK_MSG = "A" const KILL_MSG = "K" -type ZMQCMan <: ClusterManager +mutable struct ZMQCMan <: ClusterManager map_zmq_julia::Dict{Int, Tuple} c::Condition isfree::Bool diff --git a/examples/clustermanager/simple/UnixDomainCM.jl b/examples/clustermanager/simple/UnixDomainCM.jl index 0822997d70149..f96c6e0fcf7a6 100644 --- a/examples/clustermanager/simple/UnixDomainCM.jl +++ b/examples/clustermanager/simple/UnixDomainCM.jl @@ -2,7 +2,7 @@ import Base: launch, manage, connect, exit -type UnixDomainCM <: ClusterManager +mutable struct UnixDomainCM <: ClusterManager np::Integer end diff --git a/examples/dictchannel.jl b/examples/dictchannel.jl index 5ac2e28e9f800..83c8e1eebc70c 100644 --- a/examples/dictchannel.jl +++ b/examples/dictchannel.jl @@ -2,7 +2,7 @@ import Base: put!, wait, isready, take!, fetch -type DictChannel <: AbstractChannel +mutable struct DictChannel <: AbstractChannel d::Dict cond_take::Condition # waiting for data to become available DictChannel() = new(Dict(), Condition()) diff --git a/examples/juliatypes.jl b/examples/juliatypes.jl index effb8bd0884bb..efd924c18e828 100644 --- a/examples/juliatypes.jl +++ b/examples/juliatypes.jl @@ -2,9 +2,9 @@ import Base: convert, show -abstract Ty +abstract type Ty end -type TypeName +mutable struct TypeName name::Symbol abs::Bool super::Ty # actually TagT @@ -17,7 +17,7 @@ end show(io::IO, x::TypeName) = print(io, x.name) -type TagT <: Ty +mutable struct TagT <: Ty name::TypeName params vararg::Bool @@ -40,12 +40,12 @@ function show(io::IO, t::TagT) print(io, '}') end -type BottomTy <: Ty +mutable struct BottomTy <: Ty end show(io::IO, ::BottomTy) = print(io, "BottomT") -type UnionT <: Ty +mutable struct UnionT <: Ty a b UnionT() = BottomT @@ -69,7 +69,7 @@ function show(io::IO, t::UnionT) print(io, ')') end -type Var +mutable struct Var name::Symbol lb ub @@ -96,7 +96,7 @@ end show(io::IO, v::Var) = print(io, v.name) -type UnionAllT <: Ty +mutable struct UnionAllT <: Ty var::Var T UnionAllT(v::Var, t) = new(v, t) @@ -151,7 +151,7 @@ subst(t, env) = t isequal_type(x, y) = issub(x, y) && issub(y, x) -type Bounds +mutable struct Bounds # record current lower and upper bounds of a Var # right: whether this Var is on the right-hand side of A <: B lb @@ -159,14 +159,14 @@ type Bounds right::Bool end -type UnionState +mutable struct UnionState depth::Int # number of union decision points we're inside more::Bool # new union found; need to grow stack stack::Vector{Bool} # stack of decisions UnionState() = new(1,0,Bool[]) end -type Env +mutable struct Env vars::Dict{Var,Bounds} Lunions::UnionState Runions::UnionState diff --git a/examples/lru.jl b/examples/lru.jl index a8342d8d1f221..dd682ba5177e7 100644 --- a/examples/lru.jl +++ b/examples/lru.jl @@ -25,17 +25,17 @@ import Base.haskey, Base.get import Base.setindex!, Base.getindex, Base.delete!, Base.empty! import Base.show -abstract LRU{K,V} <: Associative{K,V} +abstract type LRU{K,V} <: Associative{K,V} end # Default cache size const __MAXCACHE = 1024 -type CacheItem{K,V} +mutable struct CacheItem{K,V} k::K v::V end -type UnboundedLRU{K,V} <: LRU{K,V} +mutable struct UnboundedLRU{K,V} <: LRU{K,V} ht::Dict q::Vector{CacheItem} @@ -43,7 +43,7 @@ type UnboundedLRU{K,V} <: LRU{K,V} end UnboundedLRU() = UnboundedLRU{Any, Any}() -type BoundedLRU{K,V} <: LRU{K,V} +mutable struct BoundedLRU{K,V} <: LRU{K,V} ht::Dict q::Vector{CacheItem} maxsize::Int diff --git a/examples/time.jl b/examples/time.jl index a69d348becd54..98f14449c8d81 100644 --- a/examples/time.jl +++ b/examples/time.jl @@ -5,7 +5,7 @@ export TimeDelta import Base.show, Base.+, Base.-, Base.convert, Base.promote_rule -immutable TimeDelta{p} +struct TimeDelta{p} v::Int64 end diff --git a/examples/typetree.jl b/examples/typetree.jl index a86bc7c3e4aaa..bda8fe239459a 100644 --- a/examples/typetree.jl +++ b/examples/typetree.jl @@ -5,7 +5,7 @@ module TypeTrees # Generate a text graphic of Julia modules type tree ## -immutable Binding +struct Binding mod::Module sym::Symbol end @@ -13,7 +13,7 @@ Binding(tn::TypeName) = Binding(tn.module, tn.name) Base.isless(a::Binding, b::Binding) = isless(a.sym, b.sym) # The node type holds the type of the current node and a dict of subtypes -immutable TTNode +struct TTNode typ::Type subtypes::Dict{Binding, TTNode} diff --git a/src/abi_aarch64.cpp b/src/abi_aarch64.cpp index e2334490317d4..ac624e2a330a2 100644 --- a/src/abi_aarch64.cpp +++ b/src/abi_aarch64.cpp @@ -45,7 +45,7 @@ Type *get_llvm_vectype(jl_datatype_t *dt) const // the homogeneity check. jl_datatype_t *ft0 = (jl_datatype_t*)jl_field_type(dt, 0); // `ft0` should be a `VecElement` type and the true element type - // should be a `bitstype` + // should be a primitive type if (ft0->name != jl_vecelement_typename || ((jl_datatype_t*)jl_field_type(ft0, 0))->layout->nfields) return nullptr; diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index 7323bc077b50e..52db8098c2ea1 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -409,10 +409,10 @@ static jl_cgval_t generic_bitcast(const jl_cgval_t *argv, jl_codectx_t *ctx) if (!jl_is_bitstype(v.typ)) { if (isboxed) { Value *isbits = emit_datatype_isbitstype(typ); - error_unless(isbits, "bitcast: expected bitstype value for second argument", ctx); + error_unless(isbits, "bitcast: expected primitive type value for second argument", ctx); } else { - emit_error("bitcast: expected bitstype value for second argument", ctx); + emit_error("bitcast: expected primitive type value for second argument", ctx); return jl_cgval_t(); } } diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 241cbe1ea7618..62f240040598c 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -113,8 +113,9 @@ (define operator? (Set operators)) (define initial-reserved-words '(begin while if for try return break continue - function macro quote let local global const - abstract typealias type bitstype immutable do + function macro quote let local global const do + struct + abstract typealias bitstype type immutable ;; to be deprecated module baremodule using import export importall)) (define initial-reserved-word? (Set initial-reserved-words)) @@ -978,7 +979,7 @@ ;; also handles looking for syntactic reserved words (define (parse-call s) (let ((ex (parse-unary-prefix s))) - (if (initial-reserved-word? ex) + (if (or (initial-reserved-word? ex) (memq ex '(mutable primitive))) (parse-resword s ex) (parse-call-chain s ex #f)))) @@ -1134,6 +1135,13 @@ (and (eq? (car sig) 'where) (valid-func-sig? paren (cadr sig)))))) +(define (parse-struct-def s mut? word) + (if (reserved-word? (peek-token s)) + (error (string "invalid type name \"" (take-token s) "\""))) + (let ((sig (parse-subtype-spec s))) + (begin0 (list 'type (if mut? 'true 'false) sig (parse-block s)) + (expect-end s word)))) + ;; parse expressions or blocks introduced by syntactic reserved words (define (parse-resword s word) (with-bindings @@ -1254,22 +1262,51 @@ (body (parse-block s))) (expect-end s word) (list word def body))))) + ((abstract) - (list 'abstract (parse-subtype-spec s))) - ((type immutable) - (let ((immu? (eq? word 'immutable))) - (if (reserved-word? (peek-token s)) - (error (string "invalid type name \"" (take-token s) "\""))) - (let ((sig (parse-subtype-spec s))) - (begin0 (list 'type (if (eq? word 'type) 'true 'false) - sig (parse-block s)) - (expect-end s word))))) + (let ((ty (eq? (peek-token s) 'type))) + (if ty + (take-token s)) + (let ((spec (parse-subtype-spec s))) + (if (not ty) + (syntax-deprecation s (string "abstract " (deparse spec)) + (string "abstract type " (deparse spec) " end"))) + (begin0 (list 'abstract spec) + (if ty (expect-end s "abstract type")))))) + ((struct) + (begin (take-token s) + (parse-struct-def s #f word))) + ((mutable) + (if (not (eq? (peek-token s) 'struct)) + (parse-call-chain s word #f) + (begin (take-token s) + (parse-struct-def s #t word)))) + ((primitive) + (if (not (eq? (peek-token s) 'type)) + (parse-call-chain s word #f) + (begin (take-token s) + (let* ((spec (with-space-sensitive (parse-subtype-spec s))) + (nb (with-space-sensitive (parse-cond s)))) + (begin0 (list 'bitstype nb spec) + (expect-end s "primitive type")))))) + ;; deprecated type keywords + ((type) + ;; TODO fully deprecate post-0.6 + ;;(syntax-deprecation s "type" "mutable struct") + (parse-struct-def s #t word)) + ((immutable) + ;;(syntax-deprecation s "immutable" "struct") + (parse-struct-def s #f word)) ((bitstype) - (list 'bitstype (with-space-sensitive (parse-cond s)) - (parse-subtype-spec s))) + (let* ((nb (with-space-sensitive (parse-cond s))) + (spec (parse-subtype-spec s))) + (syntax-deprecation s (string "bitstype " (deparse nb) " " (deparse spec)) + (string "primitive type " (deparse spec) " " (deparse nb) " end")) + (list 'bitstype nb spec))) ((typealias) (let ((lhs (with-space-sensitive (parse-call s)))) - (list 'typealias lhs (parse-where s)))) + (list 'typealias lhs (parse-where s)))) + ((try) (let ((try-block (if (memq (require-token s) '(catch finally)) '(block) diff --git a/src/runtime_intrinsics.c b/src/runtime_intrinsics.c index f05da229718d2..c868319167044 100644 --- a/src/runtime_intrinsics.c +++ b/src/runtime_intrinsics.c @@ -19,9 +19,9 @@ JL_DLLEXPORT jl_value_t *jl_bitcast(jl_value_t *ty, jl_value_t *v) { JL_TYPECHK(bitcast, datatype, ty); if (!jl_is_leaf_type(ty) || !jl_is_bitstype(ty)) - jl_error("bitcast: target type not a leaf bitstype"); + jl_error("bitcast: target type not a leaf primitive type"); if (!jl_is_bitstype(jl_typeof(v))) - jl_error("bitcast: value not a bitstype"); + jl_error("bitcast: value not a primitive type"); if (jl_datatype_size(jl_typeof(v)) != jl_datatype_size(ty)) jl_error("bitcast: argument size does not match size of target type"); if (ty == jl_typeof(v)) @@ -322,9 +322,9 @@ jl_value_t *jl_iintrinsic_1(jl_value_t *ty, jl_value_t *a, const char *name, jl_value_t *(*lambda1)(jl_value_t*, void*, unsigned, unsigned, const void*), const void *list) { if (!jl_is_bitstype(jl_typeof(a))) - jl_errorf("%s: value is not a bitstype", name); + jl_errorf("%s: value is not a primitive type", name); if (!jl_is_bitstype(ty)) - jl_errorf("%s: type is not a bitstype", name); + jl_errorf("%s: type is not a primitive type", name); void *pa = jl_data_ptr(a); unsigned isize = jl_datatype_size(jl_typeof(a)); unsigned isize2 = next_power_of_two(isize); @@ -391,9 +391,9 @@ static inline jl_value_t *jl_intrinsic_cvt(jl_value_t *ty, jl_value_t *a, const jl_ptls_t ptls = jl_get_ptls_states(); jl_value_t *aty = jl_typeof(a); if (!jl_is_bitstype(aty)) - jl_errorf("%s: value is not a bitstype", name); + jl_errorf("%s: value is not a primitive type", name); if (!jl_is_bitstype(ty)) - jl_errorf("%s: type is not a bitstype", name); + jl_errorf("%s: type is not a primitive type", name); void *pa = jl_data_ptr(a); unsigned isize = jl_datatype_size(aty); unsigned osize = jl_datatype_size(ty); @@ -430,9 +430,9 @@ static inline jl_value_t *jl_fintrinsic_1(jl_value_t *ty, jl_value_t *a, const c { jl_ptls_t ptls = jl_get_ptls_states(); if (!jl_is_bitstype(jl_typeof(a))) - jl_errorf("%s: value is not a bitstype", name); + jl_errorf("%s: value is not a primitive type", name); if (!jl_is_bitstype(ty)) - jl_errorf("%s: type is not a bitstype", name); + jl_errorf("%s: type is not a primitive type", name); unsigned sz2 = jl_datatype_size(ty); jl_value_t *newv = jl_gc_alloc(ptls, sz2, ty); void *pa = jl_data_ptr(a), *pr = jl_data_ptr(newv); @@ -542,10 +542,10 @@ jl_value_t *jl_iintrinsic_2(jl_value_t *a, jl_value_t *b, const char *name, if (!cvtb) jl_errorf("%s: types of a and b must match", name); if (!jl_is_bitstype(tyb)) - jl_errorf("%s: b is not a bitstypes", name); + jl_errorf("%s: b is not a primitive type", name); } if (!jl_is_bitstype(ty)) - jl_errorf("%s: a is not a bitstypes", name); + jl_errorf("%s: a is not a primitive type", name); void *pa = jl_data_ptr(a), *pb = jl_data_ptr(b); unsigned sz = jl_datatype_size(ty); unsigned sz2 = next_power_of_two(sz); @@ -628,7 +628,7 @@ JL_DLLEXPORT jl_value_t *jl_##name(jl_value_t *a, jl_value_t *b) \ if (jl_typeof(b) != ty) \ jl_error(#name ": types of a and b must match"); \ if (!jl_is_bitstype(ty)) \ - jl_error(#name ": values are not bitstypes"); \ + jl_error(#name ": values are not primitive types"); \ int sz = jl_datatype_size(ty); \ jl_value_t *newv = jl_gc_alloc(ptls, sz, ty); \ void *pa = jl_data_ptr(a), *pb = jl_data_ptr(b), *pr = jl_data_ptr(newv); \ @@ -655,7 +655,7 @@ JL_DLLEXPORT jl_value_t *jl_##name(jl_value_t *a, jl_value_t *b) \ if (jl_typeof(b) != ty) \ jl_error(#name ": types of a and b must match"); \ if (!jl_is_bitstype(ty)) \ - jl_error(#name ": values are not bitstypes"); \ + jl_error(#name ": values are not primitive types"); \ void *pa = jl_data_ptr(a), *pb = jl_data_ptr(b); \ int sz = jl_datatype_size(ty); \ int cmp; \ @@ -683,7 +683,7 @@ JL_DLLEXPORT jl_value_t *jl_##name(jl_value_t *a, jl_value_t *b, jl_value_t *c) if (jl_typeof(b) != ty || jl_typeof(c) != ty) \ jl_error(#name ": types of a, b, and c must match"); \ if (!jl_is_bitstype(ty)) \ - jl_error(#name ": values are not bitstypes"); \ + jl_error(#name ": values are not primitive types"); \ int sz = jl_datatype_size(ty); \ jl_value_t *newv = jl_gc_alloc(ptls, sz, ty); \ void *pa = jl_data_ptr(a), *pb = jl_data_ptr(b), *pc = jl_data_ptr(c), *pr = jl_data_ptr(newv); \ @@ -871,7 +871,7 @@ JL_DLLEXPORT jl_value_t *jl_check_top_bit(jl_value_t *a) { jl_value_t *ty = jl_typeof(a); if (!jl_is_bitstype(ty)) - jl_error("check_top_bit: value is not a bitstype"); + jl_error("check_top_bit: value is not a primitive type"); if (signbitbyte(jl_data_ptr(a), jl_datatype_size(ty))) jl_throw(jl_inexact_exception); return a; @@ -930,9 +930,9 @@ JL_DLLEXPORT jl_value_t *jl_powi_llvm(jl_value_t *a, jl_value_t *b) jl_ptls_t ptls = jl_get_ptls_states(); jl_value_t *ty = jl_typeof(a); if (!jl_is_bitstype(ty)) - jl_error("powi_llvm: a is not a bitstype"); + jl_error("powi_llvm: a is not a primitive type"); if (!jl_is_bitstype(jl_typeof(b)) || jl_datatype_size(jl_typeof(b)) != 4) - jl_error("powi_llvm: b is not a 32-bit bitstype"); + jl_error("powi_llvm: b is not a 32-bit primitive type"); int sz = jl_datatype_size(ty); jl_value_t *newv = jl_gc_alloc(ptls, sz, ty); void *pa = jl_data_ptr(a), *pr = jl_data_ptr(newv); diff --git a/test/TestHelpers.jl b/test/TestHelpers.jl index 56f6e59ac7041..4afc619c833b5 100644 --- a/test/TestHelpers.jl +++ b/test/TestHelpers.jl @@ -2,7 +2,7 @@ module TestHelpers -type FakeTerminal <: Base.Terminals.UnixTerminal +mutable struct FakeTerminal <: Base.Terminals.UnixTerminal in_stream::Base.IO out_stream::Base.IO err_stream::Base.IO @@ -54,7 +54,7 @@ using Base: Indices, LinearSlow, LinearFast, tail export OffsetArray -immutable OffsetArray{T,N,AA<:AbstractArray} <: AbstractArray{T,N} +struct OffsetArray{T,N,AA<:AbstractArray} <: AbstractArray{T,N} parent::AA offsets::NTuple{N,Int} end diff --git a/test/abstractarray.jl b/test/abstractarray.jl index a6a01611559ed..5bd1f95cef8bf 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -165,12 +165,12 @@ end # token type on which to dispatch testing methods in order to avoid potential # name conflicts elsewhere in the base test suite -type TestAbstractArray end +mutable struct TestAbstractArray end ## Tests for the abstract array interfaces with minimally defined array types # A custom linear fast array type with 24 elements that doesn't rely upon Array storage -type T24Linear{T,N,dims} <: AbstractArray{T,N} +mutable struct T24Linear{T,N,dims} <: AbstractArray{T,N} v1::T; v2::T; v3::T; v4::T; v5::T; v6::T; v7::T; v8::T v9::T; v10::T; v11::T; v12::T; v13::T; v14::T; v15::T; v16::T v17::T; v18::T; v19::T; v20::T; v21::T; v22::T; v23::T; v24::T @@ -197,7 +197,7 @@ Base.getindex(A::T24Linear, i::Int) = getfield(A, i) Base.setindex!{T}(A::T24Linear{T}, v, i::Int) = setfield!(A, i, convert(T, v)) # A custom linear slow sparse-like array that relies upon Dict for its storage -immutable TSlow{T,N} <: AbstractArray{T,N} +struct TSlow{T,N} <: AbstractArray{T,N} data::Dict{NTuple{N,Int}, T} dims::NTuple{N,Int} end @@ -433,7 +433,7 @@ function test_primitives{T}(::Type{T}, shape, ::Type{TestAbstractArray}) end let - type TestThrowNoGetindex{T} <: AbstractVector{T} end + mutable struct TestThrowNoGetindex{T} <: AbstractVector{T} end Base.length(::TestThrowNoGetindex) = 2 Base.size(::TestThrowNoGetindex) = (2,) @test_throws ErrorException isassigned(TestThrowNoGetindex{Float64}(), 1) @@ -450,13 +450,13 @@ function test_in_bounds(::Type{TestAbstractArray}) @test checkbounds(Bool, A, len + 1) == false end -type UnimplementedFastArray{T, N} <: AbstractArray{T, N} end +mutable struct UnimplementedFastArray{T, N} <: AbstractArray{T, N} end Base.linearindexing(::UnimplementedFastArray) = Base.LinearFast() -type UnimplementedSlowArray{T, N} <: AbstractArray{T, N} end +mutable struct UnimplementedSlowArray{T, N} <: AbstractArray{T, N} end Base.linearindexing(::UnimplementedSlowArray) = Base.LinearSlow() -type UnimplementedArray{T, N} <: AbstractArray{T, N} end +mutable struct UnimplementedArray{T, N} <: AbstractArray{T, N} end function test_getindex_internals{T}(::Type{T}, shape, ::Type{TestAbstractArray}) N = prod(shape) @@ -590,7 +590,7 @@ function test_ind2sub(::Type{TestAbstractArray}) end # A custom linear slow array that insists upon Cartesian indexing -type TSlowNIndexes{T,N} <: AbstractArray{T,N} +mutable struct TSlowNIndexes{T,N} <: AbstractArray{T,N} data::Array{T,N} end Base.linearindexing{A<:TSlowNIndexes}(::Type{A}) = Base.LinearSlow() @@ -599,7 +599,7 @@ Base.getindex(A::TSlowNIndexes, index::Int...) = error("Must use $(ndims(A)) ind Base.getindex{T}(A::TSlowNIndexes{T,2}, i::Int, j::Int) = A.data[i,j] -type GenericIterator{N} end +mutable struct GenericIterator{N} end Base.start{N}(::GenericIterator{N}) = 1 Base.next{N}(::GenericIterator{N}, i) = (i, i + 1) Base.done{N}(::GenericIterator{N}, i) = i > N ? true : false diff --git a/test/ambiguous.jl b/test/ambiguous.jl index 8470d9a4ad524..fa6cc8c54e355 100644 --- a/test/ambiguous.jl +++ b/test/ambiguous.jl @@ -178,7 +178,7 @@ end # issue #17350 module Ambig6 -immutable ScaleMinMax{To,From} end +struct ScaleMinMax{To,From} end map1{To<:Union{Float32,Float64},From<:Real}(mapi::ScaleMinMax{To,From}, val::From) = 1 map1{To<:Union{Float32,Float64},From<:Real}(mapi::ScaleMinMax{To,From}, val::Union{Real,Complex}) = 2 end @@ -186,14 +186,14 @@ end @test isempty(detect_ambiguities(Ambig6)) module Ambig7 -immutable T end +struct T end (::T)(x::Int8, y) = 1 (::T)(x, y::Int8) = 2 end @test length(detect_ambiguities(Ambig7)) == 1 module Ambig17648 -immutable MyArray{T,N} <: AbstractArray{T,N} +struct MyArray{T,N} <: AbstractArray{T,N} data::Array{T,N} end diff --git a/test/arrayops.jl b/test/arrayops.jl index 2b5c6641fb1c9..9f245df944807 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -558,7 +558,7 @@ D = cat(3, B, B) @test unique(D, 3) == cat(3, B) # With hash collisions -immutable HashCollision +struct HashCollision x::Float64 end Base.hash(::HashCollision, h::UInt) = h @@ -1602,7 +1602,7 @@ module RetTypeDecl using Base.Test import Base: +, *, broadcast, convert - immutable MeterUnits{T,P} <: Number + struct MeterUnits{T,P} <: Number val::T end MeterUnits{T}(val::T, pow::Int) = MeterUnits{T,pow}(val) @@ -1644,7 +1644,7 @@ end ### ### LinearSlow workout ### -immutable LinSlowMatrix{T} <: DenseArray{T,2} +struct LinSlowMatrix{T} <: DenseArray{T,2} data::Matrix{T} end @@ -1734,7 +1734,7 @@ x13250[UInt(1):UInt(2)] = 1.0 @test x13250[2] == 1.0 @test x13250[3] == 0.0 -immutable SquaresVector <: AbstractArray{Int, 1} +struct SquaresVector <: AbstractArray{Int, 1} count::Int end Base.size(S::SquaresVector) = (S.count,) @@ -1800,7 +1800,7 @@ end @inferred map(Int8, Int[0]) # make sure @inbounds isn't used too much -type OOB_Functor{T}; a::T; end +mutable struct OOB_Functor{T}; a::T; end (f::OOB_Functor)(i::Int) = f.a[i] let f = OOB_Functor([1,2]) @test_throws BoundsError map(f, [1,2,3,4,5]) @@ -1879,7 +1879,7 @@ module AutoRetType using Base.Test -immutable Foo end +struct Foo end for op in (:+, :*, :÷, :%, :<<, :>>, :-, :/, :\, ://, :^) @eval import Base.$(op) @eval $(op)(::Foo, ::Foo) = Foo() @@ -2030,7 +2030,7 @@ end end # issue #11053 -type T11053 +mutable struct T11053 a::Float64 end Base.:*(a::T11053, b::Real) = T11053(a.a*b) diff --git a/test/broadcast.jl b/test/broadcast.jl index c708e2ebec83d..324fa60d8666b 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -376,7 +376,7 @@ let s = "foo" end # Ensure that even strange constructors that break `T(x)::T` work with broadcast -immutable StrangeType18623 end +struct StrangeType18623 end StrangeType18623(x) = x StrangeType18623(x,y) = (x,y) @test @inferred(broadcast(StrangeType18623, 1:3)) == [1,2,3] @@ -415,7 +415,7 @@ end @test let z = 1; A = broadcast!(x -> z += x, zeros(2), 1); A[1] != A[2]; end # broadcasting for custom AbstractArray -immutable Array19745{T,N} <: AbstractArray{T,N} +struct Array19745{T,N} <: AbstractArray{T,N} data::Array{T,N} end Base.getindex(A::Array19745, i::Integer...) = A.data[i...] diff --git a/test/ccall.jl b/test/ccall.jl index ab97417d4e99c..661d199e270bc 100644 --- a/test/ccall.jl +++ b/test/ccall.jl @@ -44,7 +44,7 @@ macro ccall_echo_objref(x, T, U) gen_ccall_echo(x, :(Ptr{$T}), U, :unsafe_pointer_to_objref) end -type IntLike +mutable struct IntLike x::Int end @test @ccall_echo_load(132, Ptr{Int}, Ref{Int}) === 132 @@ -128,11 +128,11 @@ end ## Tests for various sized data types (ByVal) -type Struct1 +mutable struct Struct1 x::Float32 y::Float64 end -immutable Struct1I +struct Struct1I x::Float32 y::Float64 end @@ -212,12 +212,12 @@ let a, b, x, y, z @test z == a + 1*b end -type Struct4 +mutable struct Struct4 x::Int32 y::Int32 z::Int32 end -immutable Struct4I +struct Struct4I x::Int32 y::Int32 z::Int32 @@ -240,13 +240,13 @@ end test_struct4(Struct4) test_struct4(Struct4I) -type Struct5 +mutable struct Struct5 x::Int32 y::Int32 z::Int32 a::Int32 end -immutable Struct5I +struct Struct5I x::Int32 y::Int32 z::Int32 @@ -271,12 +271,12 @@ end test_struct5(Struct5) test_struct5(Struct5I) -type Struct6 +mutable struct Struct6 x::Int64 y::Int64 z::Int64 end -immutable Struct6I +struct Struct6I x::Int64 y::Int64 z::Int64 @@ -299,11 +299,11 @@ end test_struct6(Struct6) test_struct6(Struct6I) -type Struct7 +mutable struct Struct7 x::Int64 y::Cchar end -immutable Struct7I +struct Struct7I x::Int64 y::Cchar end @@ -324,11 +324,11 @@ end test_struct7(Struct7) test_struct7(Struct7I) -type Struct8 +mutable struct Struct8 x::Int32 y::Cchar end -immutable Struct8I +struct Struct8I x::Int32 y::Cchar end @@ -349,11 +349,11 @@ end test_struct8(Struct8) test_struct8(Struct8I) -type Struct9 +mutable struct Struct9 x::Int32 y::Int16 end -immutable Struct9I +struct Struct9I x::Int32 y::Int16 end @@ -374,13 +374,13 @@ end test_struct9(Struct9) test_struct9(Struct9I) -type Struct10 +mutable struct Struct10 x::Cchar y::Cchar z::Cchar a::Cchar end -immutable Struct10I +struct Struct10I x::Cchar y::Cchar z::Cchar @@ -405,10 +405,10 @@ end test_struct10(Struct10) test_struct10(Struct10I) -type Struct11 +mutable struct Struct11 x::Complex64 end -immutable Struct11I +struct Struct11I x::Complex64 end @@ -427,11 +427,11 @@ end test_struct11(Struct11) test_struct11(Struct11I) -type Struct12 +mutable struct Struct12 x::Complex64 y::Complex64 end -immutable Struct12I +struct Struct12I x::Complex64 y::Complex64 end @@ -452,10 +452,10 @@ end test_struct12(Struct12) test_struct12(Struct12I) -type Struct13 +mutable struct Struct13 x::Complex128 end -immutable Struct13I +struct Struct13I x::Complex128 end @@ -474,11 +474,11 @@ end test_struct13(Struct13) test_struct13(Struct13I) -type Struct14 +mutable struct Struct14 x::Float32 y::Float32 end -immutable Struct14I +struct Struct14I x::Float32 y::Float32 end @@ -499,11 +499,11 @@ end test_struct14(Struct14) test_struct14(Struct14I) -type Struct15 +mutable struct Struct15 x::Float64 y::Float64 end -immutable Struct15I +struct Struct15I x::Float64 y::Float64 end @@ -524,7 +524,7 @@ end test_struct15(Struct15) test_struct15(Struct15I) -type Struct16 +mutable struct Struct16 x::Float32 y::Float32 z::Float32 @@ -532,7 +532,7 @@ type Struct16 b::Float64 c::Float64 end -immutable Struct16I +struct Struct16I x::Float32 y::Float32 z::Float32 @@ -562,11 +562,11 @@ end test_struct16(Struct16) test_struct16(Struct16I) -type Struct17 +mutable struct Struct17 a::Int8 b::Int16 end -immutable Struct17I +struct Struct17I a::Int8 b::Int16 end @@ -587,12 +587,12 @@ end test_struct17(Struct17) test_struct17(Struct17I) -type Struct18 +mutable struct Struct18 a::Int8 b::Int8 c::Int8 end -immutable Struct18I +struct Struct18I a::Int8 b::Int8 c::Int8 @@ -625,12 +625,12 @@ let a, b, x @test a == Int128(0x7f00123456789abc)<<64 + typemax(UInt64) end -type Struct_Big +mutable struct Struct_Big x::Int y::Int z::Int8 end -immutable Struct_BigI +struct Struct_BigI x::Int y::Int z::Int8 @@ -670,30 +670,30 @@ const Struct_huge1a = NTuple{8, Int64} const Struct_huge1b = NTuple{9, Int64} const Struct_huge2a = NTuple{8, Cdouble} const Struct_huge2b = NTuple{9, Cdouble} -type Struct_huge3a +mutable struct Struct_huge3a cf::NTuple{3, Complex{Cfloat}} f7::Cfloat f8::Cfloat end -type Struct_huge3b +mutable struct Struct_huge3b cf::NTuple{7, Complex{Cfloat}} r8a::Cfloat r8b::Cfloat end -type Struct_huge3c +mutable struct Struct_huge3c cf::NTuple{7, Complex{Cfloat}} r8a::Cfloat r8b::Cfloat r9::Cfloat end -type Struct_huge4a +mutable struct Struct_huge4a r12::Complex{Cdouble} r34::Complex{Cdouble} r5::Complex{Cfloat} r67::Complex{Cdouble} r8::Cdouble end -type Struct_huge4b +mutable struct Struct_huge4b r12::Complex{Cdouble} r34::Complex{Cdouble} r5::Complex{Cfloat} @@ -901,79 +901,79 @@ typealias V2xF64 VecReg{2,Float64} typealias V2xI32 VecReg{2,Int32} typealias V4xI32 VecReg{4,Int32} -immutable Struct_AA64_1 +struct Struct_AA64_1 v1::Int32 v2::Int128 end -immutable Struct_AA64_2 +struct Struct_AA64_2 v1::Float16 v2::Float64 end # This is a homogenious short vector aggregate -immutable Struct_AA64_3 +struct Struct_AA64_3 v1::VecReg{8,Int8} v2::VecReg{2,Float32} end # This is NOT a homogenious short vector aggregate -immutable Struct_AA64_4 +struct Struct_AA64_4 v2::VecReg{2,Float32} v1::VecReg{8,Int16} end -type Struct_huge1_ppc64 +mutable struct Struct_huge1_ppc64 m::Int64 v::V4xF32 end -type Struct_huge2_ppc64 +mutable struct Struct_huge2_ppc64 v1::V4xF32 v2::V2xI32 end -type Struct_huge3_ppc64 +mutable struct Struct_huge3_ppc64 v1::V4xF32 f::NTuple{4,Float32} end -type Struct_huge4_ppc64 +mutable struct Struct_huge4_ppc64 v1::V2xF32 v2::V2xF64 end -type Struct_huge5_ppc64 +mutable struct Struct_huge5_ppc64 v1::NTuple{9,V4xF32} end -type Struct_huge6_ppc64 +mutable struct Struct_huge6_ppc64 v1::NTuple{8,V4xF32} v2::V4xF32 end -type Struct_huge7_ppc64 +mutable struct Struct_huge7_ppc64 v1::VecReg{3,Int32} v2::VecReg{3,Int32} end -type Struct_huge1_ppc64_hva +mutable struct Struct_huge1_ppc64_hva v1::NTuple{8,V4xF32} end -type Struct_huge2_ppc64_hva +mutable struct Struct_huge2_ppc64_hva v1::NTuple{2,NTuple{2,V4xF32}} end -type Struct_huge3_ppc64_hva +mutable struct Struct_huge3_ppc64_hva vf1::V4xF32 vf2::Tuple{NTuple{2,V4xF32}} end -type Struct_huge4_ppc64_hva +mutable struct Struct_huge4_ppc64_hva v1::V4xI32 v2::V4xF32 end -type Struct_huge5_ppc64_hva +mutable struct Struct_huge5_ppc64_hva v1::V4xI32 v2::V2xF64 end @@ -1156,7 +1156,7 @@ for i in 1:3 ccall((:test_echo_p, libccalltest), Ptr{Void}, (Any,), f17413()) end -immutable SpillPint +struct SpillPint a::Ptr{Cint} b::Ptr{Cint} end diff --git a/test/compile.jl b/test/compile.jl index 718c24f6f7a24..91b0f1e4192f8 100644 --- a/test/compile.jl +++ b/test/compile.jl @@ -47,7 +47,7 @@ try end # test for creation of some reasonably complicated type - immutable MyType{T} end + struct MyType{T} end const t17809s = Any[ Tuple{ Type{Ptr{MyType{i}}}, @@ -67,20 +67,20 @@ try const nothingkw = Core.kwfunc(Base.nothing) # issue 16908 (some complicated types and external method definitions) - abstract CategoricalPool{T, R <: Integer, V} - abstract CategoricalValue{T, R <: Integer} - immutable NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V} + abstract type CategoricalPool{T, R <: Integer, V} end + abstract type CategoricalValue{T, R <: Integer} end + struct NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V} index::Vector{T} invindex::Dict{T, R} order::Vector{R} ordered::Vector{T} valindex::Vector{V} end - immutable NominalValue{T, R <: Integer} <: CategoricalValue{T, R} + struct NominalValue{T, R <: Integer} <: CategoricalValue{T, R} level::R pool::NominalPool{T, R, NominalValue{T, R}} end - immutable OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R} + struct OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R} level::R pool::NominalPool{T, R, NominalValue{T, R}} end @@ -92,10 +92,10 @@ try # more tests for method signature involving a complicated type # issue 18343 - immutable Pool18343{R, V} + struct Pool18343{R, V} valindex::Vector{V} end - immutable Value18343{T, R} + struct Value18343{T, R} pool::Pool18343{R, Value18343{T, R}} end Base.convert{S}(::Type{Nullable{S}}, ::Value18343{Nullable}) = 2 diff --git a/test/copy.jl b/test/copy.jl index fd4cf26b98a0c..015e3b3e507bf 100644 --- a/test/copy.jl +++ b/test/copy.jl @@ -110,11 +110,11 @@ let x = BigFloat[1:1000;], y, z, v end # issue #19921 -type Foo19921 +mutable struct Foo19921 a::String end -type Bar19921 +mutable struct Bar19921 foo::Foo19921 fooDict::Dict{Foo19921, Int64} end diff --git a/test/core.jl b/test/core.jl index f5499e64f4d1b..43579839dbefd 100644 --- a/test/core.jl +++ b/test/core.jl @@ -130,9 +130,9 @@ Type{Integer} # cache this @test Base.typeseq(typejoin(Union{Int,AbstractString},Int8), Any) # typejoin associativity -abstract Foo____{K} -type Wow____{K,V} <: Foo____{K} end -type Bar____{K,V} <: Foo____{K} end +abstract type Foo____{K} end +mutable struct Wow____{K,V} <: Foo____{K} end +mutable struct Bar____{K,V} <: Foo____{K} end let a = Wow____{Int64, Int64} b = Wow____{Int64, Float64} @@ -161,8 +161,8 @@ nttest1{n}(x::NTuple{n,Int}) = n # type declarations -abstract Sup_{A,B} -abstract Qux_{T} <: Sup_{Qux_{Int},T} +abstract type Sup_{A,B} end +abstract type Qux_{T} <: Sup_{Qux_{Int},T} end @test Qux_{Int}.super <: Sup_ @test ===(Qux_{Int}, Qux_{Int}.super.parameters[1]) @@ -175,43 +175,43 @@ abstract Qux_{T} <: Sup_{Qux_{Int},T} @test ===(Qux_{Int}, Qux_.body.super.parameters[1].super.parameters[1]) @test ===(Int, Qux_.body.super.parameters[1].super.parameters[2]) -type Foo_{T} x::Foo_{Int} end +mutable struct Foo_{T} x::Foo_{Int} end @test ===(Foo_.body.types[1], Foo_{Int}) @test ===(Foo_.body.types[1].types[1], Foo_{Int}) -type Circ_{T} x::Circ_{T} end +mutable struct Circ_{T} x::Circ_{T} end @test ===(Circ_{Int}, Circ_{Int}.types[1]) -abstract Sup2a_ -abstract Sup2b_{A <: Sup2a_, B} <: Sup2a_ -@test_throws ErrorException @eval abstract Qux2_{T} <: Sup2b_{Qux2_{Int}, T} # wrapped in eval to avoid #16793 +abstract type Sup2a_ end +abstract type Sup2b_{A <: Sup2a_, B} <: Sup2a_ end +@test_throws ErrorException @eval abstract type Qux2_{T} <: Sup2b_{Qux2_{Int}, T} end # wrapped in eval to avoid #16793 # issue #3890 -type A3890{T1} +mutable struct A3890{T1} x::Matrix{Complex{T1}} end @test A3890{Float64}.types[1] === Array{Complex{Float64},2} # make sure the field type Matrix{Complex{T1}} isn't cached -type B3890{T2} +mutable struct B3890{T2} x::Matrix{Complex{T2}} end @test B3890{Float64}.types[1] === Array{Complex{Float64},2} # issue #786 -type Node{T} +mutable struct Node{T} v::Vector{Node} end @test ===(Node{Int}.types[1].parameters[1], Node) -type Node2{T} +mutable struct Node2{T} v::Vector{Node2{T}} end @test ===(Node2{Int}.types[1].parameters[1], Node2{Int}) -type FooFoo{A,B} y::FooFoo{A} end +mutable struct FooFoo{A,B} y::FooFoo{A} end @test FooFoo{Int} <: FooFoo{Int,AbstractString}.types[1] @@ -469,7 +469,7 @@ end @test [-1 ~1] == [(-1) (~1)] # undefinedness -type UndefField +mutable struct UndefField field UndefField() = new() end @@ -497,7 +497,7 @@ let end # isassigned, issue #11167 -type Type11167{T,N} end +mutable struct Type11167{T,N} end Type11167{Int,2} let tname = Type11167.body.body.name @test !isassigned(tname.cache, 0) @@ -549,7 +549,7 @@ let @test isa(mytype(some_data),Vector{Tuple{String, DataType}}) end -type MyArray{N} <: AbstractArray{Int, N} +mutable struct MyArray{N} <: AbstractArray{Int, N} end let local x @@ -568,7 +568,7 @@ let @test ===(g(a), a) end -type _AA{T}; a::T; end +mutable struct _AA{T}; a::T; end typealias _AoA{T} _AA{_AA{T}} let local g, a @@ -827,7 +827,7 @@ let end # issue #1153 -type SI{m, s, kg} +mutable struct SI{m, s, kg} value::AbstractFloat end @@ -897,7 +897,7 @@ let @test_throws InexactError unsafe_wrap(Array, pointer(a), -3) end -immutable FooBar2515 +struct FooBar2515 foo::Int bar::Int end @@ -935,7 +935,7 @@ let end # issue #1442 -type S1442{T} +mutable struct S1442{T} end let @@ -948,9 +948,9 @@ let end # issue #1727 -abstract Component +abstract type Component end -type Transform <: Component +mutable struct Transform <: Component x y z @@ -958,7 +958,7 @@ type Transform <: Component Transform() = new(0, 0, 0) end -type Body <: Component +mutable struct Body <: Component vel curr_force @@ -1035,7 +1035,7 @@ let end # issue #2365 -type B2365{T} +mutable struct B2365{T} v::Union{T, Void} end @test B2365{Int}(nothing).v === nothing @@ -1051,18 +1051,18 @@ let end # issue #2509 -immutable Foo2509; foo::Int; end +struct Foo2509; foo::Int; end @test Foo2509(1) != Foo2509(2) @test Foo2509(42) == Foo2509(42) # issue #2517 -immutable Foo2517; end +struct Foo2517; end @test repr(Foo2517()) == "$(curmod_prefix)Foo2517()" @test repr(Array{Foo2517}(1)) == "$(curmod_prefix)Foo2517[$(curmod_prefix)Foo2517()]" @test Foo2517() === Foo2517() # issue #1474 -type X1474{a,b} end +mutable struct X1474{a,b} end let local Y Y{A,B}(::Type{X1474{A,B}}) = 1 @@ -1074,7 +1074,7 @@ let end # issue #2562 -type Node2562{T} +mutable struct Node2562{T} value::T Node2562{T}(value::T) where T = new(value) end @@ -1084,7 +1084,7 @@ makenode2562(value) = Node2562(value) @test isa(makenode2562(0), Node2562) # issue #2619 -type I2619{T} +mutable struct I2619{T} v::T I2619{T}(v) where T = new(convert(T,v)) end @@ -1103,15 +1103,15 @@ i2619() # issue #2919 typealias Foo2919 Int -type Baz2919; Foo2919::Foo2919; end +mutable struct Baz2919; Foo2919::Foo2919; end @test Baz2919(3).Foo2919 === 3 # issue #2982 module M2982 -abstract U +abstract type U end macro bad(Y) quote - type $(esc(Y)) <: U + mutable struct $(esc(Y)) <: U end end end @@ -1169,7 +1169,7 @@ end @test isa(f3821(), Array) # issue #4075 -immutable Foo4075 +struct Foo4075 x::Int64 y::Float64 end @@ -1202,7 +1202,7 @@ end # TODO!! # issue #4115 -#type Foo4115 +#mutable struct Foo4115 #end #typealias Foo4115s NTuple{3,Union{Foo4115,Type{Foo4115}}} #baz4115(x::Foo4115s) = x @@ -1210,18 +1210,18 @@ end # (Foo4115,Foo4115,Foo4115()))) == (Foo4115,Foo4115,Foo4115()) # issue #4129 -type Foo4129; end +mutable struct Foo4129; end -abstract Bar4129 +abstract type Bar4129 end -type Bar41291 <: Bar4129 +mutable struct Bar41291 <: Bar4129 f::Foo4129 end -type Bar41292 <: Bar4129 +mutable struct Bar41292 <: Bar4129 f::Foo4129 end -type Baz4129 +mutable struct Baz4129 b::Bar4129 end @@ -1233,15 +1233,15 @@ foo4129(a::Baz4129,args...) = foo4129(a,a.b,args...) @test isa(foo4129(Baz4129(Bar41291(Foo4129())),1,2), Tuple{Baz4129,Bar4129,Foo4129,Int,Int}) # issue #4141 -type Vertex4141{N,T}; end -type Face4141{V}; end -type Hull4141{F<:Face4141}; end +mutable struct Vertex4141{N,T}; end +mutable struct Face4141{V}; end +mutable struct Hull4141{F<:Face4141}; end g4141(N,T) = Hull4141{Face4141{Vertex4141{N,T}}}() @test isa(g4141(4,Int), Hull4141{Face4141{Vertex4141{4,Int}}}) # issue #4154 -type MyType4154{T} +mutable struct MyType4154{T} a1::T a2 end @@ -1254,11 +1254,11 @@ g4154() = typeof(foo4154(rand(2,2,2,2,2,2,2,2,2))) @test g4154() === MyType4154{Array{Float64,9}} # issue #4208 -type a4208 +mutable struct a4208 a4208 end @test isa(a4208(5),a4208) -type b4208 +mutable struct b4208 b4208() = (local b4208=1;new()) end @test isa(b4208(),b4208) @@ -1270,7 +1270,7 @@ convert_default_should_fail_here() = similar([1],typeof(zero(typeof(rand(2,2)))) # issue #4343 @test_throws ErrorException Array{Float64}{Int, 2} -type Foo4376{T} +mutable struct Foo4376{T} x Foo4376{T}(x::T) where T = new(x) Foo4376{T}(a::Foo4376{Int}) where T = new(a.x) @@ -1278,14 +1278,14 @@ end @test isa(Foo4376{Float32}(Foo4376{Int}(2)), Foo4376{Float32}) -type _0_test_ctor_syntax_ +mutable struct _0_test_ctor_syntax_ _0_test_ctor_syntax_{T<:AbstractString}(files::Vector{T},step) = 0 end # issue #4413 -type A4413 end -type B4413 end -type C4413 end +mutable struct A4413 end +mutable struct B4413 end +mutable struct C4413 end f4413(::Union{A4413, B4413, C4413}) = "ABC" f4413(::Union{A4413, B4413}) = "AB" g4413(::Union{A4413, C4413}) = "AC" @@ -1351,7 +1351,7 @@ end # issue #4681 # ccall should error if convert() returns something of the wrong type -type Z4681 +mutable struct Z4681 x::Ptr{Void} Z4681() = new(C_NULL) end @@ -1376,7 +1376,7 @@ end @test b4688(1) == "an Int" # issue #4731 -type SIQ{A,B} <: Number +mutable struct SIQ{A,B} <: Number x::A end import Base: promote_rule @@ -1408,7 +1408,7 @@ end # module @test (Lib4771.@make_closure)(0) == 1 # issue #4805 -abstract IT4805{N, T} +abstract type IT4805{N, T} end let test0{T <: Int64}(::Type{IT4805{1, T}}, x) = x @@ -1446,7 +1446,7 @@ f5150(T) = Array{Rational{T}}(1) # issue #5165 -bitstype 64 T5165{S} +primitive type T5165{S} 64 end make_t(x::Int64) = Core.Intrinsics.bitcast(T5165{Void}, x) xs5165 = T5165[make_t(Int64(1))] b5165 = IOBuffer() @@ -1456,7 +1456,7 @@ end # support tuples as type parameters -type TupleParam{P} +mutable struct TupleParam{P} x::Bool end @@ -1515,7 +1515,7 @@ end @test isequal(tighttypes!(Any[Any[1.0,2.0],]), [1,2]) # issue #5142 -bitstype 64 Int5142 +primitive type Int5142 64 end function h5142(a::Bool) x=a ? (Int64(0),reinterpret(Int5142,Int64(0))) : (Int64(1),reinterpret(Int5142,Int64(1))) x[2]::Int5142 @@ -1534,7 +1534,7 @@ try f5142() end -bitstype 8 Int5142b +primitive type Int5142b 8 end function h5142b(a::Int) x=((Int8(1),Int8(2)),(reinterpret(Int5142b,Int8(3)),reinterpret(Int5142b,Int8(4)))) x[a]::Tuple{Int8,Int8} @@ -1553,7 +1553,7 @@ end @test real(test_bits_tuples()) == 10 # issue #5374 -type FileObj5374 +mutable struct FileObj5374 io::IO end function read_file5374(fileobj) @@ -1587,7 +1587,7 @@ f5584() # issue #5884 -type Polygon5884{T<:Real} +mutable struct Polygon5884{T<:Real} points::Vector{Complex{T}} end @@ -1651,7 +1651,7 @@ test5536(a::Union{Real, AbstractArray}) = "Non-splatting" # issue #6142 import Base: + -type A6142 <: AbstractMatrix{Float64}; end +mutable struct A6142 <: AbstractMatrix{Float64}; end +{TJ}(x::A6142, y::UniformScaling{TJ}) = "UniformScaling method called" +(x::A6142, y::AbstractArray) = "AbstractArray method called" @test A6142() + I == "UniformScaling method called" @@ -1675,11 +1675,11 @@ end @test g6292() == 2 # issue #6404 -type type_2{T <: Integer, N} <: Number +mutable struct type_2{T <: Integer, N} <: Number x::T type_2{T,N}(n::T) where {T<:Integer,N} = new(n) end -type type_1{T <: Number} <: Number +mutable struct type_1{T <: Number} <: Number x::Vector{T} type_1{T}(x::Vector{T}) where T<:Number = new(x) end @@ -1753,12 +1753,12 @@ let end # issue #6387 -bitstype 64 Date6387{C} +primitive type Date6387{C} 64 end -type DateRange6387{C} <: Range{Date6387{C}} +mutable struct DateRange6387{C} <: Range{Date6387{C}} end -type ObjMember +mutable struct ObjMember member::DateRange6387 end @@ -1823,8 +1823,8 @@ let x = zeros(2) end # issue #6980 -abstract A6980 -type B6980 <: A6980 end +abstract type A6980 end +mutable struct B6980 <: A6980 end f6980(::Union{Int, Float64}, ::A6980) = false f6980(::Union{Int, Float64}, ::B6980) = true @test f6980(1, B6980()) @@ -1881,7 +1881,7 @@ const (¬) = ! @test ¬false # issue #7652 -type A7652 +mutable struct A7652 a :: Int end a7652 = A7652(0) @@ -1918,7 +1918,7 @@ end # issue #7582 aₜ = "a variable using Unicode 6" -immutable My8156{A, B} +struct My8156{A, B} a::A b::B end @@ -1929,7 +1929,7 @@ let m = My8156(nothing, 1) end # issue #8184 -immutable Foo8184 +struct Foo8184 x::Void y::Void z::Float64 @@ -1956,7 +1956,7 @@ let x = 10 @test x((3,)...) == 19 @test issue2403func(x) == 31 end -type Issue2403 +mutable struct Issue2403 x end (i::Issue2403)(y) = i.x + 2y @@ -2134,7 +2134,7 @@ g9535() = (f9535(),f9535()) @test g9535() == (3,4) # weak references -type Obj; x; end +mutable struct Obj; x; end @testset "weak references" begin @noinline function mk_wr(r, wr) x = Obj(1) @@ -2169,7 +2169,7 @@ end #issue #9835 module M9835 using Base.Test - type A end; type B end + mutable struct A end; mutable struct B end f() = (isa(A(), A) ? A : B)() @test isa(f(), A) end @@ -2202,10 +2202,10 @@ y8d003 = 777 @test eval(:(string(:(f($($(x8d003...))))))) == "f(777)" # issue #9378 -abstract Foo9378{T,S} -immutable B9378{T} end +abstract type Foo9378{T,S} end +struct B9378{T} end typealias FooB9378{T} Foo9378{T,B9378} -immutable CFoo9378 <: FooB9378{Float64} end +struct CFoo9378 <: FooB9378{Float64} end @test isa(CFoo9378(),FooB9378) # issue #10281 @@ -2223,7 +2223,7 @@ file = open(fname, "w") redirect_stdout(file) versioninfo() try - type Foo{T} + mutable struct Foo{T} val::Bar{T} end end @@ -2236,7 +2236,7 @@ end # issue #10373 f10373(x) = x g10373(x) = x -type newtype10373 +mutable struct newtype10373 end let f for f in (f10373,g10373) @@ -2257,7 +2257,7 @@ f7221(::AbstractVecOrMat) = 3 @test f7221(trues(1)) == 2 # issue #10570 -immutable Array_512_Uint8 +struct Array_512_Uint8 d1::UInt8 d2::UInt8 d3::UInt8 @@ -2824,7 +2824,7 @@ function func8283 end @test_throws MethodError func8283() # issue #11243 -type Type11243{A, B} +mutable struct Type11243{A, B} x::A y::B end @@ -2852,7 +2852,7 @@ end @test isa(f11295(:a,:b), Expr) # issue #11675 -immutable T11675{T} +struct T11675{T} x::T T11675{T}() where T = new() end @@ -2879,8 +2879,8 @@ f11715(x) = (x === Tuple{Any}) # part of #11597 # make sure invalid, partly-constructed types don't end up in the cache -abstract C11597{T<:Union{Void, Int}} -type D11597{T} <: C11597{T} d::T end +abstract type C11597{T<:Union{Void, Int}} end +mutable struct D11597{T} <: C11597{T} d::T end @test_throws TypeError D11597(1.0) @test_throws TypeError repr(D11597(1.0)) @@ -2914,12 +2914,12 @@ let a = (1:1000...), end # issue 11858 -type Foo11858 +mutable struct Foo11858 x::Float64 Foo11858(x::Float64) = new(x) end -type Bar11858 +mutable struct Bar11858 x::Float64 Bar11858(x::Float64) = new(x) end @@ -2948,7 +2948,7 @@ end @test !isnull(foo11904(Nullable(1))) # issue 11874 -immutable Foo11874 +struct Foo11874 x::Int end @@ -2989,7 +2989,7 @@ end @test_throws ErrorException NTuple{-1, Int} @test_throws TypeError Union{Int, 1} -type FooNTuple{N} +mutable struct FooNTuple{N} z::Tuple{Integer, Vararg{Int, N}} end @test_throws ErrorException FooNTuple{-1} @@ -2997,7 +2997,7 @@ end @test_throws TypeError FooNTuple{0x01} @test fieldtype(FooNTuple{0}, 1) == Tuple{Integer} -type FooTupleT{T} +mutable struct FooTupleT{T} z::Tuple{Int, T, Int} end @test_throws TypeError FooTupleT{Vararg{Int, 2}} @@ -3011,13 +3011,13 @@ const DATE12003 = DateTime(1917,1,1) failure12003(dt=DATE12003) = Dates.year(dt) @test isa(failure12003(), Integer) -# issue #12023 Test error checking in bitstype -@test_throws ErrorException (@eval bitstype 0 SPJa12023) -@test_throws ErrorException (@eval bitstype 4294967312 SPJb12023) -@test_throws ErrorException (@eval bitstype -4294967280 SPJc12023) +# issue #12023 Test error checking in primitive type +@test_throws ErrorException (@eval primitive type 0 SPJa12023 end) +@test_throws ErrorException (@eval primitive type 4294967312 SPJb12023 end) +@test_throws ErrorException (@eval primitive type -4294967280 SPJc12023 end) # issue #12089 -type A12089{K, N} +mutable struct A12089{K, N} sz::NTuple{N, Int} A12089{K,N}(sz::NTuple{N, Int}) where {K,N} = new(sz) end @@ -3037,7 +3037,7 @@ g12063() = f12063(0, 0, 0, 0, 0, 0, 0.0, spzeros(0,0), Int[]) @test g12063() == 1 # issue #11587 -type Sampler11587{N} +mutable struct Sampler11587{N} clampedpos::Array{Int,2} buf::Array{Float64,N} end @@ -3048,34 +3048,34 @@ end @test isa(Sampler11587(), Sampler11587{2}) # issue #8010 - error when convert returns wrong type during new() -immutable Vec8010{T} +struct Vec8010{T} x::T y::T end Vec8010(a::AbstractVector) = Vec8010(ntuple(x->a[x],2)...) Base.convert{T}(::Type{Vec8010{T}},x::AbstractVector) = Vec8010(x) Base.convert(::Type{Void},x::AbstractVector) = Vec8010(x) -immutable MyType8010 +struct MyType8010 m::Vec8010{Float32} end -immutable MyType8010_ghost +struct MyType8010_ghost m::Void end @test_throws TypeError MyType8010([3.0;4.0]) @test_throws TypeError MyType8010_ghost([3.0;4.0]) # don't allow redefining types if ninitialized changes -immutable NInitializedTestType +struct NInitializedTestType a end -@test_throws ErrorException @eval immutable NInitializedTestType +@test_throws ErrorException @eval struct NInitializedTestType a NInitializedTestType() = new() end # issue #12394 -type Empty12394 end +mutable struct Empty12394 end let x = Array{Empty12394}(1), y = [Empty12394()] @test_throws UndefRefError x==y @test_throws UndefRefError y==x @@ -3094,11 +3094,11 @@ test_eq_array_int() = ===(const_array_int1, const_array_int2) @test test_eq_array_int() # object_id of haspadding field -immutable HasPadding +struct HasPadding x::Bool y::Int end -immutable HasHasPadding +struct HasHasPadding x::HasPadding end hashaspadding = HasHasPadding(HasPadding(true,1)) @@ -3163,7 +3163,7 @@ for j = 1:1 end # PR 11888 -immutable A11888{T} +struct A11888{T} a::NTuple{16,T} end @@ -3172,8 +3172,8 @@ typealias B11888{T} A11888{A11888{A11888{T}}} @test sizeof(B11888{B11888{Int64}}) == (1 << 24) * 8 # issue #13175 -immutable EmptyImmutable13175 end -immutable EmptyIIOtherField13175 +struct EmptyImmutable13175 end +struct EmptyIIOtherField13175 x::EmptyImmutable13175 y::Float64 end @@ -3185,7 +3185,7 @@ gg13183{X}(x::X...) = 1==0 ? gg13183(x, x) : 0 @test gg13183(5) == 0 # issue 8932 (llvm return type legalizer error) -immutable Vec3_8932 +struct Vec3_8932 x::Float32 y::Float32 z::Float32 @@ -3216,12 +3216,12 @@ end @test f13432b(false) == false #13433, read!(::IO, a::Vector{UInt8}) should return a -type IO13433 <: IO end +mutable struct IO13433 <: IO end Base.read(::IO13433, ::Type{UInt8}) = 0x01 @test read!(IO13433(), Array{UInt8}(4)) == [0x01, 0x01, 0x01, 0x01] # issue #13647, comparing boxed isbits immutables -immutable X13647 +struct X13647 a::Int b::Bool end @@ -3248,8 +3248,8 @@ end # issue #11327 and #13547 @test_throws MethodError convert(Type{Int}, Float32) @test_throws MethodError Array{Type{Int64}}([Float32]) -abstract A11327 -abstract B11327 <: A11327 +abstract type A11327 end +abstract type B11327 <: A11327 end f11327{T}(::Type{T},x::T) = x @test_throws MethodError f11327(Type{A11327},B11327) @@ -3356,7 +3356,7 @@ end @test __f_isa_arg_1() == 1 # issue #14477 -immutable Z14477 +struct Z14477 fld::Z14477 Z14477() = new(new()) end @@ -3410,7 +3410,7 @@ end @test isa(object_id(Tuple.name.cache), Integer) # issue #14691 -type T14691; a::UInt; end +mutable struct T14691; a::UInt; end @test (T14691(0).a = 0) === 0 # issue #14245 @@ -3452,7 +3452,7 @@ f10985(::Any...) = 1 @test f10985(1, 2, 3) == 1 # a tricky case for closure conversion -type _CaptureInCtor +mutable struct _CaptureInCtor yy function _CaptureInCtor(list_file::AbstractString="") y = 0 @@ -3476,14 +3476,14 @@ let end # issue #14825 -abstract abstest_14825 +abstract type abstest_14825 end -type t1_14825{A <: abstest_14825, B} +mutable struct t1_14825{A <: abstest_14825, B} x::A y::B end -type t2_14825{C, B} <: abstest_14825 +mutable struct t2_14825{C, B} <: abstest_14825 x::C y::t1_14825{t2_14825{C, B}, B} end @@ -3943,7 +3943,7 @@ end end # issue #8712 -type Issue8712; end +mutable struct Issue8712; end @test isa(invoke(Issue8712, Tuple{}), Issue8712) # issue #16089 @@ -4124,8 +4124,8 @@ undefined_x16090 = (Int,) @test_throws TypeError f16090() # issue #12238 -type A12238{T} end -type B12238{T,S} +mutable struct A12238{T} end +mutable struct B12238{T,S} a::A12238{B12238{Int,S}} end @test B12238.body.body.types[1] === A12238{B12238{Int}.body} @@ -4163,11 +4163,11 @@ end @test @inferred(f16431(1)) == 4 # issue #14878 -type A14878 +mutable struct A14878 ext end A14878() = A14878(Dict()) -type B14878 +mutable struct B14878 end B14878(ng) = B14878() function trigger14878() @@ -4206,7 +4206,7 @@ end @test where1090([4]) === 6 @test_throws MethodError where1090(String[]) -type A1090 end +mutable struct A1090 end Base.convert(::Type{Int}, ::A1090) = "hey" f1090()::Int = A1090() @test_throws TypeError f1090() @@ -4224,13 +4224,13 @@ end @test f16783()() == 1 # issue #16767 -type A16767{T} +mutable struct A16767{T} a::Base.RefValue{T} end -type B16767{T} +mutable struct B16767{T} b::A16767{B16767{T}} end -type C16767{T} +mutable struct C16767{T} b::A16767{C16767{:a}} end @test B16767.body.types[1].types[1].parameters[1].types[1] === A16767{B16767.body} @@ -4249,11 +4249,11 @@ end # issue #16793 try - abstract T16793 + abstract type T16793 end catch end @test isa(T16793, Type) -@test isa(abstract T16793_2, Void) +@test isa(abstract type T16793_2 end, Void) # issue #17147 f17147(::Tuple) = 1 @@ -4343,7 +4343,7 @@ ptr18236 = cfunction(identity, VecElement{Float64}, Tuple{VecElement{Float64}}) (VecElement{Float64},), $v18236) @test f18236(ptr18236) === v18236 @test !contains(sprint(code_llvm, f18236, Tuple{Ptr{Void}}), "double undef") -# VecElement of struct type, not necessarily useful but does have special +# VecElement of struct, not necessarily useful but does have special # ABI so should be handled correctly # This struct should be small enough to be passed by value in C ABI # in order to trigger the problematic code path. @@ -4612,7 +4612,7 @@ f19599{T}(x::((S)->Vector{S})(T)...) = 1 # avoiding StackOverflowErrors (issues #12007, #10326, #15736) module SOE -type Sgnd <: Signed +mutable struct Sgnd <: Signed v::Int end using Base.Test @@ -4620,7 +4620,7 @@ using Base.Test io = IOBuffer() @test_throws ErrorException show(io, Sgnd(1)) #12007 -immutable MyTime <: Dates.TimeType +struct MyTime <: Dates.TimeType value::Int end @test_throws ErrorException isless(MyTime(1), now()) diff --git a/test/dict.jl b/test/dict.jl index 3fbb3dd73bc3d..916c764366e40 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -168,7 +168,7 @@ let end # issue #1438 -type I1438T +mutable struct I1438T id end import Base.hash @@ -308,7 +308,7 @@ let d = Dict((1=>2) => (3=>45), (3=>10) => (10=>11)) end # issue #9463 -type Alpha end +mutable struct Alpha end Base.show(io::IO, ::Alpha) = print(io,"α") let sbuff = IOBuffer(), io = Base.IOContext(sbuff, limit=true, displaysize=(10, 20)) @@ -359,7 +359,7 @@ let d = Dict() end # issue #10647 -type T10647{T}; x::T; end +mutable struct T10647{T}; x::T; end let a = ObjectIdDict() a[1] = a a[a] = 2 @@ -514,7 +514,7 @@ let d = Dict(zip(1:1000,1:1000)), f = (k,v) -> iseven(k) end # issue #15077 -immutable MyString <: AbstractString +struct MyString <: AbstractString str::String end import Base.== @@ -565,7 +565,7 @@ let badKeys = [ end end -immutable MyInt <: Integer +struct MyInt <: Integer val::UInt end @@ -651,7 +651,7 @@ end @test hash(a) != hash(b) end -type Foo_15776 +mutable struct Foo_15776 x::Vector{Pair{Tuple{Function, Vararg{Int}}, Int}} end @testset "issue #15776, convert for pair" begin @@ -667,7 +667,7 @@ end @test_throws UndefVarError Dict(x => y for x in 1:10) end -type Error19179 <: Exception +mutable struct Error19179 <: Exception end @testset "issue #19179 throwing error in dict constructor" begin diff --git a/test/docs.jl b/test/docs.jl index ae0d7ffdbdc42..631835ea0689f 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -26,7 +26,7 @@ end docstring_startswith(d1::DocStr, d2) = docstring_startswith(parsedoc(d1), d2) @doc "Doc abstract type" -> -abstract C74685{T,N} <: AbstractArray{T,N} +abstract type C74685{T,N} <: AbstractArray{T,N} end @test stringmime("text/plain", Docs.doc(C74685))=="Doc abstract type\n" macro macro_doctest() end @@ -73,16 +73,16 @@ end function g end "AT" -abstract AT +abstract type AT end "BT" -bitstype 8 BT +primitive type BT 8 end "BT2" -bitstype 8 BT2 <: Integer +primitive type BT2 <: Integer 8 end "T" -type T <: AT +mutable struct T <: AT "T.x" x "T.y" @@ -90,7 +90,7 @@ type T <: AT end "IT" -immutable IT +struct IT "IT.x" x :: Int "IT.y" @@ -132,7 +132,7 @@ t(::Int, ::Any) t{S <: Integer}(::S) "FieldDocs" -type FieldDocs +mutable struct FieldDocs "one" one doc"two" @@ -152,7 +152,7 @@ import .Inner.@m "Inner.@m" :@m -type Foo +mutable struct Foo x end @@ -316,10 +316,10 @@ macro m() end const C = 1 "A" -abstract A +abstract type A end "T" -type T +mutable struct T "x" x "y" @@ -415,7 +415,7 @@ end module DocVars -immutable __FIELDS__ end +struct __FIELDS__ end function Docs.formatdoc(buffer, docstr, ::Type{__FIELDS__}) fields = get(docstr.data, :fields, Dict()) @@ -432,7 +432,7 @@ end $__FIELDS__ """ -type T +mutable struct T "x" x "y" @@ -445,7 +445,7 @@ end $__FIELDS__ """ -type S +mutable struct S x y z @@ -506,7 +506,7 @@ end module I15424 -immutable LazyHelp +struct LazyHelp text end @@ -594,7 +594,7 @@ end module I12515 -immutable EmptyType{T} end +struct EmptyType{T} end "A new method" Base.collect{T}(::Type{EmptyType{T}}) = "borked" @@ -696,12 +696,12 @@ end module Undocumented -abstract A -abstract B <: A +abstract type A end +abstract type B <: A end -type C <: A end +mutable struct C <: A end -immutable D <: B +struct D <: B one two::String three::Float64 @@ -727,7 +727,7 @@ No documentation found. **Summary:** ``` -abstract $(curmod_prefix)Undocumented.A <: Any +abstract type $(curmod_prefix)Undocumented.A <: Any ``` **Subtypes:** @@ -743,7 +743,7 @@ No documentation found. **Summary:** ``` -abstract $(curmod_prefix)Undocumented.B <: $(curmod_prefix)Undocumented.A +abstract type $(curmod_prefix)Undocumented.B <: $(curmod_prefix)Undocumented.A ``` **Subtypes:** @@ -758,7 +758,7 @@ No documentation found. **Summary:** ``` -type $(curmod_prefix)Undocumented.C <: $(curmod_prefix)Undocumented.A +mutable struct $(curmod_prefix)Undocumented.C <: $(curmod_prefix)Undocumented.A ``` """) @test docstrings_equal(@doc(Undocumented.C), doc"$doc_str") @@ -768,7 +768,7 @@ No documentation found. **Summary:** ``` -immutable $(curmod_prefix)Undocumented.D <: $(curmod_prefix)Undocumented.B +struct $(curmod_prefix)Undocumented.D <: $(curmod_prefix)Undocumented.B ``` **Fields:** @@ -935,7 +935,7 @@ end # Dynamic docstrings -type DynamicDocType +mutable struct DynamicDocType x end @@ -958,4 +958,4 @@ dynamic_test.x = "test 2" @test HTML("docstring") == HTML("docstring") @test Text("docstring1") ≠ Text("docstring2") @test hash(Text("docstring1")) ≠ hash(Text("docstring2")) -@test hash(Text("docstring")) ≠ hash(HTML("docstring")) \ No newline at end of file +@test hash(Text("docstring")) ≠ hash(HTML("docstring")) diff --git a/test/inference.jl b/test/inference.jl index e3e57b8f06648..10095be45fb5d 100644 --- a/test/inference.jl +++ b/test/inference.jl @@ -23,7 +23,7 @@ end # issue #1628 -type I1628{X} +mutable struct I1628{X} x::X end let @@ -65,16 +65,16 @@ end # issue #5906 -abstract Outer5906{T} +abstract type Outer5906{T} end -immutable Inner5906{T} +struct Inner5906{T} a:: T end -immutable Empty5906{T} <: Outer5906{T} +struct Empty5906{T} <: Outer5906{T} end -immutable Hanoi5906{T} <: Outer5906{T} +struct Hanoi5906{T} <: Outer5906{T} a::T succ :: Outer5906{Inner5906{T}} Hanoi5906{T}(a) where T = new(a, Empty5906{Inner5906{T}}()) @@ -91,13 +91,13 @@ end # issue on the flight from DFW # (type inference deducing Type{:x} rather than Symbol) -type FooBarDFW{s}; end +mutable struct FooBarDFW{s}; end fooDFW(p::Type{FooBarDFW}) = string(p.parameters[1]) fooDFW(p) = string(p.parameters[1]) @test fooDFW(FooBarDFW{:x}) == "x" # not ":x" # Type inference for tuple parameters -immutable fooTuple{s}; end +struct fooTuple{s}; end barTuple1() = fooTuple{(:y,)}() barTuple2() = fooTuple{tuple(:y)}() @@ -124,8 +124,8 @@ Base.return_types(getindex, (Vector{nothing},)) # issue #12636 module MyColors -abstract Paint{T} -immutable RGB{T<:AbstractFloat} <: Paint{T} +abstract type Paint{T} end +struct RGB{T<:AbstractFloat} <: Paint{T} r::T g::T b::T @@ -148,13 +148,13 @@ f12826{I<:Integer}(v::Vector{I}) = v[1] # non-terminating inference, issue #14009 # non-terminating codegen, issue #16201 -type A14009{T}; end +mutable struct A14009{T}; end A14009{T}(a::T) = A14009{T}() f14009(a) = rand(Bool) ? f14009(A14009(a)) : a code_typed(f14009, (Int,)) code_llvm(DevNull, f14009, (Int,)) -type B14009{T}; end +mutable struct B14009{T}; end g14009(a) = g14009(B14009{a}) code_typed(g14009, (Type{Int},)) code_llvm(DevNull, f14009, (Int,)) @@ -199,7 +199,7 @@ end # pr #15259 -immutable A15259 +struct A15259 x y end @@ -217,7 +217,7 @@ end # issue #7810 -type Foo7810{T<:AbstractVector} +mutable struct Foo7810{T<:AbstractVector} v::T end bar7810() = [Foo7810([(a,b) for a in 1:2]) for b in 3:4] @@ -310,11 +310,11 @@ let f(x) = (x===nothing) ? 1 : 1.0 end # issue #16530 -type Foo16530a{dim} +mutable struct Foo16530a{dim} c::Vector{NTuple{dim, Float64}} d::Vector end -type Foo16530b{dim} +mutable struct Foo16530b{dim} c::Vector{NTuple{dim, Float64}} end f16530a() = fieldtype(Foo16530a, :c) @@ -348,7 +348,7 @@ let T1 = Tuple{Int, Float64}, end # issue #18015 -type Triple18015 +mutable struct Triple18015 a::Int b::Int c::Int @@ -371,7 +371,7 @@ g18222(x) = f18222(x) # issue #18399 # TODO: this test is rather brittle -type TSlow18399{T} +mutable struct TSlow18399{T} x::T end function hvcat18399(as) @@ -485,14 +485,14 @@ end @test Type{Tuple{Vararg{Int}}} <: Base.return_types(maybe_vararg_tuple_2, ())[1] # inference of `fieldtype` -type UndefField__ +mutable struct UndefField__ x::Union{} end f_infer_undef_field() = fieldtype(UndefField__, :x) @test Base.return_types(f_infer_undef_field, ()) == Any[Type{Union{}}] @test f_infer_undef_field() === Union{} -type HasAbstractlyTypedField +mutable struct HasAbstractlyTypedField x::Union{Int,String} end f_infer_abstract_fieldtype() = fieldtype(HasAbstractlyTypedField, :x) @@ -528,8 +528,8 @@ test_fast_le(a, b) = @fastmath a <= b @inferred test_fast_lt(1.0, 1.0) @inferred test_fast_le(1.0, 1.0) -abstract AbstractMyType18457{T,F,G} -immutable MyType18457{T,F,G}<:AbstractMyType18457{T,F,G} end +abstract type AbstractMyType18457{T,F,G} end +struct MyType18457{T,F,G}<:AbstractMyType18457{T,F,G} end tpara18457{I}(::Type{AbstractMyType18457{I}}) = I tpara18457{A<:AbstractMyType18457}(::Type{A}) = tpara18457(supertype(A)) @test tpara18457(MyType18457{true}) === true @@ -579,7 +579,7 @@ f_inferred_union_int(::Any) = "broken" @test @inferred(f_inferred_union()) in (1, 2, 3) # issue #11015 -type AT11015 +mutable struct AT11015 f::Union{Bool,Function} end @@ -601,7 +601,7 @@ let pub = Base.parameter_upper_bound, x = fComplicatedUnionAll(Real) end # issue #20267 -type T20267{T} +mutable struct T20267{T} inds::Vector{T} end # infinite type growth via lower bounds (formed by intersection) diff --git a/test/int.jl b/test/int.jl index 1ae1922694cbc..00708302a21a1 100644 --- a/test/int.jl +++ b/test/int.jl @@ -86,7 +86,7 @@ end @test round(UInt8, 123) == 123 @test mod(123, UInt8) == 0x7b -bitstype 8 MyBitsType <: Integer +primitive type MyBitsType <: Integer 8 end @test_throws MethodError ~reinterpret(MyBitsType, 0x7b) UItypes = Base.BitUnsigned_types diff --git a/test/intrinsics.jl b/test/intrinsics.jl index dedc4662e1b1c..03f306c1ba684 100644 --- a/test/intrinsics.jl +++ b/test/intrinsics.jl @@ -16,7 +16,7 @@ let f = Any[Core.Intrinsics.add_int, Core.Intrinsics.sub_int] end # issue #4581 -bitstype 64 Date4581{T} +primitive type Date4581{T} 64 end let x = Core.Intrinsics.bitcast(Date4581{Int}, Int64(1234)) xs = Date4581[x] @@ -34,8 +34,8 @@ let d = Core.Intrinsics.bitcast(Date4581{Int}, Int64(1)) @test isa(f6591(d), Date4581) end -# test functionality of non-power-of-2 bitstype constants -bitstype 24 Int24 +# test functionality of non-power-of-2 primitive type constants +primitive type Int24 24 end Int24(x::Int) = Core.Intrinsics.trunc_int(Int24, x) Int(x::Int24) = Core.Intrinsics.zext_int(Int, x) let x, y, f diff --git a/test/keywordargs.jl b/test/keywordargs.jl index efe02e48f5faa..e724448d88374 100644 --- a/test/keywordargs.jl +++ b/test/keywordargs.jl @@ -172,7 +172,7 @@ end @test (@TEST4538_3) == 3 # issue #4801 -type T4801{X} +mutable struct T4801{X} T4801{X}(;k=0) where X = new() end @test isa(T4801{Any}(k=0), T4801{Any}) diff --git a/test/linalg/arnoldi.jl b/test/linalg/arnoldi.jl index 494e9d73e9007..0b66a85c713e9 100644 --- a/test/linalg/arnoldi.jl +++ b/test/linalg/arnoldi.jl @@ -105,7 +105,7 @@ end # Example from Quantum Information Theory import Base: size, issymmetric, ishermitian -type CPM{T<:Base.LinAlg.BlasFloat}<:AbstractMatrix{T} # completely positive map +mutable struct CPM{T<:Base.LinAlg.BlasFloat}<:AbstractMatrix{T} # completely positive map kraus::Array{T,3} # kraus operator representation end size(Phi::CPM)=(size(Phi.kraus,1)^2,size(Phi.kraus,3)^2) diff --git a/test/linalg/generic.jl b/test/linalg/generic.jl index bc1f165284bf8..d6441fd442e88 100644 --- a/test/linalg/generic.jl +++ b/test/linalg/generic.jl @@ -5,7 +5,7 @@ using Base.Test # A custom Quaternion type with minimal defined interface and methods. # Used to test scale and scale! methods to show non-commutativity. -immutable Quaternion{T<:Real} <: Number +struct Quaternion{T<:Real} <: Number s::T v1::T v2::T diff --git a/test/linalg/matmul.jl b/test/linalg/matmul.jl index 44421f3190e92..7ee9e13b85eeb 100644 --- a/test/linalg/matmul.jl +++ b/test/linalg/matmul.jl @@ -71,7 +71,7 @@ end # Generic AbstractArrays module MyArray15367 using Base.Test - immutable MyArray{T,N} <: AbstractArray{T,N} + struct MyArray{T,N} <: AbstractArray{T,N} data::Array{T,N} end @@ -321,7 +321,7 @@ let end # Number types that lack conversion to the destination type (#14293) -immutable RootInt +struct RootInt i::Int end import Base: *, transpose @@ -398,14 +398,14 @@ end module TestPR18218 using Base.Test import Base.*, Base.+, Base.zero - immutable TypeA + struct TypeA x::Int end Base.convert(::Type{TypeA}, x::Int) = TypeA(x) - immutable TypeB + struct TypeB x::Int end - immutable TypeC + struct TypeC x::Int end Base.convert(::Type{TypeC}, x::Int) = TypeC(x) diff --git a/test/loading.jl b/test/loading.jl index 748b5f28df5a6..4fbb04d083bd6 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -50,7 +50,7 @@ push!(LOAD_PATH, dir) LOAD_PATH[end] = GenericString(LOAD_PATH[end]) @test Base.find_in_path("test_sourcepath") == joinpath(dir, "test_sourcepath.jl") -immutable CustomLoader +struct CustomLoader path::String end push!(LOAD_PATH, CustomLoader("abc")) diff --git a/test/markdown.jl b/test/markdown.jl index ad0ee9dcca35f..24298f1447020 100644 --- a/test/markdown.jl +++ b/test/markdown.jl @@ -407,7 +407,7 @@ for (input, output) in ( end # Interpolation / Custom types -type Reference +mutable struct Reference ref end diff --git a/test/misc.jl b/test/misc.jl index 2c4e09598b0dd..5a99ac9691930 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -226,10 +226,10 @@ end # test methodswith # `methodswith` relies on exported symbols export func4union, Base -immutable NoMethodHasThisType end +struct NoMethodHasThisType end @test isempty(methodswith(NoMethodHasThisType)) @test !isempty(methodswith(Int)) -immutable Type4Union end +struct Type4Union end func4union(::Union{Type4Union,Int}) = () @test !isempty(methodswith(Type4Union)) @@ -599,10 +599,10 @@ let end end -abstract DA_19281{T, N} <: AbstractArray{T, N} +abstract type DA_19281{T, N} <: AbstractArray{T, N} end Base.convert{S,T,N}(::Type{Array{S, N}}, ::DA_19281{T, N}) = error() x_19281 = [(), (1,)] -type Foo_19281 +mutable struct Foo_19281 f::Vector{Tuple} Foo_19281() = new(x_19281) end @@ -620,7 +620,7 @@ let @test isassigned(x_defined) end -type Demo_20254 +mutable struct Demo_20254 arr::Array{String} end diff --git a/test/netload/memtest.jl b/test/netload/memtest.jl index fda4b973e2f39..b69b35dec658f 100644 --- a/test/netload/memtest.jl +++ b/test/netload/memtest.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -immutable RUsage +struct RUsage ru_utime_sec::Clong # user CPU time used ru_utime_usec::Clong # user CPU time used ru_stime_sec::Clong # system CPU time used diff --git a/test/nullable.jl b/test/nullable.jl index cf103f2e203e6..6cf58550c2ff3 100644 --- a/test/nullable.jl +++ b/test/nullable.jl @@ -67,7 +67,7 @@ for T in types end -# immutable NullException <: Exception +# struct NullException <: Exception @test isa(NullException(), NullException) @test_throws NullException throw(NullException()) @@ -283,7 +283,7 @@ for T in types @test hash(x3) != hash(x4) end -type TestNType{T} +mutable struct TestNType{T} v::Nullable{T} end diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 45240f75d1cdb..3b35ca9880a76 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -406,7 +406,7 @@ end # let # (#18107) module SimilarUR using Base.Test - immutable MyURange <: AbstractUnitRange{Int} + struct MyURange <: AbstractUnitRange{Int} start::Int stop::Int end diff --git a/test/operators.jl b/test/operators.jl index 5953e1143183a..a95e2a24dc3da 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -73,7 +73,7 @@ let xs = [[i:i+4;] for i in 1:10] end # issue #19714 -immutable T19714 <: Integer end +struct T19714 <: Integer end Base.float(::T19714) = 19714.0 Base.:/(::T19714, ::T19714) = T19714() Base.convert(::Type{T19714}, ::Int) = T19714() diff --git a/test/parallel_exec.jl b/test/parallel_exec.jl index 9468fec5b9972..4d6b030ccd05a 100644 --- a/test/parallel_exec.jl +++ b/test/parallel_exec.jl @@ -463,7 +463,7 @@ map!(x->1, d, d) @test 3.0 == remotecall_fetch(D->D[1], id_other, Base.shmem_fill(3.0, 1; pids=[id_me, id_other])) # Shared arrays of singleton immutables -@everywhere immutable ShmemFoo end +@everywhere struct ShmemFoo end for T in [Void, ShmemFoo] s = @inferred(SharedArray{T}(10)) @test T() === remotecall_fetch(x->x[3], workers()[1], s) @@ -1075,7 +1075,7 @@ end @test remotecall_fetch(x->(y->2y)(x)+1, workers()[1], 3) == 7 # issue #16091 -type T16091 end +mutable struct T16091 end wid = workers()[1] @test try remotecall_fetch(()->T16091, wid) @@ -1294,7 +1294,7 @@ end @everywhere begin global testsercnt_d = Dict() - type TestSerCnt + mutable struct TestSerCnt v end import Base.hash, Base.== @@ -1466,7 +1466,7 @@ test_clear(syms, workers()) # Test partial recovery from a deserialization error in CapturedException try expr = quote - type DontExistOn1 + mutable struct DontExistOn1 x end throw(BoundsError(DontExistOn1(1), 1)) diff --git a/test/parse.jl b/test/parse.jl index 93227a3c27354..7e9c847a23b9d 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -646,12 +646,12 @@ end for (str, tag) in Dict("" => :none, "\"" => :string, "#=" => :comment, "'" => :char, "`" => :cmd, "begin;" => :block, "quote;" => :block, "let;" => :block, "for i=1;" => :block, "function f();" => :block, - "f() do x;" => :block, "module X;" => :block, "type X;" => :block, - "immutable X;" => :block, "(" => :other, "[" => :other, + "f() do x;" => :block, "module X;" => :block, "mutable struct X;" => :block, + "struct X;" => :block, "(" => :other, "[" => :other, "begin" => :other, "quote" => :other, "let" => :other, "for" => :other, "function" => :other, - "f() do" => :other, "module" => :other, "type" => :other, - "immutable" => :other) + "f() do" => :other, "module" => :other, "mutable struct" => :other, + "struct" => :other) @test Base.incomplete_tag(parse(str, raise=false)) == tag end @@ -851,7 +851,7 @@ end # issue 18756 module Mod18756 -type Type +mutable struct Type end end @test method_exists(Mod18756.Type, ()) diff --git a/test/perf/array/indexing.jl b/test/perf/array/indexing.jl index 7f6a559f3a33b..0f6af0e181919 100644 --- a/test/perf/array/indexing.jl +++ b/test/perf/array/indexing.jl @@ -104,12 +104,12 @@ function sumvector(A, n) s end -abstract MyArray{T,N} <: AbstractArray{T,N} +abstract type MyArray{T,N} <: AbstractArray{T,N} end -immutable ArrayLS{T,N} <: MyArray{T,N} # LinearSlow +struct ArrayLS{T,N} <: MyArray{T,N} # LinearSlow data::Array{T,N} end -immutable ArrayLSLS{T,N} <: MyArray{T,N} # LinearSlow with LinearSlow similar +struct ArrayLSLS{T,N} <: MyArray{T,N} # LinearSlow with LinearSlow similar data::Array{T,N} end Base.similar{T}(A::ArrayLSLS, ::Type{T}, dims::Tuple{Vararg{Int}}) = ArrayLSLS(similar(A.data, T, dims)) @@ -117,16 +117,16 @@ Base.similar{T}(A::ArrayLSLS, ::Type{T}, dims::Tuple{Vararg{Int}}) = ArrayLSLS(s @inline Base.unsafe_setindex!(A::ArrayLSLS, v, I::Int...) = Base.unsafe_setindex!(A.data, v, I...) Base.first(A::ArrayLSLS) = first(A.data) -immutable ArrayLF{T,N} <: MyArray{T,N} # LinearFast +struct ArrayLF{T,N} <: MyArray{T,N} # LinearFast data::Array{T,N} end -immutable ArrayStrides{T,N} <: MyArray{T,N} +struct ArrayStrides{T,N} <: MyArray{T,N} data::Array{T,N} strides::NTuple{N,Int} end ArrayStrides(A::Array) = ArrayStrides(A, strides(A)) -immutable ArrayStrides1{T} <: MyArray{T,2} +struct ArrayStrides1{T} <: MyArray{T,2} data::Matrix{T} stride1::Int end diff --git a/test/perf/kernel/actor_centrality.jl b/test/perf/kernel/actor_centrality.jl index 4bc1f453742ab..ae792ed804064 100644 --- a/test/perf/kernel/actor_centrality.jl +++ b/test/perf/kernel/actor_centrality.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -type Node +mutable struct Node name::String n::Set{Node} diff --git a/test/perf/kernel/go_benchmark.jl b/test/perf/kernel/go_benchmark.jl index 2f31b52a7bf0b..8b821bb356d0a 100644 --- a/test/perf/kernel/go_benchmark.jl +++ b/test/perf/kernel/go_benchmark.jl @@ -20,7 +20,7 @@ const WHITE_TERRITORY = 3 const BLACK_TERRITORY = 4 const UNKNOWN = 5 -type XorRand +mutable struct XorRand state::UInt32 end @@ -42,7 +42,7 @@ const deltai = (-1, 1, 0, 0) const deltaj = (0, 0, -1, 1) neighbor(i::Int, j::Int, k::Int) = (i + deltai[k], j + deltaj[k]) -type Board +mutable struct Board size::Int komi::Float64 diff --git a/test/perf/kernel/perf.jl b/test/perf/kernel/perf.jl index 1b6b30a888f5c..620a508365a7d 100644 --- a/test/perf/kernel/perf.jl +++ b/test/perf/kernel/perf.jl @@ -2,12 +2,12 @@ include("../perfutil.jl") -abstract List{T} +abstract type List{T} end -type Nil{T} <: List{T} +mutable struct Nil{T} <: List{T} end -type Cons{T} <: List{T} +mutable struct Cons{T} <: List{T} head::T tail::List{T} end diff --git a/test/perf/kernel/raytracer.jl b/test/perf/kernel/raytracer.jl index e1ac918e9fb39..5601143bf7a22 100644 --- a/test/perf/kernel/raytracer.jl +++ b/test/perf/kernel/raytracer.jl @@ -11,7 +11,7 @@ const delta = sqrt(eps(Float64)) -immutable Vec +struct Vec x::Float64 y::Float64 z::Float64 @@ -25,19 +25,19 @@ import Base: +, -, * dot(a::Vec, b::Vec) = (a.x*b.x + a.y*b.y + a.z*b.z) unitize(a::Vec) = (1. / sqrt(dot(a, a)) * a) -type Ray +mutable struct Ray orig::Vec dir::Vec end -type Hit +mutable struct Hit lambda::Float64 normal::Vec end -abstract Scene +abstract type Scene end -immutable Sphere <: Scene +struct Sphere <: Scene center::Vec radius::Float64 end @@ -67,7 +67,7 @@ function intersect(s::Sphere, i::Hit, ray::Ray) end end -immutable Group <: Scene +struct Group <: Scene bound::Sphere objs::Array{Scene} end diff --git a/test/perf/shootout/binary_trees.jl b/test/perf/shootout/binary_trees.jl index 5df7479867af2..9200748615648 100644 --- a/test/perf/shootout/binary_trees.jl +++ b/test/perf/shootout/binary_trees.jl @@ -8,12 +8,12 @@ # Ported from an OCaml version # -abstract BTree +abstract type BTree end -type Empty <: BTree +mutable struct Empty <: BTree end -type Node <: BTree +mutable struct Node <: BTree info left::BTree right::BTree diff --git a/test/perf/shootout/k_nucleotide.jl b/test/perf/shootout/k_nucleotide.jl index d1353371ddcb3..b28555b1e1c20 100644 --- a/test/perf/shootout/k_nucleotide.jl +++ b/test/perf/shootout/k_nucleotide.jl @@ -26,7 +26,7 @@ function count_one(data::AbstractString, s::AbstractString) count(data, length(s))[s] end -type KNuc +mutable struct KNuc name::AbstractString count::Int end diff --git a/test/perf/shootout/nbody.jl b/test/perf/shootout/nbody.jl index 1fc3b0ce7d44b..156d666daf4be 100644 --- a/test/perf/shootout/nbody.jl +++ b/test/perf/shootout/nbody.jl @@ -15,7 +15,7 @@ const solar_mass = 4 * pi * pi const days_per_year = 365.24 # A heavenly body in the system -type Body +mutable struct Body x::Float64 y::Float64 z::Float64 diff --git a/test/perf/shootout/nbody_vec.jl b/test/perf/shootout/nbody_vec.jl index e2f506a3c492b..7f1fda5f0646e 100644 --- a/test/perf/shootout/nbody_vec.jl +++ b/test/perf/shootout/nbody_vec.jl @@ -15,7 +15,7 @@ const solar_mass = 4 * pi * pi const days_per_year = 365.24 # A heavenly body in the system -type Body +mutable struct Body pos::Array{Float64, 1} v::Array{Float64, 1} mass::Float64 diff --git a/test/reduce.jl b/test/reduce.jl index f0a699b5b5931..87bd3361cfe2a 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -246,7 +246,7 @@ end # any and all with functors -immutable SomeFunctor end +struct SomeFunctor end (::SomeFunctor)(x) = true @test any(SomeFunctor(), 1:10) diff --git a/test/reflection.jl b/test/reflection.jl index 6797de0fe8136..1e83ad4b09097 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -71,10 +71,10 @@ tag = Base.have_color ? Base.error_color() : "UNION" @test warntype_hastag(pos_unstable, Tuple{Float64}, tag) @test !warntype_hastag(pos_stable, Tuple{Float64}, tag) -type Stable{T,N} +mutable struct Stable{T,N} A::Array{T,N} end -type Unstable{T} +mutable struct Unstable{T} A::Array{T} end Base.getindex(A::Stable, i) = A.A[i] @@ -177,7 +177,7 @@ d7648 = 9 const f7648 = 10 foo7648(x) = x function foo7648_nomethods end -type Foo7648 end +mutable struct Foo7648 end module TestModSub9475 using Base.Test @@ -284,7 +284,7 @@ foo13825{T, N}(::Array{T,N}, ::Array, ::Vector) = nothing @test startswith(string(first(methods(foo13825))), "foo13825(::Array{T,N}, ::Array, ::Array{T,1} where T)") -type TLayout +mutable struct TLayout x::Int8 y::Int16 z::Int32 @@ -575,7 +575,7 @@ let a = @code_typed 1 + 1 @test length(b) == 0 end -type A18434 +mutable struct A18434 end (::Type{A18434})(x; y=1) = 1 @@ -617,7 +617,7 @@ end @test isempty(subtypes(Float64)) # New reflection methods in 0.6 -immutable ReflectionExample{T<:AbstractFloat, N} +struct ReflectionExample{T<:AbstractFloat, N} x::Tuple{T, N} end @@ -640,8 +640,8 @@ let end # Issue #20086 -abstract A20086{T,N} -immutable B20086{T,N} <: A20086{T,N} end +abstract type A20086{T,N} end +struct B20086{T,N} <: A20086{T,N} end @test subtypes(A20086) == [B20086] @test subtypes(A20086{Int}) == [B20086{Int}] @test subtypes(A20086{T,3} where T) == [B20086{T,3} where T] diff --git a/test/repl.jl b/test/repl.jl index 9858f989ffe14..ec112b5526c55 100644 --- a/test/repl.jl +++ b/test/repl.jl @@ -435,7 +435,7 @@ begin # Test removal of prefix in multiple statement paste sendrepl2("""\e[200~ - julia> type T17599; a::Int; end + julia> mutable struct T17599; a::Int; end julia> function foo(julia) julia> 3 @@ -545,7 +545,7 @@ end end # let exename # issue #19864: -type Error19864 <: Exception; end +mutable struct Error19864 <: Exception; end function test19864() @eval current_module() Base.showerror(io::IO, e::Error19864) = print(io, "correct19864") buf = IOBuffer() diff --git a/test/replcompletions.jl b/test/replcompletions.jl index d91450d18703a..1fdebef6872f5 100644 --- a/test/replcompletions.jl +++ b/test/replcompletions.jl @@ -4,10 +4,10 @@ using Base.REPLCompletions ex = quote module CompletionFoo - type Test_y + mutable struct Test_y yy end - type Test_x + mutable struct Test_x xx :: Test_y end type_test = Test_x(Test_y(1)) @@ -22,7 +22,7 @@ ex = quote end # Support non-Dict Associatives, #19441 - type CustomDict{K, V} <: Associative{K, V} + mutable struct CustomDict{K, V} <: Associative{K, V} mydict::Dict{K, V} end diff --git a/test/replutil.jl b/test/replutil.jl index 0e688f83e119c..aa113c5258a24 100644 --- a/test/replutil.jl +++ b/test/replutil.jl @@ -86,7 +86,7 @@ Base.show_method_candidates(buf, MethodError(method_c5,(Int32,))) test_have_color(buf, "\e[0m\nClosest candidates are:\n method_c5(\e[1m\e[31m::Type{Float64}\e[0m)$cfile$c5line\e[0m", "\nClosest candidates are:\n method_c5(!Matched::Type{Float64})$cfile$c5line") -type Test_type end +mutable struct Test_type end test_type = Test_type() for f in [getindex, setindex!] Base.show_method_candidates(buf, MethodError(f,(test_type, 1,1))) @@ -94,7 +94,7 @@ for f in [getindex, setindex!] end PR16155line = @__LINE__ + 2 -type PR16155 +mutable struct PR16155 a::Int64 b end @@ -215,9 +215,9 @@ macro except_stackframe(expr, err_type) end # Pull Request 11007 -abstract InvokeType11007 -abstract MethodType11007 <: InvokeType11007 -type InstanceType11007 <: MethodType11007 +abstract type InvokeType11007 end +abstract type MethodType11007 <: InvokeType11007 end +mutable struct InstanceType11007 <: MethodType11007 end let f11007(::MethodType11007) = nothing @@ -252,13 +252,13 @@ let @test contains(err_str, "column vector") end -abstract T11007 +abstract type T11007 end let err_str = @except_str T11007() MethodError @test contains(err_str, "no method matching $(curmod_prefix)T11007()") end -immutable TypeWithIntParam{T <: Integer} end +struct TypeWithIntParam{T <: Integer} end let undefvar err_str = @except_strbt sqrt(-1) DomainError @test contains(err_str, "Try sqrt(complex(x)).") @@ -319,9 +319,9 @@ let end # Issue #14884 -bitstype 8 EightBitType -bitstype 8 EightBitTypeT{T} -immutable FunctionLike <: Function; end +primitive type EightBitType 8 end +primitive type EightBitTypeT{T} 8 end +struct FunctionLike <: Function; end let err_str, i = reinterpret(EightBitType, 0x54), j = reinterpret(EightBitTypeT{Int32}, 0x54) diff --git a/test/serialize.jl b/test/serialize.jl index fb335a8a213a4..76c19a7402d65 100644 --- a/test/serialize.jl +++ b/test/serialize.jl @@ -129,7 +129,7 @@ end create_serialization_stream() do s # user-defined type usertype = "SerializeSomeType" - eval(parse("abstract $(usertype)")) + eval(parse("abstract type $(usertype) end")) utype = eval(parse("$(usertype)")) serialize(s, utype) seek(s, 0) @@ -138,7 +138,7 @@ end create_serialization_stream() do s # user-defined type usertype = "SerializeSomeType1" - eval(parse("type $(usertype); end")) + eval(parse("mutable struct $(usertype); end")) utype = eval(parse("$(usertype)")) serialize(s, utype) seek(s, 0) @@ -147,43 +147,43 @@ end create_serialization_stream() do s # user-defined type usertype = "SerializeSomeType2" - eval(parse("abstract $(usertype){T}")) + eval(parse("abstract type $(usertype){T} end")) utype = eval(parse("$(usertype)")) serialize(s, utype) seek(s, 0) @test deserialize(s) == utype end -create_serialization_stream() do s # immutable type with 1 field +create_serialization_stream() do s # immutable struct with 1 field usertype = "SerializeSomeType3" - eval(parse("immutable $(usertype){T}; a::T; end")) + eval(parse("struct $(usertype){T}; a::T; end")) utype = eval(parse("$(usertype)")) serialize(s, utype) seek(s, 0) @test deserialize(s) == utype end -create_serialization_stream() do s # immutable type with 2 field +create_serialization_stream() do s # immutable struct with 2 field usertype = "SerializeSomeType4" - eval(parse("immutable $(usertype){T}; a::T; b::T; end")) + eval(parse("struct $(usertype){T}; a::T; b::T; end")) utval = eval(parse("$(usertype)(1,2)")) serialize(s, utval) seek(s, 0) @test deserialize(s) === utval end -create_serialization_stream() do s # immutable type with 3 field +create_serialization_stream() do s # immutable struct with 3 field usertype = "SerializeSomeType5" - eval(parse("immutable $(usertype){T}; a::T; b::T; c::T; end")) + eval(parse("struct $(usertype){T}; a::T; b::T; c::T; end")) utval = eval(parse("$(usertype)(1,2,3)")) serialize(s, utval) seek(s, 0) @test deserialize(s) === utval end -create_serialization_stream() do s # immutable type with 4 field +create_serialization_stream() do s # immutable struct with 4 field usertype = "SerializeSomeType6" - eval(parse("immutable $(usertype){T}; a::T; b::T; c::T; d::T; end")) + eval(parse("struct $(usertype){T}; a::T; b::T; c::T; d::T; end")) utval = eval(parse("$(usertype)(1,2,3,4)")) serialize(s, utval) seek(s, 0) @@ -204,7 +204,7 @@ create_serialization_stream() do s end # Array -type TA1 +mutable struct TA1 v::UInt8 end create_serialization_stream() do s # small 1d array @@ -248,7 +248,7 @@ end # Objects that have a SubArray as a type in a type-parameter list module ArrayWrappers -immutable ArrayWrapper{T,N,A<:AbstractArray} <: AbstractArray{T,N} +struct ArrayWrapper{T,N,A<:AbstractArray} <: AbstractArray{T,N} data::A end ArrayWrapper{T,N}(data::AbstractArray{T,N}) = ArrayWrapper{T,N,typeof(data)}(data) @@ -317,7 +317,7 @@ create_serialization_stream() do s # user-defined type array @test r.exception === nothing end -immutable MyErrorTypeTest <: Exception end +struct MyErrorTypeTest <: Exception end create_serialization_stream() do s # user-defined type array t = Task(()->throw(MyErrorTypeTest())) @test_throws MyErrorTypeTest wait(schedule(t)) @@ -328,7 +328,7 @@ create_serialization_stream() do s # user-defined type array @test isa(t.exception, MyErrorTypeTest) end -# corner case: undefined inside immutable type +# corner case: undefined inside immutable struct create_serialization_stream() do s serialize(s, Nullable{Any}()) seekstart(s) @@ -402,7 +402,7 @@ str = String(take!(io)) end # module Test13452 # issue #15163 -type B15163{T} +mutable struct B15163{T} x::Array{T} end let b = IOBuffer() diff --git a/test/show.jl b/test/show.jl index bbf65fc40f476..b697acf0d8f54 100644 --- a/test/show.jl +++ b/test/show.jl @@ -11,13 +11,13 @@ replstr(x) = sprint((io,x) -> show(IOContext(io, limit=true), MIME("text/plain") @test replstr(Array{Any}(2,2,2)) == "2×2×2 Array{Any,3}:\n[:, :, 1] =\n #undef #undef\n #undef #undef\n\n[:, :, 2] =\n #undef #undef\n #undef #undef" @test replstr([1f10]) == "1-element Array{Float32,1}:\n 1.0f10" -immutable T5589 +struct T5589 names::Vector{String} end @test replstr(T5589(Array{String,1}(100))) == "$(curmod_prefix)T5589(String[#undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef … #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef])" -@test replstr(parse("type X end")) == ":(type X # none, line 1:\n end)" -@test replstr(parse("immutable X end")) == ":(immutable X # none, line 1:\n end)" +@test replstr(parse("mutable struct X end")) == ":(mutable struct X # none, line 1:\n end)" +@test replstr(parse("struct X end")) == ":(struct X # none, line 1:\n end)" s = "ccall(:f, Int, (Ptr{Void},), &x)" @test replstr(parse(s)) == ":($s)" @@ -94,7 +94,7 @@ end @test_repr "(a == b == c) != (c == d < e)" # control structures (shamelessly stolen from base/bitarray.jl) -@test_repr """type BitArray{N} <: AbstractArray{Bool, N} +@test_repr """mutable struct BitArray{N} <: AbstractArray{Bool, N} chunks::Vector{UInt64} len::Int dims::NTuple{N,Int} @@ -232,7 +232,7 @@ for s in ("(1::Int64 == 1::Int64)::Bool", "(1:2:3) + 4", "x = 1:2:3") end # parametric type instantiation printing -immutable TParametricPrint{a}; end +struct TParametricPrint{a}; end @test sprint(show, :(TParametricPrint{false}())) == ":(TParametricPrint{false}())" # issue #9797 @@ -285,10 +285,10 @@ end @test_repr "(1 => 2) => 3" # pr 12008 -@test_repr "bitstype A B" -@test_repr "bitstype 100 B" -@test repr(:(bitstype A B)) == ":(bitstype A B)" -@test repr(:(bitstype 100 B)) == ":(bitstype 100 B)" +@test_repr "primitive type A B end" +@test_repr "primitive type B 100 end" +@test repr(:(primitive type A B end)) == ":(primitive type A B end)" +@test repr(:(primitive type B 100 end)) == ":(primitive type B 100 end)" # `where` syntax @test_repr "A where T<:B" @@ -367,7 +367,7 @@ let filename = tempname() end # issue #12960 -type T12960 end +mutable struct T12960 end let A = speye(3) B = similar(A, T12960) diff --git a/test/sorting.jl b/test/sorting.jl index 539dc669ad745..635eea81d127a 100644 --- a/test/sorting.jl +++ b/test/sorting.jl @@ -95,7 +95,7 @@ end @test searchsortedlast(500:1.0:600, 1.0e20) == 101 # exercise the codepath in searchsorted* methods for ranges that check for zero step range -immutable ConstantRange{T} <: Range{T} +struct ConstantRange{T} <: Range{T} val::T len::Int end @@ -337,7 +337,7 @@ end @test sortperm([-1.0, 1.0, 1.0], rev=true) == [2, 3, 1] # issue #8825 - stability of min/max -type Twain +mutable struct Twain a :: Int b :: Int end diff --git a/test/strings/basic.jl b/test/strings/basic.jl index e5d264c66b971..7ecb5bebbf13e 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -158,7 +158,7 @@ end @test lcfirst("*")=="*" # test AbstractString functions at beginning of string.jl -immutable tstStringType <: AbstractString +struct tstStringType <: AbstractString data::Array{UInt8,1} end tstr = tstStringType("12") @@ -444,7 +444,7 @@ end # Test cmp with AbstractStrings that don't index the same as UTF-8, which would include # (LegacyString.)UTF16String and (LegacyString.)UTF32String, among others. -type CharStr <: AbstractString +mutable struct CharStr <: AbstractString chars::Vector{Char} CharStr(x) = new(collect(x)) end diff --git a/test/strings/io.jl b/test/strings/io.jl index da07b114a98ab..dedb7463d48b0 100644 --- a/test/strings/io.jl +++ b/test/strings/io.jl @@ -144,7 +144,7 @@ end @test join(["apples", "bananas", "pineapples"], ", ", " and ") == "apples, bananas and pineapples" # issue #9178 `join` calls `done()` twice on the iterables -type i9178 +mutable struct i9178 nnext::Int64 ndone::Int64 end diff --git a/test/subarray.jl b/test/subarray.jl index cb10e3f1c4be4..0ff38ff999298 100644 --- a/test/subarray.jl +++ b/test/subarray.jl @@ -547,7 +547,7 @@ end # issue #18034 # ensure that it is possible to create an isbits, LinearFast view of an immutable Array let - immutable ImmutableTestArray{T, N} <: Base.DenseArray{T, N} + struct ImmutableTestArray{T, N} <: Base.DenseArray{T, N} end Base.size(::Union{ImmutableTestArray, Type{ImmutableTestArray}}) = (0, 0) Base.linearindexing(::Union{ImmutableTestArray, Type{ImmutableTestArray}}) = Base.LinearFast() diff --git a/test/subtype.jl b/test/subtype.jl index d8c6e6e53df4c..01698e27af9d6 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -599,17 +599,17 @@ macro testintersect(a, b, result) end) end -abstract IT4805_2{N, T} -abstract AbstractThing{T,N} -type ConcreteThing{T<:AbstractFloat,N} <: AbstractThing{T,N} +abstract type IT4805_2{N, T} end +abstract type AbstractThing{T,N} end +mutable struct ConcreteThing{T<:AbstractFloat,N} <: AbstractThing{T,N} end -type A11136 end -type B11136 end -abstract Foo11367 +mutable struct A11136 end +mutable struct B11136 end +abstract type Foo11367 end -abstract AbstractTriangular{T,S<:AbstractMatrix} <: AbstractMatrix{T} -immutable UpperTriangular{T,S<:AbstractMatrix} <: AbstractTriangular{T,S} end -immutable UnitUpperTriangular{T,S<:AbstractMatrix} <: AbstractTriangular{T,S} end +abstract type AbstractTriangular{T,S<:AbstractMatrix} <: AbstractMatrix{T} end +struct UpperTriangular{T,S<:AbstractMatrix} <: AbstractTriangular{T,S} end +struct UnitUpperTriangular{T,S<:AbstractMatrix} <: AbstractTriangular{T,S} end function test_intersection() @testintersect(Vector{Float64}, Vector{Union{Float64,Float32}}, Bottom) @@ -865,8 +865,8 @@ test_intersection_properties() @test NTuple{170,Matrix{Int}} <: (Tuple{Vararg{Union{Array{T,1},Array{T,2},Array{T,3}}}} where T) # Issue #12580 -abstract AbstractMyType12580{T} -immutable MyType12580{T}<:AbstractMyType12580{T} end +abstract type AbstractMyType12580{T} end +struct MyType12580{T}<:AbstractMyType12580{T} end tpara{A<:AbstractMyType12580}(::Type{A}) = tpara(supertype(A)) tpara{I}(::Type{AbstractMyType12580{I}}) = I @test tpara(MyType12580{true}) @@ -886,7 +886,7 @@ f12721{T<:Type{Int}}(::T) = true @test_throws MethodError f12721(Float64) # implicit "covariant" type parameters: -type TwoParams{S,T}; x::S; y::T; end +mutable struct TwoParams{S,T}; x::S; y::T; end @test TwoParams{<:Real,<:Number} == (TwoParams{S,T} where S<:Real where T<:Number) == (TwoParams{S,<:Number} where S<:Real) == (TwoParams{<:Real,T} where T<:Number) @test TwoParams(3,0im) isa TwoParams{<:Real,<:Number} diff --git a/test/test.jl b/test/test.jl index b7fefdb894444..cdd45a37ff980 100644 --- a/test/test.jl +++ b/test/test.jl @@ -47,7 +47,7 @@ a[1,1,1,1,1] = 10 "Thrown: ErrorException") # Test printing of Fail results -type NoThrowTestSet <: Base.Test.AbstractTestSet +mutable struct NoThrowTestSet <: Base.Test.AbstractTestSet results::Vector NoThrowTestSet(desc) = new([]) end @@ -265,7 +265,7 @@ redirect_stderr(OLD_STDERR) import Base.Test: record, finish using Base.Test: get_testset_depth, get_testset using Base.Test: AbstractTestSet, Result, Pass, Fail, Error -immutable CustomTestSet <: Base.Test.AbstractTestSet +struct CustomTestSet <: Base.Test.AbstractTestSet description::AbstractString foo::Int results::Vector @@ -374,7 +374,7 @@ end # Test that @inferred works with A[i] expressions @test @inferred((1:3)[2]) == 2 -immutable SillyArray <: AbstractArray{Float64,1} end +struct SillyArray <: AbstractArray{Float64,1} end Base.getindex(a::SillyArray, i) = rand() > 0.5 ? 0 : false test_result = @test_throws ErrorException @inferred(SillyArray()[2]) @test contains(test_result.value.msg, "Bool") diff --git a/test/threads.jl b/test/threads.jl index 5a673c9353544..d0626fdbc3d79 100644 --- a/test/threads.jl +++ b/test/threads.jl @@ -176,7 +176,7 @@ end @test_throws TypeError Atomic{Complex128} # Test atomic memory ordering with load/store -type CommBuf +mutable struct CommBuf var1::Atomic{Int} var2::Atomic{Int} correct_write::Bool @@ -221,7 +221,7 @@ test_atomic() # Test ordering with fences using Peterson's algorithm # Example adapted from -type Peterson +mutable struct Peterson # State for Peterson's algorithm flag::Vector{Atomic{Int}} turn::Atomic{Int} diff --git a/test/topology.jl b/test/topology.jl index 156813105709f..52cdad0ffc8c1 100644 --- a/test/topology.jl +++ b/test/topology.jl @@ -32,7 +32,7 @@ end remove_workers_and_test() # connect even pids to other even pids, odd to odd. -type TopoTestManager <: ClusterManager +mutable struct TopoTestManager <: ClusterManager np::Integer end diff --git a/test/tuple.jl b/test/tuple.jl index acf40f4306fd5..9f2496d364007 100644 --- a/test/tuple.jl +++ b/test/tuple.jl @@ -179,7 +179,7 @@ end @test_throws BoundsError ()[[false]] @test_throws BoundsError ()[[true]] -immutable BitPerm_19352 +struct BitPerm_19352 p::NTuple{8,UInt8} function BitPerm(p::NTuple{8,UInt8}) sort(collect(p)) != collect(0:7) && error("$p is not a permutation of 0:7") @@ -195,11 +195,11 @@ end # issue #15703 let - immutable A_15703{N} + struct A_15703{N} keys::NTuple{N, Int} end - immutable B_15703 + struct B_15703 x::A_15703 end diff --git a/test/vecelement.jl b/test/vecelement.jl index 17fc162855e94..31de4cb0586e9 100644 --- a/test/vecelement.jl +++ b/test/vecelement.jl @@ -24,7 +24,7 @@ for i=1:20 end # Another crash report for #15244 motivated this test. -immutable Bunch{N,T} +struct Bunch{N,T} elts::NTuple{N,Base.VecElement{T}} end @@ -38,7 +38,7 @@ b = Bunch((VecElement(1.0), VecElement(2.0))) @test rewrap(b)===VecElement(1.0) -immutable Herd{N,T} +struct Herd{N,T} elts::NTuple{N,Base.VecElement{T}} Herd{N,T}(elts::NTuple{N,T}) where {N,T} = new(ntuple(i->Base.VecElement{T}(elts[i]), N)) end @@ -53,7 +53,7 @@ check(Herd{1,Int}((1,))) check(Herd{2,Int}((4,5))) check(Herd{4,Int}((16,17,18,19))) -immutable Gr{N, T} +struct Gr{N, T} u::T v::Bunch{N,T} w::T diff --git a/test/workspace.jl b/test/workspace.jl index 3fc35bfab69f0..01d5fb843e241 100644 --- a/test/workspace.jl +++ b/test/workspace.jl @@ -18,9 +18,9 @@ run(`$exename --startup-file=no -e $script`) # issue #17764 script2 = """ -type Foo end +mutable struct Foo end workspace() -type Foo end +mutable struct Foo end @assert Tuple{Type{LastMain.Foo}} !== Tuple{Type{Main.Foo}} """ run(`$exename --startup-file=no -e $script2`) diff --git a/test/worlds.jl b/test/worlds.jl index d9f54d662ed8b..28a89b2e5c9dc 100644 --- a/test/worlds.jl +++ b/test/worlds.jl @@ -54,7 +54,7 @@ begin end # test constructor narrowing -type A265{T} +mutable struct A265{T} field1::T end A265_() = A265(1) @@ -63,7 +63,7 @@ A265(fld::Int) = A265(Float64(fld)) @test (A265_()::A265{Float64}).field1 === 1.0e0 # test constructor widening -type B265{T} +mutable struct B265{T} field1::T # dummy arg is present to prevent (::Type{T}){T}(arg) from matching the test calls B265{T}(field1::Any, dummy::Void) where T = new(field1) # prevent generation of outer ctor From 1519a2fe1e2a20c12928c2b15cca87dd7eb4a6aa Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 7 Feb 2017 17:41:46 -0500 Subject: [PATCH 2/3] update manual for changed type keywords --- base/reflection.jl | 2 +- doc/src/manual/calling-c-and-fortran-code.md | 18 +- doc/src/manual/constructors.md | 49 +++--- doc/src/manual/control-flow.md | 4 +- doc/src/manual/documentation.md | 10 +- doc/src/manual/faq.md | 4 +- doc/src/manual/interfaces.md | 6 +- doc/src/manual/methods.md | 2 +- doc/src/manual/parallel-computing.md | 2 +- doc/src/manual/performance-tips.md | 16 +- doc/src/manual/strings.md | 4 +- doc/src/manual/style-guide.md | 4 +- doc/src/manual/types.md | 171 ++++++++++--------- doc/src/manual/variables-and-scoping.md | 6 +- 14 files changed, 149 insertions(+), 149 deletions(-) diff --git a/base/reflection.jl b/base/reflection.jl index c5eefc9b661f1..087a6ad5e938f 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -198,7 +198,7 @@ datatype_fielddesc_type(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefErro """ isimmutable(v) -Return `true` iff value `v` is immutable. See [Immutable Composite Types](@ref) +Return `true` iff value `v` is immutable. See [Mutable 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. """ diff --git a/doc/src/manual/calling-c-and-fortran-code.md b/doc/src/manual/calling-c-and-fortran-code.md index d0e8c920ffa09..bae4528bd693a 100644 --- a/doc/src/manual/calling-c-and-fortran-code.md +++ b/doc/src/manual/calling-c-and-fortran-code.md @@ -264,13 +264,13 @@ First, a review of some relevant Julia type terminology: | Syntax / Keyword | Example | Description | |:----------------------------- |:------------------------------------------- |:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `mutable` | `String` | "Leaf Type" :: A group of related data that includes a type-tag, is managed by the Julia GC, and is defined by object-identity. The type parameters of a leaf type must be fully defined (no `TypeVars` are allowed) in order for the instance to be constructed. | -| `abstract` | `Any`, `AbstractArray{T, N}`, `Complex{T}` | "Super Type" :: A super-type (not a leaf-type) that cannot be instantiated, but can be used to describe a group of types. | -| `{T}` | `Vector{Int}` | "Type Parameter" :: A specialization of a type (typically used for dispatch or storage optimization). | +| `mutable struct` | `String` | "Leaf Type" :: A group of related data that includes a type-tag, is managed by the Julia GC, and is defined by object-identity. The type parameters of a leaf type must be fully defined (no `TypeVars` are allowed) in order for the instance to be constructed. | +| `abstract type` | `Any`, `AbstractArray{T, N}`, `Complex{T}` | "Super Type" :: A super-type (not a leaf-type) that cannot be instantiated, but can be used to describe a group of types. | +| `T{A}` | `Vector{Int}` | "Type Parameter" :: A specialization of a type (typically used for dispatch or storage optimization). | | | | "TypeVar" :: The `T` in the type parameter declaration is referred to as a TypeVar (short for type variable). | -| `bitstype` | `Int`, `Float64` | "Bits Type" :: A type with no fields, but a size. It is stored and defined by-value. | +| `primitive type` | `Int`, `Float64` | "Primitive Type" :: A type with no fields, but a size. It is stored and defined by-value. | | `struct` | `Pair{Int, Int}` | "Struct" :: A type with all fields defined to be constant. It is defined by-value. And may be stored with a type-tag. | -| | `Complex128` (`isbits`) | "Is-Bits" :: A `bitstype`, or a `struct` type where all fields are other `isbits` types. It is defined by-value, and is stored without a type-tag. | +| | `Complex128` (`isbits`) | "Is-Bits" :: A `primitive type`, or a `struct` type where all fields are other `isbits` types. It is defined by-value, and is stored without a type-tag. | | `struct ...; end` | `nothing` | "Singleton" :: a Leaf Type or Struct with no fields. | | `(...)` or `tuple(...)` | `(1, 2, 3)` | "Tuple" :: an immutable data-structure similar to an anonymous struct type, or a constant array. Represented as either an array or a struct. | | `typealias` | Not applicable here | Type aliases, and other similar mechanisms of doing type indirection, are resolved to their base type (this includes assigning a type to another name, or getting the type out of a function call). | @@ -491,7 +491,7 @@ the static parameters of the function are considered to be part of this static e The static parameters of the function may be used as type parameters in the `ccall` signature, as long as they don't affect the layout of the type. For example, `f{T}(x::T) = ccall(:valid, Ptr{T}, (Ptr{T},), x)` -is valid, since `Ptr` is always a word-size bitstype. +is valid, since `Ptr` is always a word-size primitive type. But, `g{T}(x::T) = ccall(:notvalid, T, (T,), x)` is not valid, since the type layout of `T` is not known statically. @@ -504,7 +504,7 @@ Julia type is a homogeneous tuple of `VecElement` that naturally maps to the SIM > * The tuple must be the same size as the SIMD type. For example, a tuple representing an `__m128` > on x86 must have a size of 16 bytes. -> * The element type of the tuple must be an instance of `VecElement{T}` where `T` is a bitstype that +> * The element type of the tuple must be an instance of `VecElement{T}` where `T` is a primitive type that > is 1, 2, 4 or 8 bytes. For instance, consider this C routine that uses AVX intrinsics: @@ -937,12 +937,12 @@ back to a Julia object reference by [`unsafe_pointer_to_objref(ptr)`](@ref). (Ju can be converted to `jl_value_t*` pointers, as `Ptr{Void}`, by calling [`pointer_from_objref(v)`](@ref).) The reverse operation (writing data to a `Ptr{T}`), can be performed using [`unsafe_store!(ptr, value, [index])`](@ref). - Currently, this is only supported for bitstypes or other pointer-free (`isbits`) immutable struct types. +Currently, this is only supported for primitive types or other pointer-free (`isbits`) immutable struct types. Any operation that throws an error is probably currently unimplemented and should be posted as a bug so that it can be resolved. -If the pointer of interest is a plain-data array (bitstype or immutable struct), the function [`unsafe_wrap(Array, ptr,dims,[own])`](@ref) +If the pointer of interest is a plain-data array (primitive type or immutable struct), the function [`unsafe_wrap(Array, ptr,dims,[own])`](@ref) may be more useful. The final parameter should be true if Julia should "take ownership" of the underlying buffer and call `free(ptr)` when the returned `Array` object is finalized. If the `own` parameter is omitted or false, the caller must ensure the buffer remains in existence until diff --git a/doc/src/manual/constructors.md b/doc/src/manual/constructors.md index 6aa899cf50085..1ad1743a4c4ab 100644 --- a/doc/src/manual/constructors.md +++ b/doc/src/manual/constructors.md @@ -6,7 +6,7 @@ when applied to an argument tuple as a function. This much was already mentioned composite types were introduced. For example: ```jldoctest footype -julia> type Foo +julia> struct Foo bar baz end @@ -88,7 +88,7 @@ the constraint that the first number is not greater than the second one. One cou like this: ```jldoctest pairtype -julia> type OrderedPair +julia> struct OrderedPair x::Real y::Real OrderedPair(x,y) = x > y ? error("out of order") : new(x,y) @@ -108,18 +108,15 @@ Stacktrace: [1] OrderedPair(::Int64, ::Int64) at ./none:4 ``` -You can still reach in and directly change the field values to violate this invariant, but messing -around with an object's internals uninvited is considered poor form. You (or someone else) can -also provide additional outer constructor methods at any later point, but once a type is declared, -there is no way to add more inner constructor methods. Since outer constructor methods can only -create objects by calling other constructor methods, ultimately, some inner constructor must be -called to create an object. This guarantees that all objects of the declared type must come into +If the type were declared `mutable`, you could reach in and directly change the field values to +violate this invariant, but messing around with an object's internals uninvited is considered poor form. +You (or someone else) can also provide additional outer constructor methods at any later point, but +once a type is declared, there is no way to add more inner constructor methods. Since outer constructor +methods can only create objects by calling other constructor methods, ultimately, some inner constructor +must be called to create an object. This guarantees that all objects of the declared type must come into existence by a call to one of the inner constructor methods provided with the type, thereby giving some degree of enforcement of a type's invariants. -Of course, if the type is declared as `immutable`, then its constructor-provided invariants are -fully enforced. This is an important consideration when deciding whether a type should be immutable. - If any inner constructor method is defined, no default constructor method is provided: it is presumed that you have supplied yourself with all the inner constructors you need. The default constructor is equivalent to writing your own inner constructor method that takes all of the object's fields @@ -127,7 +124,7 @@ as parameters (constrained to be of the correct type, if the corresponding field and passes them to `new`, returning the resulting object: ```jldoctest -julia> type Foo +julia> struct Foo bar baz Foo(bar,baz) = new(bar,baz) @@ -140,11 +137,11 @@ inner constructor method. The following two types are equivalent -- one with a d the other with an explicit constructor: ```jldoctest -julia> type T1 +julia> struct T1 x::Int64 end -julia> type T2 +julia> struct T2 x::Int64 T2(x) = new(x) end @@ -175,7 +172,7 @@ or more generally, recursive data structures. Since the fundamental difficulty m obvious, let us briefly explain it. Consider the following recursive type declaration: ```jldoctest selfrefer -julia> type SelfReferential +julia> mutable struct SelfReferential obj::SelfReferential end @@ -201,7 +198,7 @@ at defining the `SelfReferential` type, with a zero-argument inner constructor r having `obj` fields pointing to themselves: ```jldoctest selfrefer2 -julia> type SelfReferential +julia> mutable struct SelfReferential obj::SelfReferential SelfReferential() = (x = new(); x.obj = x) end @@ -227,7 +224,7 @@ Although it is generally a good idea to return a fully initialized object from a incompletely initialized objects can be returned: ```jldoctest incomplete -julia> type Incomplete +julia> mutable struct Incomplete xx Incomplete() = new() end @@ -245,12 +242,12 @@ ERROR: UndefRefError: access to undefined reference This avoids the need to continually check for `null` values. However, not all object fields are references. Julia considers some types to be "plain data", meaning all of their data is self-contained -and does not reference other objects. The plain data types consist of bits types (e.g. `Int`) +and does not reference other objects. The plain data types consist of primitive types (e.g. `Int`) and immutable structs of other plain data types. The initial contents of a plain data type is undefined: ```julia -julia> type HasPlain +julia> struct HasPlain n::Int HasPlain() = new() end @@ -264,7 +261,7 @@ Arrays of plain data types exhibit the same behavior. You can pass incomplete objects to other functions from inner constructors to delegate their completion: ```jldoctest -julia> type Lazy +julia> mutable struct Lazy xx Lazy(v) = complete_me(new(), v) end @@ -282,7 +279,7 @@ given type parameters or with type parameters implied by the types of the argume constructor. Here are some examples: ```jldoctest parametric -julia> type Point{T<:Real} +julia> struct Point{T<:Real} x::T y::T end @@ -331,7 +328,7 @@ outer `Point` constructor that takes pairs of real arguments, which must be of t This automatic provision of constructors is equivalent to the following explicit declaration: ```jldoctest parametric2 -julia> type Point{T<:Real} +julia> struct Point{T<:Real} x::T y::T Point{T}(x,y) where T<:Real = new(x,y) @@ -416,7 +413,7 @@ parametric composite type and its constructor methods. To that end, here is the which implements Julia's [Rational Numbers](@ref): ```jldoctest rational -julia> immutable OurRational{T<:Integer} <: Real +julia> struct OurRational{T<:Integer} <: Real num::T den::T function OurRational{T}(num::T, den::T) where T<:Integer @@ -462,7 +459,7 @@ julia> function //(x::Complex, y::Complex) // (generic function with 6 methods) ``` -The first line -- `immutable OurRational{T<:Integer} <: Real` -- declares that `OurRational` takes one +The first line -- `struct OurRational{T<:Integer} <: Real` -- declares that `OurRational` takes one type parameter of an integer type, and is itself a real type. The field declarations `num::T` and `den::T` indicate that the data held in a `OurRational{T}` object are a pair of integers of type `T`, one representing the rational value's numerator and the other representing its denominator. @@ -546,7 +543,7 @@ For example, say we define a type that stores a vector along with an accurate re its sum: ```jldoctest -julia> type SummedArray{T<:Number,S<:Number} +julia> struct SummedArray{T<:Number,S<:Number} data::Vector{T} sum::S end @@ -562,7 +559,7 @@ Therefore we want to avoid an interface that allows the user to construct instan but inside the `type` definition block to suppress generation of default constructors: ```jldoctest -julia> type SummedArray{T<:Number,S<:Number} +julia> struct SummedArray{T<:Number,S<:Number} data::Vector{T} sum::S function SummedArray(a::Vector{T}) where T diff --git a/doc/src/manual/control-flow.md b/doc/src/manual/control-flow.md index eec97d5df6d06..7d43f557c948e 100644 --- a/doc/src/manual/control-flow.md +++ b/doc/src/manual/control-flow.md @@ -577,7 +577,7 @@ Stacktrace: You may define your own exceptions in the following way: ```jldoctest -julia> type MyCustomException <: Exception end +julia> struct MyCustomException <: Exception end ``` ### The [`throw()`](@ref) function @@ -621,7 +621,7 @@ This mechanism can be implemented easily by custom exception types following the is written: ```jldoctest -julia> type MyUndefVarError <: Exception +julia> struct MyUndefVarError <: Exception var::Symbol end diff --git a/doc/src/manual/documentation.md b/doc/src/manual/documentation.md index a14a1e1e3bc06..bbf8adc2fcc78 100644 --- a/doc/src/manual/documentation.md +++ b/doc/src/manual/documentation.md @@ -359,15 +359,15 @@ Adds docstring `"..."` to the macro named `@m`. ``` "..." -abstract T1 +abstract type T1 end "..." -type T2 +mutable struct T2 ... end "..." -immutable T3 +struct T3 ... end ``` @@ -376,7 +376,7 @@ Adds the docstring `"..."` to types `T1`, `T2`, and `T3`. ```julia "..." -type T +struct T "x" x "y" @@ -385,7 +385,7 @@ end ``` Adds docstring `"..."` to type `T`, `"x"` to field `T.x` and `"y"` to field `T.y`. Also applicable -to `immutable` types. +to `mutable struct` types. ```julia "..." diff --git a/doc/src/manual/faq.md b/doc/src/manual/faq.md index f20ed7204ca5e..23dd41e4e1721 100644 --- a/doc/src/manual/faq.md +++ b/doc/src/manual/faq.md @@ -12,7 +12,7 @@ If memory usage is your concern, you can always replace objects with ones that c with `A = 0`. The memory will be released the next time the garbage collector runs; you can force this to happen with [`gc()`](@ref). -### How can I modify the declaration of a type/immutable in my session? +### How can I modify the declaration of a type in my session? Perhaps you've defined a type and then realize you need to add a new field. If you try this at the REPL, you get the error: @@ -610,7 +610,7 @@ that, rather than storing the result in the same location in memory as `x`, it a array to store the result. While this behavior might surprise some, the choice is deliberate. The main reason is the presence -of `immutable` objects within Julia, which cannot change their value once created. Indeed, a +of immutable objects within Julia, which cannot change their value once created. Indeed, a number is an immutable object; the statements `x = 5; x += 1` do not modify the meaning of `5`, they modify the value bound to `x`. For an immutable, the only way to change the value is to reassign it. diff --git a/doc/src/manual/interfaces.md b/doc/src/manual/interfaces.md index f639a7802847d..04d4f550a5c66 100644 --- a/doc/src/manual/interfaces.md +++ b/doc/src/manual/interfaces.md @@ -61,7 +61,7 @@ end A simple example is an iterable sequence of square numbers with a defined length: ```jldoctest squaretype -julia> immutable Squares +julia> struct Squares count::Int end @@ -238,7 +238,7 @@ Returning to the sequence of squares from above, we could instead define it as a `AbstractArray{Int, 1}`: ```jldoctest squarevectype -julia> immutable SquaresVector <: AbstractArray{Int, 1} +julia> struct SquaresVector <: AbstractArray{Int, 1} count::Int end @@ -283,7 +283,7 @@ As a more complicated example, let's define our own toy N-dimensional sparse-lik on top of [`Dict`](@ref): ```jldoctest squarevectype -julia> immutable SparseArray{T,N} <: AbstractArray{T,N} +julia> struct SparseArray{T,N} <: AbstractArray{T,N} data::Dict{NTuple{N,Int}, T} dims::NTuple{N,Int} end diff --git a/doc/src/manual/methods.md b/doc/src/manual/methods.md index 42dd84f5c9fc1..1f6c9cc8c0062 100644 --- a/doc/src/manual/methods.md +++ b/doc/src/manual/methods.md @@ -590,7 +590,7 @@ For example, you can define a type that stores the coefficients of a polynomial, a function evaluating the polynomial: ```jldoctest polynomial -julia> immutable Polynomial{R} +julia> struct Polynomial{R} coeffs::Vector{R} end diff --git a/doc/src/manual/parallel-computing.md b/doc/src/manual/parallel-computing.md index c9731bc61e38b..70c7619f5460a 100644 --- a/doc/src/manual/parallel-computing.md +++ b/doc/src/manual/parallel-computing.md @@ -1029,7 +1029,7 @@ As an example let us see how the `LocalManager`, the manager responsible for sta on the same host, is implemented: ``` -immutable LocalManager <: ClusterManager +struct LocalManager <: ClusterManager np::Integer end diff --git a/doc/src/manual/performance-tips.md b/doc/src/manual/performance-tips.md index 4cdd7ac568bc4..8dbc3912ee5b0 100644 --- a/doc/src/manual/performance-tips.md +++ b/doc/src/manual/performance-tips.md @@ -162,7 +162,7 @@ specific instances where declarations are helpful. Types can be declared without specifying the types of their fields: ```jldoctest myambig -julia> type MyAmbiguousType +julia> struct MyAmbiguousType a end ``` @@ -196,7 +196,7 @@ You can do better by declaring the type of `a`. Here, we are focused on the case be any one of several types, in which case the natural solution is to use parameters. For example: ```jldoctest myambig2 -julia> type MyType{T<:AbstractFloat} +julia> mutable struct MyType{T<:AbstractFloat} a::T end ``` @@ -204,7 +204,7 @@ julia> type MyType{T<:AbstractFloat} This is a better choice than ```jldoctest myambig2 -julia> type MyStillAmbiguousType +julia> mutable struct MyStillAmbiguousType a::AbstractFloat end ``` @@ -296,11 +296,11 @@ to resolve the type at run-time. This results in shorter and faster code. The same best practices also work for container types: ```jldoctest containers -julia> type MySimpleContainer{A<:AbstractVector} +julia> mutable struct MySimpleContainer{A<:AbstractVector} a::A end -julia> type MyAmbiguousContainer{T} +julia> mutable struct MyAmbiguousContainer{T} a::AbstractVector{T} end ``` @@ -372,7 +372,7 @@ or other abstract types. To prevent such tedium, you can use two parameters in t of `MyContainer`: ```jldoctest containers2 -julia> type MyContainer{T, A<:AbstractVector} +julia> mutable struct MyContainer{T, A<:AbstractVector} a::A end @@ -439,7 +439,7 @@ MyContainer{Int64,UnitRange{Float64}} To prevent this, we can add an inner constructor: ```jldoctest containers3 -julia> type MyBetterContainer{T<:Real, A<:AbstractVector} +julia> mutable struct MyBetterContainer{T<:Real, A<:AbstractVector} a::A MyBetterContainer(v::AbstractVector{T}) = new(v) end @@ -731,7 +731,7 @@ and try to use it for everything. For example, you might imagine using it to sto e.g. ``` -immutable Car{Make,Model} +struct Car{Make,Model} year::Int ...more fields... end diff --git a/doc/src/manual/strings.md b/doc/src/manual/strings.md index f04f55b65f594..a1231da2fa912 100644 --- a/doc/src/manual/strings.md +++ b/doc/src/manual/strings.md @@ -29,7 +29,7 @@ There are a few noteworthy high-level features about Julia's strings: a string argument, you should declare the type as `AbstractString` in order to accept any string type. * Like C and Java, but unlike most dynamic languages, Julia has a first-class type representing - a single character, called `Char`. This is just a special kind of 32-bit bitstype whose numeric + a single character, called `Char`. This is just a special kind of 32-bit primitive type whose numeric value represents a Unicode code point. * As in Java, strings are immutable: the value of an `AbstractString` object cannot be changed. To construct a different string value, you construct a new string from parts of other strings. @@ -41,7 +41,7 @@ There are a few noteworthy high-level features about Julia's strings: ## [Characters](@id man-characters) -A `Char` value represents a single character: it is just a 32-bit bitstype with a special literal +A `Char` value represents a single character: it is just a 32-bit primitive type with a special literal representation and appropriate arithmetic behaviors, whose numeric value is interpreted as a [Unicode code point](https://en.wikipedia.org/wiki/Code_point). Here is how `Char` values are input and shown: diff --git a/doc/src/manual/style-guide.md b/doc/src/manual/style-guide.md index e4063f58e2f3b..2b0b0fc09dba7 100644 --- a/doc/src/manual/style-guide.md +++ b/doc/src/manual/style-guide.md @@ -154,7 +154,7 @@ uses (e.g. `a[i]::Int`) than to try to pack many alternatives into one type. ## Use naming conventions consistent with Julia's `base/` - * modules and type names use capitalization and camel case: `module SparseArrays`, `immutable UnitRange`. + * modules and type names use capitalization and camel case: `module SparseArrays`, `struct UnitRange`. * functions are lowercase ([`maximum()`](@ref), [`convert()`](@ref)) and, when readable, with multiple words squashed together ([`isequal()`](@ref), [`haskey()`](@ref)). When necessary, use underscores as word separators. Underscores are also used to indicate a combination of concepts ([`remotecall_fetch()`](@ref) @@ -225,7 +225,7 @@ it. The preferred style is to use instances by default, and only add methods involving `Type{MyType}` later if they become necessary to solve some problem. -If a type is effectively an enumeration, it should be defined as a single (ideally `immutable`) +If a type is effectively an enumeration, it should be defined as a single (ideally immutable struct or primitive) type, with the enumeration values being instances of it. Constructors and conversions can check whether values are valid. This design is preferred over making the enumeration an abstract type, with the "values" as subtypes. diff --git a/doc/src/manual/types.md b/doc/src/manual/types.md index 86abb5ebe1d3c..0659db24d0e44 100644 --- a/doc/src/manual/types.md +++ b/doc/src/manual/types.md @@ -146,12 +146,12 @@ of a hierarchy of types, providing a context into which concrete types can fit. for example, to easily program to any type that is an integer, without restricting an algorithm to a specific type of integer. -Abstract types are declared using the `abstract` keyword. The general syntaxes for declaring an +Abstract types are declared using the `abstract type` keyword. The general syntaxes for declaring an abstract type are: ``` -abstract «name» -abstract «name» <: «supertype» +abstract type «name» end +abstract type «name» <: «supertype» end ``` The `abstract` keyword introduces a new abstract type, whose name is given by `«name»`. This @@ -167,12 +167,12 @@ opposite of `Any`: no object is an instance of `Union{}` and all types are super Let's consider some of the abstract types that make up Julia's numerical hierarchy: ```julia -abstract Number -abstract Real <: Number -abstract AbstractFloat <: Real -abstract Integer <: Real -abstract Signed <: Integer -abstract Unsigned <: Integer +abstract type Number end +abstract type Real <: Number end +abstract type AbstractFloat <: Real end +abstract type Integer <: Real end +abstract type Signed <: Integer end +abstract type Unsigned <: Integer end ``` The `Number` type is a direct child type of `Any`, and `Real` is its child. In turn, `Real` has @@ -231,42 +231,42 @@ a function whose arguments are abstract types, because it is recompiled for each concrete types with which it is invoked. (There may be a performance issue, however, in the case of function arguments that are containers of abstract types; see [Performance Tips](@ref man-performance-tips).) -## Bits Types +## Primitive Types -A bits type is a concrete type whose data consists of plain old bits. Classic examples of bits +A primitive type is a concrete type whose data consists of plain old bits. Classic examples of primitive types are integers and floating-point values. Unlike most languages, Julia lets you declare your -own bits types, rather than providing only a fixed set of built-in bits types. In fact, the standard -bits types are all defined in the language itself: +own primitive types, rather than providing only a fixed set of built-in ones. In fact, the standard +primitive types are all defined in the language itself: ```julia -bitstype 16 Float16 <: AbstractFloat -bitstype 32 Float32 <: AbstractFloat -bitstype 64 Float64 <: AbstractFloat +primitive type Float16 <: AbstractFloat 16 end +primitive type Float32 <: AbstractFloat 32 end +primitive type Float64 <: AbstractFloat 64 end -bitstype 8 Bool <: Integer -bitstype 32 Char +primitive type Bool <: Integer 8 end +primitive type Char 32 end -bitstype 8 Int8 <: Signed -bitstype 8 UInt8 <: Unsigned -bitstype 16 Int16 <: Signed -bitstype 16 UInt16 <: Unsigned -bitstype 32 Int32 <: Signed -bitstype 32 UInt32 <: Unsigned -bitstype 64 Int64 <: Signed -bitstype 64 UInt64 <: Unsigned -bitstype 128 Int128 <: Signed -bitstype 128 UInt128 <: Unsigned +primitive type Int8 <: Signed 8 end +primitive type UInt8 <: Unsigned 8 end +primitive type Int16 <: Signed 16 end +primitive type UInt16 <: Unsigned 16 end +primitive type Int32 <: Signed 32 end +primitive type UInt32 <: Unsigned 32 end +primitive type Int64 <: Signed 64 end +primitive type UInt64 <: Unsigned 64 end +primitive type Int128 <: Signed 128 end +primitive type UInt128 <: Unsigned 128 end ``` -The general syntaxes for declaration of a `bitstype` are: +The general syntaxes for declaring a primitive type are: ``` -bitstype «bits» «name» -bitstype «bits» «name» <: «supertype» +primitive type «name» «bits» end +primitive type «name» <: «supertype» «bits» end ``` The number of bits indicates how much storage the type requires and the name gives the new type -a name. A bits type can optionally be declared to be a subtype of some supertype. If a supertype +a name. A primitive type can optionally be declared to be a subtype of some supertype. If a supertype is omitted, then the type defaults to having `Any` as its immediate supertype. The declaration of `Bool` above therefore means that a boolean value takes eight bits to store, and has `Integer` as its immediate supertype. Currently, only sizes that are multiples of 8 bits are supported. @@ -284,8 +284,8 @@ be impossible to make `Bool` behave any differently than `Int8` or `UInt8`. ## Composite Types -[Composite types](https://en.wikipedia.org/wiki/Composite_data_type) are called records, structures -(`struct`s in C), or objects in various languages. A composite type is a collection of named fields, +[Composite types](https://en.wikipedia.org/wiki/Composite_data_type) are called records, structs, +or objects in various languages. A composite type is a collection of named fields, an instance of which can be treated as a single value. In many languages, composite types are the only kind of user-definable type, and they are by far the most commonly used user-defined type in Julia as well. @@ -304,12 +304,11 @@ for more information on methods and dispatch). Thus, it would be inappropriate f named bags of methods "inside" each object ends up being a highly beneficial aspect of the language design. -Since composite types are the most common form of user-defined concrete type, they are simply -introduced with the `type` keyword followed by a block of field names, optionally annotated with -types using the `::` operator: +Composite types are introduced with the `struct` keyword followed by a block of field names, optionally +annotated with types using the `::` operator: ```jldoctest footype -julia> type Foo +julia> struct Foo bar baz::Int qux::Float64 @@ -318,7 +317,7 @@ julia> type Foo Fields with no type annotation default to `Any`, and can accordingly hold any type of value. -New objects of composite type `Foo` are created by applying the `Foo` type object like a function +New objects of type `Foo` are created by applying the `Foo` type object like a function to values for its fields: ```jldoctest footype @@ -369,20 +368,25 @@ julia> foo.qux 1.5 ``` -You can also change the values as one would expect: +Composite objects declared with `struct` are *immutable*; they cannot be modified +after construction. This may seem odd at first, but it has several advantages: -```jldoctest footype -julia> foo.qux = 2 -2 + * It can be more efficient. Some structs can be packed efficiently into arrays, and in some cases the + compiler is able to avoid allocating immutable objects entirely. + * It is not possible to violate the invariants provided by the type's constructors. + * Code using immutable objects can be easier to reason about. -julia> foo.bar = 1//2 -1//2 -``` +An immutable object might contain mutable objects, such as arrays, as fields. Those contained +objects will remain mutable; only the fields of the immutable object itself cannot be changed +to point to different objects. + +Where required, mutable composite objects can be declared with the keyword `mutable struct`, to be +discussed in the next section. Composite types with no fields are singletons; there can be only one instance of such types: ```jldoctest -julia> type NoFields +julia> struct NoFields end julia> NoFields() === NoFields() @@ -396,34 +400,33 @@ There is much more to say about how instances of composite types are created, bu depends on both [Parametric Types](@ref) and on [Methods](@ref), and is sufficiently important to be addressed in its own section: [Constructors](@ref man-constructors). -## Immutable Composite Types +## Mutable Composite Types -It is also possible to define *immutable* composite types by using the keyword `immutable` instead -of `type`: +If a composite type is declared with `mutable struct` instead of `struct`, then instances of +it can be modified: -```julia -immutable Complex - real::Float64 - imag::Float64 -end -``` +```jldoctest bartype +julia> mutable struct Bar + baz + qux::Float64 + end -Such types behave much like other composite types, except that instances of them cannot be modified. -Immutable types have several advantages: +julia> bar = Bar("Hello", 1.5); - * They are more efficient in some cases. Types like the `Complex` example above can be packed efficiently - into arrays, and in some cases the compiler is able to avoid allocating immutable objects entirely. - * It is not possible to violate the invariants provided by the type's constructors. - * Code using immutable objects can be easier to reason about. +julia> bar.qux = 2.0 +2.0 -An immutable object might contain mutable objects, such as arrays, as fields. Those contained -objects will remain mutable; only the fields of the immutable object itself cannot be changed -to point to different objects. +julia> bar.baz = 1//2 +1//2 +``` -A useful way to think about immutable composites is that each instance is associated with specific -field values -- the field values alone tell you everything about the object. In contrast, a mutable -object is like a little container that might hold different values over time, and so is not identified -with specific field values. In deciding whether to make a type immutable, ask whether two instances +In order to support mutation, such objects are generally allocated on the heap, and have +stable memory addresses. +A mutable object is like a little container that might hold different values over time, +and so can only be reliably identified with its address. +In contrast, an instance of an immutable type is associated with specific field values --- +the field values alone tell you everything about the object. +In deciding whether to make a type mutable, ask whether two instances with the same field values would be considered identical, or if they might need to change independently over time. If they would be considered identical, the type should probably be immutable. @@ -517,7 +520,7 @@ abstract types, and finally parametric bits types. Type parameters are introduced immediately after the type name, surrounded by curly braces: ```jldoctest pointtype -julia> type Point{T} +julia> struct Point{T} x::T y::T end @@ -690,7 +693,7 @@ Parametric abstract type declarations declare a collection of abstract types, in way: ```jldoctest pointytype -julia> abstract Pointy{T} +julia> abstract type Pointy{T} end ``` With this declaration, `Pointy{T}` is a distinct abstract type for each type or integer value @@ -730,7 +733,7 @@ parametric abstract types serve the same purpose with respect to parametric comp could, for example, have declared `Point{T}` to be a subtype of `Pointy{T}` as follows: ```jldoctest pointytype -julia> type Point{T} <: Pointy{T} +julia> struct Point{T} <: Pointy{T} x::T y::T end @@ -764,7 +767,7 @@ implementation that only requires a single coordinate because the point is on th *x = y*: ```jldoctest pointytype -julia> type DiagPoint{T} <: Pointy{T} +julia> struct DiagPoint{T} <: Pointy{T} x::T end ``` @@ -779,7 +782,7 @@ There are situations where it may not make sense for type parameters to range fr possible types. In such situations, one can constrain the range of `T` like so: ```jldoctest realpointytype -julia> abstract Pointy{T<:Real} +julia> abstract type Pointy{T<:Real} end ``` With such a declaration, it is acceptable to use any type that is a subtype of `Real` in place @@ -802,7 +805,7 @@ ERROR: TypeError: Pointy: in T, expected T<:Real, got Int64 Type parameters for parametric composite types can be restricted in the same manner: ```julia -type Point{T<:Real} <: Pointy{T} +struct Point{T<:Real} <: Pointy{T} x::T y::T end @@ -813,7 +816,7 @@ the actual definition of Julia's `Rational` immutable type (except that we omit here for simplicity), representing an exact ratio of integers: ```julia -immutable Rational{T<:Integer} <: Real +struct Rational{T<:Integer} <: Real num::T den::T end @@ -831,7 +834,7 @@ to a parameterized immutable type where each parameter is the type of one field. a 2-element tuple type resembles the following immutable type: ```julia -immutable Tuple2{A,B} +struct Tuple2{A,B} a::A b::B end @@ -953,17 +956,17 @@ the term "singleton type" refers to a type whose only instance is a single value applies to Julia's singleton types, but with that caveat that only type objects have singleton types. -### Parametric Bits Types +### Parametric Primitive Types -Bits types can also be declared parametrically. For example, pointers are represented as boxed -bits types which would be declared in Julia like this: +Primitive types can also be declared parametrically. For example, pointers are represented as +primitive types which would be declared in Julia like this: ```julia # 32-bit system: -bitstype 32 Ptr{T} +primitive type Ptr{T} 32 end # 64-bit system: -bitstype 64 Ptr{T} +primitive type Ptr{T} 64 end ``` The slightly odd feature of these declarations as compared to typical parametric composite types, @@ -1159,7 +1162,7 @@ overloading the [`show()`](@ref) function. For example, suppose we define a typ complex numbers in polar form: ```jldoctest polartype -julia> type Polar{T<:Real} <: Number +julia> struct Polar{T<:Real} <: Number r::T Θ::T end @@ -1250,7 +1253,7 @@ elaborate hierarchy. `Val` is defined as: ```jldoctest valtype -julia> immutable Val{T} +julia> struct Val{T} end ``` diff --git a/doc/src/manual/variables-and-scoping.md b/doc/src/manual/variables-and-scoping.md index ba6b85c1046e8..af4d02bfcefc8 100644 --- a/doc/src/manual/variables-and-scoping.md +++ b/doc/src/manual/variables-and-scoping.md @@ -17,7 +17,7 @@ constructs introducing scope blocks are: |:-------------------- |:-------------------------------------------------------------------------------------------------------- | | [Global Scope](@ref) | `module`, `baremodule`, at interactive prompt (REPL) | | [Local Scope](@ref) | [Soft Local Scope](@ref): `for`, `while`, comprehensions, try-catch-finally, `let` | -| [Local Scope](@ref) | [Hard Local Scope](@ref): functions (either syntax, anonymous & do-blocks), `type`, `immutable`, `macro` | +| [Local Scope](@ref) | [Hard Local Scope](@ref): functions (either syntax, anonymous & do-blocks), `struct`, `macro` | Notably missing from this table are [begin blocks](@ref man-compound-expressions) and [if blocks](@ref man-conditional-evaluation), which do *not* introduce new scope blocks. All three types of scopes follow somewhat different rules which will @@ -186,7 +186,7 @@ ERROR: syntax: `global j`: j is local variable in the enclosing scope ### Hard Local Scope -Hard local scopes are introduced by function definitions (in all their forms), type & immutable-blocks, +Hard local scopes are introduced by function definitions (in all their forms), struct type definition blocks, and macro-definitions. > In a hard local scope, all variables are inherited from its parent scope unless: @@ -488,7 +488,7 @@ not change, adding a `const` declaration solves this performance problem. Local constants are quite different. The compiler is able to determine automatically when a local variable is constant, so local constant declarations are not necessary for performance purposes. -Special top-level assignments, such as those performed by the `function` and `type` keywords, +Special top-level assignments, such as those performed by the `function` and `struct` keywords, are constant by default. Note that `const` only affects the variable binding; the variable may be bound to a mutable object From dc84a12477bf7c96d3c0cf31c206737c66b255e9 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 9 Feb 2017 13:13:10 -0500 Subject: [PATCH 3/3] update ctags and editor files for new type definition keywords --- contrib/Julia_Notepad++.xml | 2 +- contrib/ctags | 2 +- contrib/julia.hrc | 12 ++++++------ contrib/julia.lang | 8 ++++---- contrib/julia.xml | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/contrib/Julia_Notepad++.xml b/contrib/Julia_Notepad++.xml index fe0f0a0f27c3f..2d548197bd9de 100644 --- a/contrib/Julia_Notepad++.xml +++ b/contrib/Julia_Notepad++.xml @@ -26,7 +26,7 @@ true false C_NULL Inf NaN Inf32 NaN32 nothing AbstractArray AbstractMatrix AbstractRemoteRef AbstractSparseMatrix AbstractString AbstractVector Any ArgumentError Array Associative BigFloat BigInt BitArray BitMatrix BitVector Bool BunchKaufman Cchar Cdouble Cfloat Char CharString CholeskyDense CholeskyPivotedDense Cint Cintmax_t Clong Clonglong Colon Complex Complex128 Complex64 ComplexPair Cptrdiff_t Cshort Csize_t Cuchar Cuint Cuintmax_t Culong Culonglong Cushort DArray Dict Dims DisconnectException EOFError EachLine EnvHash ErrorException Exception Expr Factorization Filter Float Float32 Float64 Function GSVDDense IO IOBuffer IOStream ImaginaryUnit InsertionSort Int Int128 Int16 Int32 Int64 Int8 IntSet Integer KeyError LDLTTridiagonal LUDense LUTridiagonal LoadError LocalProcess Matrix MergeSort MethodError NTuple Number ObjectIdDict ObjectIdDict OrdinalRange ParseError PipeBuffer ProcessGroup Ptr QRDense QRPivotedDense QuickSort Range Range1 RangeIndex Ranges Rational Real Regex RegexMatch RegexMatchIterator RepString RevString Reverse SVDDense Set Signed SparseMatrixCSC SpawnNullStream Stat StridedArray StridedMatrix StridedVecOrMat StridedVector String SubArray SubDArray SubOrDArray SubString SymTridiagonal Symbol SystemError Task TCPSocket TimSort Tridiagonal Tuple Type TypeError UInt UInt128 UInt16 UInt32 UInt64 UInt8 UVError Union Unsigned VecOrMat Vector VersionNumber Void WeakKeyDict WeakRef Zip - abstract begin baremodule bitstype break catch ccall const continue do else elseif end export finally for function global if immutable import importall let local macro module quote return try type typealias using while + abstract begin baremodule primitive break catch ccall const continue do else elseif end export finally for function global if struct import importall let local macro module quote return try mutable typealias using while close enumerate error info open print println read write warn print println diff --git a/contrib/ctags b/contrib/ctags index 9b0977a0e627f..b5a431a99f45d 100644 --- a/contrib/ctags +++ b/contrib/ctags @@ -1,4 +1,4 @@ --langdef=julia --langmap=julia:.jl ---regex-julia=/^[ \t]*(function|macro|abstract|type|typealias|immutable)[ \t]+([^ \t({[]+).*$/\2/f,function/ +--regex-julia=/^[ \t]*(function|macro|abstract type|primitive type|struct|mutable struct|typealias)[ \t]+([^ \t({[]+).*$/\2/f,function/ --regex-julia=/^[ \t]*(([^@#$ \t({[]+)|\(([^@#$ \t({[]+)\)|\((\$)\))[ \t]*(\{.*\})?[ \t]*\([^#]*\)[ \t]*=([^=].*$|$)/\2\3\4/f,function/ diff --git a/contrib/julia.hrc b/contrib/julia.hrc index 4ab36ca633ee4..5162fc0447b13 100644 --- a/contrib/julia.hrc +++ b/contrib/julia.hrc @@ -34,8 +34,8 @@ - - + + @@ -85,11 +85,11 @@ - + - + @@ -97,7 +97,7 @@ - + @@ -105,7 +105,7 @@ - + diff --git a/contrib/julia.lang b/contrib/julia.lang index 7427ed635d4c6..95fed9c9c0fd5 100644 --- a/contrib/julia.lang +++ b/contrib/julia.lang @@ -154,11 +154,11 @@ in function if - immutable + struct let quote try - type + mutable type while catch finally @@ -166,8 +166,8 @@ elseif end - abstract - bitstype + abstract type + primitive type break ccall const diff --git a/contrib/julia.xml b/contrib/julia.xml index 578d6e4650ba5..978dc6e0b726e 100644 --- a/contrib/julia.xml +++ b/contrib/julia.xml @@ -38,11 +38,11 @@ for function if - immutable + struct let quote try - type + mutable struct while @@ -55,8 +55,8 @@ end - abstract - bitstype + abstract type + primitive type break ccall const