Skip to content

Commit

Permalink
Remove deprecated stuff from stdlib (#14699)
Browse files Browse the repository at this point in the history
* update to the latest Jester

* remove deprecated procs from some stdlib modules

* 'criterion' is not maintained anymore and relies on obsolete stuff
  • Loading branch information
narimiran committed Jun 17, 2020
1 parent 8619534 commit e7f280b
Show file tree
Hide file tree
Showing 41 changed files with 155 additions and 519 deletions.
2 changes: 1 addition & 1 deletion doc/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ A similar thing happens with C code invoking Nim code which returns a
.. code-block:: nim
proc gimme(): cstring {.exportc.} =
result = "Hey there C code! " & $random(100)
result = "Hey there C code! " & $rand(100)
Since Nim's garbage collector is not aware of the C code, once the
``gimme`` proc has finished it can reclaim the memory of the ``cstring``.
Expand Down
6 changes: 0 additions & 6 deletions lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -996,12 +996,6 @@ macro dumpAstGen*(s: untyped): untyped = echo s.astGenRepr
##
## Also see ``dumpTree`` and ``dumpLisp``.

macro dumpTreeImm*(s: untyped): untyped {.deprecated.} = echo s.treeRepr
## Deprecated. Use `dumpTree` instead.

macro dumpLispImm*(s: untyped): untyped {.deprecated.} = echo s.lispRepr
## Deprecated. Use `dumpLisp` instead.

proc newEmptyNode*(): NimNode {.compileTime, noSideEffect.} =
## Create a new empty node.
result = newNimNode(nnkEmpty)
Expand Down
7 changes: 0 additions & 7 deletions lib/impure/re.nim
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,6 @@ proc multiReplace*(s: string, subs: openArray[
# copy the rest:
add(result, substr(s, i))

proc parallelReplace*(s: string, subs: openArray[
tuple[pattern: Regex, repl: string]]): string {.deprecated:
"Deprecated since v0.18.0: Use ``multiReplace`` instead.".} =
## Returns a modified copy of ``s`` with the substitutions in ``subs``
## applied in parallel.
result = multiReplace(s, subs)

proc transformFile*(infile, outfile: string,
subs: openArray[tuple[pattern: Regex, repl: string]]) =
## reads in the file ``infile``, performs a parallel replacement (calls
Expand Down
4 changes: 0 additions & 4 deletions lib/pure/algorithm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,6 @@ proc binarySearch*[T](a: openArray[T], key: T): int =
assert binarySearch([0, 1, 4, 2, 3], 4) == 2
binarySearch(a, key, cmp[T])

proc smartBinarySearch*[T](a: openArray[T], key: T): int {.deprecated:
"Deprecated since v0.18.1; Use 'binarySearch'".} =
binarySearch(a, key, cmp[T])

const
onlySafeCode = true

Expand Down
2 changes: 1 addition & 1 deletion lib/pure/asyncdispatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ when defined(windows) or defined(nimdoc):
new result
result.ioPort = createIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 1)
result.handles = initHashSet[AsyncFD]()
result.timers.newHeapQueue()
result.timers.clear()
result.callbacks = initDeque[proc () {.closure, gcsafe.}](64)

var gDisp{.threadvar.}: owned PDispatcher ## Global dispatcher
Expand Down
8 changes: 0 additions & 8 deletions lib/pure/collections/heapqueue.nim
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,6 @@ proc `$`*[T](heap: HeapQueue[T]): string =
result.addQuoted(x)
result.add("]")

proc newHeapQueue*[T](): HeapQueue[T] {.deprecated:
"Deprecated since v0.20.0: use 'initHeapQueue' instead.".} =
initHeapQueue[T]()

proc newHeapQueue*[T](heap: var HeapQueue[T]) {.deprecated:
"Deprecated since v0.20.0: use 'clear' instead.".} =
heap.clear()

when isMainModule:
proc toSortedSeq[T](h: HeapQueue[T]): seq[T] =
var tmp = h
Expand Down
39 changes: 2 additions & 37 deletions lib/pure/collections/sets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ proc init*[A](s: var HashSet[A], initialSize = defaultInitialSize) =
## * `toHashSet proc <#toHashSet,openArray[A]>`_
runnableExamples:
var a: HashSet[int]
assert(not a.isValid)
init(a)
assert a.isValid

initImpl(s, initialSize)

Expand Down Expand Up @@ -647,9 +645,7 @@ proc init*[A](s: var OrderedSet[A], initialSize = defaultInitialSize) =
## * `toOrderedSet proc <#toOrderedSet,openArray[A]>`_
runnableExamples:
var a: OrderedSet[int]
assert(not a.isValid)
init(a)
assert a.isValid

initImpl(s, initialSize)

Expand Down Expand Up @@ -923,38 +919,15 @@ iterator pairs*[A](s: OrderedSet[A]): tuple[a: int, b: A] =



proc isValid*[A](s: OrderedSet[A]): bool {.deprecated:
"Deprecated since v0.20; sets are initialized by default".} =
##
## Returns `true` if the set has been initialized (with `initHashSet proc
## <#initOrderedSet,int>`_ or `init proc <#init,OrderedSet[A],int>`_).
##
## **Examples:**
##
## .. code-block ::
## proc savePreferences(options: OrderedSet[string]) =
## assert options.isValid, "Pass an initialized set!"
## # Do stuff here, may crash in release builds!
result = s.data.len > 0


# -----------------------------------------------------------------------



when isMainModule and not defined(release):
proc testModule() =
## Internal micro test to validate docstrings and such.
block isValidTest: # isValid is deprecated
var options: HashSet[string]
proc savePreferences(options: HashSet[string]) =
assert options.isValid, "Pass an initialized set!"
options = initHashSet[string]()
options.savePreferences

block lenTest:
var values: HashSet[int]
assert(not values.isValid)
assert values.len == 0
assert values.card == 0

Expand Down Expand Up @@ -1046,16 +1019,8 @@ when isMainModule and not defined(release):
var b = a.map(proc (x: int): string = $x)
assert b == toHashSet(["1", "2", "3"])

block isValidTest: # isValid is deprecated
var cards: OrderedSet[string]
proc saveTarotCards(cards: OrderedSet[string]) =
assert cards.isValid, "Pass an initialized set!"
cards = initOrderedSet[string]()
cards.saveTarotCards

block lenTest:
var values: OrderedSet[int]
assert(not values.isValid)
assert values.len == 0
assert values.card == 0

Expand Down Expand Up @@ -1119,7 +1084,7 @@ when isMainModule and not defined(release):
a.init(4)
a.incl(2)
a.init
assert a.len == 0 and a.isValid
assert a.len == 0
a = initOrderedSet[int](4)
a.incl(2)
assert a.len == 1
Expand All @@ -1128,7 +1093,7 @@ when isMainModule and not defined(release):
b.init(4)
b.incl(2)
b.init
assert b.len == 0 and b.isValid
assert b.len == 0
b = initHashSet[int](4)
b.incl(2)
assert b.len == 1
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/concurrency/cpuload.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ when not defined(testing) and isMainModule and not defined(nimdoc):

proc busyLoop() =
while true:
discard random(80)
discard rand(80)
os.sleep(100)

spawn busyLoop()
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/httpclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ proc `[]=`*(p: MultipartData, name: string,
proc getBoundary(p: MultipartData): string =
if p == nil or p.content.len == 0: return
while true:
result = $random(int.high)
result = $rand(int.high)
for i, entry in p.content:
if result in entry.content: break
elif i == p.content.high: return
Expand Down
39 changes: 0 additions & 39 deletions lib/pure/math.nim
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,6 @@ proc nextPowerOfTwo*(x: int): int {.noSideEffect.} =
result = result or (result shr 1)
result += 1 + ord(x <= 0)

proc countBits32*(n: int32): int {.noSideEffect, deprecated:
"Deprecated since v0.20.0; use 'bitops.countSetBits' instead".} =
runnableExamples:
doAssert countBits32(7) == 3
doAssert countBits32(8) == 1
doAssert countBits32(15) == 4
doAssert countBits32(16) == 1
doAssert countBits32(17) == 2

bitops.countSetBits(n)

proc sum*[T](x: openArray[T]): T {.noSideEffect.} =
## Computes the sum of the elements in ``x``.
##
Expand Down Expand Up @@ -611,13 +600,6 @@ when not defined(js): # C
## echo gamma(4.0) # 6.0
## echo gamma(11.0) # 3628800.0
## echo gamma(-1.0) # nan
proc tgamma*(x: float32): float32
{.deprecated: "Deprecated since v0.19.0; use 'gamma' instead",
importc: "tgammaf", header: "<math.h>".}
proc tgamma*(x: float64): float64
{.deprecated: "Deprecated since v0.19.0; use 'gamma' instead",
importc: "tgamma", header: "<math.h>".}
## The gamma function
proc lgamma*(x: float32): float32 {.importc: "lgammaf", header: "<math.h>".}
proc lgamma*(x: float64): float64 {.importc: "lgamma", header: "<math.h>".}
## Computes the natural log of the gamma function for ``x``.
Expand Down Expand Up @@ -750,12 +732,6 @@ when not defined(js): # C
## echo trunc(PI) # 3.0
## echo trunc(-1.85) # -1.0

proc fmod*(x, y: float32): float32 {.deprecated: "Deprecated since v0.19.0; use 'mod' instead",
importc: "fmodf", header: "<math.h>".}
proc fmod*(x, y: float64): float64 {.deprecated: "Deprecated since v0.19.0; use 'mod' instead",
importc: "fmod", header: "<math.h>".}
## Computes the remainder of ``x`` divided by ``y``.

proc `mod`*(x, y: float32): float32 {.importc: "fmodf", header: "<math.h>".}
proc `mod`*(x, y: float64): float64 {.importc: "fmod", header: "<math.h>".}
## Computes the modulo operation for float values (the remainder of ``x`` divided by ``y``).
Expand Down Expand Up @@ -1111,7 +1087,6 @@ when isMainModule and not defined(js) and not windowsCC89:

# check gamma function
assert(gamma(5.0) == 24.0) # 4!
assert($tgamma(5.0) == $24.0) # 4!
assert(lgamma(1.0) == 0.0) # ln(1.0) == 0.0
assert(erf(6.0) > erf(5.0))
assert(erfc(6.0) < erfc(5.0))
Expand All @@ -1133,20 +1108,6 @@ when isMainModule:
doAssert round(-54.652) ==~ -55.0
doAssert round(-54.352) ==~ -54.0
doAssert round(0.0) ==~ 0.0
# Round to positive decimal places
doAssert round(-547.652, 1) ==~ -547.7
doAssert round(547.652, 1) ==~ 547.7
doAssert round(-547.652, 2) ==~ -547.65
doAssert round(547.652, 2) ==~ 547.65
# Round to negative decimal places
doAssert round(547.652, -1) ==~ 550.0
doAssert round(547.652, -2) ==~ 500.0
doAssert round(547.652, -3) ==~ 1000.0
doAssert round(547.652, -4) ==~ 0.0
doAssert round(-547.652, -1) ==~ -550.0
doAssert round(-547.652, -2) ==~ -500.0
doAssert round(-547.652, -3) ==~ -1000.0
doAssert round(-547.652, -4) ==~ 0.0

block: # splitDecimal() tests
doAssert splitDecimal(54.674).intpart ==~ 54.0
Expand Down
16 changes: 0 additions & 16 deletions lib/pure/nativesockets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,6 @@ proc createNativeSocket*(domain: Domain = AF_INET,
## by child processes.
createNativeSocket(toInt(domain), toInt(sockType), toInt(protocol), inheritable)

proc newNativeSocket*(domain: Domain = AF_INET,
sockType: SockType = SOCK_STREAM,
protocol: Protocol = IPPROTO_TCP): SocketHandle
{.deprecated: "deprecated since v0.18.0; use 'createNativeSocket' instead".} =
## Creates a new socket; returns `osInvalidSocket` if an error occurs.
createNativeSocket(domain, sockType, protocol)

proc newNativeSocket*(domain: cint, sockType: cint,
protocol: cint): SocketHandle
{.deprecated: "deprecated since v0.18.0; use 'createNativeSocket' instead".} =
## Creates a new socket; returns `osInvalidSocket` if an error occurs.
##
## Use this overload if one of the enums specified above does
## not contain what you need.
createNativeSocket(domain, sockType, protocol)

proc bindAddr*(socket: SocketHandle, name: ptr SockAddr,
namelen: SockLen): cint =
result = bindSocket(socket, name, namelen)
Expand Down
34 changes: 1 addition & 33 deletions lib/pure/random.nim
Original file line number Diff line number Diff line change
Expand Up @@ -206,30 +206,6 @@ proc skipRandomNumbers*(s: var Rand) =
s.a0 = s0
s.a1 = s1

proc random*(max: int): int {.benign, deprecated:
"Deprecated since v0.18.0; use 'rand' instead".} =
while true:
let x = next(state)
if x < randMax - (randMax mod Ui(max)):
return int(x mod uint64(max))

proc random*(max: float): float {.benign, deprecated:
"Deprecated since v0.18.0; use 'rand' instead".} =
let x = next(state)
when defined(js):
result = (float(x) / float(high(uint32))) * max
else:
let u = (0x3FFu64 shl 52u64) or (x shr 12u64)
result = (cast[float](u) - 1.0) * max

proc random*[T](x: HSlice[T, T]): T {.deprecated:
"Deprecated since v0.18.0; use 'rand' instead".} =
result = T(random(x.b - x.a)) + x.a

proc random*[T](a: openArray[T]): T {.deprecated:
"Deprecated since v0.18.0; use 'sample' instead".} =
result = a[random(a.low..a.len)]

proc rand*(r: var Rand; max: Natural): int {.benign.} =
## Returns a random integer in the range `0..max` using the given state.
##
Expand Down Expand Up @@ -362,10 +338,6 @@ proc rand*[T: Ordinal or SomeFloat](x: HSlice[T, T]): T =
doAssert rand(1..6) == 6
result = rand(state, x)

proc rand*[T](r: var Rand; a: openArray[T]): T {.deprecated:
"Deprecated since v0.20.0; use 'sample' instead".} =
result = a[rand(r, a.low..a.high)]

proc rand*[T: SomeInteger](t: typedesc[T]): T =
## Returns a random integer in the range `low(T)..high(T)`.
##
Expand Down Expand Up @@ -395,10 +367,6 @@ proc rand*[T: SomeInteger](t: typedesc[T]): T =
else:
result = cast[T](state.next)

proc rand*[T](a: openArray[T]): T {.deprecated:
"Deprecated since v0.20.0; use 'sample' instead".} =
result = a[rand(a.low..a.high)]

proc sample*[T](r: var Rand; s: set[T]): T =
## Returns a random element from the set ``s`` using the given state.
##
Expand Down Expand Up @@ -687,6 +655,6 @@ when isMainModule:


# don't use causes integer overflow
doAssert compiles(random[int](low(int) .. high(int)))
doAssert compiles(rand[int](low(int) .. high(int)))

main()
19 changes: 0 additions & 19 deletions lib/pure/selectors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,3 @@ else:
include ioselects/ioselectors_select
else:
include ioselects/ioselectors_poll

proc register*[T](s: Selector[T], fd: int | SocketHandle,
events: set[Event], data: T) {.deprecated: "use registerHandle instead".} =
## **Deprecated since v0.18.0:** Use ``registerHandle`` instead.
s.registerHandle(fd, events, data)

proc setEvent*(ev: SelectEvent) {.deprecated: "use trigger instead".} =
## Trigger event ``ev``.
##
## **Deprecated since v0.18.0:** Use ``trigger`` instead.
ev.trigger()

proc update*[T](s: Selector[T], fd: int | SocketHandle,
events: set[Event]) {.deprecated: "use updateHandle instead".} =
## Update file/socket descriptor ``fd``, registered in selector
## ``s`` with new events set ``event``.
##
## **Deprecated since v0.18.0:** Use ``updateHandle`` instead.
s.updateHandle()

0 comments on commit e7f280b

Please sign in to comment.