Version 0.17.0 released

The Nim team is happy to announce that the latest release of Nim, version 0.17.0, is now available. Nim is a systems programming language that focuses on performance, portability and expressiveness.

This release fixes the most important regressions introduced in version 0.16.0. In particular memory manager and channel bugs have been fixed. There was also many significant improvements to the language, in particular a lot of work was put into concepts. Zahary has been leading this effort and we thank him for his hard work. Be sure to check out the changelog below for a comprehensive list of changes.

The NSIS based installer is not provided anymore as the Nim website moved to https and this caused NSIS downloads to fail. The latest version of Nim for Windows can still be downloaded as a zip archive from the downloads page.

We would also like to invite you to test a brand new tool that aims to make the installation and management of multiple Nim versions much easier. This tool is called choosenim and allows you to install the latest version of Nim with a single command. Check out the installation instructions on GitHub to give it a go, but keep in mind that this tool is still experimental.

This release also includes version 0.8.6 of the Nimble package manager, be sure to check out its changelog for a list of changes since its last release.

Changelog

Changes affecting backwards compatibility

There are now two different HTTP response types, Response and AsyncResponse . AsyncResponse ’s body accessor returns a Future[string] ! Due to this change you may need to add another await in your code.

httpclient.request now respects the maxRedirects option. Previously redirects were handled only by get and post procs.

now respects the option. Previously redirects were handled only by and procs. The IO routines now raise EOFError for the “end of file” condition. EOFError is a subtype of IOError and so it’s easier to distinguish between “error during read” and “error due to EOF”.

for the “end of file” condition. is a subtype of and so it’s easier to distinguish between “error during read” and “error due to EOF”. A hash procedure has been added for cstring type in hashes module. Previously, hash of a cstring would be calculated as a hash of the pointer. Now the hash is calculated from the contents of the string, assuming cstring is a null-terminated string. Equal string and cstring values produce an equal hash value.

type in module. Previously, hash of a would be calculated as a hash of the pointer. Now the hash is calculated from the contents of the string, assuming is a null-terminated string. Equal and values produce an equal hash value. Macros accepting varargs arguments will now receive a node having the nkArgList node kind. Previous code expecting the node kind to be nkBracket may have to be updated.

arguments will now receive a node having the node kind. Previous code expecting the node kind to be may have to be updated. memfiles.open now closes file handles/fds by default. Passing allowRemap=true to memfiles.open recovers the old behavior. The old behavior is only needed to call mapMem on the resulting MemFile .

now closes file handles/fds by default. Passing to recovers the old behavior. The old behavior is only needed to call on the resulting . posix.nim : For better C++ interop the field sa_sigaction*: proc (x: cint, y: var SigInfo, z: pointer) {.noconv.} was changed to sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.} .

: For better C++ interop the field was changed to . The compiler doesn’t infer effects for .base methods anymore. This means you need to annotate them with .gcsafe or similar to clearly declare upfront every implementation needs to fullfill these contracts.

methods anymore. This means you need to annotate them with or similar to clearly declare upfront every implementation needs to fullfill these contracts. system.getAst templateCall(x, y) now typechecks the templateCall properly. You need to patch your code accordingly.

now typechecks the properly. You need to patch your code accordingly. macros.getType and macros.getTypeImpl for an enum will now return an AST that is the same as what is used to define an enum. Previously the AST returned had a repeated EnumTy node and was missing the initial pragma node (which is currently empty for an enum).

and for an enum will now return an AST that is the same as what is used to define an enum. Previously the AST returned had a repeated node and was missing the initial pragma node (which is currently empty for an enum). macros.getTypeImpl now correctly returns the implementation for a symbol of type tyGenericBody .

now correctly returns the implementation for a symbol of type . If the dispatcher parameter’s value used in multi method is nil , a NilError exception is raised. The old behavior was that the method would be a nop then.

, a exception is raised. The old behavior was that the method would be a then. posix.nim : the family of ntohs procs now takes unsigned integers instead of signed integers.

: the family of procs now takes unsigned integers instead of signed integers. In Nim identifiers en-dash (Unicode point U+2013) is not an alias for the underscore anymore. Use underscores instead.

When the requiresInit pragma is applied to a record type, future versions of Nim will also require you to initialize all the fields of the type during object construction. For now, only a warning will be produced.

pragma is applied to a record type, future versions of Nim will also require you to initialize all the fields of the type during object construction. For now, only a warning will be produced. The Object construction syntax now performs a number of additional safety checks. When fields within case objects are initialiazed, the compiler will now demand that the respective discriminator field has a matching known compile-time value.

On posix, the results of waitForExit , peekExitCode , execCmd will return 128 + signal number if the application terminates via signal.

, , will return 128 + signal number if the application terminates via signal. ospaths.getConfigDir now conforms to the XDG Base Directory specification on non-Windows OSs. It returns the value of the XDG_CONFIG_DIR environment variable if it is set, and returns the default configuration directory, “~/.config/”, otherwise.

now conforms to the XDG Base Directory specification on non-Windows OSs. It returns the value of the environment variable if it is set, and returns the default configuration directory, “~/.config/”, otherwise. Renamed the line info node parameter for newNimNode procedure.

procedure. The parsing rules of do changed. foo bar do : baz Used to be parsed as: foo ( bar ( do : baz )) Now it is parsed as: foo ( bar , do : baz )

Library Additions

Added system.onThreadDestruction .

Added dial procedure to networking modules: net , asyncdispatch , asyncnet . It merges socket creation, address resolution, and connection into single step. When using dial , you don’t have to worry about the IPv4 vs IPv6 problem. httpclient now supports IPv6.

Added to macro which allows JSON to be unmarshalled into a type. import json type Person = object name : string age : int let data = """ { "name": "Amy", "age": 4 } """ let node = parseJson ( data ) let obj = node . to ( Person ) echo ( obj )

Tool Additions

The finish tool can now download MingW for you should it not find a working MingW installation.

Compiler Additions

The name mangling rules used by the C code generator changed. Most of the time local variables and parameters are not mangled at all anymore. This improves the debugging experience.

The compiler produces explicit name mangling files when --debugger:native is enabled. Debuggers can read these .ndi files in order to improve debugging Nim code.

Language Additions

The try statement’s except branches now support the binding of a caught exception to a variable: try : raise newException ( Exception , "Hello World" ) except Exception as exc : echo ( exc . msg ) This replaces the getCurrentException and getCurrentExceptionMsg() procedures, although these procedures will remain in the stdlib for the foreseeable future. This new language feature is actually implemented using these procedures. In the near future we will be converting all exception types to refs to remove the need for the newException template.

A new pragma .used can be used for symbols to prevent the “declared but not used” warning. More details can be found here.

can be used for symbols to prevent the “declared but not used” warning. More details can be found here. The popular “colon block of statements” syntax is now also supported for let and var statements and assignments: template ve ( value , effect ): untyped = effect value let x = ve ( 4 ): echo "welcome to Nim!" This is particularly useful for DSLs that help in tree construction.

Language changes

The .procvar annotation is not required anymore. That doesn’t mean you can pass system.$ to map just yet though.

Bugfixes

The list below has been generated based on the commits in Nim’s git repository. As such it lists only the issues which have been closed via a commit, for a full list see this link on Github.