summary refs log tree commit diff stats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
...
* fixes #4695; closure iterators support for JS backend (#23493)ringabout2024-04-181-0/+4
| | | | | | | | | | | | | | | | | | | | | | | fixes #4695 ref https://github.com/nim-lang/Nim/pull/15818 Since `nkState` is only for the main loop state labels and `nkGotoState` is used only for dispatching the `:state` (since https://github.com/nim-lang/Nim/pull/7770), it's feasible to rewrite the loop body into a single case-based dispatcher, which enables support for JS, VM backend. `nkState` Node is replaced by a label and Node pair and `nkGotoState` is only used for intermediary processing. Backends only need to implement `nkBreakState` and `closureIterSetupExc` to support closure iterators. pending https://github.com/nim-lang/Nim/pull/23484 <del> I also observed some performance boost for C backend in the release mode (not in the danger mode though, I suppose the old implementation is optimized into computed goto in the danger mode) </del> allPathsAsgnResult???
* allow Nix builds by not calling git in isGitRepo for Nimble (#23515)Jakub2024-04-181-10/+3
| | | | | | | | | | | | | | | Because `isGitRepo()` call requires `/bin/sh` it will always fail when building Nim in a Nix build sandbox, and the check doesn't even make sense if Nix already provides Nimble source code. Since for Nimble `allowBundled` is set to `true` this effectlvely does not change behavior for normal builds, but does avoid ugly hacks when building in Nix which lacks `/bin/sh` and fails to call `git`. Reference: * https://github.com/status-im/nimbus-eth2/pull/6180#discussion_r1570237858 Signed-off-by: Jakub Sokołowski <jakub@status.im>
* strictdefs for `repr` so that it can used for debugging purposes in t… ↵ringabout2024-04-151-2/+2
| | | | | (#23501) …he compiler
* fixes #23487; JS chckNilDisp is wrong (#23490)ringabout2024-04-131-1/+1
| | | | | fixes #23487 uses JSRef
* fix JSON deep copy description (#23495)Pouriya Jamshidi2024-04-121-1/+1
| | | | | | Hi, This is a tiny change, fixing the error in the documentation of JSON's deep copy proc.
* fixes #4299 #12492 #10849; lambda lifting for JS backend (#23484)ringabout2024-04-112-1/+13
| | | | | | | | fixes #4299 fixes #12492 fixes #10849 It binds `function` with `env`: `function.bind(:env)` to ease codegen for now
* Better documentation for typedthreads module (#23483)Antoine Delègue2024-04-111-27/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added a second example inside the `typedthreads` file. Also, add a more detailed introduction. When Nim is one's first programming language, a short explanation of what a thread is might not hurt. For reference, the thread documentation of other languages looks like this: - https://en.cppreference.com/w/cpp/thread/thread - https://doc.rust-lang.org/std/thread/ The documentation of a module is the first place one will look when using a standard library feature, so I think it is important to have a few usable examples for the main modules. This is the example added ```nim import locks var l: Lock proc threadFunc(obj: ptr seq[int]) {.thread.} = withLock l: for i in 0..<100: obj[].add(obj[].len * obj[].len) proc threadHandler() = var thr: array[0..4, Thread[ptr seq[int]]] var s = newSeq[int]() for i in 0..high(thr): createThread(thr[i], threadFunc, s.addr) joinThreads(thr) echo s initLock(l) threadHandler() deinitLock(l) ``` Sharing memory between threads is very very common, so I think having an example showcasing this is crucial. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes addr/hiddenAddr in strictdefs (#23477)ringabout2024-04-101-1/+1
|
* Update encodings.nim, fix `open` with bad arg raising no `EncodingError` ↵lit2024-04-061-1/+1
| | | | | | (#23481) On POSIX, `std/encodings` uses iconv, and `iconv_open` returns `(iconv_t) -1` on failure, not `NULL`
* remove `internalNew` from system (#23475)ringabout2024-04-041-3/+0
|
* fixes #16771; lower `swap` for JS backend (#23473)ringabout2024-04-031-3/+1
| | | | | | | | | | | | fixes #16771 follow up https://github.com/nim-lang/Nim/pull/16536 Ideally it should be handled in the IR part in the future I have also checked the double evaluation of `swap` in the JS runtime https://github.com/nim-lang/Nim/issues/16779, that might be solved by a copy flag or something. Well, it should be best solved in the IR so that it doesn't bother backends anymore.
* Update syncio.nim, fixes "open by FileHandle" doesn't work on Windows (#23456)lit2024-04-031-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Reprodution if on Windows: ```Nim when defined(windows): var file: File let succ = file.open(<aFileHandle>) ``` then `succ` will be false. If tested, it can be found to fail with errno `22` and message: `Invalid argument` ## Problem After some investigations and tests, I found it's due to the `mode` argument for `fdopen`. Currently `NoInheritFlag`(`'N'` in Windows) is added to `mode` arg passed to `_fdopen`, but if referring to [Windows `_fdopen` doc](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fdopen-wfdopen?view=msvc-170), you'll find there is no `'N'` describled. That's `'N'` is not accepted by `_fdopen`. Therefore, the demo above will fail. ## In Addition To begin with, technologically speaking, when opening with a `fileHandle`(or called `fd`), there is no concept of fd-inheritable as `fd` is opened already. In POSIX, `NoInheritFlag` is defined as `e`. It's pointed out in [POSIX `open` man-doc](https://www.man7.org/linux/man-pages/man3/fopen.3.html) that `e` in mode is ignored for fdopen(), which means `e` for `fdopen()` is not wanted, just allowed. Therefore, better to also not pass `e` to `fdopen` --- In all, that's this PR.
* dynlib keeps exported functions alive in emscripten (#23469)ringabout2024-04-021-5/+12
| | | | | | | | | | | | | | | | | | | ref https://forum.nim-lang.org/t/11338 ref https://github.com/beef331/wasm3/blob/master/src/wasm3/exporter.nim ref https://github.com/emscripten-core/emscripten/issues/6233 ref https://github.com/emscripten-core/emscripten/blob/3.1.56/system/include/emscripten/em_macros.h#L10 `EMSCRIPTEN_KEEPALIVE` is a macro that is used to prevent unused functions from being deadcode eliminated in emscripten, which is a simple wrapper around `__attribute__((used))`. This PR follows suits and expects dynlib is supposed to keep these functions alive. In the future, `exportwasm` might be introduced. After this PR, a function with `{.dynlib, exportc.}` can be reused from other wasm programs reliably.
* Fix compile time errors when using tables on 8/16-bits systems. (#23450)Gianmarco2024-03-281-1/+4
| | | Refer to the discussion in #23439.
* Change unicode lookup tables to have int32 elements to support platforms ↵Gianmarco2024-03-252-9/+9
| | | | | | | | | | | | | | | where sizeof(int) < 4 (#23433) Fixes an issue that comes up when using strutils.`%` or any other strutils/strformat feature that uses the unicode lookup tables behind the scenes, on systems where ints are than 32-bit wide. Tested with: ```bash ./koch test cat lib ``` Refer to the discussion in #23125.
* fix atomicarc increment (#23427)Jaremy Creechley2024-03-251-1/+1
| | | | | | | | | | | | The fix to the atomicArc looks to use `-1` as the check value from the `SharedPtr` solution. However, it should be `-rcIncrement` since the refcount is bit shifted in ARC/ORC. I discovered this playing around doing atomic updates of refcounts in a user library. Related to https://github.com/nim-lang/Nim/issues/22711 @ringabout I believe you ported the sharedptr fix?
* Adds support for custom ASTs in the Nim parser (#23417)Andreas Rumpf2024-03-181-1/+1
|
* chore: fix some typos (#23412)soonsouth2024-03-161-2/+2
| | | Signed-off-by: soonsouth <cuibuwei@163.com>
* fix BigInt conversion, xOffset/yOffset to int from int64 (#23404)Chancy K2024-03-151-1/+1
| | | | | Problem described here: https://github.com/karaxnim/karax/issues/284 Co-authored-by: Chancy Kennedy <chancy@conciergecloset.com>
* Fix #23381, Use `sink` and `lent` to avoid Future[object] making a copy (#23389)握猫猫2024-03-141-10/+16
| | | | | | | | | fix #23381 As for the read function, the original plan was to use lent for annotation, but after my experiments, it still produced copies, so I had to move it out. Now the `read` function cannot be called repeatedly
* fixes #22166; adds sideeffects for `close` and `setFilePos` (#23380)ringabout2024-03-091-2/+2
| | | fixes #22166
* fix `isAbsolute` broken when `nodejs` on Windows (#23365)litlighilit2024-03-041-3/+3
| | | | | | | | | | | When target is nodejs, `isAbsolute` used to only check in the POSIX flavor, i.e. for js backend on Windows, ```nim isAbsolute(r"C:\Windows") == false ``` This fixes it.
* ref #23333; fixes AF_INET6 value on Linux (#23334)ringabout2024-03-031-1/+1
| | | ref #23333
* Update browsers.nim, deprecate unimplemented `openDefaultBrowser()` (#23332)litlighilit2024-03-031-14/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | For this [proc](https://github.com/nim-lang/Nim/blob/773c066634d831a968bb464eab35b25a00026525/lib/pure/browsers.nim#L83) `proc openDefaultBrowser*() {.since: (1, 1).}`: though it's documented to open default browser with `about:blank` page, it behaves differently: - On Windows, it failed and open no window - On Linux(Debian with Kde), it opens not default browser but `Konqueror` I have paid much effort to implement this variant, but even the implementation on Windows is considerably complex. In short, it's not only hard but unworthy to fix this. Just as Araq [said](https://github.com/nim-lang/Nim/issues/22250#issuecomment-1631360617), we shall remove the `proc openDefaultBrowser*() {.since: (1, 1).}` variant --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* strformat: detect format string errors at compile-time (#23356)Jacek Sieka2024-03-031-39/+97
| | | | | | | | | | | | This also prevents unwanted `raises: [ValueError]` effects from bubbling up from correct format strings which makes `fmt` broadly unusable with `raises`. The old runtime-based `formatValue` overloads are kept for backwards-compatibility, should anyone be using runtime format strings. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* ORC: added -d:nimOrcStats switch and related API (#23272)Andreas Rumpf2024-02-214-18/+62
|
* Remove count field from Deque (#23318)Tomohiro2024-02-201-51/+46
| | | | This PR removes `count` field from `Deque` and get `count` from `tail - head`.
* fixes #23304; uses `snprintf` instead of `sprintf` (#23322)ringabout2024-02-204-9/+12
| | | fixes #23304
* fixes refc with non-var destructor; cancel warnings (#23156)ringabout2024-02-132-2/+4
| | | fixes https://forum.nim-lang.org/t/10807
* Remove mask field from Deque (#23299)Tomohiro2024-02-111-5/+6
| | | | | | | | | It seems Deque doesn't need `mask` field because `data.len - 1` equals to `mask`. Deque without `mask` field passes test `tests/stdlib/tdeques.nim`. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Add items and contains to heapqueue (#23296)Antonis Geralis2024-02-091-0/+15
| | | | The implementation of these functions are trivial yet they were missing from the module.
* fixes #23275; Add `==` for Deque (#23276)Tomohiro2024-02-081-1/+28
|
* follow up #22380; fixes incorrect usages of `newWideCString` (#23278)ringabout2024-02-054-5/+6
| | | follow up #22380
* Docs-improve: os.getCurrentCompilerExe replace with clearer short-desc (#23270)litlighilit2024-02-021-1/+1
| | | | | | | | | | | | | | | | | The doc for `getCurrentCompilerExe` was originally added at [this commit](https://github.com/nim-lang/Nim/commit/c4e3c4ca2d0a1f44ed1e3dd9db564b66031f0843), saying "`getAppFilename` at CT", and modified as "This is `getAppFilename()`_ at compile time..." since [this](https://github.com/nim-lang/Nim/commit/0c2c2dca2a8a3bcdb9729021d1f4734b8db9efbd#diff-8ed10106605d9e0e3f28a927432acd8312e96791c96dbb126a52a7010cf4b44a) Which means "at compile time, get result innerly from Nim compiler via `getAppFilename`", not "get from nim programs". Thus, the doc was confusing, only mentioning `compile time` and `getAppFilename` --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* Additional speed ups of complex.pow (#23264)Angel Ezquerra2024-01-291-8/+25
| | | | | | | | | | | | | | | | | | | | | This PR speeds up complex.pow when both base and exponent are real; when only the exponent is real; and when the base is Euler's number. These are some pretty common cases which appear in many formulas. The speed ups are pretty significant. According to my measurements (using the timeit library) when both base and exponent are real the speedup is ~2x; when only the exponent is real it is ~1.5x and when the base is Euler's number it is ~2x. There is no measurable difference when using other exponents which makes sense since I refactored the code a little to reduce the total number of branches that are needed to get to the final "fallback" branch, and those branches have less comparisons. Anecdotally the fallback case feels slightly faster, but the improvement is so small that I cannot claim an improvement. If it is there it is perhaps in the order of 3 or 4%. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Update cmdline.nim, fix broken (dragged) doc-reference for getAppFile… ↵litlighilit2024-01-281-4/+4
| | | | | | | | (#23262) In doc, there are 4 references for `getAppFilename` `getAppFilename` is still in `os`, but the references refer it as if it's in the current module `cmdline`
* clean up goto exceptions; remove the setjmp.h dep (#23259)ringabout2024-01-273-35/+53
|
* Fix system.currentSourcePath() documentation [backport 2.0] (#23243)rockcavera2024-01-231-4/+5
| | | | | The documentation links for `parentDir()` and `getCurrentDir()` are broken as they are no longer part of `std/os`. Link changed to `std/private/ospaths2`.
* remove unreachable code (#23244)ringabout2024-01-221-1/+0
|
* fixes a broken link in `std/algorithm` (#23246)ringabout2024-01-221-1/+1
| | | https://nim-lang.github.io/Nim/manual.html#procedures-do-notation
* Speed up complex.pow when the exponent is 2.0 or 0.5 (#23237)Angel Ezquerra2024-01-201-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR speeds up the calculation of the power of a complex number when the exponent is 2.0 or 0.5 (i.e the square and the square root of a complex number). These are probably two of (if not) the most common exponents. The speed up that is achieved according to my measurements (using the timeit library) when the exponent is set to 2.0 or 0.5 is > x7, while there is no measurable difference when using other exponents. For the record, this is the function I used to mesure the performance: ```nim import std/complex import timeit proc calculcatePows(v: seq[Complex], factor: Complex): seq[Complex] {.noinit, discardable.} = result = newSeq[Complex](v.len) for n in 0 ..< v.len: result[n] = pow(v[n], factor) let v: seq[Complex64] = collect: for n in 0 ..< 1000: complex(float(n)) echo timeGo(calculcatePows(v, complex(1.5))) echo timeGo(calculcatePows(v, complex(0.5))) echo timeGo(calculcatePows(v, complex(2.0))) ``` Which with the original code got: > [177μs 857.03ns] ± [1μs 234.85ns] per loop (mean ± std. dev. of 7 runs, 1000 loops each) > [128μs 217.92ns] ± [1μs 630.93ns] per loop (mean ± std. dev. of 7 runs, 1000 loops each) > [136μs 220.16ns] ± [3μs 475.56ns] per loop (mean ± std. dev. of 7 runs, 1000 loops each) While with the improved code got: > [176μs 884.30ns] ± [1μs 307.30ns] per loop (mean ± std. dev. of 7 runs, 1000 loops each) > [23μs 160.79ns] ± [340.18ns] per loop (mean ± std. dev. of 7 runs, 10000 loops each) > [19μs 93.29ns] ± [1μs 128.92ns] per loop (mean ± std. dev. of 7 runs, 10000 loops each) That is, the new optimized path is 5.6 (23 vs 128 us per loop) to 7.16 times faster (19 vs 136 us per loop), while the non-optimized path takes the same time as the original code.
* fix mime types data (#23226)Bung2024-01-191-1725/+851
| | | | | | generated via https://github.com/bung87/mimetypes_gen source data: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co
* Make std/math classify work without `--passc:-fast-math`. (#23211)Angel Ezquerra2024-01-181-3/+2
| | | | By using the existing isNaN function we can make std/math's classify function work even if `--passc:-fast-math` is used.
* workaround arrayWith issues (#23230)ringabout2024-01-181-1/+2
| | | I'm working on it, but it's quite tricky. I will fix it soon
* Add `^` operator support for Rational numbers (#23219)Angel Ezquerra2024-01-181-0/+20
| | | | Since pow() cannot be supported for rationals, we support negative integer exponents instead.
* fixes #23223; prevents `insert` self-assignment (#23225)ringabout2024-01-181-0/+2
| | | fixes #23223
* remove unnecessary workaround from `arrayWith` (#23208)ringabout2024-01-151-2/+1
| | | The problem was fixed by https://github.com/nim-lang/Nim/pull/23195
* patches for #23129 (#23198)ringabout2024-01-111-1/+1
| | | fixes it in the normal situation
* fixes #22923; fixes `=dup` issues (#23182)ringabout2024-01-111-1/+2
| | | fixes #22923
* Docs:strutils. Expand `multiReplace` docs, add runnableExamples (#23181)Zoom2024-01-081-7/+20
| | | | | | | | | - Clarified the implications of order of operation. - Mentioned overlapping isn't handled - Added the runnableExamples block Fixes #23160, which supposedly should have been fixed in an earlier PR #23022, but the wording was still not clear enough to my liking, which the raised issue kind of confirms.