From f53dc143f6a143a2c3a0d148b77e9a68d9a346fb Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 15 Feb 2021 12:12:06 -0800 Subject: [PATCH 1/5] document `since` --- compiler/commands.nim | 7 +++---- lib/std/private/since.nim | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/compiler/commands.nim b/compiler/commands.nim index 0c835a2f7bdc..4b632f8ec8e5 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -940,8 +940,6 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; of "1.0": defineSymbol(conf.symbols, "NimMajor", "1") defineSymbol(conf.symbols, "NimMinor", "0") - # always be compatible with 1.0.100: - defineSymbol(conf.symbols, "NimPatch", "100") # old behaviors go here: defineSymbol(conf.symbols, "nimOldRelativePathBehavior") undefSymbol(conf.symbols, "nimDoesntTrackDefects") @@ -951,10 +949,11 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; defineSymbol(conf.symbols, "NimMajor", "1") defineSymbol(conf.symbols, "NimMinor", "2") # always be compatible with 1.2.100: - defineSymbol(conf.symbols, "NimPatch", "100") conf.globalOptions.incl optNimV12Emulation else: - localError(conf, info, "unknown Nim version; currently supported values are: {1.0}") + localError(conf, info, "unknown Nim version; currently supported values are: `1.0`, `1.2`") + # always be compatible with 1.x.100: + defineSymbol(conf.symbols, "NimPatch", "100") of "benchmarkvm": processOnOffSwitchG(conf, {optBenchmarkVM}, arg, pass, info) of "profilevm": diff --git a/lib/std/private/since.nim b/lib/std/private/since.nim index e4aecb61ae4f..e97ac2a07234 100644 --- a/lib/std/private/since.nim +++ b/lib/std/private/since.nim @@ -1,3 +1,16 @@ +##[ +`since` is used to emulate older versions of nim stdlib with `--useVersion`, +see `tuse_version.nim`. + +If a symbol `foo` is added in version `(1,3,5)`, use `{.since: (1.3.5).}`, not +`{.since: (1.4).}`, so that it works in devel in between releases. + +`since` is not needed in those cases: +* if a new module is added +* if an overload is added (this would add complexity for little benefit) +* if an extra parameter to an existing routine is added. +]## + template since*(version: (int, int), body: untyped) {.dirty.} = ## Evaluates `body` if the ``(NimMajor, NimMinor)`` is greater than ## or equal to `version`. Usage: @@ -16,4 +29,4 @@ template since*(version: (int, int, int), body: untyped) {.dirty.} = ## proc fun*() {.since: (1, 3, 1).} ## since (1, 3, 1): fun() when (NimMajor, NimMinor, NimPatch) >= version: - body \ No newline at end of file + body From 389197b0fc1a42bc6960b648f5ff51d525137dc7 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 15 Feb 2021 12:13:15 -0800 Subject: [PATCH 2/5] fixup --- compiler/commands.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/commands.nim b/compiler/commands.nim index 4b632f8ec8e5..fa53a3ce6672 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -948,7 +948,6 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; of "1.2": defineSymbol(conf.symbols, "NimMajor", "1") defineSymbol(conf.symbols, "NimMinor", "2") - # always be compatible with 1.2.100: conf.globalOptions.incl optNimV12Emulation else: localError(conf, info, "unknown Nim version; currently supported values are: `1.0`, `1.2`") From 3984a87fae3f35b3fc514df5d1a375306868afce Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 15 Feb 2021 12:14:08 -0800 Subject: [PATCH 3/5] fixup --- doc/advopt.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/advopt.txt b/doc/advopt.txt index 93a985a37bcd..1882ee60b43f 100644 --- a/doc/advopt.txt +++ b/doc/advopt.txt @@ -146,7 +146,7 @@ Advanced options: enable experimental language feature --legacy:$2 enable obsolete/legacy language feature - --useVersion:1.0 emulate Nim version X of the Nim compiler + --useVersion:1.0 emulate Nim version X of the Nim compiler, for testing --profiler:on|off enable profiling; requires `import nimprof`, and works better with `--stackTrace:on` see also https://nim-lang.github.io/Nim/estp.html From e866b3c916d5a0aff4372722a2e73ac9541ca8db Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 15 Feb 2021 12:17:56 -0800 Subject: [PATCH 4/5] fixup --- lib/std/private/since.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/std/private/since.nim b/lib/std/private/since.nim index e97ac2a07234..5b22b6391766 100644 --- a/lib/std/private/since.nim +++ b/lib/std/private/since.nim @@ -5,10 +5,11 @@ see `tuse_version.nim`. If a symbol `foo` is added in version `(1,3,5)`, use `{.since: (1.3.5).}`, not `{.since: (1.4).}`, so that it works in devel in between releases. +The emulation cannot be 100% faithful and to avoid adding too much complexity, `since` is not needed in those cases: * if a new module is added -* if an overload is added (this would add complexity for little benefit) -* if an extra parameter to an existing routine is added. +* if an overload is added +* if an extra parameter to an existing routine is added ]## template since*(version: (int, int), body: untyped) {.dirty.} = From ce1716e5cd751f1a277a40f21d05c7c10757b543 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 15 Feb 2021 14:41:26 -0800 Subject: [PATCH 5/5] address comment --- doc/advopt.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/advopt.txt b/doc/advopt.txt index 1882ee60b43f..7aa5d3a94e88 100644 --- a/doc/advopt.txt +++ b/doc/advopt.txt @@ -146,7 +146,7 @@ Advanced options: enable experimental language feature --legacy:$2 enable obsolete/legacy language feature - --useVersion:1.0 emulate Nim version X of the Nim compiler, for testing + --useVersion:1.0|1.2 emulate Nim version X of the Nim compiler, for testing --profiler:on|off enable profiling; requires `import nimprof`, and works better with `--stackTrace:on` see also https://nim-lang.github.io/Nim/estp.html