13 KiB
v0.19.X - XX/XX/2018
Changes affecting backwards compatibility
- The stdlib module
futurehas been renamed tosugar. macros.callsiteis now deprecated. Since the introduction ofvarargsparameters this became unnecessary.- Anonymous tuples with a single element can now be written as
(1,)with a trailing comma. The underlying AST isnnkTupleConstr(newLit 1)for this example.nnkTupleConstris a new node kind your macros need to be able to deal with! - Indexing into a
cstringfor the JS target is now mapped tocharCodeAt. - Assignments that would "slice" an object into its supertype are now prevented
at runtime. Use
ref objectwith inheritance rather thanobjectwith inheritance to prevent this issue. - The
not niltype annotation now has to be enabled explicitly via{.experimental: "notnil"}as we are still not pleased with how this feature works with Nim's containers. - The parser now warns about inconsistent spacing around binary operators as these can easily be confused with unary operators. This warning will likely become an error in the future.
- The
'cand'C'suffix for octal literals is now deprecated to bring the language in line with the standard library (e.g.parseOct). - The dot style for import paths (e.g
import path.to.moduleinstead ofimport path/to/module) has been deprecated.
Breaking changes in the standard library
-
re.splitfor empty regular expressions now yields every character in the string which is what other programming languages chose to do. -
The returned tuple of
system.instantiationInfonow has a third field containing the column of the instantiation. -
cookies.setCookieno longer assumes UTC for the expiration date. -
strutils.formatEngdoes not distinguish betweenniland""strings anymore for itsunitparameter. Instead the space is controlled by a new parameteruseUnitSpace. -
The
times.parseandtimes.formatprocs have been rewritten. The proc signatures are the same so it should generally not break anything. However, the new implementation is a bit stricter, which is a breaking change. For exampleparse("2017-01-01 foo", "yyyy-MM-dd")will now raise an error. -
proc `-`*(a, b: Time): int64in thetimesmodule has changed return type totimes.Durationin order to support higher time resolutions. The proc is no longer deprecated. -
The
times.Timezoneis now an immutable ref-type that must be initialized with an explicit constructor (newTimezone). -
posix.Timeval.tv_sechas changed type toposix.Time. -
math.`mod`for floats now behaves the same asmodfor integers (previously it used floor division like Python). Usemath.floorModfor the old behavior. -
For string inputs,
unicode.isUpperandunicode.isLowernow require a second mandatory parameterskipNonAlpha. -
For string inputs,
strutils.isUpperAsciiandstrutils.isLowerAsciinow require a second mandatory parameterskipNonAlpha. -
osLastErroris now marked withsideEffect -
The procs
parseHexIntandparseOctIntnow fail on empty strings and strings containing only valid prefixes, e.g. "0x" for hex integers. -
terminal.setCursorPosandterminal.setCursorXPosnow work correctly with 0-based coordinates on POSIX (previously, you needed to use 1-based coordinates on POSIX for correct behaviour; the Windows behaviour was always correct). -
lineInfoObjnow returns absolute path instead of project path. It's used bylineInfo,check,expect,require, etc. -
net.sendTono longer returns an int and now raises anOSError. -
threadpool'sawaitand derivatives have been renamed toblockUntilto avoid confusions withawaitfrom theasyncmacro.
Breaking changes in the compiler
- The undocumented
#? bracesparsing mode was removed. - The undocumented PHP backend was removed.
- The default location of
nimcachefor the native code targets was changed. Read the compiler user guide for more information.
Library additions
re.splitnow also supports themaxsplitparameter for consistency withstrutils.split.- Added
system.toOpenArrayin order to support zero-copy slicing operations. This is currently not yet available for the JavaScript target. - Added
getCurrentDir,findExe,cpDirandmvDirprocs tonimscript. - The
timesmodule now supports up to nanosecond time resolution when available. - Added the type
times.Durationfor representing fixed durations of time. - Added the proc
times.convertfor converting between different time units, e.g days to seconds. - Added the proc
algorithm.binarySearch[T, K]with thecmpparameter. - Added the proc
algorithm.upperBound. - Added inverse hyperbolic functions,
math.arcsinh,math.arccoshandmath.arctanhprocs. - Added cotangent, secant and cosecant procs
math.cot,math.secandmath.csc; and their hyperbolic, inverse and inverse hyperbolic functions,math.coth,math.sech,math.csch,math.arccot,math.arcsec,math.arccsc,math.arccoth,math.arcsechandmath.arccschprocs. - Added the procs
math.floorModandmath.floorDivfor floor based integer division. - Added the procs
rationals.`div```,rationals.`mod```,rationals.floorDivandrationals.floorModfor rationals. - Added the proc
math.prodfor product of elements in openArray. - Added the proc
parseBinIntto parse a binary integer from a string, which returns the value. parseOctandparseBinin parseutils now also support themaxLenargument similar toparseHexInt.- Added the proc
flushfor memory mapped files. - Added the
MemMapFileStream. - Added a simple interpreting event parser template
eventParserto thepegsmodule. - Added
macros.copyLineInfoto copy lineInfo from other node. - Added
system.ashran arithmetic right shift for integers.
Library changes
macros.astGenRepr,macros.lispReprandmacros.treeReprnow escapes the content of string literals consistently.macros.NimSymandmacros.NimIdentis now deprecated in favor of the more generalNimNode.macros.getImplnow includes the pragmas of types, instead of omitting them.macros.hasCustomPragmaandmacros.getCustomPragmaValnow also supportrefandptrtypes, pragmas on types and variant fields.system.SomeRealis now calledSomeFloatfor consistency and correctness.algorithm.smartBinarySearchandalgorithm.binarySearchis now joined inbinarySearch.smartbinarySearchis now deprecated.- The
terminalmodule now exports additional procs for generating ANSI color codes as strings. - Added the parameter
valfor theCritBitTree[int].incproc. - An exception raised from a
testblock ofunittestnow shows its type in error message. - The
compiler/nimevalAPI was rewritten to simplify the "compiler as an API". Using the Nim compiler and its VM as a scripting engine has never been easier. Seetests/compilerapi/tcompilerapi.nimfor an example of how to use the Nim VM in a native Nim application. - Added the parameter
valfor theCritBitTree[T].inclproc. - The proc
tgammawas renamed togamma.tgammais deprecated. - The
pegsmodule now exports getters for the fields of itsPegandNonTerminalobject types.Pegs with child nodes now have the standarditemsandpairsiterators. - The
acceptsocket procedure defined in thenetmodule can now accept a nil socket.
Language additions
-
Dot calls combined with explicit generic instantiations can now be written as
x.y[:z]which is transformed intoy[z](x)by the parser. -
funcis now an alias forproc {.noSideEffect.}. -
In order to make
forloops and iterators more flexible to use Nim now supports so called "for-loop macros". See the manual for more details. This feature enables a Python-like genericenumerateimplementation. -
Case statements can now be rewritten via macros. See the manual for more information. This feature enables custom pattern matchers.
-
the
typedescspecial type has been renamed to justtype. -
staticandtypeare now also modifiers similar torefandptr. They denote the special typesstatic[T]andtype[T]. -
Forcing compile-time evaluation with
staticnow supports specifying the desired target type (as a concrete type or as a type class) -
The
typeoperator now supports checking that the supplied expression matches an expected type constraint.
Language changes
-
The
importcpppragma now allows importing the listed fields of generic C++ types. Support for numeric parameters have also been added through the use ofstatic[T]types. (#6415) -
Native C++ exceptions can now be imported with
importcpppragma. Imported exceptions can be raised and caught just like Nim exceptions. More details in language manual. -
nilfor strings/seqs is finally gone. Instead the default value for these is"" / @[]. Use--nilseqs:onfor a transition period. -
Accessing the binary zero terminator in Nim's native strings is now invalid. Internally a Nim string still has the trailing zero for zero-copy interoperability with
cstring. Compile your code with the new switch--laxStrings:onif you need a transition period. -
The command syntax now supports keyword arguments after the first comma.
-
Thread-local variables can now be declared inside procs. This implies all the effects of the
globalpragma. -
Nim now supports the
exceptclause in the export statement. -
Range float types, example
range[0.0 .. Inf]. More details in language manual. -
The
{.this.}pragma has been deprecated. It never worked within generics and we found the resulting code harder to read than the more explicitobj.fieldsyntax. -
"Memory regions" for pointer types have been deprecated, they were hardly used anywhere. Note that this has nothing to do with the
--gc:regionsswitch of managing memory. -
The exception hierarchy was slightly reworked,
SystemErrorwas renamed toCatchableErrorand is the new base class for any exception that is guaranteed to be catchable. This change should have minimal impact on most existing Nim code.
Tool changes
jsondoc2has been renamedjsondoc, similar to howdoc2was renameddoc. The oldjsondoccan still be invoked withjsondoc0.
Compiler changes
-
The VM's instruction count limit was raised to 3 million instructions in order to support more complex computations at compile-time.
-
Support for hot code reloading has been implemented for the JavaScript target. To use it, compile your code with
--hotCodeReloading:onand use a helper library such as LiveReload or BrowserSync. -
A new compiler option
--cppCompileToNamespaceputs the generated C++ code into the namespace "Nim" in order to avoid naming conflicts with existing C++ code. This is done for all Nim code - internal and exported. -
Added
macros.getProjectPathandospaths.putEnvprocs to Nim's virtual machine. -
The
deadCodeElimoption is now always turned on and the switch has no effect anymore, but is recognized for backwards compatibility. -
experimentalis now a pragma / command line switch that can enable specific language extensions, it is not an all-or-nothing switch anymore. -
Nintendo Switch was added as a new platform target. See the compiler user guide for more info.
-
macros.bindSym now capable to accepts not only literal string or string constant expression. bindSym enhancement make it also can accepts computed string or ident node inside macros / compile time functions / static blocks. Only in templates / regular code it retains it's old behavior. This new feature can be accessed via {.experimental: "dynamicBindSym".} pragma/switch.
-
On Posix systems the global system wide configuration is now put under
/etc/nim/nim.cfg, it used to be/etc/nim.cfg. Usually it does not exist, however. -
On Posix systems the user configuration is now looked under
$XDG_CONFIG_HOME/nim/nim.cfg(ifXDG_CONFIG_HOMEis not defined, then under~/.config/nim/nim.cfg). It used to be$XDG_CONFIG_DIR/nim.cfg(and~/.config/nim.cfg).Similarly, on Windows, the user configuration is now looked under
%APPDATA%/nim/nim.cfg. This used to be%APPDATA%/nim.cfg.