move since from inclrtl to std/private/since (#14188)

* move since from inclrtl to std/private/since
* move since import in system below for HCR
This commit is contained in:
hlaaftana 2020-05-03 00:51:59 +03:00 • committed by GitHub
commit fbc97e712a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 60 additions and 59 deletions

View file

@ -8,6 +8,7 @@
# #
include "system/inclrtl" include "system/inclrtl"
import std/private/since
## This module contains the interface to the compiler's abstract syntax ## This module contains the interface to the compiler's abstract syntax
## tree (`AST`:idx:). Macros operate on this tree. ## tree (`AST`:idx:). Macros operate on this tree.

View file

@ -9,7 +9,7 @@
## Declaration of the Document Object Model for the `JavaScript backend ## Declaration of the Document Object Model for the `JavaScript backend
## <backends.html#backends-the-javascript-target>`_. ## <backends.html#backends-the-javascript-target>`_.
include "system/inclrtl" import std/private/since
when not defined(js) and not defined(Nimdoc): when not defined(js) and not defined(Nimdoc):
{.error: "This module only works on the JavaScript platform".} {.error: "This module only works on the JavaScript platform".}

View file

@ -95,12 +95,8 @@
## runForever() ## runForever()
## ##
include "system/inclrtl" import std/private/since
import asyncdispatch, nativesockets, net, os
import asyncdispatch
import nativesockets
import net
import os
export SOBool export SOBool

View file

@ -12,8 +12,9 @@
## ##
## Unstable API. ## Unstable API.
import std/private/since
import strutils import strutils
include "system/inclrtl"
when defined(windows): when defined(windows):
import winlean import winlean

View file

@ -12,7 +12,7 @@
## by Adam Langley. ## by Adam Langley.
## (A crit bit tree is a form of `radix tree`:idx: or `patricia trie`:idx:.) ## (A crit bit tree is a form of `radix tree`:idx: or `patricia trie`:idx:.)
include "system/inclrtl" import std/private/since
type type
NodeObj[T] {.acyclic.} = object NodeObj[T] {.acyclic.} = object

View file

@ -51,7 +51,7 @@
## * `lists module <lists.html>`_ for singly and doubly linked lists and rings ## * `lists module <lists.html>`_ for singly and doubly linked lists and rings
## * `channels module <channels.html>`_ for inter-thread communication ## * `channels module <channels.html>`_ for inter-thread communication
include system/inclrtl import std/private/since
import math import math

View file

@ -73,7 +73,7 @@
## heterogeneous members ## heterogeneous members
include "system/inclrtl" import std/private/since
import macros import macros

View file

@ -217,9 +217,9 @@
## * `hashes module<hashes.html>`_ for helper functions for hashing ## * `hashes module<hashes.html>`_ for helper functions for hashing
import hashes, math, algorithm import std/private/since
include "system/inclrtl" import hashes, math, algorithm
type type
KeyValuePair[A, B] = tuple[hcode: Hash, key: A, val: B] KeyValuePair[A, B] = tuple[hcode: Hash, key: A, val: B]

View file

@ -44,7 +44,7 @@
## * `std/sha1 module <sha1.html>`_ for a sha1 encoder and decoder ## * `std/sha1 module <sha1.html>`_ for a sha1 encoder and decoder
## * `tables module <tables.html>`_ for hash tables ## * `tables module <tables.html>`_ for hash tables
include "system/inclrtl" import std/private/since
type type
Hash* = int ## A hash value. Hash tables using these values should Hash* = int ## A hash value. Hash tables using these values should

View file

@ -200,7 +200,7 @@
## let client = newHttpClient(maxRedirects = 0) ## let client = newHttpClient(maxRedirects = 0)
## ##
include "system/inclrtl" import std/private/since
import net, strutils, uri, parseutils, base64, os, mimetypes, streams, import net, strutils, uri, parseutils, base64, os, mimetypes, streams,
math, random, httpcore, times, tables, streams, std/monotimes math, random, httpcore, times, tables, streams, std/monotimes

View file

@ -52,7 +52,7 @@
## are on system directly, to name a few ``shr``, ``shl``, ``xor``, ``clamp``, etc. ## are on system directly, to name a few ``shr``, ``shl``, ``xor``, ``clamp``, etc.
include "system/inclrtl" import std/private/since
{.push debugger: off.} # the user does not want to trace a part {.push debugger: off.} # the user does not want to trace a part
# of the standard library! # of the standard library!

View file

@ -64,7 +64,7 @@
## socket.acceptAddr(client, address) ## socket.acceptAddr(client, address)
## echo("Client connected from: ", address) ## echo("Client connected from: ", address)
include "system/inclrtl" import std/private/since
import nativesockets, os, strutils, times, sets, options, std/monotimes import nativesockets, os, strutils, times, sets, options, std/monotimes
from ssl_certs import scanSSLCertificates from ssl_certs import scanSSLCertificates

View file

@ -42,6 +42,7 @@
## * `streams module <streams.html>`_ ## * `streams module <streams.html>`_
include "system/inclrtl" include "system/inclrtl"
import std/private/since
import import
strutils, pathnorm strutils, pathnorm

View file

@ -94,7 +94,7 @@
## * `asyncstreams module <asyncstreams.html>`_ ## * `asyncstreams module <asyncstreams.html>`_
## * `io module <io.html>`_ for `FileMode enum <io.html#FileMode>`_ ## * `io module <io.html>`_ for `FileMode enum <io.html#FileMode>`_
include "system/inclrtl" import std/private/since
const taintMode = compileOption("taintmode") const taintMode = compileOption("taintmode")

View file

@ -48,6 +48,7 @@ runnableExamples:
## * `json module<json.html>`_ for table-like structure which allows ## * `json module<json.html>`_ for table-like structure which allows
## heterogeneous members ## heterogeneous members
import std/private/since
import import
hashes, strutils hashes, strutils

View file

@ -10,8 +10,7 @@
## This module implements nice syntactic sugar based on Nim's ## This module implements nice syntactic sugar based on Nim's
## macro system. ## macro system.
include system/inclrtl import std/private/since
import macros import macros
import typetraits import typetraits

View file

@ -194,6 +194,7 @@
import strutils, math, options import strutils, math, options
import std/private/since
include "system/inclrtl" include "system/inclrtl"
when defined(js): when defined(js):
@ -980,7 +981,7 @@ proc low*(typ: typedesc[Time]): Time =
# DateTime & Timezone # DateTime & Timezone
# #
proc isLeapDay*(t: DateTime): bool {.since: (1,1).} = proc isLeapDay*(t: DateTime): bool {.since: (1, 1).} =
## returns whether `t` is a leap day, ie, Feb 29 in a leap year. This matters ## returns whether `t` is a leap day, ie, Feb 29 in a leap year. This matters
## as it affects time offset calculations. ## as it affects time offset calculations.
runnableExamples: runnableExamples:

View file

@ -12,10 +12,9 @@
## ##
## Unstable API. ## Unstable API.
import std/private/since
export system.`$` # for backward compatibility export system.`$` # for backward compatibility
include "system/inclrtl"
proc name*(t: typedesc): string {.magic: "TypeTrait".} proc name*(t: typedesc): string {.magic: "TypeTrait".}
## Returns the name of the given type. ## Returns the name of the given type.
## ##
@ -79,15 +78,13 @@ since (1, 1):
doAssert 12.MyInt.distinctBase == 12 doAssert 12.MyInt.distinctBase == 12
distinctBase(type(a))(a) distinctBase(type(a))(a)
proc tupleLen*(T: typedesc[tuple]): int {.magic: "TypeTrait", since: (1, 1).} proc tupleLen*(T: typedesc[tuple]): int {.magic: "TypeTrait".}
## Return number of elements of `T` ## Return number of elements of `T`
since (1, 1):
template tupleLen*(t: tuple): int = template tupleLen*(t: tuple): int =
## Return number of elements of `t` ## Return number of elements of `t`
tupleLen(type(t)) tupleLen(type(t))
since (1, 1):
template get*(T: typedesc[tuple], i: static int): untyped = template get*(T: typedesc[tuple], i: static int): untyped =
## Return `i`\th element of `T` ## Return `i`\th element of `T`
# Note: `[]` currently gives: `Error: no generic parameters allowed for ...` # Note: `[]` currently gives: `Error: no generic parameters allowed for ...`

View file

@ -93,11 +93,11 @@
## ##
## echo "suite teardown: run once after the tests" ## echo "suite teardown: run once after the tests"
import std/private/since
import import
macros, strutils, streams, times, sets, sequtils macros, strutils, streams, times, sets, sequtils
include "system/inclrtl"
when declared(stdout): when declared(stdout):
import os import os

View file

@ -44,7 +44,7 @@
## doAssert getDataUri("Hello World", "text/plain") == "data:text/plain;charset=utf-8;base64,SGVsbG8gV29ybGQ=" ## doAssert getDataUri("Hello World", "text/plain") == "data:text/plain;charset=utf-8;base64,SGVsbG8gV29ybGQ="
## doAssert getDataUri("Nim", "text/plain") == "data:text/plain;charset=utf-8;base64,Tmlt" ## doAssert getDataUri("Nim", "text/plain") == "data:text/plain;charset=utf-8;base64,Tmlt"
include "system/inclrtl" import std/private/since
import strutils, parseutils, base64 import strutils, parseutils, base64
type type

View file

@ -34,8 +34,8 @@
## * `parsexml module <parsexml.html>`_ for low-level XML parsing ## * `parsexml module <parsexml.html>`_ for low-level XML parsing
## * `htmlgen module <htmlgen.html>`_ for html code generator ## * `htmlgen module <htmlgen.html>`_ for html code generator
import std/private/since
import macros, strtabs, strutils import macros, strtabs, strutils
include "system/inclrtl"
type type
XmlNode* = ref XmlNodeObj ## An XML tree consisting of XML nodes. XmlNode* = ref XmlNodeObj ## An XML tree consisting of XML nodes.
@ -103,7 +103,7 @@ proc newText*(text: string): XmlNode =
result = newXmlNode(xnText) result = newXmlNode(xnText)
result.fText = text result.fText = text
proc newVerbatimText*(text: string): XmlNode {.since:(1, 3).} = proc newVerbatimText*(text: string): XmlNode {.since: (1, 3).} =
## Creates a new ``XmlNode`` of kind ``xnVerbatimText`` with the text `text`. ## Creates a new ``XmlNode`` of kind ``xnVerbatimText`` with the text `text`.
## **Since**: Version 1.3. ## **Since**: Version 1.3.
result = newXmlNode(xnVerbatimText) result = newXmlNode(xnVerbatimText)

19
lib/std/private/since.nim Normal file
View file

@ -0,0 +1,19 @@
template since*(version: (int, int), body: untyped) {.dirty.} =
## Evaluates `body` if the ``(NimMajor, NimMinor)`` is greater than
## or equal to `version`. Usage:
##
## .. code-block:: Nim
## proc fun*() {.since: (1, 3).}
## since (1, 3): fun()
when (NimMajor, NimMinor) >= version:
body
template since*(version: (int, int, int), body: untyped) {.dirty.} =
## Evaluates `body` if ``(NimMajor, NimMinor, NimPatch)`` is greater than
## or equal to `version`. Usage:
##
## .. code-block:: Nim
## proc fun*() {.since: (1, 3, 1).}
## since (1, 3, 1): fun()
when (NimMajor, NimMinor, NimPatch) >= version:
body

View file

@ -1124,6 +1124,8 @@ elif hostOS != "standalone":
var programResult* {.compilerproc, exportc: "nim_program_result".}: int var programResult* {.compilerproc, exportc: "nim_program_result".}: int
## deprecated, prefer ``quit`` ## deprecated, prefer ``quit``
import std/private/since
proc align(address, alignment: int): int = proc align(address, alignment: int): int =
if alignment == 0: # Actually, this is illegal. This branch exists to actively if alignment == 0: # Actually, this is illegal. This branch exists to actively
# hide problems. # hide problems.
@ -2054,8 +2056,8 @@ const
## is the major number of Nim's version. Example: ## is the major number of Nim's version. Example:
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## when (NimMajor, NimMinor, NimPatch) >= (1, 3, 1): discard ## when (NimMajor, NimMinor, NimPatch) >= (1, 3, 1): discard
# See also private symbol `since: (1, 3)` reserved for stdlib # see also std/private/since
NimMinor* {.intdefine.}: int = 3 NimMinor* {.intdefine.}: int = 3
## is the minor number of Nim's version. ## is the minor number of Nim's version.

View file

@ -1,4 +1,4 @@
include system/inclrtl import std/private/since
proc `$`*(x: int): string {.magic: "IntToStr", noSideEffect.} proc `$`*(x: int): string {.magic: "IntToStr", noSideEffect.}
## The stringify operator for an integer argument. Returns `x` ## The stringify operator for an integer argument. Returns `x`

View file

@ -48,21 +48,3 @@ when defined(nimlocks):
{.pragma: benign, gcsafe, locks: 0.} {.pragma: benign, gcsafe, locks: 0.}
else: else:
{.pragma: benign, gcsafe.} {.pragma: benign, gcsafe.}
template isSince(version: (int, int)): bool =
(NimMajor, NimMinor) >= version
template isSince(version: (int, int, int)): bool =
(NimMajor, NimMinor, NimPatch) >= version
template since(version, body: untyped) {.dirty, used.} =
## Usage:
##
## .. code-block:: Nim
## proc fun*() {since: (1, 3).}
## proc fun*() {since: (1, 3, 1).}
##
## Limitation: can't be used to annotate a template (eg typetraits.get), would
## error: cannot attach a custom pragma.
# `dirty` needed because `NimMajor` may not yet be defined in caller.
when isSince(version):
body

View file

@ -11,6 +11,7 @@
include inclrtl include inclrtl
import std/private/since
import formatfloat import formatfloat
# ----------------- IO Part ------------------------------------------------ # ----------------- IO Part ------------------------------------------------

View file

@ -1,9 +1,9 @@
include system/inclrtl import std/private/since
proc fun1(): int {.since: (1,3).} = 12 proc fun1(): int {.since: (1, 3).} = 12
proc fun1Bad(): int {.since: (99,3).} = 12 proc fun1Bad(): int {.since: (99, 3).} = 12
proc fun2(): int {.since: (1,3,1).} = 12 proc fun2(): int {.since: (1, 3, 1).} = 12
proc fun2Bad(): int {.since: (99,3,1).} = 12 proc fun2Bad(): int {.since: (99, 3, 1).} = 12
doAssert fun1() == 12 doAssert fun1() == 12
doAssert declared(fun1) doAssert declared(fun1)
@ -23,7 +23,7 @@ since (1, 3, 1):
ok = true ok = true
doAssert ok doAssert ok
since (99,3): since (99, 3):
doAssert false doAssert false
when false: when false: