8.6 KiB
v2.2.0 - yyyy-mm-dd
Changes affecting backward compatibility
-
-d:nimStrictDeletebecomes the default. An index error is produced when the index passed tosystem.deleteis out of bounds. Use-d:nimAuditDeleteto mimic the old behavior for backward compatibility. -
The default user-agent in
std/httpclienthas been changed toNim-httpclient/<version>instead ofNim httpclient/<version>which was incorrect according to the HTTP spec. -
Methods now support implementations based on a VTable by using
--experimental:vtables. Methods are then confined to the same module where their type has been defined. -
With
-d:nimPreviewNonVarDestructor, non-var destructors become the default. -
A bug where tuple unpacking assignment with a longer tuple on the RHS than the LHS was allowed has been fixed, i.e. code like:
var a, b: int (a, b) = (1, 2, 3, 4)will no longer compile.
-
internalNewis removed from thesystemmodule, usenewinstead. -
bindMethodinstd/jsffiis deprecated, don't use it with closures. -
JS backend now supports lambda lifting for closures. Use
--legacy:jsNoLambdaLiftingto emulate old behaviors. -
JS backend now supports closure iterators.
-
ownerinstd/macrosis deprecated. -
Ambiguous type symbols in generic procs and templates now generate symchoice nodes. Previously; in templates they would error immediately at the template definition, and in generic procs a type symbol would arbitrarily be captured, losing the information of the other symbols. This means that generic code can now give errors for ambiguous type symbols, and macros operating on generic proc AST may encounter symchoice nodes instead of the arbitrarily resolved type symbol nodes.
-
Partial generic instantiation of routines is no longer allowed. Previously it compiled in niche situations due to bugs in the compiler.
proc foo[T, U](x: T, y: U) = echo (x, y) proc foo[T, U](x: var T, y: U) = echo "var ", (x, y) proc bar[T]() = foo[float](1, "abc") bar[int]() # before: (1.0, "abc"), now: type mismatch, missing generic parameter -
constvalues now open a new scope for each constant, meaning symbols declared in them can no longer be used outside or in the value of other constants.const foo = (var a = 1; a) const bar = a # error let baz = a # error -
The following POSIX wrappers have had their types changed from signed to unsigned types on OSX and FreeBSD/OpenBSD to correct codegen errors:
Gid(wasint32, is nowuint32)Uid(wasint32, is nowuint32)Dev(wasint32, is nowuint32on FreeBSD)Nlink(wasint16, is nowuint32on OpenBSD anduint16on OSX/other BSD)sin6_flowinfoandsin6_scope_idfields ofSockaddr_in6(wereint32, are nowuint32)n_netfield ofTnetent(wasint32, is nowuint32)
Standard library additions and changes
- Changed
std/osfiles.copyFileto allow specifyingbufferSizeinstead of a hard-coded one. - Changed
std/osfiles.copyFileto usePOSIX_FADV_SEQUENTIALhints for kernel-level aggressive sequential read-aheads. std/htmlparserhas been moved to a nimble package, usenimbleoratlasto install it.
- Added
newStringUninitto thesystemmodule, which creates a new string of lengthlenlikenewStringbut with uninitialized content. - Added
setLenUninitto thesystemmodule, which doesn't initialize slots when enlarging a sequence. - Added
hasDefaultValuetostd/typetraitsto check if a type has a valid default value. - Added
rangeBasetostd/typetraitsto obtain the base type of a range type or convert a value with a range type to its base type. - Added Viewport API for the JavaScript targets in the
dommodule. - Added
toSinglyLinkedRingandtoDoublyLinkedRingtostd/liststo convert fromopenArrays. - ORC: To be enabled via
nimOrcStatsthere is a new API calledGC_orcStatsthat can be used to query how many objects the cyclic collector did free. If the number is zero that is a strong indicator that you can use--mm:arcinstead of--mm:orc. - A
$template is provided forPathinstd/paths. std/hashes.hash(x:string)changed to produce a 64-bit stringHash(based on Google's Farm Hash) which is also often faster than the present one. DefinenimStringHash2to get the old values back.--jsbigint=offmode always only produces the old values. This may impact your automated tests if they depend on hash order in some obvious or indirect way. UsingsortedorOrderedTableis often an easy workaround.
- Deprecates
system.newSeqUninitialized, which is replaced bynewSeqUninit.
Language changes
-
noInitcan be used in types and fields to disable member initializers in the C++ backend. -
C++ custom constructors initializers see https://nim-lang.org/docs/manual_experimental.html#constructor-initializer
-
membercan be used to attach a procedure to a C++ type. -
C++
constructornow reusesresultinstead creatingthis. -
Tuple unpacking changes:
- Tuple unpacking assignment now supports using underscores to discard values.
var a, c: int (a, _, c) = (1, 2, 3) - Tuple unpacking variable declarations now support type annotations, but
only for the entire tuple.
let (a, b): (int, int) = (1, 2) let (a, (b, c)): (byte, (float, cstring)) = (1, (2, "abc"))
- Tuple unpacking assignment now supports using underscores to discard values.
-
The experimental option
--experimental:openSymhas been added to allow captured symbols in generic routine and template bodies respectively to be replaced by symbols injected locally by templates/macros at instantiation time.bindmay be used to keep the captured symbols over the injected ones regardless of enabling the option, but other methods like renaming the captured symbols should be used instead so that the code is not affected by context changes.Since this change may affect runtime behavior, the experimental switch
openSymneeds to be enabled; and a warning is given in the case where an injected symbol would replace a captured symbol not bound bybindand the experimental switch isn't enabled.const value = "captured" template foo(x: int, body: untyped): untyped = let value {.inject.} = "injected" body proc old[T](): string = foo(123): return value # warning: a new `value` has been injected, use `bind` or turn on `experimental:openSym` echo old[int]() # "captured" template oldTempl(): string = block: foo(123): value # warning: a new `value` has been injected, use `bind` or turn on `experimental:openSym` echo oldTempl() # "captured" {.experimental: "openSym".} proc bar[T](): string = foo(123): return value assert bar[int]() == "injected" # previously it would be "captured" proc baz[T](): string = bind value foo(123): return value assert baz[int]() == "captured" template barTempl(): string = block: foo(123): value assert barTempl() == "injected" # previously it would be "captured" template bazTempl(): string = bind value block: foo(123): value assert bazTempl() == "captured"This option also generates a new node kind
nnkOpenSymwhich contains exactly 1nnkSymnode. In the future this might be merged with a slightly modifiednnkOpenSymChoicenode but macros that want to support the experimental feature should still handlennkOpenSym, as the node kind would simply not be generated as opposed to being removed.Another experimental switch
genericsOpenSymexists that enables this behavior at instantiation time, meaning templates etc can enable it specifically when they are being called. However this does not generatennkOpenSymnodes (unless the other switch is enabled) and so doesn't reflect the regular behavior of the switch.const value = "captured" template foo(x: int, body: untyped): untyped = let value {.inject.} = "injected" {.push experimental: "genericsOpenSym".} body {.pop.} proc bar[T](): string = foo(123): return value echo bar[int]() # "injected" template barTempl(): string = block: var res: string foo(123): res = value res assert barTempl() == "injected"
Compiler changes
--nimcacheusing a relative path as the argument in a config file is now relative to the config file instead of the current directory.
Tool changes
- koch now allows bootstrapping with
-d:nimHasLibFFI, replacing the older option of building the compiler directly w/ thelibffinimble package in tow.