-
Solaris and illumos are now separate targets (
--os:solarisand--os:illumos). Both definesunos,posix, andunix; illumos no longer definessolaris. Usedefined(sunos)for code shared by both systems. Native illumos compilers reporthostOS == "illumos", and NimScript exposesOsPlatform.illumos. niminst distinguishes SunOS systems usinguname -o, falling back to Solaris when that query is unavailable or unrecognized.koch boothandles the transition from bootstrap compilers that identify illumos as Solaris; source distributions must regenerate their csources with the updated compiler and niminst. -
--compileOnlyno longer implies the host's C compiler settings and no longer omits the/* Compiled for ... */header comment: cross compilation settings (cpu.os.cc.*) are honored, which also fixes cross compilation with--spawnCodegen. The old behavior, needed by niminst to generate C code that can be shared among targets, is available via the new--mergeableCcodeswitch. -
-d:nimPreviewFloatRoundtripbecomes the default.system.addFloatandsystem.$now can produce string representations of floating point numbers that are minimal in size and possess round-trip and correct rounding guarantees (via the Dragonbox algorithm). Use-d:nimLegacySprintfto emulate old behaviors. -
The
defaultparameter oftables.getOrDefaulthas been renamed todefto avoid conflicts withsystem.default, so named argument usage for this parameter likegetOrDefault(..., default = ...)will have to be changed. -
With
-d:nimPreviewCheckedClose, theclosefunction in thestd/synciomodule now raises an IO exception in case of an error. -
With
-d:nimPreviewCheckedFlush, theflushFilefunction in thestd/synciomodule raises an IO exception when the buffered data cannot be written. -
Unknown warnings and hints now gives warnings
warnUnknownNotesinstead of errors. -
With
-d:nimPreviewAsmSemSymbol, backticked symbols are type checked in theasm/emitstatements. -
The bare
except:now panics onDefect. Useexcept Exception:orexcept Defect:to catchDefect.--legacy:noPanicOnExceptis provided for a transition period. -
With
-d:nimPreviewCStringComparisons, comparsions (<,>,<=,>=) between cstrings switch from reference semantics to value semantics like==and!=. -
std/parsesqlhas been moved to a nimble package, usenimbleoratlasto install it. -
With
-d:nimPreviewDuplicateModuleError, importing two modules that share the same name becomes a compile-time error. This includes importing the same module more than once. Useimport foo as foo1(or other aliases) to avoid collisions. -
Adds the switch
--mangle:nim|cpp, which selectsnimorcppstyle name mangling when used withdebuginfoon, defaults tocpp. -
The second parameter of
succ,pred,inc, anddecinsystemnow acceptsSomeInteger(previouslyOrdinal). -
Bitshift operators (
shl,shr,ashr) now apply bitmasking to the right operand in the C/C++/VM/JS backends. -
Adds a new warning
--warning:ImplicitRangeConversionthat detects downsizing implicit conversions to range types (e.g.,int -> range[0..255]orrange[1..256] -> range[0..255]) that could cause runtime panics. Safe conversions likerange[0..255] -> range[0..65535]and explicit casts do not trigger warnings.inttoNaturalandPositiveconversions do not trigger warnings, which can be enabled with--warning:systemRangeConversion. -
Procedure compatibility also checks the backend representation of the parameter and result types, not just their source-level shape. Use
--legacy:procParamTypeBackendAliasesto restore the older behavior. -
itemsforarraynow yieldslent T, as it already did forseqandopenArray, instead of a copy of each element. A closure cannot capture alentvalue, so a closure that captures the loop variable of such aforloop no longer compiles ("cannot be captured as it would violate memory safety"). Copy the variable first (for x in a: let x = x), or use-d:nimNoLentIteratorsto restore the old behavior. The JS backend and NimScript are unaffected: thereitemsyields copies. -
std/asyncnet(andAsyncHttpClientwith it) now checks that the server certificate matches the host name when the context usesCVerifyPeer, asstd/netalready does. Before, any certificate signed by a trusted CA was accepted for any host. A mismatch now raisesSslErrorfromAsyncSocket.connect, or from the firstsendorrecvafterwrapConnectedSocket. Connections to IP addresses and contexts created withCVerifyNoneare not checked. A failed TLS handshake now also raisesSslErrorfromAsyncSocket.connectinstead of being ignored. -
std/netandstd/asyncnetnow also check the certificate host name on Windows. Before, the check was skipped there becauseX509_check_hostwas imported from the wrong DLL (libssl instead of libcrypto).
-
Added
system.readRawDataStable, a companion toreadRawDatathat returns a rawptr UncheckedArray[char]into a string's character data which stays valid across moves and copies of the string value. It is available under every string implementation (refc, ARC/ORC and--strings:sso) with the same signature, so code can pin an interior buffer pointer today and be ready for--strings:ssowithoutwhen declaredguards. Under--strings:ssoit promotes a small inline string to its heap representation first; under the other implementations the data is already heap-resident, so it is equivalent toreadRawData. -
setutils.symmetricDifferencealong with its operator versionsetutils.`-+-`and in-place versionsetutils.togglehave been added to more efficiently calculate the symmetric difference of bitsets. -
strutils.multiReplaceoverload for character set replacements in a single pass. Useful for string sanitation. Follows existing multiReplace semantics. -
std/filesadds:- Exports
CopyFlagenum andFilePermissiontype for fine-grained control of file operations - New file operation procs with
Pathsupport:getFilePermissions,setFilePermissionsfor managing permissionstryRemoveFilefor file deletioncopyFilewith configurable buffer size and symlink handlingcopyFileWithPermissionsto preserve file attributescopyFileToDirfor copying files into directories
- Exports
-
std/dirsadds:- New directory operation procs with
Pathsupport:copyDirwith special file handling optionscopyDirWithPermissionsto recursively preserve attributes
- New directory operation procs with
-
system.setLenUninitnow supports refc, JS and VM backends. -
system.setLenUninitfor thestringtype. Allows setting length without initializing new memory on growth. -
std/parseoptnow supports multiple parser modes via aCliModeenum. Modes includeNim(default, fully compatible) and two new experimental modes:LaxandGnufor different option parsing behaviors. -
std/symlinks.expandSymlinknow supports Windows symlinks and junctions with POSIX-like single-hopreadlinksemantics. -
std/nre2is added to replace deprecated NRE. -
system.typeofadds a new parametermodifierModeto specify how type modifiers are handled. -
std/asynchttpserver.newAsyncHttpServeradds a parameterreadTimeout, the number of milliseconds a client has to deliver a complete request. A client that is slower is disconnected (after a408 Request Timeoutresponse once its request line was received). The default of 0 keeps waiting indefinitely.
-
uri.decodeQuerynow honours a non-defaultsepwhen splitting keys. Previously only the value was terminated bysep; the key was terminated by'='or a hardcoded'&', sodecodeQuery("a;b=2;c", ';')yielded the key"a;b". A literal'&'in a query with a custom separator is now data rather than a separator. -
std/mathThe^symbol now supports floating-point as exponent in addition to the Natural type. -
min,max, andsequtils'minIndex,maxIndexandminmaxforopenArrays now accept a comparison function. -
system.substrimplementation now usescopymem(wrapped Cmemcpy) for copying data, if available at compilation. -
system.newStringUninitis now considered free of side-effects allowing it to be used with--experimental:strictFuncs. -
os.moveFile,os.copyFileWithPermissionsandos.copyDirWithPermissionsno longer have the effectException; they raiseOSErrorandIOError. -
dynlib.loadLibPatternanddynlib.checkedSymAddrno longer have the effectException: they raise what the platform'sloadLibandsymAddrraise (nothing on POSIX and Windows). The OpenSSL procs thatstd/opensslloads at run time are declaredraises: [], sonet.newContextandhttpclient.newHttpClientcan be called from a{.raises: [CatchableError].}proc. -
std/reandstd/nreare deprecated as PCRE library is obsolete. Use https://github.com/nitely/nim-regex orstd/nre2. See: nim-lang#23668. -
std/pegsnow correctly lexes UTF-8 bytes inside bare identifier-style terminals, so case-insensitive matching of non-ASCII terms (e.g.\i café) works without single-quoting. -
std/uri: The?operator now appends query parameters to an existing query string instead of replacing it. Fixes #19782. -
std/jsonutils:fromJsonnow throws an exception when converting toarray/seqif the JSON isn't an array instead of silently failing -
std/strutils:rsplitwith a string separator that can overlap itself (e.g."..","aa") no longer matches bytes already consumed by the separator to its right, so"a...b".rsplit("..")is@["a.", "b"]instead of@["a", "", "b"]. Fixes #24949. -
std/pegsno longer crashes on some patterns: repetition of an expression that can match the empty input (e.g.('a'?)*) is now valid (the matcher terminates on zero-length matches) instead of aborting withAssertionDefect; unknown builtin escapes inside character classes (e.g.[^\n]) raiseEInvalidPeginstead ofIndexDefect. An empty capture{}with no previous capture is now a no-op instead of underflowing the matcher's capture array.
-
An experimental option
--experimental:typeBoundOpshas been added that implements the RFC nim-lang/RFCs#380. This makes the behavior of interfaces likehash,$,==etc. more reliable for nominal types across indirect/restricted imports.# objs.nim import std/hashes type Obj* = object x*, y*: int z*: string # to be ignored for equality proc `==`*(a, b: Obj): bool = a.x == b.x and a.y == b.y proc hash*(a: Obj): Hash = $!(hash(a.x) &! hash(a.y))
# main.nim {.experimental: "typeBoundOps".} from objs import Obj # objs.hash, objs.`==` not imported import std/tables var t: Table[Obj, int] t[Obj(x: 3, y: 4, z: "debug")] = 34 echo t[Obj(x: 3, y: 4, z: "ignored")] # 34
See the experimental manual for more information.
-
Seven more Unicode characters are now parsed as operators, implementing the RFC nim-lang/RFCs#571:
⟑ ⟇ ⩓ ⩔ ■ □ ☆. They all have the same priority as*(multiplication). As with the other Unicode operators, Nim only lexes them; their meaning is up to user code. -
An experimental option
--experimental:ownedRefshas been added that implements the RFC nim-lang/RFCs#575:owned ref Tandowned procare statically checked unique ownership annotations on top of ARC/ORC/YRC. Converting an owned reference to an unowned one produces a counted reference, so there is no runtime failure mode. A type whose references are allownedor.cursorcannot form a cycle and stays out of the cycle collector, so for example a callback field of typeowned proc ()no longer makes its enclosing type cyclic. Without the featureownedcontinues to be erased. -
Sum types, ported from Nimony: an object
casewithout a discriminator declares a sum type. The branch names construct values, and a pattern matchingcasebinds the fields of a branch:type Node = ref object case of AddOpr, SubOpr: a, b: Node of Value: val: int proc eval(n: Node): int = case n of Value(v): v of AddOpr(a, b): eval(a) + eval(b) of SubOpr(a, b): eval(a) - eval(b) echo eval(AddOpr(a: Value(val: 40), b: Value(val: 2))) # 42
The fields of a branch can only be accessed through such a
case, or in a{.cast(uncheckedAccess).}section.$andreprrender a sum type like its constructor. See the manual for more information.
-
An import annotated with
{.cyclic.}(import b {.cyclic.}) makes the modules of an import cycle a group whose types and leading routines are visible to each other regardless of declaration order, so procs of different modules can call each other. See the manual's section about cyclic imports. An import cycle without{.cyclic.}is deprecated; the new warningImplicitCyclicImport(off by default) reports it. -
Fixed a bug where
sizeof(T)inside atypedesctemplate called from a generic type'swhenclause would error with "'sizeof' requires '.importc' types to be '.completeStruct'". The issue was thathasValuelessStaticsinsemtypinst.nimdidn't recognizetyTypeDesc(tyGenericParam)as an unresolved generic parameter. -
The JS backend now implements write-through for
var openArrayparameters that receive atoOpenArrayview (bug #15952): mutations reach the caller's storage instead of silently writing to a copy. Fixed homogeneous numeric arrays (array[N, T], JS typed arrays) slice viasubarray;seqand non-numeric arrays slice via a{base, off, len}view. This also covers seq/non-numeric-array write-through, pass-through, re-slicing and@(openArray-to-seq) of such views. -
On
--os:ios, the default file name for--app:libis nowlibfoo.dylibinstead oflibfoo.so, matching--os:macosxand the Darwin convention. -
With
--hotCodeReloading:on, a module can use the thread-local variables and the methods of another module, which made the program fail to link or to dispatch before;std/loggingworks with it now. A thread-local variable keeps its value, for each thread, when its module is reloaded.
- Added
--rawflag when generating JSON docs to not render markup. - Added
--stdinfileflag to name of the file used when running program from stdin (defaults tostdinfile.nim) - Added
--styleCheck:warningflag to treat style check violations as warnings.
- Added documentation for the
completeStructpragma in the manual.