From f6dc30e52d94f433d1a132d73a5cf357c57e6a34 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 17 Sep 2022 04:35:53 +0800 Subject: [PATCH 01/17] fixes Thread initializer for ARC/ORC on Macos (#20368) * fixes Thread initializer for ARC/ORC * another try * fix * use int --- lib/system/threadlocalstorage.nim | 2 +- tests/generics/tthread_generic.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/system/threadlocalstorage.nim b/lib/system/threadlocalstorage.nim index cea9abb420..b62c903c34 100644 --- a/lib/system/threadlocalstorage.nim +++ b/lib/system/threadlocalstorage.nim @@ -141,7 +141,7 @@ else: header: "".} = cint else: type - SysThread* {.importc: "pthread_t", header: "".} = object + SysThread* {.importc: "pthread_t", header: "".} = int Pthread_attr {.importc: "pthread_attr_t", header: "".} = object ThreadVarSlot {.importc: "pthread_key_t", diff --git a/tests/generics/tthread_generic.nim b/tests/generics/tthread_generic.nim index 2af5a76158..300da56a68 100644 --- a/tests/generics/tthread_generic.nim +++ b/tests/generics/tthread_generic.nim @@ -1,5 +1,5 @@ discard """ - cmd: "nim $target --hints:on --threads:on $options $file" + matrix: "--mm:refc; --mm:orc" action: compile """ From 97259a5ab37892bedca64b14ffc6e0b7d25dd789 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Mon, 19 Sep 2022 15:16:54 +0800 Subject: [PATCH 02/17] fixes #19713; Revert "Remove tlsEmulation enabled from Windows + GCC config" (#19119) (#20327) * Revert "Remove tlsEmulation enabled from Windows + GCC config (#19119) [backport:1.6]" This reverts commit 77b696c2c92b5f478526290c5e184a4c41060f7b. * increase nimTlsSize to 48000 * enable for windows * fixes tests * fixes tlsEmulation:on --- compiler/nim.cfg | 1 + compiler/ropes.nim | 8 ++++++-- config/nim.cfg | 3 +++ tests/config.nims | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler/nim.cfg b/compiler/nim.cfg index 7ed70fb5f2..853a657b39 100644 --- a/compiler/nim.cfg +++ b/compiler/nim.cfg @@ -11,6 +11,7 @@ define:nimPreviewSlimSystem @if windows: cincludes: "$lib/wrappers/libffi/common" + tlsEmulation:off @end define:useStdoutAsStdmsg diff --git a/compiler/ropes.nim b/compiler/ropes.nim index 3a2fbe44e2..b84cfad527 100644 --- a/compiler/ropes.nim +++ b/compiler/ropes.nim @@ -86,8 +86,12 @@ proc newRope(data: string = ""): Rope = result.L = -data.len result.data = data -var - cache {.threadvar.} : array[0..2048*2 - 1, Rope] +when compileOption("tlsEmulation"): # fixme: be careful if you want to make ropes support multiple threads + var + cache: array[0..2048*2 - 1, Rope] +else: + var + cache {.threadvar.} : array[0..2048*2 - 1, Rope] proc resetRopeCache* = for i in low(cache)..high(cache): diff --git a/config/nim.cfg b/config/nim.cfg index fd2642391b..55b7a41c15 100644 --- a/config/nim.cfg +++ b/config/nim.cfg @@ -169,6 +169,9 @@ nimblepath="$home/.nimble/pkgs/" # Configuration for the GNU C/C++ compiler: @if windows: #gcc.path = r"$nim\dist\mingw\bin" + @if gcc or tcc: + tlsEmulation:on + @end @end gcc.maxerrorsimpl = "-fmax-errors=3" diff --git a/tests/config.nims b/tests/config.nims index 894c4bea0a..5195ebcafb 100644 --- a/tests/config.nims +++ b/tests/config.nims @@ -40,3 +40,5 @@ switch("define", "nimPreviewFloatRoundtrip") switch("define", "nimPreviewDotLikeOps") switch("define", "nimPreviewJsonutilsHoleyEnum") switch("define", "nimPreviewHashRef") +when defined(windows): + switch("tlsEmulation", "off") From 7a756bfaef29ff521059b3310b67a0344001f5fd Mon Sep 17 00:00:00 2001 From: Amjad Ben Hedhili Date: Mon, 19 Sep 2022 14:09:41 +0100 Subject: [PATCH 03/17] Shorten JS block code (#20370) --- compiler/jsgen.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index cacdb3fb98..116d31de4d 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -971,12 +971,12 @@ proc genBlock(p: PProc, n: PNode, r: var TCompRes) = sym.loc.k = locOther sym.position = idx+1 let labl = p.unique - lineF(p, "Label$1: do {$n", [labl.rope]) + lineF(p, "Label$1: {$n", [labl.rope]) setLen(p.blocks, idx + 1) p.blocks[idx].id = - p.unique # negative because it isn't used yet gen(p, n[1], r) setLen(p.blocks, idx) - lineF(p, "} while (false);$n", [labl.rope]) + lineF(p, "};$n", [labl.rope]) proc genBreakStmt(p: PProc, n: PNode) = var idx: int @@ -2426,9 +2426,9 @@ proc genProcBody(p: PProc, prc: PSym): Rope = else: result = nil if p.beforeRetNeeded: - result.add p.indentLine(~"BeforeRet: do {$n") + result.add p.indentLine(~"BeforeRet: {$n") result.add p.body - result.add p.indentLine(~"} while (false);$n") + result.add p.indentLine(~"};$n") else: result.add(p.body) if prc.typ.callConv == ccSysCall: From 7023176dcbc557907f5842f0a4f90b5774735e1e Mon Sep 17 00:00:00 2001 From: Amjad Ben Hedhili Date: Mon, 19 Sep 2022 22:43:46 +0100 Subject: [PATCH 04/17] Recommend `mapIt` in some cases (#20347) * Recommend `mapIt` in some cases * Remove runnableExample --- lib/pure/sugar.nim | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/pure/sugar.nim b/lib/pure/sugar.nim index d7beef8d9a..ff2a3bb585 100644 --- a/lib/pure/sugar.nim +++ b/lib/pure/sugar.nim @@ -391,6 +391,10 @@ macro collect*(init, body: untyped): untyped {.since: (1, 1).} = macro collect*(body: untyped): untyped {.since: (1, 5).} = ## Same as `collect` but without an `init` parameter. + ## + ## **See also:** + ## * `sequtils.toSeq proc`_ + ## * `sequtils.mapIt template`_ runnableExamples: import std/[sets, tables] let data = @["bird", "word"] @@ -411,10 +415,4 @@ macro collect*(body: untyped): untyped {.since: (1, 5).} = for i, d in data.pairs: {i: d} assert m == {0: "bird", 1: "word"}.toTable - # avoid `collect` when `sequtils.toSeq` suffices: - assert collect(for i in 1..3: i*i) == @[1, 4, 9] # ok in this case - assert collect(for i in 1..3: i) == @[1, 2, 3] # overkill in this case - from std/sequtils import toSeq - assert toSeq(1..3) == @[1, 2, 3] # simpler - result = collectImpl(nil, body) From c8000b1025b7383066cbaab282772d4a11ab197e Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 19 Sep 2022 18:47:39 -0300 Subject: [PATCH 05/17] Add missing symbols to regex (#20383) * Add missing attribute to jsre * Add missing attribute to jsre --- changelog.md | 7 ++++--- lib/js/jsre.nim | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 8d574f2b0b..5fb58718cb 100644 --- a/changelog.md +++ b/changelog.md @@ -69,6 +69,7 @@ in `jscore` for JavaScript targets. - Added `UppercaseLetters`, `LowercaseLetters`, `PunctuationChars`, `PrintableChars` sets to `std/strutils`. - Added `complex.sgn` for obtaining the phase of complex numbers. +- Added [`jsre.hasIndices`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices) [//]: # "Deprecations:" - Deprecated `selfExe` for Nimscript. @@ -137,10 +138,10 @@ added to make this work explicitly, and a warning is generated in the case where it is implicit. This behavior only applies to templates, redefinition is generally disallowed for other symbols. - + - A new form of type inference called [top-down inference](https://nim-lang.github.io/Nim/manual_experimental.html#topminusdown-type-inference) has been implemented for a variety of basic cases. For example, code like the following now compiles: - + ```nim let foo: seq[(float, byte, cstring)] = @[(1, 2, "abc")] ``` @@ -153,7 +154,7 @@ - The `gc` switch has been renamed to `mm` ("memory management") in order to reflect the reality better. (Nim moved away from all techniques based on "tracing".) - + - Defines the `gcRefc` symbol which allows writing specific code for the refc GC. - `nim` can now compile version 1.4.0 as follows: `nim c --lib:lib --stylecheck:off compiler/nim`, diff --git a/lib/js/jsre.nim b/lib/js/jsre.nim index 0cc2f8a872..19888aaa90 100644 --- a/lib/js/jsre.nim +++ b/lib/js/jsre.nim @@ -20,6 +20,7 @@ type RegExp* = ref object of JsRoot lastParen*: cstring ## Ditto. leftContext*: cstring ## Ditto. rightContext*: cstring ## Ditto. + hasIndices*: bool ## https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices func newRegExp*(pattern: cstring; flags: cstring): RegExp {.importjs: "new RegExp(@)".} From 2147b116a1e7d2c0fdd018a64386d8885e04b6a1 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 19 Sep 2022 18:51:47 -0300 Subject: [PATCH 06/17] Add missing proc to dom (#20378) * Add missing proc from dom * Add missing proc from dom * Add missing proc from dom Co-authored-by: Clay Sweetser --- changelog.md | 6 +++++- lib/js/dom.nim | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 5fb58718cb..9364ab573a 100644 --- a/changelog.md +++ b/changelog.md @@ -69,6 +69,11 @@ in `jscore` for JavaScript targets. - Added `UppercaseLetters`, `LowercaseLetters`, `PunctuationChars`, `PrintableChars` sets to `std/strutils`. - Added `complex.sgn` for obtaining the phase of complex numbers. +- Added `insertAdjacentText`, `insertAdjacentElement`, `insertAdjacentHTML`, + `after`, `before`, `closest`, `append`, `hasAttributeNS`, `removeAttributeNS`, + `hasPointerCapture`, `releasePointerCapture`, `requestPointerLock`, + `replaceChildren`, `replaceWith`, `scrollIntoViewIfNeeded`, `setHTML`, + `toggleAttribute`, and `matches` to `std/dom`. - Added [`jsre.hasIndices`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices) [//]: # "Deprecations:" @@ -172,4 +177,3 @@ - Nim now supports Nimble version 0.14 which added support for lock-files. This is done by a simple configuration change setting that you can do yourself too. In `$nim/config/nim.cfg` replace `pkgs` by `pkgs2`. - diff --git a/lib/js/dom.nim b/lib/js/dom.nim index 1a62780a7a..9859e95aee 100644 --- a/lib/js/dom.nim +++ b/lib/js/dom.nim @@ -1782,3 +1782,60 @@ since (1, 3): since (1, 5): proc elementsFromPoint*(n: DocumentOrShadowRoot; x, y: float): seq[Element] {.importcpp.} + + +since (1, 7): + + proc insertAdjacentText*(self: Node; position, data: cstring) {.importjs: "#.$1(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentText + + proc insertAdjacentElement*(self: Node; position: cstring; element: Node) {.importjs: "#.$1(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentElement + + proc insertAdjacentHTML*(self: Node; position, html: cstring) {.importjs: "#.$1(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML + + proc after*(self: Node; element: Node): Node {.importjs: "#.$1(@)", varargs.} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/after + + proc before*(self: Node; element: Node): Node {.importjs: "#.$1(@)", varargs.} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/before + + proc append*(self: Node; element: Node): Node {.importjs: "#.$1(@)", varargs.} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/append + + proc closest*(self: Node; cssSelector: cstring): Node {.importjs: "#.$1(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/closest + + proc hasAttributeNS*(self: Node; namespace, localName: cstring): bool {.importjs: "(#.$1(#, #) || false)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttributeNS + + proc removeAttributeNS*(self: Node; namespace, attributeName: cstring) {.importjs: "#.$1(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttributeNS + + proc hasPointerCapture*(self: Node; pointerId: SomeNumber): bool {.importjs: "(#.$1(#) || false)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/hasPointerCapture + + proc releasePointerCapture*(self: Node; pointerId: SomeNumber) {.importjs: "#.$1(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/releasePointerCapture + + proc requestPointerLock*(self: Node) {.importjs: "#.$1()".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/requestPointerLock + + proc replaceChildren*(self: Node; replacements: Node) {.importjs: "#.$1(@)", varargs.} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren + + proc replaceWith*(self: Node; replacements: Node) {.importjs: "#.$1(@)", varargs.} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceWith + + proc scrollIntoViewIfNeeded*(self: Node; centerIfNeeded: bool) {.importjs: "#.$1(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded + + proc setHTML*(self: Node; html: cstring) {.importjs: "#.$1(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/setHTML + + proc toggleAttribute*(self: Node; name: cstring; force = false): bool {.importjs: "(#.$1(#, #) || false)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/toggleAttribute + + proc matches*(self: Node; cssSelector: cstring): bool {.importjs: "(#.$1(#) || false)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Element/matches From c4ba4f06f819d6356fff8ee8ee1df0392091de9a Mon Sep 17 00:00:00 2001 From: Andrey Makarov Date: Tue, 20 Sep 2022 01:24:40 +0300 Subject: [PATCH 07/17] Markdown link migration part 2 (#20371) --- doc/docs.md | 22 ++-- doc/docstyle.md | 2 +- doc/drnim.md | 2 +- doc/idetools.md | 20 ++-- doc/intern.md | 14 +-- doc/koch.md | 10 +- doc/lib.md | 278 +++++++++++++++++++++++----------------------- doc/mm.md | 10 +- doc/nep1.md | 2 +- doc/nimc.md | 50 ++++----- doc/niminst.md | 4 +- doc/nims.md | 101 +++++++++-------- doc/nimsuggest.md | 8 +- doc/packaging.md | 4 +- doc/refc.md | 2 +- doc/spawn.txt | 2 +- doc/testament.md | 23 ++-- doc/tools.md | 16 +-- 18 files changed, 287 insertions(+), 283 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index 3c348fcb83..b6ff6d2c70 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1,38 +1,38 @@ The documentation consists of several documents: -- | `Tutorial (part I) `_ +- | [Tutorial (part I)](tut1.html) | The Nim tutorial part one deals with the basics. -- | `Tutorial (part II) `_ +- | [Tutorial (part II)](tut2.html) | The Nim tutorial part two deals with the advanced language constructs. -- | `Tutorial (part III) `_ +- | [Tutorial (part III)](tut3.html) | The Nim tutorial part three about Nim's macro system. -- | `Language Manual `_ +- | [Language Manual](manual.html) | The Nim manual is a draft that will evolve into a proper specification. -- | `Library documentation `_ +- | [Library documentation](lib.html) | This document describes Nim's standard library. -- | `Compiler user guide `_ +- | [Compiler user guide](nimc.html) | The user guide lists command line arguments, special features of the compiler, etc. -- | `Tools documentation `_ +- | [Tools documentation](tools.html) | Description of some tools that come with the standard distribution. -- | `Memory management `_ +- | [Memory management](mm.html) | Additional documentation about Nim's memory management strategies | and how to operate them in a realtime setting. -- | `Source code filters `_ +- | [Source code filters](filters.html) | The Nim compiler supports source code filters as a simple yet powerful builtin templating system. -- | `Internal documentation `_ +- | [Internal documentation](intern.html) | The internal documentation describes how the compiler is implemented. Read this if you want to hack the compiler. -- | `Index `_ +- | [Index](theindex.html) | The generated index. **Index + (Ctrl+F) == Joy** diff --git a/doc/docstyle.md b/doc/docstyle.md index 1651a6e03f..291a34cf68 100644 --- a/doc/docstyle.md +++ b/doc/docstyle.md @@ -4,7 +4,7 @@ Documentation Style General Guidelines ------------------ -* See also `nep1`_ which should probably be merged here. +* See also [nep1](nep1.html) which should probably be merged here. * Authors should document anything that is exported; documentation for private procs can be useful too (visible via `nim doc --docInternal foo.nim`:cmd:). * Within documentation, a period (`.`) should follow each sentence (or sentence fragment) in a comment block. diff --git a/doc/drnim.md b/doc/drnim.md index 036ae0d147..48a6334468 100644 --- a/doc/drnim.md +++ b/doc/drnim.md @@ -14,7 +14,7 @@ Introduction ============ This document describes the usage of the *DrNim* tool. DrNim combines -the Nim frontend with the `Z3 `_ proof +the Nim frontend with the [Z3](https://github.com/Z3Prover/z3) proof engine, in order to allow verify/validate software written in Nim. DrNim's command-line options are the same as the Nim compiler's. diff --git a/doc/idetools.md b/doc/idetools.md index 7c69232e36..8f4b3e995e 100644 --- a/doc/idetools.md +++ b/doc/idetools.md @@ -12,19 +12,19 @@ > "yes, I'm the creator" -- Araq, 2013-07-26 19:28:32. -Note: this is mostly outdated, see instead `nimsuggest `_ +Note: this is mostly outdated, see instead [nimsuggest](nimsuggest.html) Nim differs from many other compilers in that it is really fast, and being so fast makes it suited to provide external queries for text editors about the source code being written. Through the -`idetools` command of `the compiler `_, any IDE +`idetools` command of [the compiler](nimc.html), any IDE can query a `.nim` source file and obtain useful information like definition of symbols or suggestions for completion. This document will guide you through the available options. If you want to look at practical examples of idetools support you can look -at the test files found in the `Test suite`_ or `various editor -integrations `_ +at the test files found in the [Test suite] or [various editor +integrations](https://github.com/Araq/Nim/wiki/Editor-Support) already available. @@ -124,8 +124,8 @@ to the case insensitiveness of the language (plus underscores as separators!). The typical usage scenario for this option is to call it after the -user has typed the dot character for `the object oriented call -syntax `_. +user has typed the dot character for [the object oriented call +syntax](tut2.html#object-oriented-programming-method-call-syntax). Idetools will try to return the suggestions sorted first by scope (from innermost to outermost) and then by item name. @@ -196,7 +196,7 @@ of text it thinks necessary plus an empty line to indicate the end of the answer. You can find examples of client/server communication in the idetools -tests found in the `Test suite`_. +tests found in the [Test suite]. Parsing idetools output @@ -367,8 +367,8 @@ defined, since at that point in the file the parser hasn't processed the full line yet. The signature will be returned complete in posterior instances of the method. -Methods imply `dynamic dispatch -`_ and +Methods imply [dynamic dispatch]( +tut2.html#object-oriented-programming-dynamic-dispatch) and idetools performs a static analysis on the code. For this reason idetools may not return the definition of the correct method you are querying because it may be impossible to know until the code @@ -590,7 +590,7 @@ All the `tests/caas/*.txt` files encode a session with the compiler: modes, you can prefix a line with the mode and the line will be processed only in that mode. -* The rest of the line is treated as a `regular expression `_, +* The rest of the line is treated as a [regular expression](re.html), so be careful escaping metacharacters like parenthesis. Before the line is processed as a regular expression, some basic diff --git a/doc/intern.md b/doc/intern.md index 71d695e7d3..fe2e59f512 100644 --- a/doc/intern.md +++ b/doc/intern.md @@ -64,7 +64,7 @@ And for a debug version compatible with GDB: The `koch`:cmd: program is Nim's maintenance script. It is a replacement for make and shell scripting with the advantage that it is much more portable. -More information about its options can be found in the `koch `_ +More information about its options can be found in the [koch](koch.html) documentation. @@ -105,7 +105,7 @@ current commit: You can also bisect using custom options to build the compiler, for example if you don't need a debug version of the compiler (which runs slower), you can replace -`./koch temp`:cmd: by explicit compilation command, see `Bootstrapping the compiler`_. +`./koch temp`:cmd: by explicit compilation command, see [Bootstrapping the compiler]. Building an instrumented compiler @@ -269,7 +269,7 @@ Native debugging Stepping through the compiler with a native debugger is a very powerful tool to both learn and debug it. However, there is still the need to constrain when -breakpoints are triggered. The same methods as in `Debug logging`_ can be applied +breakpoints are triggered. The same methods as in [Debug logging] can be applied here when combined with calls to the debug helpers `enteringDebugSection()`:nim: and `exitingDebugSection()`:nim:. @@ -309,7 +309,7 @@ The syntax tree consists of nodes which may have an arbitrary number of children. Types and symbols are represented by other nodes, because they may contain cycles. The AST changes its shape after semantic checking. This is needed to make life easier for the code generators. See the "ast" module -for the type definitions. The `macros `_ module contains many +for the type definitions. The [macros](macros.html) module contains many examples how the AST represents each syntactic structure. @@ -324,7 +324,7 @@ ARC/ORC. The new runtime is active `when defined(nimV2)`. Coding Guidelines ================= -* We follow Nim's official style guide, see ``_. +* We follow Nim's official style guide, see [NEP1](nep1.html). * Max line length is 100 characters. * Provide spaces around binary operators if that enhances readability. * Use a space after a colon, but not before it. @@ -332,7 +332,7 @@ Coding Guidelines pointers/references which start with `P`. * Prefer `import package`:nim: over `from package import symbol`:nim:. -See also the `API naming design `_ document. +See also the [API naming design](apis.html) document. Porting to new platforms @@ -452,7 +452,7 @@ could stem from a complex expression: receivesClosure(returnsDefaultCC[i]) ``` -A thunk would need to call 'returnsDefaultCC[i]' somehow and that would require +A thunk would need to call `returnsDefaultCC[i]` somehow and that would require an *additional* closure generation... Ok, not really, but it requires to pass the function to call. So we'd end up with 2 indirect calls instead of one. Another much more severe problem with this solution is that it's not GC-safe diff --git a/doc/koch.md b/doc/koch.md index 2454ac2f49..8fa19ce448 100644 --- a/doc/koch.md +++ b/doc/koch.md @@ -48,16 +48,16 @@ csource command --------------- The `csource`:idx: command builds the C sources for installation. It accepts -the same options as you would pass to the `boot command -<#commands-boot-command>`_. +the same options as you would pass to the [boot command]( +#commands-boot-command). temp command ------------ The temp command builds the Nim compiler but with a different final name (`nim_temp`:cmd:), so it doesn't overwrite your normal compiler. You can use -this command to test different options, the same you would issue for the `boot -command <#commands-boot-command>`_. +this command to test different options, the same you would issue for the [boot +command](#commands-boot-command). test command ------------ @@ -88,4 +88,4 @@ pdf command The `pdf`:idx: command builds PDF versions of Nim documentation: Manual, Tutorial and a few other documents. To run it one needs to -`install Latex/xelatex `_ first. +[install Latex/xelatex](https://www.latex-project.org/get) first. diff --git a/doc/lib.md b/doc/lib.md index 2f3a315a8f..468ee84e32 100644 --- a/doc/lib.md +++ b/doc/lib.md @@ -15,14 +15,14 @@ Pure libraries do not depend on any external ``*.dll`` or ``lib*.so`` binary while impure libraries do. A wrapper is an impure library that is a very low-level interface to a C library. -Read this `document `_ for a quick overview of the API design. +Read [this document](apis.html) for a quick overview of the API design. Nimble ====== Nim's standard library only covers the basics, check -out ``_ for a list of 3rd party packages. +out https://nimble.directory/ for a list of 3rd party packages. Pure libraries @@ -31,17 +31,17 @@ Pure libraries Automatic imports ----------------- -* `system `_ +* [system](system.html) Basic procs and operators that every program needs. It also provides IO facilities for reading and writing text and binary files. It is imported implicitly by the compiler. Do not import it directly. It relies on compiler magic to work. -* `threads `_ +* [threads](threads.html) Basic Nim thread support. **Note:** This is part of the system module. Do not import it explicitly. Enabled with `--threads:on`:option:. -* `channels_builtin `_ +* [channels_builtin](channels_builtin.html) Nim message passing support for threads. **Note:** This is part of the system module. Do not import it explicitly. Enabled with `--threads:on`:option:. @@ -49,40 +49,40 @@ Automatic imports Core ---- -* `atomics `_ +* [atomics](atomics.html) Types and operations for atomic operations and lockless algorithms. -* `bitops `_ +* [bitops](bitops.html) Provides a series of low-level methods for bit manipulation. -* `cpuinfo `_ +* [cpuinfo](cpuinfo.html) This module implements procs to determine the number of CPUs / cores. -* `endians `_ +* [endians](endians.html) This module contains helpers that deal with different byte orders. -* `lenientops `_ +* [lenientops](lenientops.html) Provides binary operators for mixed integer/float expressions for convenience. -* `locks `_ +* [locks](locks.html) Locks and condition variables for Nim. -* `macrocache `_ +* [macrocache](macrocache.html) Provides an API for macros to collect compile-time information across modules. -* `macros `_ +* [macros](macros.html) Contains the AST API and documentation of Nim for writing macros. -* `rlocks `_ +* [rlocks](rlocks.html) Reentrant locks for Nim. -* `typeinfo `_ +* [typeinfo](typeinfo.html) Provides (unsafe) access to Nim's run-time type information. -* `typetraits `_ +* [typetraits](typetraits.html) This module defines compile-time reflection procs for working with types. -* `volatile `_ +* [volatile](volatile.html) This module contains code for generating volatile loads and stores, which are useful in embedded and systems programming. @@ -90,169 +90,169 @@ Core Algorithms ---------- -* `algorithm `_ +* [algorithm](algorithm.html) This module implements some common generic algorithms like sort or binary search. -* `enumutils `_ +* [enumutils](enumutils.html) This module adds functionality for the built-in `enum` type. -* `sequtils `_ +* [sequtils](sequtils.html) This module implements operations for the built-in `seq` type which were inspired by functional programming languages. -* `setutils `_ +* [setutils](setutils.html) This module adds functionality for the built-in `set` type. Collections ----------- -* `critbits `_ +* [critbits](critbits.html) This module implements a *crit bit tree* which is an efficient container for a sorted set of strings, or a sorted mapping of strings. -* `deques `_ +* [deques](deques.html) Implementation of a double-ended queue. The underlying implementation uses a `seq`. -* `heapqueue `_ +* [heapqueue](heapqueue.html) Implementation of a binary heap data structure that can be used as a priority queue. -* `intsets `_ +* [intsets](intsets.html) Efficient implementation of a set of ints as a sparse bit set. -* `lists `_ +* [lists](lists.html) Nim linked list support. Contains singly and doubly linked lists and circular lists ("rings"). -* `options `_ +* [options](options.html) The option type encapsulates an optional value. -* `packedsets `_ +* [packedsets](packedsets.html) Efficient implementation of a set of ordinals as a sparse bit set. -* `sets `_ +* [sets](sets.html) Nim hash set support. -* `tables `_ +* [tables](tables.html) Nim hash table support. Contains tables, ordered tables, and count tables. String handling --------------- -* `cstrutils `_ +* [cstrutils](cstrutils.html) Utilities for `cstring` handling. -* `editdistance `_ +* [editdistance](editdistance.html) This module contains an algorithm to compute the edit distance between two Unicode strings. -* `encodings `_ +* [encodings](encodings.html) Converts between different character encodings. On UNIX, this uses the `iconv` library, on Windows the Windows API. -* `parseutils `_ +* [parseutils](parseutils.html) This module contains helpers for parsing tokens, numbers, identifiers, etc. -* `pegs `_ +* [pegs](pegs.html) This module contains procedures and operators for handling PEGs. -* `punycode `_ +* [punycode](punycode.html) Implements a representation of Unicode with the limited ASCII character subset. -* `ropes `_ +* [ropes](ropes.html) This module contains support for a *rope* data type. Ropes can represent very long strings efficiently; in particular, concatenation is done in O(1) instead of O(n). -* `strbasics `_ +* [strbasics](strbasics.html) This module provides some high performance string operations. -* `strformat `_ +* [strformat](strformat.html) Macro based standard string interpolation/formatting. Inspired by Python's f-strings. -* `strmisc `_ +* [strmisc](strmisc.html) This module contains uncommon string handling operations that do not fit with the commonly used operations in strutils. -* `strscans `_ +* [strscans](strscans.html) This module contains a `scanf` macro for convenient parsing of mini languages. -* `strtabs `_ +* [strtabs](strtabs.html) The `strtabs` module implements an efficient hash table that is a mapping from strings to strings. Supports a case-sensitive, case-insensitive and style-insensitive modes. -* `strutils `_ +* [strutils](strutils.html) This module contains common string handling operations like changing case of a string, splitting a string into substrings, searching for substrings, replacing substrings. -* `unicode `_ +* [unicode](unicode.html) This module provides support to handle the Unicode UTF-8 encoding. -* `unidecode `_ +* [unidecode](unidecode.html) It provides a single proc that does Unicode to ASCII transliterations. Based on Python's Unidecode module. -* `wordwrap `_ +* [wordwrap](wordwrap.html) This module contains an algorithm to wordwrap a Unicode string. Time handling ------------- -* `monotimes `_ +* [monotimes](monotimes.html) The `monotimes` module implements monotonic timestamps. -* `times `_ +* [times](times.html) The `times` module contains support for working with time. Generic Operating System Services --------------------------------- -* `distros `_ +* [distros](distros.html) This module implements the basics for OS distribution ("distro") detection and the OS's native package manager. Its primary purpose is to produce output for Nimble packages, but it also contains the widely used **Distribution** enum that is useful for writing platform-specific code. - See `packaging `_ for hints on distributing Nim using OS packages. + See [packaging](packaging.html) for hints on distributing Nim using OS packages. -* `dynlib `_ +* [dynlib](dynlib.html) This module implements the ability to access symbols from shared libraries. -* `marshal `_ +* [marshal](marshal.html) Contains procs for serialization and deserialization of arbitrary Nim data structures. -* `memfiles `_ +* [memfiles](memfiles.html) This module provides support for memory-mapped files (Posix's `mmap`) on the different operating systems. -* `os `_ +* [os](os.html) Basic operating system facilities like retrieving environment variables, reading command line arguments, working with directories, running shell commands, etc. -* `osproc `_ +* [osproc](osproc.html) Module for process communication beyond `os.execShellCmd`. -* `streams `_ +* [streams](streams.html) This module provides a stream interface and two implementations thereof: the `FileStream` and the `StringStream` which implement the stream interface for Nim file objects (`File`) and strings. Other modules may provide other implementations for this standard stream interface. -* `terminal `_ +* [terminal](terminal.html) This module contains a few procedures to control the *terminal* (also called *console*). The implementation simply uses ANSI escape sequences and does not depend on any other module. -* `tempfiles `_ +* [tempfiles](tempfiles.html) This module provides some utils to generate temporary path names and create temporary files and directories. @@ -260,131 +260,131 @@ Generic Operating System Services Math libraries -------------- -* `complex `_ +* [complex](complex.html) This module implements complex numbers and relevant mathematical operations. -* `fenv `_ +* [fenv](fenv.html) Floating-point environment. Handling of floating-point rounding and exceptions (overflow, zero-divide, etc.). -* `math `_ +* [math](math.html) Mathematical operations like cosine, square root. -* `random `_ +* [random](random.html) Fast and tiny random number generator. -* `rationals `_ +* [rationals](rationals.html) This module implements rational numbers and relevant mathematical operations. -* `stats `_ +* [stats](stats.html) Statistical analysis. -* `sums `_ +* [sums](sums.html) Accurate summation functions. -* `sysrand `_ +* [sysrand](sysrand.html) Cryptographically secure pseudorandom number generator. Internet Protocols and Support ------------------------------ -* `asyncdispatch `_ +* [asyncdispatch](asyncdispatch.html) This module implements an asynchronous dispatcher for IO operations. -* `asyncfile `_ +* [asyncfile](asyncfile.html) This module implements asynchronous file reading and writing using `asyncdispatch`. -* `asyncftpclient `_ - This module implements an asynchronous FTP client using the `asyncnet` +* `asyncftpclient](asyncftpclient.html) + [his module implements an asynchronous FTP client using the `asyncnet` module. -* `asynchttpserver `_ - This module implements an asynchronous HTTP server using the `asyncnet` +* `asynchttpserver](asynchttpserver.html) + [his module implements an asynchronous HTTP server using the `asyncnet` module. -* `asyncnet `_ +* [asyncnet](asyncnet.html) This module implements asynchronous sockets based on the `asyncdispatch` module. -* `asyncstreams `_ +* [asyncstreams](asyncstreams.html) This module provides `FutureStream` - a future that acts as a queue. -* `cgi `_ +* [cgi](cgi.html) This module implements helpers for CGI applications. -* `cookies `_ +* [cookies](cookies.html) This module contains helper procs for parsing and generating cookies. -* `httpclient `_ +* [httpclient](httpclient.html) This module implements a simple HTTP client which supports both synchronous and asynchronous retrieval of web pages. -* `mimetypes `_ +* [mimetypes](mimetypes.html) This module implements a mimetypes database. -* `nativesockets `_ +* [nativesockets](nativesockets.html) This module implements a low-level sockets API. -* `net `_ +* [net](net.html) This module implements a high-level sockets API. It replaces the `sockets` module. -* `selectors `_ +* [selectors](selectors.html) This module implements a selector API with backends specific to each OS. Currently, epoll on Linux and select on other operating systems. -* `smtp `_ +* [smtp](smtp.html) This module implements a simple SMTP client. -* `uri `_ +* [uri](uri.html) This module provides functions for working with URIs. Threading --------- -* `threadpool `_ - Implements Nim's `spawn `_. +* [threadpool](threadpool.html) + Implements Nim's [spawn](manual_experimental.html#parallel-amp-spawn). Parsers ------- -* `htmlparser `_ +* [htmlparser](htmlparser.html) This module parses an HTML document and creates its XML tree representation. -* `json `_ +* [json](json.html) High-performance JSON parser. -* `jsonutils `_ +* [jsonutils](jsonutils.html) This module implements a hookable (de)serialization for arbitrary types. -* `lexbase `_ +* [lexbase](lexbase.html) This is a low-level module that implements an extremely efficient buffering scheme for lexers and parsers. This is used by the diverse parsing modules. -* `parsecfg `_ +* [parsecfg](parsecfg.html) The `parsecfg` module implements a high-performance configuration file parser. The configuration file's syntax is similar to the Windows ``.ini`` format, but much more powerful, as it is not a line based parser. String literals, raw string literals, and triple quote string literals are supported as in the Nim programming language. -* `parsecsv `_ +* [parsecsv](parsecsv.html) The `parsecsv` module implements a simple high-performance CSV parser. -* `parsejson `_ - This module implements a JSON parser. It is used and exported by the `json `_ module, but can also be used in its own right. +* [parsejson](parsejson.html) + This module implements a JSON parser. It is used and exported by the [json](json.html) module, but can also be used in its own right. -* `parseopt `_ +* [parseopt](parseopt.html) The `parseopt` module implements a command line option parser. -* `parsesql `_ +* [parsesql](parsesql.html) The `parsesql` module implements a simple high-performance SQL parser. -* `parsexml `_ +* [parsexml](parsexml.html) The `parsexml` module implements a simple high performance XML/HTML parser. The only encoding that is supported is UTF-8. The parser has been designed to be somewhat error-correcting, so that even some "wild HTML" found on the @@ -394,37 +394,37 @@ Parsers Docutils -------- -* `packages/docutils/highlite `_ +* [packages/docutils/highlite](highlite.html) Source highlighter for programming or markup languages. Currently, only a few languages are supported, other languages may be added. The interface supports one language nested in another. -* `packages/docutils/rst `_ +* [packages/docutils/rst](rst.html) This module implements a reStructuredText parser. A large subset is implemented. Some features of the markdown wiki syntax are also supported. -* `packages/docutils/rstast `_ +* [packages/docutils/rstast](rstast.html) This module implements an AST for the reStructuredText parser. -* `packages/docutils/rstgen `_ +* [packages/docutils/rstgen](rstgen.html) This module implements a generator of HTML/Latex from reStructuredText. XML Processing -------------- -* `xmltree `_ +* [xmltree](xmltree.html) A simple XML tree. More efficient and simpler than the DOM. It also contains a macro for XML/HTML code generation. -* `xmlparser `_ +* [xmlparser](xmlparser.html) This module parses an XML document and creates its XML tree representation. Generators ---------- -* `htmlgen `_ +* [htmlgen](htmlgen.html) This module implements a simple XML and HTML code generator. Each commonly used HTML tag has a corresponding macro that generates a string with its HTML representation. @@ -433,81 +433,81 @@ Generators Hashing ------- -* `base64 `_ +* [base64](base64.html) This module implements a Base64 encoder and decoder. -* `hashes `_ +* [hashes](hashes.html) This module implements efficient computations of hash values for diverse Nim types. -* `md5 `_ +* [md5](md5.html) This module implements the MD5 checksum algorithm. -* `oids `_ +* [oids](oids.html) An OID is a global ID that consists of a timestamp, a unique counter, and a random value. This combination should suffice to produce a globally distributed unique ID. This implementation was extracted from the MongoDB interface and it thus binary compatible with a MongoDB OID. -* `sha1 `_ +* [sha1](sha1.html) This module implements the SHA-1 checksum algorithm. Miscellaneous ------------- -* `browsers `_ +* [browsers](browsers.html) This module implements procs for opening URLs with the user's default browser. -* `colors `_ +* [colors](colors.html) This module implements color handling for Nim. -* `coro `_ +* [coro](coro.html) This module implements experimental coroutines in Nim. -* `enumerate `_ +* [enumerate](enumerate.html) This module implements `enumerate` syntactic sugar based on Nim's macro system. -* `logging `_ +* [logging](logging.html) This module implements a simple logger. -* `segfaults `_ +* [segfaults](segfaults.html) Turns access violations or segfaults into a `NilAccessDefect` exception. -* `sugar `_ +* [sugar](sugar.html) This module implements nice syntactic sugar based on Nim's macro system. -* `unittest `_ +* [unittest](unittest.html) Implements a Unit testing DSL. -* `varints `_ +* [varints](varints.html) Decode variable-length integers that are compatible with SQLite. -* `with `_ +* [with](with.html) This module implements the `with` macro for easy function chaining. Modules for the JS backend -------------------------- -* `asyncjs `_ +* [asyncjs](asyncjs.html) Types and macros for writing asynchronous procedures in JavaScript. -* `dom `_ +* [dom](dom.html) Declaration of the Document Object Model for the JS backend. -* `jsbigints `_ +* [jsbigints](jsbigints.html) Arbitrary precision integers. -* `jsconsole `_ +* [jsconsole](jsconsole.html) Wrapper for the `console` object. -* `jscore `_ +* [jscore](jscore.html) The wrapper of core JavaScript functions. For most purposes, you should be using the `math`, `json`, and `times` stdlib modules instead of this module. -* `jsffi `_ +* [jsffi](jsffi.html) Types and macros for easier interaction with JavaScript. @@ -517,7 +517,7 @@ Impure libraries Regular expressions ------------------- -* `re `_ +* [re](re.html) This module contains procedures and operators for handling regular expressions. The current implementation uses PCRE. @@ -525,15 +525,15 @@ Regular expressions Database support ---------------- -* `db_postgres `_ +* [db_postgres](db_postgres.html) A higher level PostgreSQL database wrapper. The same interface is implemented for other databases too. -* `db_mysql `_ +* [db_mysql](db_mysql.html) A higher level MySQL database wrapper. The same interface is implemented for other databases too. -* `db_sqlite `_ +* [db_sqlite](db_sqlite.html) A higher level SQLite database wrapper. The same interface is implemented for other databases too. @@ -541,7 +541,7 @@ Database support Generic Operating System Services --------------------------------- -* `rdstdin `_ +* [rdstdin](rdstdin.html) This module contains code for reading from stdin. @@ -555,43 +555,43 @@ not contained in the distribution. You can then find them on the website. Windows-specific ---------------- -* `winlean `_ +* [winlean](winlean.html) Contains a wrapper for a small subset of the Win32 API. -* `registry `_ +* [registry](registry.html) Windows registry support. UNIX specific ------------- -* `posix `_ +* [posix](posix.html) Contains a wrapper for the POSIX standard. -* `posix_utils `_ +* [posix_utils](posix_utils.html) Contains helpers for the POSIX standard or specialized for Linux and BSDs. Regular expressions ------------------- -* `pcre `_ +* [pcre](pcre.html) Wrapper for the PCRE library. Database support ---------------- -* `postgres `_ +* [postgres](postgres.html) Contains a wrapper for the PostgreSQL API. -* `mysql `_ +* [mysql](mysql.html) Contains a wrapper for the mySQL API. -* `sqlite3 `_ +* [sqlite3](sqlite3.html) Contains a wrapper for the SQLite 3 API. -* `odbcsql `_ +* [odbcsql](odbcsql.html) interface to the ODBC driver. Network Programming and Internet Protocols ------------------------------------------ -* `openssl `_ +* [openssl](openssl.html) Wrapper for OpenSSL. diff --git a/doc/mm.md b/doc/mm.md index 09b235228e..2ba854adda 100644 --- a/doc/mm.md +++ b/doc/mm.md @@ -35,7 +35,7 @@ the involved heap sizes. The reference counting operations (= "RC ops") do not use atomic instructions and do not have to -- instead entire subgraphs are *moved* between threads. The Nim compiler also aggressively -optimizes away RC ops and exploits `move semantics `_. +optimizes away RC ops and exploits [move semantics](destructors.html#move-semantics). Nim performs a fair share of optimizations for ARC/ORC; you can inspect what it did to your time critical function via `--expandArc:functionName`. @@ -62,7 +62,7 @@ Other MM modes --mm:refc This is the default memory management strategy. It's a deferred reference counting based garbage collector with a simple Mark&Sweep backup GC in order to collect cycles. Heaps are thread-local. - `This document `_ contains further information. + [This document](refc.html) contains further information. --mm:markAndSweep Simple Mark-And-Sweep based garbage collector. Heaps are thread-local. --mm:boehm Boehm based garbage collector, it offers a shared heap. @@ -89,7 +89,7 @@ None Manual Manual Manual `--mm:none` .. default-role:: code .. include:: rstcommon.rst -JavaScript's garbage collector is used for the `JavaScript and NodeJS -`_ compilation targets. -The `NimScript `_ target uses the memory management strategy built into +JavaScript's garbage collector is used for the [JavaScript and NodeJS]( +backends.html#backends-the-javascript-target) compilation targets. +The [NimScript](nims.html) target uses the memory management strategy built into the Nim compiler. diff --git a/doc/nep1.md b/doc/nep1.md index ea928b82e1..0c62e3f9c6 100644 --- a/doc/nep1.md +++ b/doc/nep1.md @@ -21,7 +21,7 @@ library should follow. Note that there can be exceptions to these rules. Nim being as flexible as it is, there will be parts of this style guide that don't make sense in certain contexts. Furthermore, just as -`Python's style guide`_ changes +[Python's style guide](http://legacy.python.org/dev/peps/pep-0008/) changes over time, this style guide will too. These rules will only be enforced for contributions to the Nim diff --git a/doc/nimc.md b/doc/nimc.md index cd980a37bd..1b3318ee60 100644 --- a/doc/nimc.md +++ b/doc/nimc.md @@ -21,10 +21,10 @@ Introduction This document describes the usage of the *Nim compiler* on the different supported platforms. It is not a definition of the Nim -programming language (which is covered in the `manual `_). +programming language (which is covered in the [manual](manual.html)). Nim is free software; it is licensed under the -`MIT License `_. +[MIT License](http://www.opensource.org/licenses/mit-license.php). Compiler Usage @@ -130,13 +130,13 @@ Level Description ===== ============================================ 0 Minimal output level for the compiler. 1 Displays compilation of all the compiled files, including those imported - by other modules or through the `compile pragma - `_. + by other modules or through the [compile pragma]( + manual.html#implementation-specific-pragmas-compile-pragma). This is the default level. 2 Displays compilation statistics, enumerates the dynamic libraries that will be loaded by the final binary, and dumps to - standard output the result of applying `a filter to the source code - `_ if any filter was used during compilation. + standard output the result of applying [a filter to the source code]( + filters.html) if any filter was used during compilation. 3 In addition to the previous levels dumps a debug stack trace for compiler developers. ===== ============================================ @@ -147,16 +147,16 @@ Compile-time symbols Through the `-d:x`:option: or `--define:x`:option: switch you can define compile-time symbols for conditional compilation. The defined switches can be checked in -source code with the `when statement -`_ and -`defined proc `_. The typical use of this switch is +source code with the [when statement]( +manual.html#statements-and-expressions-when-statement) and +[defined proc](system.html#defined,untyped). The typical use of this switch is to enable builds in release mode (`-d:release`:option:) where optimizations are enabled for better performance. Another common use is the `-d:ssl`:option: switch to activate SSL sockets. Additionally, you may pass a value along with the symbol: `-d:x=y`:option: -which may be used in conjunction with the `compile-time define -pragmas`_ +which may be used in conjunction with the [compile-time define +pragmas](manual.html#implementation-specific-pragmas-compileminustime-define-pragmas) to override symbols during build time. Compile-time symbols are completely **case insensitive** and underscores are @@ -268,7 +268,7 @@ The `_r` suffix is used for release builds, `_d` is for debug builds. This makes it easy to delete all generated files. The `--nimcache`:option: -`compiler switch <#compiler-usage-commandminusline-switches>`_ can be used to +[compiler switch][command-line switches] can be used to to change the ``nimcache`` directory. However, the generated C code is not platform-independent. C code generated for @@ -355,7 +355,7 @@ There are two ways to compile for Android: terminal programs (Termux) and with the NDK (Android Native Development Kit). The first one is to treat Android as a simple Linux and use -`Termux `_ to connect and run the Nim compiler +[Termux](https://wiki.termux.com) to connect and run the Nim compiler directly on android as if it was Linux. These programs are console-only programs that can't be distributed in the Play Store. @@ -363,8 +363,8 @@ Use regular `nim c`:cmd: inside termux to make Android terminal programs. Normal Android apps are written in Java, to use Nim inside an Android app you need a small Java stub that calls out to a native library written in -Nim using the `NDK `_. You can also use -`native-activity `_ +Nim using the [NDK](https://developer.android.com/ndk). You can also use +[native-activity](https://developer.android.com/ndk/samples/sample_na) to have the Java stub be auto-generated for you. Use `nim c -c --cpu:arm --os:android -d:androidNDK --noMain:on`:cmd: to @@ -444,8 +444,8 @@ or setup a ``nim.cfg`` file like so:: --passL="-specs=$DEVKITPRO/libnx/switch.specs -L$DEVKITPRO/libnx/lib -lnx" The devkitPro setup must be the same as the default with their new installer -`here for Mac/Linux `_ or -`here for Windows `_. +[here for Mac/Linux](https://github.com/devkitPro/pacman/releases) or +[here for Windows](https://github.com/devkitPro/installer/releases). For example, with the above-mentioned config: @@ -455,7 +455,7 @@ For example, with the above-mentioned config: This will generate a file called ``switchhomebrew.elf`` which can then be turned into an nro file with the `elf2nro`:cmd: tool in the devkitPro release. Examples can be found at -`the nim-libnx github repo `_. +[the nim-libnx github repo](https://github.com/jyapayne/nim-libnx.git). There are a few things that don't work because the devkitPro libraries don't support them. They are: @@ -512,7 +512,7 @@ Define Effect This only works with `--mm:none`:option:, `--mm:arc`:option: and `--mm:orc`:option:. `useRealtimeGC` Enables support of Nim's GC for *soft* realtime - systems. See the documentation of the `mm `_ + systems. See the documentation of the [mm](mm.html) for further information. `logGC` Enable GC logging to stdout. `nodejs` The JS target is actually ``node.js``. @@ -591,7 +591,7 @@ The typical compiler usage involves using the `compile`:option: or `c`:option: command to transform a ``.nim`` file into one or more ``.c`` files which are then compiled with the platform's C compiler into a static binary. However, there are other commands to compile to C++, Objective-C, or JavaScript. More details -can be read in the `Nim Backend Integration document `_. +can be read in the [Nim Backend Integration document](backends.html). Nim documentation tools @@ -599,13 +599,13 @@ Nim documentation tools Nim provides the `doc`:idx: command to generate HTML documentation from ``.nim`` source files. Only exported symbols will appear in -the output. For more details `see the docgen documentation `_. +the output. For more details see [the docgen documentation](docgen.html). Nim idetools integration ======================== Nim provides language integration with external IDEs through the -idetools command. See the documentation of `idetools `_ +idetools command. See the documentation of [idetools](idetools.html) for further information. .. @@ -666,7 +666,7 @@ The `--opt:size`:option: flag instructs Nim to optimize code generation for smal size (with the help of the C compiler), the `-flto`:option: flags enable link-time optimization in the compiler and linker. -Check the `Cross-compilation`_ section for instructions on how to compile the +Check the [Cross-compilation] section for instructions on how to compile the program for your target. @@ -717,8 +717,8 @@ Currently only Zephyr and FreeRTOS support these configurations. Nim for realtime systems ======================== -See the `--mm:arc` or `--mm:orc` memory management settings in `MM `_ for further -information. +See the `--mm:arc` or `--mm:orc` memory management settings in +[MM](mm.html) for further information. Signal handling in Nim diff --git a/doc/niminst.md b/doc/niminst.md index 2da8664a9a..b1bbade146 100644 --- a/doc/niminst.md +++ b/doc/niminst.md @@ -14,7 +14,7 @@ Introduction niminst is a tool to generate an installer for a Nim program. Currently it can create an installer for Windows -via `Inno Setup `_ as well as +via [Inno Setup](http://www.jrsoftware.org/isinfo.php) as well as installation/deinstallation scripts for UNIX. Later versions will support Linux' package management systems. @@ -26,7 +26,7 @@ systems. Configuration file ================== -niminst uses the Nim `parsecfg `_ module to parse the +niminst uses the Nim [parsecfg](parsecfg.html) module to parse the configuration file. Here's an example of how the syntax looks like: .. include:: mytest.cfg diff --git a/doc/nims.md b/doc/nims.md index 5870f7bb61..ecda526fb2 100644 --- a/doc/nims.md +++ b/doc/nims.md @@ -29,7 +29,7 @@ previous settings): ``$project.nim``. This file can be skipped with the same `--skipProjCfg`:option: command line option. -For available procs and implementation details see `nimscript `_. +For available procs and implementation details see [nimscript](nimscript.html). Limitations @@ -61,52 +61,53 @@ Standard library modules At least the following standard library modules are available: -* `macros `_ -* `os `_ -* `strutils `_ -* `math `_ -* `distros `_ -* `sugar `_ -* `algorithm `_ -* `base64 `_ -* `bitops `_ -* `chains `_ -* `colors `_ -* `complex `_ -* `htmlgen `_ -* `httpcore `_ -* `lenientops `_ -* `mersenne `_ -* `options `_ -* `parseutils `_ -* `punycode `_ -* `random `_ -* `stats `_ -* `strformat `_ -* `strmisc `_ -* `strscans `_ -* `unicode `_ -* `uri `_ -* `std/editdistance `_ -* `std/wordwrap `_ -* `std/sums `_ -* `parsecsv `_ -* `parsecfg `_ -* `parsesql `_ -* `xmlparser `_ -* `htmlparser `_ -* `ropes `_ -* `json `_ -* `parsejson `_ -* `strtabs `_ -* `unidecode `_ +* [macros](macros.html) +* [os](os.html) +* [strutils](strutils.html) +* [math](math.html) +* [distros](distros.html) +* [sugar](sugar.html) +* [algorithm](algorithm.html) +* [base64](base64.html) +* [bitops](bitops.html) +* [chains](chains.html) +* [colors](colors.html) +* [complex](complex.html) +* [htmlgen](htmlgen.html) +* [httpcore](httpcore.html) +* [lenientops](lenientops.html) +* [mersenne](mersenne.html) +* [options](options.html) +* [parseutils](parseutils.html) +* [punycode](punycode.html) +* [random](punycode.html) +* [stats](stats.html) +* [strformat](strformat.html) +* [strmisc](strmisc.html) +* [strscans](strscans.html) +* [unicode](unicode.html) +* [uri](uri.html) +* [std/editdistance](editdistance.html) +* [std/wordwrap](wordwrap.html) +* [std/sums](sums.html) +* [parsecsv](parsecsv.html) +* [parsecfg](parsecfg.html) +* [parsesql](parsesql.html) +* [xmlparser](xmlparser.html) +* [htmlparser](htmlparser.html) +* [ropes](ropes.html) +* [json](json.html) +* [parsejson](parsejson.html) +* [strtabs](strtabs.html) +* [unidecode](unidecode.html) -In addition to the standard Nim syntax (`system `_ module), +In addition to the standard Nim syntax ([system](system.html) module), NimScripts support the procs and templates defined in the -`nimscript `_ module too. +[nimscript](nimscript.html) module too. See also: -* `Check the tests for more information about modules compatible with NimScript. `_ +* [Check the tests for more information about modules compatible with NimScript]( + https://github.com/nim-lang/Nim/blob/devel/tests/test_nimscript.nims) NimScript as a configuration file @@ -169,14 +170,14 @@ Task Description ========= =================================================== -Look at the module `distros `_ for some support of the +Look at the module [distros](distros.html) for some support of the OS's native package managers. Nimble integration ================== -See the `Nimble readme `_ +See the [Nimble readme](https://github.com/nim-lang/nimble#readme) for more information. @@ -297,7 +298,7 @@ translations.cfg ``` -* `Nimterlingua `_ +* [Nimterlingua](https://nimble.directory/pkg/nimterlingua) Graceful Fallback @@ -329,14 +330,15 @@ Evolving Scripting language --------------------------- NimScript evolves together with Nim, -`occasionally new features might become available on NimScript `_ , +[occasionally new features might become available on NimScript]( +https://github.com/nim-lang/Nim/pulls?utf8=%E2%9C%93&q=nimscript), adapted from compiled Nim or added as new features on both. Scripting Language with a Package Manager ----------------------------------------- You can create your own modules to be compatible with NimScript, -and check `Nimble `_ +and check [Nimble](https://nimble.directory) to search for third party modules that may work on NimScript. DevOps Scripting @@ -345,4 +347,5 @@ DevOps Scripting You can use NimScript to deploy to production, run tests, build projects, do benchmarks, generate documentation, and all kinds of DevOps/SysAdmin specific tasks. -* `An example of a third party NimScript that can be used as a project-agnostic tool. `_ +* [An example of a third party NimScript that can be used as a project-agnostic + tool.](https://github.com/kaushalmodi/nim_config#list-available-tasks) diff --git a/doc/nimsuggest.md b/doc/nimsuggest.md index bfa4237071..97cb2b1fab 100644 --- a/doc/nimsuggest.md +++ b/doc/nimsuggest.md @@ -20,7 +20,7 @@ definition of symbols or suggestions for completion. This document will guide you through the available options. If you want to look at practical examples of nimsuggest support you can look at the -`various editor integrations `_ +[various editor integrations](https://github.com/Araq/Nim/wiki/Editor-Support) already available. @@ -49,7 +49,7 @@ via sockets is more reasonable so that is the default. It listens to port 6000 by default. Nimsuggest is basically a frontend for the nim compiler so `--path`:option: flags and -`config files `_ +[config files](https://nim-lang.org/docs/nimc.html#compiler-usage-configuration-files) can be used to specify additional dependencies like `nimsuggest --stdin --debug --path:"dependencies" myproject.nim`:cmd:. @@ -113,8 +113,8 @@ The `sug` Nimsuggest command performs a query about possible completion symbols at some point in the file. The typical usage scenario for this option is to call it after the -user has typed the dot character for `the object oriented call -syntax `_. +user has typed the dot character for [the object oriented call +syntax](tut2.html#object-oriented-programming-method-call-syntax). Nimsuggest will try to return the suggestions sorted first by scope (from innermost to outermost) and then by item name. diff --git a/doc/packaging.md b/doc/packaging.md index 6445017271..9a1cc0f6eb 100644 --- a/doc/packaging.md +++ b/doc/packaging.md @@ -4,9 +4,9 @@ Packaging Nim This page provide hints on distributing Nim using OS packages. -See `distros `_ for tools to detect Linux distribution at runtime. +See [distros](distros.html) for tools to detect Linux distribution at runtime. -See `here `_ for how to +See [here](intern.html#bootstrapping-the-compiler-reproducible-builds) for how to compile reproducible builds. Supported architectures diff --git a/doc/refc.md b/doc/refc.md index 504ba386c8..6e4672ac5f 100644 --- a/doc/refc.md +++ b/doc/refc.md @@ -121,7 +121,7 @@ Keeping track of memory If you need to pass around memory allocated by Nim to C, you can use the procs `GC_ref` and `GC_unref` to mark objects as referenced to avoid them being freed by the garbage collector. -Other useful procs from `system `_ you can use to keep track of memory are: +Other useful procs from [system](system.html) you can use to keep track of memory are: * `getTotalMem()` Returns the amount of total memory managed by the garbage collector. * `getOccupiedMem()` Bytes reserved by the garbage collector and used by objects. diff --git a/doc/spawn.txt b/doc/spawn.txt index 6c80d292b2..ed25ad5fdd 100644 --- a/doc/spawn.txt +++ b/doc/spawn.txt @@ -6,7 +6,7 @@ Nim has two flavors of parallelism: 1) `Structured`:idx parallelism via the ``parallel`` statement. 2) `Unstructured`:idx: parallelism via the standalone ``spawn`` statement. -Both need the `threadpool `_ module to work. +Both need the [threadpool](threadpool.html) module to work. Somewhat confusingly, ``spawn`` is also used in the ``parallel`` statement with slightly different semantics. ``spawn`` always takes a call expression of diff --git a/doc/testament.md b/doc/testament.md index 6d0b3a69cd..812b109849 100644 --- a/doc/testament.md +++ b/doc/testament.md @@ -9,7 +9,7 @@ Testament is an advanced automatic unittests runner for Nim tests, is used for the development of Nim itself, offers process isolation for your tests, it can generate statistics about test cases, supports multiple targets (C, C++, ObjectiveC, JavaScript, etc.), -simulated `Dry-Runs `_, +simulated [Dry-Runs](https://en.wikipedia.org/wiki/Dry_run_(testing)), has logging, can generate HTML reports, skip tests from a file, and more, so can be useful to run your tests, even the most complex ones. @@ -185,8 +185,10 @@ Example "template" **to edit** and write a Testament unittest: * As you can see the "Spec" is just a `discard """ """`. * Spec has sane defaults, so you don't need to provide them all, any simple assert will work just fine. -* `This is not the full spec of Testament, check the Testament Spec on GitHub, see parseSpec(). `_ -* `Nim itself uses Testament, so there are plenty of test examples. `_ +* This is not the full spec of Testament, check [the Testament Spec on GitHub, + see parseSpec()](https://github.com/nim-lang/Nim/blob/devel/testament/specs.nim#L315). +* Nim itself uses Testament, so [there are plenty of test examples]( + https://github.com/nim-lang/Nim/tree/devel/tests). * Has some built-in CI compatibility, like Azure Pipelines, etc. @@ -195,11 +197,10 @@ Inline hints, warnings and errors (notes) Testing the line, column, kind and message of hints, warnings and errors can be written inline like so: - -.. code-block:: nim - + ```nim {.warning: "warning!!"} #[tt.Warning ^ warning!! [User] ]# + ``` The opening `#[tt.` marks the message line. The `^` marks the message column. @@ -207,18 +208,17 @@ The `^` marks the message column. Inline messages can be combined with `nimout` when `nimoutFull` is false (default). This allows testing for expected messages from other modules: -.. code-block:: nim - + ```nim discard """ nimout: "config.nims(1, 1) Hint: some hint message [User]" """ {.warning: "warning!!"} #[tt.Warning ^ warning!! [User] ]# + ``` Multiple messages for a line can be checked by delimiting messages with ';': -.. code-block:: nim - + ```nim discard """ matrix: "--errorMax:0 --styleCheck:error" """ @@ -227,6 +227,7 @@ Multiple messages for a line can be checked by delimiting messages with ';': ^ 'generic_proc' should be: 'genericProc'; tt.Error ^ 'a_a' should be: 'aA' ]# discard + ``` Use `--errorMax:0` in `matrix`, or `cmd: "nim check $file"` when testing for multiple 'Error' messages. @@ -327,4 +328,4 @@ Tests without Spec: See also: -* `Unittest `_ +* [Unittest](unittest.html) diff --git a/doc/tools.md b/doc/tools.md index 0de4ac9143..6849103f9e 100644 --- a/doc/tools.md +++ b/doc/tools.md @@ -7,36 +7,36 @@ Tools available with Nim The standard distribution ships with the following tools: -- | `Hot code reloading `_ +- | [Hot code reloading](hcr.html) | The "Hot code reloading" feature is built into the compiler but has its own document explaining how it works. -- | `Documentation generator `_ +- | [Documentation generator](docgen.html) | The builtin document generator `nim doc`:cmd: generates HTML documentation from ``.nim`` source files. -- | `Nimsuggest for IDE support `_ +- | [Nimsuggest for IDE support](nimsuggest.html) | Through the `nimsuggest`:cmd: tool, any IDE can query a ``.nim`` source file and obtain useful information like the definition of symbols or suggestions for completion. -- | `C2nim `_ +- | [C2nim](https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst) | C to Nim source converter. Translates C header files to Nim. -- | `niminst `_ +- | [niminst](niminst.html) | niminst is a tool to generate an installer for a Nim program. -- | `nimgrep `_ +- | [nimgrep](nimgrep.html) | Nim search and replace utility. - | nimpretty | `nimpretty`:cmd: is a Nim source code beautifier, to format code according to the official style guide. -- | `testament `_ +- | [testament](https://nim-lang.github.io/Nim/testament.html) | `testament`:cmd: is an advanced automatic *unittests runner* for Nim tests, is used for the development of Nim itself, offers process isolation for your tests, it can generate statistics about test cases, supports multiple targets (C, JS, etc), - `simulated Dry-Runs `_, + [simulated Dry-Runs](https://en.wikipedia.org/wiki/Dry_run_(testing)), has logging, can generate HTML reports, skip tests from a file, and more, so can be useful to run your tests, even the most complex ones. From a302b26e0eaa7a2074d3caac72f7c8a7e79993c5 Mon Sep 17 00:00:00 2001 From: Bung Date: Tue, 20 Sep 2022 06:31:40 +0800 Subject: [PATCH 08/17] =?UTF-8?q?fix=20#19882=20Improve=20error=20message?= =?UTF-8?q?=20when=20instantiating=20generics=20that=20lac=E2=80=A6=20(#20?= =?UTF-8?q?356)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix #19882 Improve error message when instantiating generics that lack a type * Update tests/errmsgs/t19882.nim Co-authored-by: Clay Sweetser --- compiler/seminst.nim | 3 ++- tests/errmsgs/t19882.nim | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/errmsgs/t19882.nim diff --git a/compiler/seminst.nim b/compiler/seminst.nim index f5810c8143..bd5eb1ec31 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -54,7 +54,8 @@ iterator instantiateGenericParamList(c: PContext, n: PNode, pt: TIdTable): PSym # later by semAsgn in return type inference scenario t = q.typ else: - localError(c.config, a.info, errCannotInstantiateX % s.name.s) + if q.typ.kind != tyCompositeTypeClass: + localError(c.config, a.info, errCannotInstantiateX % s.name.s) t = errorType(c) elif t.kind in {tyGenericParam, tyConcept}: localError(c.config, a.info, errCannotInstantiateX % q.name.s) diff --git a/tests/errmsgs/t19882.nim b/tests/errmsgs/t19882.nim new file mode 100644 index 0000000000..1f2f95ab73 --- /dev/null +++ b/tests/errmsgs/t19882.nim @@ -0,0 +1,10 @@ + +discard """ + errormsg: "cannot instantiate 'A[T, P]' inside of type definition: 'init'; Maybe generic arguments are missing?" +""" +type A[T,P] = object + b:T + c:P +proc init(): ref A = + new(result) +var a = init() From 08c02f0236eec5957d54cc7f263461e06cb09a2a Mon Sep 17 00:00:00 2001 From: Bung Date: Tue, 20 Sep 2022 20:50:48 +0800 Subject: [PATCH 09/17] =?UTF-8?q?report=20expression=20has=20no=20type=20o?= =?UTF-8?q?ther=20than=20has=20to=20be=20used=20(or=20discarded=E2=80=A6?= =?UTF-8?q?=20(#20392)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit report expression has no type other than has to be used (or discarded) when typ is tyNone in discardCheck --- compiler/semstmts.nim | 3 +++ tests/errmsgs/t8064.nim | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 tests/errmsgs/t8064.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 64d56f8129..1e8930fc9b 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -139,6 +139,9 @@ proc discardCheck(c: PContext, result: PNode, flags: TExprFlags) = var n = newNodeI(nkDiscardStmt, result.info, 1) n[0] = result elif result.typ.kind != tyError and c.config.cmd != cmdInteractive: + if result.typ.kind == tyNone: + localError(c.config, result.info, "expression has no type: " & + renderTree(result, {renderNoComments})) var n = result while n.kind in skipForDiscardable: if n.kind == nkTryStmt: n = n[0] diff --git a/tests/errmsgs/t8064.nim b/tests/errmsgs/t8064.nim new file mode 100644 index 0000000000..10bb862993 --- /dev/null +++ b/tests/errmsgs/t8064.nim @@ -0,0 +1,6 @@ +discard """ + errormsg: "expression has no type: values" +""" +import tables + +values \ No newline at end of file From 3dc302662e2665a0c1467a290c689f40d8a2e263 Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 20 Sep 2022 15:58:22 +0300 Subject: [PATCH 10/17] clarify distinct pointer type `nil` change (#20376) * clarify distinct pointer type `nil` change * Update changelog.md [skip ci] Co-authored-by: Clay Sweetser * remove extra quote [skip ci] Co-authored-by: Clay Sweetser --- changelog.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 9364ab573a..3281f65264 100644 --- a/changelog.md +++ b/changelog.md @@ -29,7 +29,15 @@ - `nimPreviewDotLikeOps` is going to be removed or deprecated. - The `{.this.}` pragma, deprecated since 0.19, has been removed. -- `nil` is no longer a valid value for distinct pointer types. +- `nil` literals can no longer be directly assigned to variables or fields of `distinct` pointer types. They must be converted instead. + ```nim + type Foo = distinct ptr int + + # Before: + var x: Foo = nil + # After: + var x: Foo = Foo(nil) + ``` - Removed two type pragma syntaxes deprecated since 0.20, namely `type Foo = object {.final.}`, and `type Foo {.final.} [T] = object`. From 4a1bda667c74361c121460ca7d80cfcbf003d8d7 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 20 Sep 2022 20:59:50 +0800 Subject: [PATCH 11/17] turn nimIncrSeqV3 into deadcode (#20388) --- changelog.md | 4 +- compiler/condsyms.nim | 2 +- lib/system/gc.nim | 31 +------------ lib/system/sysstr.nim | 105 ++++++++++++++++++------------------------ 4 files changed, 50 insertions(+), 92 deletions(-) diff --git a/changelog.md b/changelog.md index 3281f65264..ff943fe885 100644 --- a/changelog.md +++ b/changelog.md @@ -26,7 +26,7 @@ - `shallowCopy` is removed for ARC/ORC. Use `move` when possible or combine assignment and `sink` for optimization purposes. -- `nimPreviewDotLikeOps` is going to be removed or deprecated. +- The `nimPreviewDotLikeOps` define is going to be removed or deprecated. - The `{.this.}` pragma, deprecated since 0.19, has been removed. - `nil` literals can no longer be directly assigned to variables or fields of `distinct` pointer types. They must be converted instead. @@ -44,6 +44,8 @@ - [Overloadable enums](https://nim-lang.github.io/Nim/manual_experimental.html#overloadable-enum-value-names) are no longer experimental. +- Removed the `nimIncrSeqV3` define. + - Static linking against OpenSSL versions below 1.1, previously done by setting `-d:openssl10`, is no longer supported. diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index d811f2d750..332a802ab8 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -70,7 +70,7 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimVmExportFixed") # deadcode defineSymbol("nimHasSymOwnerInMacro") # deadcode defineSymbol("nimNewRuntime") # deadcode - defineSymbol("nimIncrSeqV3") # xxx: turn this into deadcode + defineSymbol("nimIncrSeqV3") # deadcode defineSymbol("nimAshr") # deadcode defineSymbol("nimNoNilSeqs") # deadcode defineSymbol("nimNoNilSeqs2") # deadcode diff --git a/lib/system/gc.nim b/lib/system/gc.nim index e50e80f11d..4ab76c05e2 100644 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -561,35 +561,8 @@ proc growObj(old: pointer, newsize: int, gch: var GcHeap): pointer = gcTrace(res, csAllocated) track("growObj old", ol, 0) track("growObj new", res, newsize) - when defined(nimIncrSeqV3): - # since we steal the old seq's contents, we set the old length to 0. - cast[PGenericSeq](old).len = 0 - elif reallyDealloc: - sysAssert(allocInv(gch.region), "growObj before dealloc") - if ol.refcount shr rcShift <=% 1: - # free immediately to save space: - if (ol.refcount and ZctFlag) != 0: - var j = gch.zct.len-1 - var d = gch.zct.d - while j >= 0: - if d[j] == ol: - d[j] = res - break - dec(j) - beforeDealloc(gch, ol, "growObj stack trash") - decTypeSize(ol, ol.typ) - rawDealloc(gch.region, ol) - else: - # we split the old refcount in 2 parts. XXX This is still not entirely - # correct if the pointer that receives growObj's result is on the stack. - # A better fix would be to emit the location specific write barrier for - # 'growObj', but this is lots of more work and who knows what new problems - # this would create. - res.refcount = rcIncrement - decRef(ol) - else: - sysAssert(ol.typ != nil, "growObj: 5") - zeroMem(ol, sizeof(Cell)) + # since we steal the old seq's contents, we set the old length to 0. + cast[PGenericSeq](old).len = 0 when useCellIds: inc gch.idGenerator res.id = gch.idGenerator * 1000_000 + gch.gcThreadId diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index c4f0db7182..7655d90041 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -160,13 +160,9 @@ proc addChar(s: NimString, c: char): NimString = result = s if result.len >= result.space: let r = resize(result.space) - when defined(nimIncrSeqV3): - result = rawNewStringNoInit(r) - result.len = s.len - copyMem(addr result.data[0], unsafeAddr(s.data[0]), s.len+1) - else: - result = cast[NimString](growObj(result, - sizeof(TGenericSeq) + r + 1)) + result = rawNewStringNoInit(r) + result.len = s.len + copyMem(addr result.data[0], unsafeAddr(s.data[0]), s.len+1) result.reserved = r result.data[result.len] = c result.data[result.len+1] = '\0' @@ -210,12 +206,9 @@ proc resizeString(dest: NimString, addlen: int): NimString {.compilerRtl.} = result = dest else: # slow path: let sp = max(resize(dest.space), dest.len + addlen) - when defined(nimIncrSeqV3): - result = rawNewStringNoInit(sp) - result.len = dest.len - copyMem(addr result.data[0], unsafeAddr(dest.data[0]), dest.len+1) - else: - result = cast[NimString](growObj(dest, sizeof(TGenericSeq) + sp + 1)) + result = rawNewStringNoInit(sp) + result.len = dest.len + copyMem(addr result.data[0], unsafeAddr(dest.data[0]), dest.len+1) result.reserved = sp #result = rawNewString(sp) #copyMem(result, dest, dest.len + sizeof(TGenericSeq)) @@ -239,14 +232,11 @@ proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} = result = s else: let sp = max(resize(s.space), newLen) - when defined(nimIncrSeqV3): - result = rawNewStringNoInit(sp) - result.len = s.len - copyMem(addr result.data[0], unsafeAddr(s.data[0]), s.len+1) - zeroMem(addr result.data[s.len], newLen - s.len) - result.reserved = sp - else: - result = resizeString(s, n) + result = rawNewStringNoInit(sp) + result.len = s.len + copyMem(addr result.data[0], unsafeAddr(s.data[0]), s.len+1) + zeroMem(addr result.data[s.len], newLen - s.len) + result.reserved = sp result.len = n result.data[n] = '\0' @@ -282,15 +272,11 @@ proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerproc.} = result = s if result.len >= result.space: let r = resize(result.space) - when defined(nimIncrSeqV3): - result = cast[PGenericSeq](newSeq(typ, r)) - result.len = s.len - copyMem(dataPointer(result, typ.base.align), dataPointer(s, typ.base.align), s.len * typ.base.size) - # since we steal the content from 's', it's crucial to set s's len to 0. - s.len = 0 - else: - result = cast[PGenericSeq](growObj(result, align(GenericSeqSize, typ.base.align) + typ.base.size * r)) - result.reserved = r + result = cast[PGenericSeq](newSeq(typ, r)) + result.len = s.len + copyMem(dataPointer(result, typ.base.align), dataPointer(s, typ.base.align), s.len * typ.base.size) + # since we steal the content from 's', it's crucial to set s's len to 0. + s.len = 0 proc setLengthSeq(seq: PGenericSeq, elemSize, elemAlign, newLen: int): PGenericSeq {. compilerRtl, inl.} = @@ -324,36 +310,33 @@ proc setLengthSeqV2(s: PGenericSeq, typ: PNimType, newLen: int): PGenericSeq {. if s == nil: result = cast[PGenericSeq](newSeq(typ, newLen)) else: - when defined(nimIncrSeqV3): - let elemSize = typ.base.size - let elemAlign = typ.base.align - if s.space < newLen: - let r = max(resize(s.space), newLen) - result = cast[PGenericSeq](newSeq(typ, r)) - copyMem(dataPointer(result, elemAlign), dataPointer(s, elemAlign), s.len * elemSize) - # since we steal the content from 's', it's crucial to set s's len to 0. - s.len = 0 - elif newLen < s.len: - result = s - # we need to decref here, otherwise the GC leaks! - when not defined(boehmGC) and not defined(nogc) and - not defined(gcMarkAndSweep) and not defined(gogc) and - not defined(gcRegions): - if ntfNoRefs notin typ.base.flags: - for i in newLen..result.len-1: - forAllChildrenAux(dataPointer(result, elemAlign, elemSize, i), - extGetCellType(result).base, waZctDecRef) + let elemSize = typ.base.size + let elemAlign = typ.base.align + if s.space < newLen: + let r = max(resize(s.space), newLen) + result = cast[PGenericSeq](newSeq(typ, r)) + copyMem(dataPointer(result, elemAlign), dataPointer(s, elemAlign), s.len * elemSize) + # since we steal the content from 's', it's crucial to set s's len to 0. + s.len = 0 + elif newLen < s.len: + result = s + # we need to decref here, otherwise the GC leaks! + when not defined(boehmGC) and not defined(nogc) and + not defined(gcMarkAndSweep) and not defined(gogc) and + not defined(gcRegions): + if ntfNoRefs notin typ.base.flags: + for i in newLen..result.len-1: + forAllChildrenAux(dataPointer(result, elemAlign, elemSize, i), + extGetCellType(result).base, waZctDecRef) - # XXX: zeroing out the memory can still result in crashes if a wiped-out - # cell is aliased by another pointer (ie proc parameter or a let variable). - # This is a tough problem, because even if we don't zeroMem here, in the - # presence of user defined destructors, the user will expect the cell to be - # "destroyed" thus creating the same problem. We can destroy the cell in the - # finalizer of the sequence, but this makes destruction non-deterministic. - zeroMem(dataPointer(result, elemAlign, elemSize, newLen), (result.len-%newLen) *% elemSize) - else: - result = s - zeroMem(dataPointer(result, elemAlign, elemSize, result.len), (newLen-%result.len) *% elemSize) - result.len = newLen + # XXX: zeroing out the memory can still result in crashes if a wiped-out + # cell is aliased by another pointer (ie proc parameter or a let variable). + # This is a tough problem, because even if we don't zeroMem here, in the + # presence of user defined destructors, the user will expect the cell to be + # "destroyed" thus creating the same problem. We can destroy the cell in the + # finalizer of the sequence, but this makes destruction non-deterministic. + zeroMem(dataPointer(result, elemAlign, elemSize, newLen), (result.len-%newLen) *% elemSize) else: - result = setLengthSeq(s, typ.base.size, newLen) + result = s + zeroMem(dataPointer(result, elemAlign, elemSize, result.len), (newLen-%result.len) *% elemSize) + result.len = newLen From de70128fccba242af9b0c6fa0840d03d3566e58d Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 21 Sep 2022 04:14:01 +0800 Subject: [PATCH 12/17] follow up #19968; add more tests (#20396) --- tests/stdlib/tsystem.nim | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/stdlib/tsystem.nim b/tests/stdlib/tsystem.nim index a90a1d1d9f..5efc9fd38d 100644 --- a/tests/stdlib/tsystem.nim +++ b/tests/stdlib/tsystem.nim @@ -88,6 +88,66 @@ block: doAssert y.b == {} +block: + type + X = object + a: string + b: int + + var y = X(b: 1314) + + reset(y) + + doAssert y.b == 0 + +block: + type + X = object + a: string + b: float + + var y = X(b: 1314.521) + + reset(y) + + doAssert y.b == 0.0 + +block: + type + X = object + a: string + b: string + + var y = X(b: "1314") + + reset(y) + + doAssert y.b == "" + +block: + type + X = object + a: string + b: seq[int] + + var y = X(b: @[1, 3]) + + reset(y) + + doAssert y.b == @[] + +block: + type + X = object + a: string + b: tuple[a: int, b: string] + + var y = X(b: (1, "cc")) + + reset(y) + + doAssert y.b == (0, "") + block: type Color = enum From e0c1159fb3f1f392698f071485d3e43e1e7f1a36 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 21 Sep 2022 16:29:39 +0800 Subject: [PATCH 13/17] fixes #20391; make of operator work with generics for ORC (#20395) --- compiler/ccgtypes.nim | 2 +- tests/method/tmethod_issues.nim | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 16768685b5..654e266ba7 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -1280,7 +1280,7 @@ proc genTypeInfo2Name(m: BModule; t: PType): Rope = var it = t while it != nil: it = it.skipTypes(skipPtrs) - if it.sym != nil: + if it.sym != nil and tfFromGeneric notin it.flags: var m = it.sym.owner while m != nil and m.kind != skModule: m = m.owner if m == nil or sfSystemModule in m.flags: diff --git a/tests/method/tmethod_issues.nim b/tests/method/tmethod_issues.nim index 07d4635f6e..daaa465227 100644 --- a/tests/method/tmethod_issues.nim +++ b/tests/method/tmethod_issues.nim @@ -160,3 +160,11 @@ proc main() = main() +block: # bug #20391 + type Container[T] = ref object of RootRef + item: T + + let a = Container[int]() + + doAssert a of Container[int] + doAssert not (a of Container[string]) From ebb1b7af231e492da3e2c101adfd4d482e488fa4 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 21 Sep 2022 05:37:13 -0300 Subject: [PATCH 14/17] RFC-460 implemented (#19771) * RFC-460 implemented * RFC-460 implemented * RFC-460 implemented * Fix dumb GitHub autoupdate on changelog --- changelog.md | 1 + lib/system/seqs_v2.nim | 16 ++++++++++++++++ lib/system/strs_v2.nim | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/changelog.md b/changelog.md index ff943fe885..ea22028397 100644 --- a/changelog.md +++ b/changelog.md @@ -85,6 +85,7 @@ `replaceChildren`, `replaceWith`, `scrollIntoViewIfNeeded`, `setHTML`, `toggleAttribute`, and `matches` to `std/dom`. - Added [`jsre.hasIndices`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices) +- Added `capacity` for `string` and `seq` to return the current capacity, see https://github.com/nim-lang/RFCs/issues/460 [//]: # "Deprecations:" - Deprecated `selfExe` for Nimscript. diff --git a/lib/system/seqs_v2.nim b/lib/system/seqs_v2.nim index 1194f40eff..42d9938c55 100644 --- a/lib/system/seqs_v2.nim +++ b/lib/system/seqs_v2.nim @@ -129,3 +129,19 @@ proc setLen[T](s: var seq[T], newlen: Natural) = proc newSeq[T](s: var seq[T], len: Natural) = shrink(s, 0) setLen(s, len) + + +template capacityImpl(sek: NimSeqV2): int = + if sek.p != nil: sek.p.cap else: 0 + +func capacity*[T](self: seq[T]): int {.inline.} = + ## Returns the current capacity of the seq. + # See https://github.com/nim-lang/RFCs/issues/460 + runnableExamples: + var lst = newSeqOfCap[string](cap = 42) + lst.add "Nim" + assert lst.capacity == 42 + + {.cast(noSideEffect).}: + let sek = unsafeAddr self + result = capacityImpl(cast[ptr NimSeqV2](sek)[]) diff --git a/lib/system/strs_v2.nim b/lib/system/strs_v2.nim index 6944cdc589..74b9e7cd98 100644 --- a/lib/system/strs_v2.nim +++ b/lib/system/strs_v2.nim @@ -175,3 +175,19 @@ proc prepareMutation*(s: var string) {.inline.} = {.cast(noSideEffect).}: let s = unsafeAddr s nimPrepareStrMutationV2(cast[ptr NimStringV2](s)[]) + + +template capacityImpl(str: NimStringV2): int = + if str.p != nil: str.p.cap else: 0 + +func capacity*(self: string): int {.inline.} = + ## Returns the current capacity of the string. + # See https://github.com/nim-lang/RFCs/issues/460 + runnableExamples: + var str = newStringOfCap(cap = 42) + str.add "Nim" + assert str.capacity == 42 + + {.cast(noSideEffect).}: + let str = unsafeAddr self + result = capacityImpl(cast[ptr NimStringV2](str)[]) From 4133698f2de09cd4d1c9ff3ef44dd0bb6e31693a Mon Sep 17 00:00:00 2001 From: Judd Date: Thu, 22 Sep 2022 03:00:55 +0800 Subject: [PATCH 15/17] Update manual.md (#20394) * Update manual.md update outdated information on `ObservableStores`. * Update manual.md add `base` pragma to fix the warning. * Update doc/manual.md accept. Co-authored-by: Clay Sweetser * Update manual.md update example code. * Update manual.md 1. more updates to help keeping readers on track. 1. fix typos. Co-authored-by: Clay Sweetser --- doc/manual.md | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/doc/manual.md b/doc/manual.md index bd17f7b23d..cd19f93a61 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -4248,16 +4248,16 @@ observable differences in behavior: ``` -However, the current implementation produces a warning in these cases. -There are different ways to deal with this warning: - -1. Disable the warning via `{.push warning[ObservableStores]: off.}` ... `{.pop.}`. - Then one may need to ensure that `p` only raises *before* any stores to `result` - happen. - -2. One can use a temporary helper variable, for example instead of `x = p(8)` - use `let tmp = p(8); x = tmp`. +The compiler can produce a warning in these cases, however this behavior is +turned off by default. It can be enabled for a section of code via the +`warning[ObservableStores]` and `push`/`pop` pragmas. Take the above code +as an example: + ```nim + {.push warning[ObservableStores]: on.} + main() + {.pop.} + ``` Overloading of the subscript operator ------------------------------------- @@ -4331,7 +4331,7 @@ dispatching: Unit = ref object of Thing x: int - method collide(a, b: Thing) {.inline.} = + method collide(a, b: Thing) {.base, inline.} = quit "to override!" method collide(a: Thing, b: Unit) {.inline.} = @@ -4636,7 +4636,7 @@ the "implicitly convertible" type relation (see [Convertible relation]): A converter can also be explicitly invoked for improved readability. Note that implicit converter chaining is not supported: If there is a converter from -type A to type B and from type B to type C the implicit conversion from A to C +type A to type B and from type B to type C, the implicit conversion from A to C is not provided. @@ -4810,8 +4810,8 @@ Instead of a `try finally` statement a `defer` statement can be used, which avoids lexical nesting and offers more flexibility in terms of scoping as shown below. -Any statements following the `defer` in the current block will be considered -to be in an implicit try block: +Any statements following the `defer` will be considered +to be in an implicit try block in the current block: ```nim test = "nim c $1" proc main = @@ -4834,7 +4834,7 @@ Is rewritten to: ``` When `defer` is at the outermost scope of a template/macro, its scope extends -to the block where the template is called from: +to the block where the template/macro is called from: ```nim test = "nim c $1" template safeOpenDefer(f, path) = @@ -5002,7 +5002,7 @@ possibly raised exceptions; the algorithm operates on `p`'s call graph: The call is optimistically assumed to have no effect. Rule 2 compensates for this case. 2. Every expression `e` of some proc type within a call that is passed to parameter - marked as `.effectsOf` is assumed to be called indirectly and thus + marked as `.effectsOf` of proc `p` is assumed to be called indirectly and thus its raises list is added to `p`'s raises list. 3. Every call to a proc `q` which has an unknown body (due to a forward declaration) is assumed to @@ -5149,14 +5149,15 @@ procedure types without such lists: ## this will fail because toBeCalled1 uses MyEffect which was forbidden by ProcType1: caller1(toBeCalled1) - ## this is OK because both toBeCalled1 and ProcType1 have the same requirements: + ## this is OK because both toBeCalled2 and ProcType1 have the same requirements: caller1(toBeCalled2) ## these are OK because ProcType2 doesn't have any effect requirement: caller2(toBeCalled1) caller2(toBeCalled2) ``` -`ProcType2` is a subtype of `ProcType1`. Unlike with tags, the parent context - the function which calls other functions with forbidden effects - doesn't inherit the forbidden list of effects. +`ProcType2` is a subtype of `ProcType1`. Unlike with the `tags` pragma, the parent context - the +function which calls other functions with forbidden effects - doesn't inherit the forbidden list of effects. Side effects From 70c25c45d61926beca789fda0e57a10cbeef81e3 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 22 Sep 2022 03:04:33 +0800 Subject: [PATCH 16/17] fixes #20397; fixes stylecheck regression (#20398) * fixes #20397; fixes stylecheck * add testcase --- compiler/linter.nim | 1 + tests/stylecheck/t20397.nim | 4 ++++ tests/stylecheck/t20397_1.nim | 8 ++++++++ tests/stylecheck/t20397_2.nim | 7 +++++++ 4 files changed, 20 insertions(+) create mode 100644 tests/stylecheck/t20397.nim create mode 100644 tests/stylecheck/t20397_1.nim create mode 100644 tests/stylecheck/t20397_2.nim diff --git a/compiler/linter.nim b/compiler/linter.nim index 2c0ad4d6f4..0c2aaef792 100644 --- a/compiler/linter.nim +++ b/compiler/linter.nim @@ -93,6 +93,7 @@ proc nep1CheckDefImpl(conf: ConfigRef; info: TLineInfo; s: PSym; k: TSymKind) = template styleCheckDef*(ctx: PContext; info: TLineInfo; sym: PSym; k: TSymKind) = ## Check symbol definitions adhere to NEP1 style rules. if optStyleCheck in ctx.config.options and # ignore if styleChecks are off + {optStyleHint, optStyleError} * ctx.config.globalOptions != {} and # check only if hint/error is enabled hintName in ctx.config.notes and # ignore if name checks are not requested ctx.config.belongsToProjectPackage(ctx.module) and # ignore foreign packages optStyleUsages notin ctx.config.globalOptions and # ignore if requested to only check name usage diff --git a/tests/stylecheck/t20397.nim b/tests/stylecheck/t20397.nim new file mode 100644 index 0000000000..486a97d73e --- /dev/null +++ b/tests/stylecheck/t20397.nim @@ -0,0 +1,4 @@ +{.hintAsError[Name]:on.} +var a_b = 1 +discard a_b +{.hintAsError[Name]:off.} \ No newline at end of file diff --git a/tests/stylecheck/t20397_1.nim b/tests/stylecheck/t20397_1.nim new file mode 100644 index 0000000000..24f5791f89 --- /dev/null +++ b/tests/stylecheck/t20397_1.nim @@ -0,0 +1,8 @@ +discard """ + matrix: "--styleCheck:off" +""" + +{.hintAsError[Name]:on.} +var a_b = 1 +discard a_b +{.hintAsError[Name]:off.} \ No newline at end of file diff --git a/tests/stylecheck/t20397_2.nim b/tests/stylecheck/t20397_2.nim new file mode 100644 index 0000000000..3b8e1c4d64 --- /dev/null +++ b/tests/stylecheck/t20397_2.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "'a_b' should be: 'aB'" + matrix: "--styleCheck:error" +""" + +var a_b = 1 +discard a_b \ No newline at end of file From de089d7fdb48a25069c3716ba00774b60c3da370 Mon Sep 17 00:00:00 2001 From: Bung Date: Thu, 22 Sep 2022 06:01:22 +0800 Subject: [PATCH 17/17] contentLength default to -1 if not present (#19835) * contentLength default to -1 if not present * `httpclient.contentLength` changelog --- changelog.md | 1 + lib/pure/httpclient.nim | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index ea22028397..d70a4367d8 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## Changes affecting backward compatibility +- `httpclient.contentLength` default to `-1` if the Content-Length header is not set in the response, it followed Apache HttpClient(Java), http(go) and .Net HttpWebResponse(C#) behavior. Previously raise `ValueError`. - `addr` is now available for all addressable locations, `unsafeAddr` is now deprecated and an alias for `addr`. diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index dcd1f87d6c..405fadc2f9 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -274,9 +274,9 @@ proc contentLength*(response: Response | AsyncResponse): int = ## This is effectively the value of the "Content-Length" header. ## ## A `ValueError` exception will be raised if the value is not an integer. - var contentLengthHeader = response.headers.getOrDefault("Content-Length") + ## If the Content-Length header is not set in the response, ContentLength is set to the value -1. + var contentLengthHeader = response.headers.getOrDefault("Content-Length", @["-1"]) result = contentLengthHeader.parseInt() - doAssert(result >= 0 and result <= high(int32)) proc lastModified*(response: Response | AsyncResponse): DateTime = ## Retrieves the specified response's last modified time.