15 KiB
v2.0.0 - yyyy-mm-dd
Changes affecting backward compatibility
-
httpclient.contentLengthdefault to-1if the Content-Length header is not set in the response, it followed Apache HttpClient(Java), http(go) and .Net HttpWebResponse(C#) behavior. Previously it raisedValueError. -
addris now available for all addressable locations,unsafeAddris now deprecated and an alias foraddr. -
Certain definitions from the default
systemmodule have been moved to the following new modules:std/synciostd/assertionsstd/formatfloatstd/objectdollarstd/widestrsstd/typedthreadsstd/sysatomics
In the future, these definitions will be removed from the
systemmodule, and their respective modules will have to be imported to use them. Currently, to make these imports required, the-d:nimPreviewSlimSystemoption may be used. -
Enabling
-d:nimPreviewSlimSystemalso removes the following deprecated symbols in thesystemmodule:- Aliases with
Errorsuffix to exception types that have aDefectsuffix (see exceptions):ArithmeticError,DivByZeroError,OverflowError,AccessViolationError,AssertionError,OutOfMemError,IndexError,FieldError,RangeError,StackOverflowError,ReraiseError,ObjectAssignmentError,ObjectConversionError,FloatingPointError,FloatOverflowError,FloatUnderflowError,FloatInexactError,DeadThreadError,NilAccessError addQuitProc, replaced byexitprocs.addExitProc- Legacy unsigned conversion operations:
ze,ze64,toU8,toU16,toU32 TaintedString, formerly a distinct alias tostringPInt32,PInt64,PFloat32,PFloat64, aliases toptr int32,ptr int64,ptr float32,ptr float64
- Aliases with
-
Enabling
-d:nimPreviewSlimSystemremoves the import ofchannels_builtinin in thesystemmodule. -
Enabling
-d:nimPreviewCstringConversion,ptr char,ptr array[N, char]andptr UncheckedArray[N, char]don't support conversion to cstring anymore. -
The
gc:v2option is removed. -
The
mainmoduleandmoptions are removed. -
The
threads:onoption is now the default. -
Optional parameters in combination with
: bodysyntax (RFC #405) are now opt-in viaexperimental:flexibleOptionalParams. -
Automatic dereferencing (experimental feature) is removed.
-
The
Math.truncpolyfill for targeting Internet Explorer was previously included in most JavaScript output files. Now, it is only included with-d:nimJsMathTruncPolyfill. If you are targeting Internet Explorer, you may choose to enable this option or define your ownMath.truncpolyfill using theemitpragma. Nim usesMath.truncfor the division and modulo operators for integers. -
shallowCopyandshalloware removed for ARC/ORC. Usemovewhen possible or combine assignment andsinkfor optimization purposes. -
The
nimPreviewDotLikeOpsdefine is going to be removed or deprecated. -
The
{.this.}pragma, deprecated since 0.19, has been removed. -
nilliterals can no longer be directly assigned to variables or fields ofdistinctpointer types. They must be converted instead.type Foo = distinct ptr int # Before: var x: Foo = nil # After: var x: Foo = Foo(nil) -
Removed two type pragma syntaxes deprecated since 0.20, namely
type Foo = object {.final.}, andtype Foo {.final.} [T] = object. -
foo a = bnow meansfoo(a = b)rather thanfoo(a) = b. This is consistent with the existing behavior offoo a, b = cmeaningfoo(a, b = c). This decision was made with the assumption that the old syntax was used rarely; if your code used the old syntax, please be aware of this change. -
Overloadable enums and Unicode Operators are no longer experimental.
-
Removed the
nimIncrSeqV3define. -
macros.getImplforconstsymbols now returns the full definition node (asnnkConstDef) rather than the AST of the constant value. -
Lock levels are deprecated, now a noop.
-
ORC is now the default memory management strategy. Use
--mm:refcfor a transition period. -
strictEffectsare no longer experimental. Uselegacy:laxEffectsto keep backward compatibility. -
The
gorge/staticExeccalls will now return a descriptive message in the output if the execution fails for whatever reason. To get back legacy behaviour use-d:nimLegacyGorgeErrors. -
Pointer to
cstringconversion now triggers a[PtrToCstringConv]warning. This warning will become an error in future versions! Use acastoperation likecast[cstring](x)instead. -
loggingwill default to flushing all log level messages. To get the legacy behaviour of only flushing Error and Fatal messages, use-d:nimV1LogFlushBehavior. -
Object fields now support default values, see https://nim-lang.github.io/Nim/manual.html#types-default-values-for-object-fields for details.
-
Redefining templates with the same signature was previously allowed to support certain macro code. To do this explicitly, the
{.redefine.}pragma has been added. Note that this is only for templates. Implicit redefinition of templates is now deprecated and will give an error in the future. -
Using an unnamed break in a block is deprecated. This warning will become an error in future versions! Use a named block with a named break instead.
-
Several Standard libraries are moved to nimble packages, use
nimbleto install them:std/punycode=>punycodestd/asyncftpclient=>asyncftpclientstd/smtp=>smtpstd/db_common=>db_connector/db_commonstd/db_sqlite=>db_connector/db_sqlitestd/db_mysql=>db_connector/db_mysqlstd/db_postgres=>db_connector/db_postgresstd/db_odbc=>db_connector/db_odbc
-
Previously, calls like
foo(a, b): ...orfoo(a, b) do: ...where the final argument offoohad typeproc ()were assumed by the compiler to meanfoo(a, b, proc () = ...). This behavior is now deprecated. Usefoo(a, b) do (): ...orfoo(a, b, proc () = ...)instead.
Standard library additions and changes
-
OpenSSL 3 is now supported.
-
macros.parseExprandmacros.parseStmtnow accept an optional filename argument for more informative errors. -
Module
colorsexpanded with missing colors from the CSS color standard.colPaleVioletRedandcolMediumPurplehave also been changed to match the CSS color standard. -
Fixed
lists.SinglyLinkedListbeing broken after removing the last node (#19353). -
The
md5module now works at compile time and in JavaScript. -
Changed
mimedbto use anOrderedTableinstead ofOrderedTableRefto supportconsttables. -
strutils.findnow uses and defaults tolast = -1for whole string searches, making limiting it to just the first char (last = 0) valid. -
random.randnow works withOrdinals. -
Undeprecated
os.isvalidfilename. -
std/oidsnow usesint64to store time internally (before it was int32). -
std/uri.Uridollar$improved, precalculates thestringresult length from theUri. -
std/uri.Uri.isIpv6is now exported. -
std/logging.ConsoleLoggerandFileLoggernow have aflushThresholdattribute to set what log message levels are automatically flushed. For Nim v1 use-d:nimFlushAllLogsto automatically flush all message levels. Flushing all logs is the default behavior for Nim v2. -
std/net.IpAddressdollar$improved, uses a fixed capacity for thestringresult based from theIpAddressFamily. -
std/jsfetch.newFetchOptionsnow has default values for all parameters -
std/jsformdatanow acceptsBlobdata type.
- Added ISO 8601 week date utilities in
times:- Added
IsoWeekRange, a range type for weeks in a week-based year. - Added
IsoYear, a distinct type for a week-based year in contrast to a regular year. - Added a
initDateTimeoverload to create a datetime from an ISO week date. - Added
getIsoWeekAndYearto get an ISO week number and week-based year from a datetime. - Added
getIsoWeeksInYearto return the number of weeks in a week-based year.
- Added
- Added new modules which were part of
std/os:- Added
std/oserrorsfor OS error reporting. Addedstd/envvarsfor environment variables handling. - Added
std/paths,std/dirs,std/files,std/symlinksandstd/appdirs. - Added
std/cmdlinefor reading command line parameters.
- Added
- Added
sepparameter instd/urito specify the query separator. - Added bindings to
Array.shiftandqueueMicrotaskinjscorefor JavaScript targets. - Added
UppercaseLetters,LowercaseLetters,PunctuationChars,PrintableCharssets tostd/strutils. - Added
complex.sgnfor obtaining the phase of complex numbers. - Added
insertAdjacentText,insertAdjacentElement,insertAdjacentHTML,after,before,closest,append,hasAttributeNS,removeAttributeNS,hasPointerCapture,releasePointerCapture,requestPointerLock,replaceChildren,replaceWith,scrollIntoViewIfNeeded,setHTML,toggleAttribute, andmatchestostd/dom. - Added
jsre.hasIndices - Added
capacityforstringandseqto return the current capacity, see https://github.com/nim-lang/RFCs/issues/460 - Added
openArray[char]overloads forstd/parseutilsallowing more code reuse. - Added
openArray[char]overloads forstd/unicodeallowing more code reuse. - Added
safeparameter tobase64.encodeMime.
- Deprecated
selfExefor Nimscript. - Deprecated
std/sums. - Deprecated
std/base64.encodefor collections of arbitrary integer element type. Now onlybyteandcharare supported.
-
Removed deprecated module
parseopt2. -
Removed deprecated module
sharedstrings. -
Removed deprecated module
dom_extensions. -
Removed deprecated module
LockFreeHash. -
Removed deprecated module
events. -
Removed deprecated
oids.oidToString. -
Removed define
nimExperimentalAsyncjsThenforstd/asyncjs.thenandstd/jsfetch. -
Removed deprecated
jsre.testandjsre.toString. -
Removed deprecated
math.c_frexp. -
Removed deprecated
httpcore.`==`. -
Removed deprecated
std/posix.CMSG_SPACEandstd/posix.CMSG_LENthat takes wrong argument types. -
Removed deprecated
osproc.poDemon, symbol with typo. -
Removed deprecated
tables.rightSize. -
Removed deprecated
posix.CLONE_STOPPED.
Language changes
-
Tag tracking supports the definition of forbidden tags by the
.forbidspragma which can be used to disable certain effects in proc types. -
Case statement macros are no longer experimental, meaning you no longer need to enable the experimental switch
caseStmtMacrosto use them. -
Full command syntax and block arguments i.e.
foo a, b: care now allowed for the right-hand side of type definitions in type sections. Previously they would error with "invalid indentation". -
definednow accepts identifiers separated by dots, i.e.defined(a.b.c). In the command line, this is defined as-d:a.b.c. Older versions can use accents as indefined(`a.b.c`)to access such defines. -
Macro pragmas changes:
-
Templates now accept macro pragmas.
-
Macro pragmas for var/let/const sections have been redesigned in a way that works similarly to routine macro pragmas. The new behavior is documented in the experimental manual.
-
Pragma macros on type definitions can now return
nnkTypeSectionnodes as well asnnkTypeDef, allowing multiple type definitions to be injected in place of the original type definition.import macros macro multiply(amount: static int, s: untyped): untyped = let name = $s[0].basename result = newNimNode(nnkTypeSection) for i in 1 .. amount: result.add(newTree(nnkTypeDef, ident(name & $i), s[1], s[2])) type Foo = object Bar {.multiply: 3.} = object x, y, z: int Baz = object # becomes type Foo = object Bar1 = object x, y, z: int Bar2 = object x, y, z: int Bar3 = object x, y, z: int Baz = object
-
-
A new form of type inference called top-down inference has been implemented for a variety of basic cases. For example, code like the following now compiles:
let foo: seq[(float, byte, cstring)] = @[(1, 2, "abc")] -
cstringis now accepted as a selector incasestatements, removing the need to convert tostring. On the JS backend, this is translated directly to aswitchstatement. -
Nim now supports
outparameters and "strict definitions". -
Nim now offers a strict mode for
case objects.
Compiler changes
-
The
gcswitch has been renamed tomm("memory management") in order to reflect the reality better. (Nim moved away from all techniques based on "tracing".) -
Defines the
gcRefcsymbol which allows writing specific code for the refc GC. -
nimcan now compile version 1.4.0 as follows:nim c --lib:lib --stylecheck:off compiler/nim, without requiring-d:nimVersion140which is now a noop. -
--styleCheck,--hintAsErrorand--warningAsErrornow only apply to the current package. -
The switch
--nimMainPrefix:prefixhas been added to add a prefix to the names ofNimMainand related functions produced on the backend. This prevents conflicts with other Nim static libraries. -
When compiling for Release the flag
-fno-math-errnois used for GCC.
Tool changes
- Nim now supports Nimble version 0.14 which added support for lock-files. This is done by
a simple configuration change setting that you can do yourself too. In
$nim/config/nim.cfgreplacepkgsbypkgs2.