Julia v1.6 Release Notes
New language features
- Types written with
where
syntax can now be used to define constructors, e.g.(Foo{T} where T)(x) = ...
. <--
and<-->
are now available as infix operators, with the same precedence and associativity as other arrow-like operators (#36666).- Compilation and type inference can now be enabled or disabled at the module level using the experimental macro
Base.Experimental.@compiler_options
(#37041). - The library name passed to
ccall
or@ccall
can now be an expression involving global variables and function calls. The expression will be evaluated the first time theccall
executes (#36458). ꜛ
(U+A71B),ꜜ
(U+A71C) andꜝ
(U+A71D) can now also be used as operator suffixes. They can be tab-completed from\^uparrow
,\^downarrow
and\^!
in the REPL (#37542).- Standalone "dotted" operators now get parsed as
Expr(:., :op)
, which gets lowered toBase.BroadcastFunction(op)
. This means.op
is functionally equivalent to(x...) -> (op).(x...)
, which can be useful for passing the broadcasted version of an operator to higher-order functions, for examplemap(.*, A, B)
for an elementwise product of two arrays of arrays (#37583). - The syntax
import A as B
(plusimport A: x as y
,import A.x as y
, andusing A: x as y
) can now be used to rename imported modules and identifiers (#1255). - Unsigned literals (starting with
0x
) which are too big to fit in aUInt128
object are now interpreted asBigInt
(#23546). - It is now possible to use
...
on the left-hand side of assignments for taking any number of items from the front of an iterable collection, while also collecting the rest, for examplea, b... = [1, 2, 3]
. This syntax is implemented usingBase.rest
, which can be overloaded to customize its behavior for different collection types (#37410).
Language changes
- The postfix conjugate transpose operator
'
now accepts Unicode modifiers as suffixes, so e.g.a'ᵀ
is parsed asvar"'ᵀ"(a)
, which can be defined by the user.a'ᵀ
parsed asa' * ᵀ
before, so this is a minor breaking change (#37247). - Macros that return
:quote
expressions (e.g. viaExpr(:quote, ...)
) were previously able to work without escaping (esc(...)
) their output when needed. This has been corrected, and nowesc
must be used in these macros as it is in other macros (#37540). - The
-->
operator now lowers to a:call
expression, so it can be defined as a function like other operators. The dotted version.-->
is now parsed as well. For backwards compatibility,-->
still parses using its own expression head instead of:call
. - The
a[begin, k]
syntax now callsfirstindex(a, 1)
rather thanfirst(axes(a, 1))
(#35779), but the former now defaults to the latter for anya
(#38742). ⌿
(U+233F) and¦
(U+00A6) are now infix operators with times-like and plus-like precedence, respectively. Previously they were parsed as identifier characters (#37973).
Compiler/Runtime improvements
- All platforms can now use
@executable_path
withinjl_load_dynamic_library()
. This allows executable-relative paths to be embedded within executables on all platforms, not just MacOS, which the syntax is borrowed from (#35627). - Constant propagation now occurs through keyword arguments (#35976).
- The precompilation cache is now created atomically (#36416). Invoking n Julia processes simultaneously may create n temporary caches.
Command-line option changes
- There is no longer a concept of "home project": starting
julia --project=dir
is now exactly equivalent to startingjulia
and then doingpkg> activate $dir
andjulia --project
is exactly equivalent to doing that wheredir = Base.current_project()
. In particular, this means that if you dopkg> activate
after startingjulia
with the--project
option (or withJULIA_PROJECT
set) it will take you to the default active project, which is@v1.6
unless you have modifiedLOAD_PATH
(#36434).
Multi-threading changes
- Locks now automatically inhibit finalizers from running, to avoid deadlock (#38487).
- New function
Base.Threads.foreach(f, channel::Channel)
for multithreadedChannel
consumption (#34543).
Build system changes
- Windows Installer now has the option to 'Add Julia to Path'. To unselect this option from the commandline simply remove the tasks you do not want to be installed: e.g.
./julia-installer.exe /TASKS="desktopicon,startmenu,addtopath"
, adds a desktop icon, a startmenu group icon, and adds Julia to system PATH.
New library functions
- New function
Base.kron!
and corresponding overloads for various matrix types for performing Kronecker product in-place (#31069). - New function
Base.readeach(io, T)
for iteratively performingread(io, T)
(#36150). Iterators.map
is added. It provides another syntaxIterators.map(f, iterators...)
for writing(f(args...) for args in zip(iterators...))
, i.e. a lazymap
(#34352).- New function
sincospi
for simultaneously computingsinpi(x)
andcospi(x)
more efficiently (#35816). - New function
cispi(x)
for more accurately computingcis(pi * x)
(#38449). - New function
addenv
for adding environment mappings into aCmd
object, returning the newCmd
object. - New function
insorted
for determining whether an element is in a sorted collection or not (#37490). - New function
Base.rest
for taking the rest of a collection, starting from a specific iteration state, in a generic way (#37410).
New library features
- The
redirect_*
functions now acceptdevnull
to discard all output redirected to it, and as an empty input (#36146). - The
redirect_*
functions can now be called onIOContext
objects (#36688). findfirst
,findnext
,findlast
, andfindall
now supportAbstractVector{<:Union{Int8,UInt8}}
(pattern, array) arguments (#37283).- New constructor
NamedTuple(iterator)
that constructs a named tuple from a key-value pair iterator. - A new
reinterpret(reshape, T, a::AbstractArray{S})
reinterpretsa
to have eltypeT
while potentially inserting or consuming the first dimension depending on the ratio ofsizeof(T)
andsizeof(S)
. - New
append!(vector, collections...)
andprepend!(vector, collections...)
methods accept multiple collections to be appended or prepended (#36227). - The postfix operator
'ᵀ
can now be used as an alias fortranspose
(#38062). keys(io::IO)
has been added, which returns all keys ofio
ifio
is anIOContext
and an emptyBase.KeySet
otherwise (#37753).count
now accepts an optionalinit
argument to control the accumulation type (#37461).- New method
occursin(haystack)
that returns a function that checks whether its argument occurs inhaystack
(#38475). - New methods
∉(collection)
,∋(item)
, and∌(item)
returning corresponding containment-testing functions (#38475). - The
nextprod
function now accepts tuples and other array types for its first argument (#35791). - The
reverse(A; dims)
function for multidimensionalA
can now reverse multiple dimensions at once by passing a tuple fordims
, and defaults to reversing all dimensions; there is also a multidimensional in-placereverse!(A; dims)
(#37367). - The function
isapprox(x,y)
now accepts thenorm
keyword argument also for numeric (i.e., non-array) argumentsx
andy
(#35883). ispow2(x)
now supports non-Integer
argumentsx
(#37635).view
,@view
, and@views
now work onAbstractString
s, returning aSubString
when appropriate (#35879).- All
AbstractUnitRange{<:Integer}
s now work withSubString
,view
,@view
and@views
on strings (#35879). sum
,prod
,maximum
, andminimum
now supportinit
keyword argument (#36188, #35839).unique(f, itr; seen=Set{T}())
now allows you to declare the container type used for keeping track of values returned byf
on elements ofitr
(#36280).first
andlast
functions now accept an integer as second argument to get that many leading or trailing elements of any iterable (#34868).CartesianIndices
now supports step different from1
. It can also be constructed from threeCartesianIndex
esI
,S
,J
usingI:S:J
.step
forCartesianIndices
now returns aCartesianIndex
(#37829).RegexMatch
objects can now be probed for whether a named capture group exists within it throughhaskey()
(#36717).- For consistency
haskey(r::RegexMatch, i::Integer)
has also been added and returns if the capture group fori
exists (#37300).
Standard library changes
- A new standard library
TOML
has been added for parsing and printing TOML files (#37034). - A new standard library
Downloads
has been added, which replaces the oldBase.download
function withDownloads.download
, providing cross-platform, multi-protocol, in-process download functionality implemented with libcurl (#37340). Libdl
has been moved toBase.Libc.Libdl
, however it is still accessible as an stdlib (#35628).- To download artifacts lazily,
LazyArtifacts
now must be explicitly listed as a dependency, to avoid needing the support machinery to be available when it is not commonly needed (#37844). - It is no longer possible to create a
LinRange
,StepRange
, orStepRangeLen
with a<: Integer
eltype but non-integer step (#32439). intersect
onCartesianIndices
now returnsCartesianIndices
instead ofVector{<:CartesianIndex}
(#36643).push!(c::Channel, v)
now returns channelc
. Previously, it returned the pushed valuev
(#34202).- The composition operator
∘
now returns aBase.ComposedFunction
instead of an anonymous function (#37517). - Logging (such as
@warn
) no longer catches exceptions in the logger itself (#36600). @time
now reports if the time presented included any compilation time, which is shown as a percentage (#37678).@varinfo
can now report non-exported objects within modules, look recursively into submodules, and return a sorted results table (#38042).@testset
now supports the optionverbose
to show the test result summary of the children even if they all pass (#33755).
Package Manager
pkg> precompile
is now parallelized through depth-first precompilation of dependencies. Errors will only throw for direct dependencies listed in theProject.toml
.pkg> precompile
is now automatically triggered whenever Pkg changes the active manifest. Auto-precompilation will remember if a package has errored within the given environment and will not retry until it changes. Auto-precompilation can be gracefully interrupted with actrl-c
and disabled by setting the environment variableJULIA_PKG_PRECOMPILE_AUTO=0
.- The
Pkg.BinaryPlatforms
module has been moved intoBase
asBase.BinaryPlatforms
and heavily reworked. Applications that want to be compatible with the old API should continue to importPkg.BinaryPlatforms
, however new users should useBase.BinaryPlatforms
directly (#37320). - The
Pkg.Artifacts
module has been imported as a separate standard library. It is still available asPkg.Artifacts
, however starting from Julia v1.6+, packages may import simplyArtifacts
without importing all ofPkg
alongside (#37320).
LinearAlgebra
- New method
LinearAlgebra.issuccess(::CholeskyPivoted)
for checking whether pivoted Cholesky factorization was successful (#36002). UniformScaling
can now be indexed into using ranges to return dense matrices and vectors (#24359).- New function
LinearAlgebra.BLAS.get_num_threads()
for getting the number of BLAS threads (#36360). (+)(::UniformScaling)
is now defined, making+I
a valid unary operation (#36784).- Instances of
UniformScaling
are no longerisequal
to matrices. Previous behaviour violated the rule thatisequal(x, y)
implieshash(x) == hash(y)
. - Transposing
*Triangular
matrices now returns matrices of the opposite triangular type, consistently withadjoint!(::*Triangular)
andtranspose!(::*Triangular)
. Packages containing methods with, e.g.,Adjoint{<:Any,<:LowerTriangular{<:Any,<:OwnMatrixType}}
should replace that byUpperTriangular{<:Any,<:Adjoint{<:Any,<:OwnMatrixType}}
in the method signature (#38168).
Markdown
Printf
- Complete overhaul of internal code to use the ryu float printing algorithms (from Julia 1.4); leads to consistent 2-5x performance improvements.
- New
Printf.tofloat
function allowing custom float types to more easily integrate with Printf formatting by converting their type toFloat16
,Float32
,Float64
, orBigFloat
. - New
Printf.format"..."
andPrintf.Format(...)
functions that allow creatingPrintf.Format
objects that can be passed toPrintf.format
for easier dynamic printf formatting. Printf.format(f::Printf.Format, args...)
as a non-macro function that applies a printf formatf
to providedargs
.
Random
REPL
The
AbstractMenu
extension interface ofREPL.TerminalMenus
has been extensively overhauled. The new interface does not rely on global configuration variables, is more consistent in delegating printing of the navigation/selection markers, and provides improved support for dynamic menus. These changes are compatible with the previous (deprecated) interface, so are non-breaking.The new API offers several enhancements:
- Menus are configured in their constructors via keyword arguments.
- For custom menu types, the new
Config
andMultiSelectConfig
replace the globalCONFIG
Dict
. request(menu; cursor=1)
allows you to control the initial cursor position in the menu (defaults to first item).MultiSelectMenu
allows you to pass a list of initially-selected items with theselected
keyword argument.writeLine
was deprecated towriteline
, andwriteline
methods are not expected to print the cursor indicator. The oldwriteLine
continues to work, and any of its method extensions should print the cursor indicator as before.printMenu
has been deprecated toprintmenu
, and it both accepts a state input and returns a state output that controls the number of terminal lines erased when the menu is next refreshed. This plus related changes makesprintmenu
work properly when the number of menu items might change depending on user choices.numoptions
, returning the number of items in the menu, has been added as an alternative to implementingoptions
.suppress_output
(primarily a testing option) has been added as a keyword argument torequest
, rather than a configuration option.
Tab completion now supports runs of consecutive sub/superscript characters, e.g.
\^(3)
tab-completes to⁽³⁾
(#38649).Windows REPL now supports 24-bit colors, by correctly interpreting virtual terminal escapes.
SparseArrays
- Display large sparse matrices with a Unicode "spy" plot of their nonzero patterns, and display small sparse matrices by an
Matrix
-like 2d layout of their contents (#33821). - New convenient
spdiagm([m, n,] v::AbstractVector)
methods which callspdiagm([m, n,] 0 => v)
, consistently with their densediagm
counterparts (#37684).
Dates
Quarter
period is defined (#35519).canonicalize
can now takePeriod
as an input (#37391).- Zero-valued
FixedPeriod
s andOtherPeriod
s now compare equal, e.g.,Year(0) == Day(0)
. The behavior of non-zeroPeriod
s is not changed (#37486).
Statistics
Sockets
Distributed
- Now supports invoking Windows workers via ssh (via new keyword argument
shell=:wincmd
inaddprocs
) (#30614). - Other new keyword arguments in
addprocs
:ssh
to specify the ssh client path,env
to pass environment variables to workers, andcmdline_cookie
to work around an ssh problem with Windows workers that run older (pre-ConPTY) versions of Windows, Julia or OpenSSH (#30614).
UUIDs
- Change
uuid1
anduuid4
to useRandom.RandomDevice()
as default random number generator (#35872). - Added
parse(::Type{UUID}, ::AbstractString)
method.
Mmap
- On Unix systems, the
Mmap.madvise!
function (along with OS-specificMmap.MADV_*
constants) has been added to give advice on handling of memory-mapped arrays (#37369).
Deprecated or removed
- The
Base.download
function has been deprecated (silently, by default) in favor of the newDownloads.download
standard library function (#37340). - The
Base.Grisu
code has been officially removed (float printing was switched to the ryu algorithm code in 1.4). The code is available from JuliaAttic if needed.