last stdlib cleanups

This commit is contained in:
Araq 2019-09-20 20:22:37 +02:00 • committed by Andreas Rumpf
commit 5abe880469
31 changed files with 136 additions and 42 deletions

View file

@ -67,6 +67,31 @@ type
- Consistent error handling of two `exec` overloads. (#10967) - Consistent error handling of two `exec` overloads. (#10967)
- Officially the following modules now have an unstable API:
- std/varints
- core/allocators
- core/hotcodereloading
- asyncstreams
- base64
- browsers
- collections/rtarrays
- collections/sharedlist
- collections/sharedtable
- concurrency/atomics
- concurrency/cpuload
- concurrency/threadpool
- coro
- endians
- httpcore
- parsesql
- pathnorm
- reservedmem
- typetraits
Every other stdlib module is API stable with respect to version 1.
## Language additions ## Language additions
- Inline iterators returning `lent T` types are now supported, similarly to iterators returning `var T`: - Inline iterators returning `lent T` types are now supported, similarly to iterators returning `var T`:

View file

@ -7,6 +7,8 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
## Unstable API.
type type
AllocatorFlag* {.pure.} = enum ## flags describing the properties of the allocator AllocatorFlag* {.pure.} = enum ## flags describing the properties of the allocator
ThreadLocal ## the allocator is thread local only. ThreadLocal ## the allocator is thread local only.

View file

@ -1,3 +1,14 @@
#
#
# Nim's Runtime Library
# (c) Copyright 2019 Nim contributors
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## Unstable API.
when defined(hotcodereloading): when defined(hotcodereloading):
import import
macros macros

View file

@ -321,7 +321,7 @@ proc getFile(ftp: AsyncFtpClient, file: File, total: BiggestInt,
assertReply(await(ftp.expectReply()), "226") assertReply(await(ftp.expectReply()), "226")
proc defaultOnProgressChanged*(total, progress: BiggestInt, proc defaultOnProgressChanged*(total, progress: BiggestInt,
speed: float): Future[void] {.nimcall,gcsafe,procvar.} = speed: float): Future[void] {.nimcall, gcsafe, procvar.} =
## Default FTP ``onProgressChanged`` handler. Does nothing. ## Default FTP ``onProgressChanged`` handler. Does nothing.
result = newFuture[void]() result = newFuture[void]()
#echo(total, " ", progress, " ", speed) #echo(total, " ", progress, " ", speed)

View file

@ -1,3 +1,12 @@
#
#
# Nim's Runtime Library
# (c) Copyright 2015 Dominik Picheta
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
import os, tables, strutils, times, heapqueue, options, deques, cstrutils import os, tables, strutils, times, heapqueue, options, deques, cstrutils
# TODO: This shouldn't need to be included, but should ideally be exported. # TODO: This shouldn't need to be included, but should ideally be exported.

View file

@ -296,7 +296,7 @@ proc processClient(server: AsyncHttpServer, client: AsyncSocket, address: string
if not retry: break if not retry: break
proc serve*(server: AsyncHttpServer, port: Port, proc serve*(server: AsyncHttpServer, port: Port,
callback: proc (request: Request): Future[void] {.closure,gcsafe.}, callback: proc (request: Request): Future[void] {.closure, gcsafe.},
address = "") {.async.} = address = "") {.async.} =
## Starts the process of listening for incoming HTTP connections on the ## Starts the process of listening for incoming HTTP connections on the
## specified address and port. ## specified address and port.

View file

@ -1,3 +1,14 @@
#
#
# Nim's Runtime Library
# (c) Copyright 2015 Dominik Picheta
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## Unstable API.
import asyncfutures import asyncfutures
import deques import deques

View file

@ -9,6 +9,8 @@
## This module implements a base64 encoder and decoder. ## This module implements a base64 encoder and decoder.
## ##
## Unstable API.
##
## Base64 is an encoding and decoding technique used to convert binary ## Base64 is an encoding and decoding technique used to convert binary
## data to an ASCII string format. ## data to an ASCII string format.
## Each Base64 digit represents exactly 6 bits of data. Three 8-bit ## Each Base64 digit represents exactly 6 bits of data. Three 8-bit
@ -110,7 +112,7 @@ template encodeInternal(s: typed, lineLen: int, newLine: string): untyped =
#assert(r == result.len) #assert(r == result.len)
discard discard
proc encode*[T:SomeInteger|char](s: openArray[T], lineLen = 75, newLine=""): string = proc encode*[T: SomeInteger|char](s: openArray[T], lineLen = 75, newLine=""): string =
## Encodes ``s`` into base64 representation. After ``lineLen`` characters, a ## Encodes ``s`` into base64 representation. After ``lineLen`` characters, a
## ``newline`` is added. ## ``newline`` is added.
## ##

View file

@ -9,6 +9,8 @@
## This module implements a simple proc for opening URLs with the user's ## This module implements a simple proc for opening URLs with the user's
## default browser. ## default browser.
##
## Unstable API.
import strutils import strutils
@ -24,6 +26,8 @@ proc openDefaultBrowser*(url: string) =
## command is used. Under Unix, it is checked if ``xdg-open`` exists and ## command is used. Under Unix, it is checked if ``xdg-open`` exists and
## used if it does. Otherwise the environment variable ``BROWSER`` is ## used if it does. Otherwise the environment variable ``BROWSER`` is
## used to determine the default browser to use. ## used to determine the default browser to use.
##
## This proc doesn't raise an exception on error, beware.
when defined(windows): when defined(windows):
var o = newWideCString("open") var o = newWideCString("open")
var u = newWideCString(url) var u = newWideCString(url)

View file

@ -10,6 +10,8 @@
## Module that implements a fixed length array whose size ## Module that implements a fixed length array whose size
## is determined at runtime. Note: This is not ready for other people to use! ## is determined at runtime. Note: This is not ready for other people to use!
##
## Unstable API.
const const
ArrayPartSize = 10 ArrayPartSize = 10

View file

@ -8,6 +8,8 @@
# #
## Shared list support. ## Shared list support.
##
## Unstable API.
{.push stackTrace: off.} {.push stackTrace: off.}

View file

@ -11,6 +11,8 @@
## you'll be in trouble. Uses a single lock to protect the table, lockfree ## you'll be in trouble. Uses a single lock to protect the table, lockfree
## implementations welcome but if lock contention is so high that you need a ## implementations welcome but if lock contention is so high that you need a
## lockfree hash table, you're doing it wrong. ## lockfree hash table, you're doing it wrong.
##
## Unstable API.
import import
hashes, math, locks hashes, math, locks

View file

@ -8,6 +8,8 @@
# #
## Types and operations for atomic operations and lockless algorithms. ## Types and operations for atomic operations and lockless algorithms.
##
## Unstable API.
import macros import macros
@ -375,4 +377,3 @@ proc `+=`*[T: SomeInteger](location: var Atomic[T]; value: T) {.inline.} =
proc `-=`*[T: SomeInteger](location: var Atomic[T]; value: T) {.inline.} = proc `-=`*[T: SomeInteger](location: var Atomic[T]; value: T) {.inline.} =
## Atomically decrements the atomic integer by some `value`. ## Atomically decrements the atomic integer by some `value`.
discard location.fetchSub(value) discard location.fetchSub(value)

View file

@ -9,6 +9,8 @@
## This module implements a helper for a thread pool to determine whether ## This module implements a helper for a thread pool to determine whether
## creating a thread is a good idea. ## creating a thread is a good idea.
##
## Unstable API.
when defined(windows): when defined(windows):
import winlean, os, strutils, math import winlean, os, strutils, math

View file

@ -14,6 +14,8 @@
## * `channels module <channels.html>`_ ## * `channels module <channels.html>`_
## * `locks module <locks.html>`_ ## * `locks module <locks.html>`_
## * `asyncdispatch module <asyncdispatch.html>`_ ## * `asyncdispatch module <asyncdispatch.html>`_
##
## Unstable API.
when not compileOption("threads"): when not compileOption("threads"):
{.error: "Threadpool requires --threads:on option.".} {.error: "Threadpool requires --threads:on option.".}

View file

@ -6,6 +6,7 @@
# See the file "copying.txt", included in this # See the file "copying.txt", included in this
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
## Nim coroutines implementation, supports several context switching methods: ## Nim coroutines implementation, supports several context switching methods:
## -------- ------------ ## -------- ------------
## ucontext available on unix and alike (default) ## ucontext available on unix and alike (default)
@ -17,6 +18,8 @@
## -d:nimCoroutinesUcontext Use ucontext backend. ## -d:nimCoroutinesUcontext Use ucontext backend.
## -d:nimCoroutinesSetjmp Use setjmp backend. ## -d:nimCoroutinesSetjmp Use setjmp backend.
## -d:nimCoroutinesSetjmpBundled Use bundled setjmp implementation. ## -d:nimCoroutinesSetjmpBundled Use bundled setjmp implementation.
##
## Unstable API.
when not nimCoroutines and not defined(nimdoc): when not nimCoroutines and not defined(nimdoc):
when defined(noNimCoroutines): when defined(noNimCoroutines):

View file

@ -9,6 +9,8 @@
## This module contains helpers that deal with different byte orders ## This module contains helpers that deal with different byte orders
## (`endian`:idx:). ## (`endian`:idx:).
##
## Unstable API.
when defined(gcc) or defined(llvm_gcc) or defined(clang): when defined(gcc) or defined(llvm_gcc) or defined(clang):
const useBuiltinSwap = true const useBuiltinSwap = true

View file

@ -7,8 +7,8 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
## This module parses an HTML document and creates its XML tree representation. ## **NOTE**: The behaviour might change in future versions as it is not
## It is supposed to handle the *wild* HTML the real world uses. ## clear what "*wild* HTML the real world uses" really implies.
## ##
## It can be used to parse a wild HTML document and output it as valid XHTML ## It can be used to parse a wild HTML document and output it as valid XHTML
## document (well, if you are lucky): ## document (well, if you are lucky):

View file

@ -9,6 +9,8 @@
## Contains functionality shared between the ``httpclient`` and ## Contains functionality shared between the ``httpclient`` and
## ``asynchttpserver`` modules. ## ``asynchttpserver`` modules.
##
## Unstable API.
import tables, strutils, parseutils import tables, strutils, parseutils

View file

@ -57,4 +57,4 @@ proc `<=`*[I: SomeInteger, F: SomeFloat](f: F, i: I): bool {.noSideEffect, inlin
# Note that we must not defined `>=` and `>`, because system.nim already has a # Note that we must not defined `>=` and `>`, because system.nim already has a
# template with signature (x, y: untyped): untyped, which would lead to # template with signature (x, y: untyped): untyped, which would lead to
# ambigous calls. # ambiguous calls.

View file

@ -9,6 +9,8 @@
## The ``parsesql`` module implements a high performance SQL file ## The ``parsesql`` module implements a high performance SQL file
## parser. It parses PostgreSQL syntax and the SQL ANSI standard. ## parser. It parses PostgreSQL syntax and the SQL ANSI standard.
##
## Unstable API.
import import
strutils, lexbase strutils, lexbase

View file

@ -8,8 +8,9 @@
# #
## OS-Path normalization. Used by ``os.nim`` but also ## OS-Path normalization. Used by ``os.nim`` but also
## generally useful for dealing with paths. Note that this module ## generally useful for dealing with paths.
## does not provide a stable API. ##
## Unstable API.
# Yes, this uses import here, not include so that # Yes, this uses import here, not include so that
# we don't end up exporting these symbols from pathnorm and os: # we don't end up exporting these symbols from pathnorm and os:

View file

@ -7,6 +7,9 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
## Implements a representation of Unicode with the limited
## ASCII character subset.
import strutils import strutils
import unicode import unicode
@ -23,7 +26,7 @@ const
Delimiter = '-' Delimiter = '-'
type type
PunyError* = object of Exception PunyError* = object of ValueError
proc decodeDigit(x: char): int {.raises: [PunyError].} = proc decodeDigit(x: char): int {.raises: [PunyError].} =
if '0' <= x and x <= '9': if '0' <= x and x <= '9':

View file

@ -18,7 +18,7 @@ type Rational*[T] = object
## a rational number, consisting of a numerator and denominator ## a rational number, consisting of a numerator and denominator
num*, den*: T num*, den*: T
proc initRational*[T:SomeInteger](num, den: T): Rational[T] = proc initRational*[T: SomeInteger](num, den: T): Rational[T] =
## Create a new rational number. ## Create a new rational number.
assert(den != 0, "a denominator of zero value is invalid") assert(den != 0, "a denominator of zero value is invalid")
result.num = num result.num = num
@ -34,7 +34,7 @@ proc `$`*[T](x: Rational[T]): string =
## Turn a rational number into a string. ## Turn a rational number into a string.
result = $x.num & "/" & $x.den result = $x.num & "/" & $x.den
proc toRational*[T:SomeInteger](x: T): Rational[T] = proc toRational*[T: SomeInteger](x: T): Rational[T] =
## Convert some integer `x` to a rational number. ## Convert some integer `x` to a rational number.
result.num = x result.num = x
result.den = 1 result.den = 1
@ -82,7 +82,7 @@ proc toInt*[T](x: Rational[T]): int =
## `x` does not contain an integer value. ## `x` does not contain an integer value.
x.num div x.den x.num div x.den
proc reduce*[T:SomeInteger](x: var Rational[T]) = proc reduce*[T: SomeInteger](x: var Rational[T]) =
## Reduce rational `x`. ## Reduce rational `x`.
let common = gcd(x.num, x.den) let common = gcd(x.num, x.den)
if x.den > 0: if x.den > 0:
@ -288,20 +288,20 @@ when isMainModule:
m1 = -1 // 1 m1 = -1 // 1
tt = 10 // 2 tt = 10 // 2
assert( a == a ) assert( a == a )
assert( (a-a) == z ) assert( (a-a) == z )
assert( (a+b) == o ) assert( (a+b) == o )
assert( (a/b) == o ) assert( (a/b) == o )
assert( (a*b) == 1 // 4 ) assert( (a*b) == 1 // 4 )
assert( (3/a) == 6 // 1 ) assert( (3/a) == 6 // 1 )
assert( (a/3) == 1 // 6 ) assert( (a/3) == 1 // 6 )
assert( a*b == 1 // 4 ) assert( a*b == 1 // 4 )
assert( tt*z == z ) assert( tt*z == z )
assert( 10*a == tt ) assert( 10*a == tt )
assert( a*10 == tt ) assert( a*10 == tt )
assert( tt/10 == a ) assert( tt/10 == a )
assert( a-m1 == 3 // 2 ) assert( a-m1 == 3 // 2 )
assert( a+m1 == -1 // 2 ) assert( a+m1 == -1 // 2 )
assert( m1+tt == 16 // 4 ) assert( m1+tt == 16 // 4 )
assert( m1-tt == 6 // -1 ) assert( m1-tt == 6 // -1 )

View file

@ -15,6 +15,8 @@
## is guaranteed to remain in the same memory location. The buffer ## is guaranteed to remain in the same memory location. The buffer
## will be able to grow up to the size of the initially reserved ## will be able to grow up to the size of the initially reserved
## portion of the address space. ## portion of the address space.
##
## Unstable API.
from ospaths import raiseOSError, osLastError from ospaths import raiseOSError, osLastError

View file

@ -13,6 +13,8 @@
## ##
## Tested on these OSes: Linux, Windows, OSX ## Tested on these OSes: Linux, Windows, OSX
{.used.}
# do allocate memory upfront: # do allocate memory upfront:
var se: ref NilAccessError var se: ref NilAccessError
new(se) new(se)

View file

@ -9,6 +9,8 @@
## This module defines compile-time reflection procs for ## This module defines compile-time reflection procs for
## working with types. ## working with types.
##
## Unstable API.
export system.`$` # for backward compatibility export system.`$` # for backward compatibility

View file

@ -9,6 +9,11 @@
## :Author: Zahary Karadjov ## :Author: Zahary Karadjov
## ##
## **Note**: Instead of ``unittest.nim``, please consider to use
## the ``testament`` tool which offers process isolation for your tests.
## Also ``when isMainModule: doAssert conditionHere`` is usually a
## much simpler solution for testing purposes.
##
## This module implements boilerplate to make unit testing easy. ## This module implements boilerplate to make unit testing easy.
## ##
## The test status and name is printed after any output or traceback. ## The test status and name is printed after any output or traceback.
@ -306,7 +311,7 @@ method testEnded*(formatter: JUnitOutputFormatter, testResult: TestResult) =
let time = epochTime() - formatter.testStartTime let time = epochTime() - formatter.testStartTime
let timeStr = time.formatFloat(ffDecimal, precision = 8) let timeStr = time.formatFloat(ffDecimal, precision = 8)
formatter.stream.writeLine("\t\t<testcase name=\"$#\" time=\"$#\">" % [xmlEscape(testResult.testName), timeStr]) formatter.stream.writeLine("\t\t<testcase name=\"$#\" time=\"$#\">" % [xmlEscape(testResult.testName), timeStr])
case testResult.status: case testResult.status
of OK: of OK:
discard discard
of SKIPPED: of SKIPPED:

View file

@ -7,8 +7,10 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
## Note this API is still experimental! A variable length integer ## A variable length integer
## encoding implementation inspired by SQLite. ## encoding implementation inspired by SQLite.
##
## Unstable API.
const const
maxVarIntLen* = 9 ## the maximal number of bytes a varint can take maxVarIntLen* = 9 ## the maximal number of bytes a varint can take

View file

@ -44,15 +44,7 @@ else:
{.pragma: inl, inline.} {.pragma: inl, inline.}
{.pragma: compilerRtl, compilerproc.} {.pragma: compilerRtl, compilerproc.}
when not defined(nimsuperops):
{.pragma: operator.}
when defined(nimlocks): when defined(nimlocks):
{.pragma: benign, gcsafe, locks: 0.} {.pragma: benign, gcsafe, locks: 0.}
else: else:
{.pragma: benign, gcsafe.} {.pragma: benign, gcsafe.}
when defined(nimTableGet):
{.pragma: deprecatedGet, deprecated.}
else:
{.pragma: deprecatedGet.}

View file

@ -156,6 +156,7 @@ lib/experimental/diff.nim
lib/pure/algorithm.nim lib/pure/algorithm.nim
lib/pure/stats.nim lib/pure/stats.nim
lib/windows/winlean.nim lib/windows/winlean.nim
lib/windows/registry.nim
lib/pure/random.nim lib/pure/random.nim
lib/pure/complex.nim lib/pure/complex.nim
lib/pure/times.nim lib/pure/times.nim