12 KiB
v0.20.0 - 2019-06-06
Changes affecting backwards compatibility
-
shris now sign preserving. Use-d:nimOldShiftRightto enable the old behavior globally. -
The
isLower,isUpperfamily of procs in strutils/unicode operating on strings have been deprecated since it was unclear what these do. Note that the much more useful procs that operate oncharorRuneare not affected. -
strutils.editDistancehas been deprecated, useeditdistance.editDistanceoreditdistance.editDistanceAsciiinstead. -
The OpenMP parallel iterator `
||` now supports any#pragma omp directiveand not just#pragma omp parallel for. See OpenMP documentation.The default annotation is
parallel for, if you used OpenMP without annotation the change is transparent, if you used annotations you will have to prefix your previous annotations withparallel for.Furthermore, an overload with positive stepping is available.
-
The
uncheckedpragma was removed, instead usesystem.UncheckedArray. -
The undocumented
#? strongSpacesparsing mode has been removed. -
The
notoperator is now always a unary operator, this means that code likeassert not isFalse(3)compiles. -
getImplon avarorletsymbol will now return the fullIdentDefstree from the symbol declaration instead of just the initializer portion. -
Methods are now ordinary "single" methods, only the first parameter is used to select the variant at runtime. For backwards compatibility use the new
--multimethods:onswitch. -
Generic methods are now deprecated; they never worked well.
-
Compile time checks for integer and float conversions are now stricter. For example,
const x = uint32(-1)now gives a compile time error instead of being equivalent toconst x = 0xFFFFFFFF'u32. -
Using
typedas the result type in templates/macros now means "expression with a type". The old meaning oftypedis preserved asvoidor no result type at all. -
A bug allowed
macro foo(): int = 123to compile even though a macro has to return aNimNode. This has been fixed. -
With the exception of
uintanduint64, conversion to unsigned types are now range checked during runtime. -
Macro arguments of type
typedescare now passed to the macro asNimNodelike every other type exceptstatic. Usetypedfor a behavior that is identical in new and old Nim. See the RFC Pass typedesc as NimNode to macros for more details.
Breaking changes in the standard library
-
osproc.execProcessnow also takes aworkingDirparameter. -
std/sha1.secureHashnow acceptsopenArray[char], notstring. (Former successful matches should keep working, though former failures will not.) -
options.UnpackErroris no longer a ref type and inherits fromsystem.Defectinstead ofsystem.ValueError. -
system.ValueErrornow inherits fromsystem.CatchableErrorinstead ofsystem.Defect. -
The procs
parseutils.parseBiggestInt,parseutils.parseInt,parseutils.parseBiggestUIntandparseutils.parseUIntnow raise aValueErrorwhen the parsed integer is outside of the valid range. Previously they sometimes raised anOverflowErrorand sometimes they returned0. -
The procs
parseutils.parseBin,parseutils.parseOctandparseutils.parseHexwere not clearing theirvarparameternumberand used to push its value to the left when storing the parsed string into it. Now they always set the value of the parameter to0before storing the result of the parsing, unless the string to parse is not valid (then the value ofnumberis not changed). -
streams.StreamObjectnow restricts its fields to only raisesystem.Defect,system.IOErrorandsystem.OSError. This change only affects custom stream implementations. -
nre's
RegexMatch.{captureBounds,captures}[]no longer returnOptionornil/"", respectively. Use the newly addedn in p.capturesmethod to check if a group is captured, otherwise you'll receive an exception. -
nre's
RegexMatch.{captureBounds,captures}.toTableno longer accept a default parameter. Instead uncaptured entries are left empty. UseTable.getOrDefault()if you need defaults. -
nre's
RegexMatch.captures.{items,toSeq}now returns anOption[string]instead of astring. With the removal ofnilstrings, this is the only way to indicate a missing match. Inside your loops, instead ofcapture == ""orcapture == nil, usecapture.isSometo check if a capture is present, andcapture.getto get its value. -
nre's
replace()no longer throwsValueErrorwhen the replacement string has missing captures. It instead throwsKeyErrorfor named captures, andIndexErrorfor unnamed captures. This is consistent withRegexMatch.{captureBounds,captures}[]. -
splitFilenow correctly handles edge cases, see #10047. -
isNilis no longer false for undefined in the JavaScript backend: now it's true for both nil and undefined. UseisNullorisUndefinedif you need exact equality:isNilis consistent with===,isNullandisUndefinedwith==. -
several deprecated modules were removed:
ssl,matchers,httpserver,unsigned,actors,parseurl -
two poorly documented and not used modules (
subexes,scgi) were moved to graveyard (they are available as Nimble packages) -
procs
string.add(int)andstring.add(float)which implicitly convert ints and floats to string have been deprecated. Usestring.addInt(int)andstring.addFloat(float)instead. -
case objectbranch transitions viasystem.resetare deprecated. Compile your code with-d:nimOldCaseObjectsfor a transition period. -
base64 module: The default parameter
newLinefor theencodeprocs was changed from"\13\10"to the empty string"".
Breaking changes in the compiler
- The compiler now implements the "generic symbol prepass" for
whenstatements in generics, see bug #8603. This means that code like this does not compile anymore:
proc enumToString*(enums: openArray[enum]): string =
# typo: 'e' instead 'enums'
when e.low.ord >= 0 and e.high.ord < 256:
result = newString(enums.len)
else:
result = newString(enums.len * 2)
-
discard xis now illegal whenxis a function symbol. -
Implicit imports via
--import: modulein a config file are now restricted to the main package.
Library additions
-
There is a new stdlib module
std/editdistanceas a replacement for the deprecatedstrutils.editDistance. -
There is a new stdlib module
std/wordwrapas a replacement for the deprecatedstrutils.wordwrap. -
Added
split,splitWhitespace,size,alignLeft,align,strip,repeatprocs and iterators tounicode.nim. -
Added
orforNimNodeinmacros. -
Added
system.typeoffor more control over howtypeexpressions can be deduced. -
Added
macros.isInstantiationOffor checking if the proc symbol is instantiation of generic proc symbol. -
Added the parameter
isSortedfor thesequtils.deduplicateproc. -
There is a new stdlib module
std/diffto compute the famous "diff" of two texts by line. -
Added
os.relativePath. -
Added
parseopt.remainingArgs. -
Added
os.getCurrentCompilerExe(implemented asgetAppFilenameat CT), can be used to retrieve the currently executing compiler. -
Added
xmltree.toXmlAttributes. -
Added
std/sumsmodule for fast summation functions. -
Added
Rusage,getrusage,wait4to the posix interface. -
Added the
posix_utilsmodule. -
Added
system.default. -
Added
sequtils.itemsfor closure iterators, allows closure iterators to be used by themapIt,filterIt,allIt,anyIt, etc.
Library changes
-
The string output of
macros.lispReprproc has been tweaked slightly. ThedumpLispmacro in this module now outputs an indented proper Lisp, devoid of commas. -
Added
macros.signatureHashthat returns a stable identifier derived from the signature of a symbol. -
In
strutilsempty strings now no longer matched as substrings anymore. -
The
Complextype is now a generic object and not a tuple anymore. -
The
ospathsmodule is now deprecated, useosinstead. Note thatosis available in a NimScript environment but unsupported operations produce a compile-time error. -
The
parseoptmodule now supports a new flagallowWhitespaceAfterColon(default value: true) that can be set tofalsefor better Posix interoperability. (Bug #9619.) -
os.joinPathandos.normalizePathhandle edge cases like"a/b/../../.."differently. -
securehashwas moved tolib/deprecated. -
The switch
-d:useWinAnsiis not supported anymore. -
In
timesmodule, procsformatandparseaccept a new optionalDateTimeLocaleargument for formatting/parsing dates in other languages.
Language additions
- Vm support for float32<->int32 and float64<->int64 casts was added.
- There is a new pragma block
noSideEffectthat works like thegcsafepragma block. - added
os.getCurrentProcessId. - User defined pragmas are now allowed in the pragma blocks.
- Pragma blocks are no longer eliminated from the typed AST tree to preserve pragmas for further analysis by macros.
- Custom pragmas are now supported for
varandletsymbols. - Tuple unpacking is now supported for constants and for loop variables.
- Case object branches can be initialized with a runtime discriminator if possible discriminator values are constrained within a case statement.
Language changes
-
The standard extension for SCF (source code filters) files was changed from
.tmplto.nimf, it's more recognizable and allows tools like Github to recognize it as Nim, see #9647. The previous extension will continue to work. -
Pragma syntax is now consistent. Previous syntax where type pragmas did not follow the type name is now deprecated. Also pragma before generic parameter list is deprecated to be consistent with how pragmas are used with a proc. See #8514 and #1872 for further details.
-
Hash sets and tables are initialized by default. The explicit
initHashSet,initTable, etc. are not needed anymore.
Tool changes
jsondocnow includes amoduleDescriptionfield with the module description.jsondoc0shows comments as its own objects as shown in the documentation.nimpretty: --backup now defaults tooffinstead ofonand the flag was undocumented; usegitinstead of relying on backup files.kochnow defaults to build the latest stable Nimble version unless you explicitly ask for the latest master version via--latest.
Compiler changes
- The deprecated
fmodproc is now unavailable on the VM. - A new
--outdiroption was added. - The compiled JavaScript file for the project produced by executing
nim jswill no longer be placed in the nimcache directory. - The
--hotCodeReloadinghas been implemented for the native targets. The compiler also provides a new more flexible API for handling the hot code reloading events in the code. - The compiler now supports a
--expandMacro:macroNameHereswitch for easy introspection into what a macro expands into. - The
-d:releaseswitch now does not disable runtime checks anymore. For a release build that also disables runtime checks use-d:release -d:dangeror simply-d:danger.