summary refs log tree commit diff stats
Commit message (Collapse)AuthorAgeFilesLines
* remove bad type inference behavior for enum identifiers (#23588)metagn2024-05-102-7/+22
| | | | | | | | | | | | | | | refs https://github.com/nim-lang/Nim/issues/23586#issuecomment-2102113750 In #20091 a bad kind of type inference was mistakenly left in where if an identifier `abc` had an expected type of an enum type `Enum`, and `Enum` had a member called `abc`, the identifier would change to be that enum member. This causes bugs where a local symbol can have the same name as an enum member but have a different value. I had assumed this behavior was removed since but it wasn't, and CI seems to pass having it removed. A separate PR needs to be made for the 2.0 branch because these lines were moved around during a refactoring in #23123 which is not in 2.0.
* adds Nim-related mimetypes back (#23589)ringabout2024-05-102-0/+9
| | | ref https://github.com/nim-lang/Nim/pull/23226
* Improve strutils.rsplit doc, proc and iterator have oppose result order. ↵lit2024-05-101-6/+6
| | | | | | | | | | | | | | (#23570) [`rsplit iterator`](https://nim-lang.org/docs/strutils.html#rsplit.i,string,char,int) yields substring in reversed order, while [`proc rsplit`](https://nim-lang.org/docs/strutils.html#rsplit%2Cstring%2Cchar%2Cint)'s order is not reversed, but its doc only declare ``` The same as the rsplit iterator, but is a func that returns a sequence of substrings. ```
* fixes #23552; Invalid codegen when trying to mannualy delete distinct seq ↵ringabout2024-05-082-6/+16
| | | | | (#23558) fixes #23552
* Add a note about the sideeffect pragma (#23543)Antonis Geralis2024-05-081-0/+2
|
* Add Complex version of almostEqual function (#23549)Angel Ezquerra2024-05-082-3/+21
| | | | | | | | This adds a version of `almostEqual` (which was already available for floats) thata works with `Complex[SomeFloat]`. Proof that this is needed is that the first thing that the complex.nim runnable examples block did before this commit was define (an incomplete) `almostEqual` function that worked with complex values.
* fix semFinishOperands for bracket expressions [backport:2.0] (#23571)metagn2024-05-082-7/+32
| | | | | | | | | | | | | | | | fixes #23568, fixes #23310 In #23091 `semFinishOperands` was changed to not be called for `mArrGet` and `mArrPut`, presumably in preparation for #23188 (not sure why it was needed in #23091, maybe they got mixed together), since the compiler handles these later and needs the first argument to not be completely "typed" since brackets can serve as explicit generic instantiations in which case the first argument would have to be an unresolved generic proc (not accepted by `finishOperand`). In this PR we just make it so `mArrGet` and `mArrPut` specifically skip calling `finishOperand` on the first argument. This way the generic arguments in the explicit instantiation get typed, but not the unresolved generic proc.
* fixes 12381, HttpClient socket handle leak (#23575)Marius Andra2024-05-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Bug Fixes https://github.com/nim-lang/Nim/issues/12381 - HttpClient socket handle leak To replicate the bug, run the following code in a loop: ```nim import httpclient while true: echo "New loop" var client = newHttpClient(timeout = 1000) try: let response = client.request("http://10.44.0.4/bla", httpMethod = HttpPost, body = "boo") echo "HTTP " & $response.status except CatchableError as e: echo "Error sending logs: " & $e.msg finally: echo "Finally" client.close() ``` Note the IP address as the hostname. I'm directly connecting to a plausible local IP, but one that does not resolve, as I have everything under 10.4.x.x. The output looks like this to me: ``` New loop Error sending logs: Operation timed out Finally New loop Error sending logs: Operation timed out Finally New loop ... ``` In Nim 2.0.4, running the code above leaks the socket: <img width="944" alt="Screenshot 2024-05-05 at 22 00 13" src="https://github.com/nim-lang/Nim/assets/53387/ddac67db-d7df-45e6-b7a5-3d42f79775ea"> ## Fix With the added line of code, each old socket is cleanly removed: <img width="938" alt="Screenshot 2024-05-05 at 21 54 18" src="https://github.com/nim-lang/Nim/assets/53387/5b0b4b2d-d4f0-4e74-a9cf-74aec0c50d2e"> I believe the line below, `closeUnusedFds(ord(domain))` was supposed to clean up the failed connection attempts, but it failed to do so for the last one, assuming it succeeded. Yet it didn't. This fix makes sure failed connections are closed immediately. ## Tests I don't have a test with this PR. When testing locally, the `connect(lastFd, ..)` call on line 2032 blocks for ~75 seconds, ignoring the http timeout. I fear any test I could add would either 1) take way too long, 2) one day run in an environment where my randomly chosen IP is real, yielding in weird flakes. The only bug i can imagine is if running `lastFd.close()` twice is a bad idea. I tested by actually running it twice, and... no crash/op? So seems safe? I'm hoping the CI run will be green, and this will be enough. However I'm happy to take feedback on how I should test this, and do the necessary changes. ~Edit: looks like a test does fail, so moving to a draft while I figure this out.~ Attempt 2 fixed it.
* rework `wasMoved`, `move` on the JS backend (#23577)ringabout2024-05-089-69/+35
| | | | | `reset`, `wasMoved` and `move` doesn't support primitive types, which generate `null` for these types. It is now produce `x = default(...)` in the backend. Ideally it should be done by ast2ir in the future
* fixes #22409; don't check style for enumFieldSymChoice in the function (#23580)ringabout2024-05-083-6/+7
| | | fixes #22409
* fixes #23442, fix for FileId under Windows (#23444)lit2024-05-081-4/+4
| | | | | | | | | | | See according issue: Details: <https://github.com/nim-lang/Nim/issues/23442#issuecomment-2021763669> --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Skips generic owner when mangling instances (#23563)Juan M Gómez2024-05-072-5/+6
|
* bring `telebot` back (#23578)ringabout2024-05-071-1/+1
| | | | | Reverts nim-lang/Nim#23566 ref https://github.com/ba0f3/telebot.nim/commit/afe4ad877ec015091f5b6fde32ecb2502fe59a3f
* fixes CI failure (#23566)ringabout2024-05-041-1/+1
|
* fixes #23556; typeinfo.extendSeq generates random values in ORC (#23557)ringabout2024-05-033-2/+28
| | | | | fixes #23556 It should somehow handle default fields in the future
* Update unicode.nim: cmpRunesIgnoreCase: fix doc format (#23560)lit2024-05-021-6/+6
| | | | | | Its doc used to render wrongly where `>` is considered as quote block: ![image](https://github.com/nim-lang/Nim/assets/97860435/4aeda257-3231-42a5-9dd9-0052950a160e)
* fixes #23419; internal error with void in generic array instantiation (#23550)ringabout2024-05-012-3/+11
| | | | | | | | | fixes #23419 `void` is only supported as fields of objects/tuples. It shouldn't allow void in the array. I didn't merge it with taField because that flag is also used for tyLent, which is allowed in the fields of other types.
* fixes #23321; Error: internal error: openArrayLoc: ref array[0..0, int] (#23548)ringabout2024-04-292-1/+39
| | | | | | | | fixes #23321 In the function `mapType`, ptrs (tyPtr, tyVar, tyLent, tyRef) are mapped into ctPtrToArray, the dereference of which is skipped in the `genref`. We need to skip these ptrs in the function `genOpenArraySlice`.
* fix typo: "As can been seen" to "As can be seen" (#23544)yojiyama72024-04-281-1/+1
|
* fixes #23531; fixes invalid meta type accepted in the object fields (#23532)ringabout2024-04-262-9/+78
| | | | | fixes #23531 fixes #19546 fixes #6982
* fixes #23536; Stack trace with wrong line number when the proc called inside ↵ringabout2024-04-262-6/+34
| | | | | for loop (#23540) fixes #23536
* fixes #23522; fixes pre-existing wrong type for iter in `liftIterSym` (#23538)ringabout2024-04-262-2/+4
| | | fixes #23522
* fixes #23525; an 'emit' pragma cannot be pushed (#23537)ringabout2024-04-241-0/+13
| | | fixes #23525
* adds another fix for concept in JS (#23535)ringabout2024-04-242-5/+13
| | | ref https://github.com/nim-lang/Nim/issues/9550
* fixes #23524; global variables cannot be analysed when injecting `move` (#23529)ringabout2024-04-244-23/+41
| | | | | | | | | | | | fixes #23524 ```nim proc isAnalysableFieldAccess*(orig: PNode; owner: PSym): bool = ... result = n.kind == nkSym and n.sym.owner == owner and {sfGlobal, sfThread, sfCursor} * n.sym.flags == {} and (n.sym.kind != skParam or isSinkParam(n.sym)) ``` In `isAnalysableFieldAccess`, globals, cursors are already rejected
* * fix for the debug line info code generation (#23488)Nikolay Nikolov2024-04-222-23/+73
| | | | Previously, in certain cases, the compiler would generate debug info for the correct line number, but for the wrong .nim source file.
* updated compiler DFA docs (#23527)Andreas Rumpf2024-04-221-13/+3
|
* Fix std/base64.decode out of bounds read (#23526)bptato2024-04-222-1/+3
| | | | inputLen may end up as 0 in the loop if the input string only includes trailing characters. e.g. without the patch, decode(" ") would panic.
* fix #23518 - `<expr> is` crashes nimsuggest (#23523)José Paulo2024-04-211-1/+2
| | | | | | This solution should resolve the nimsuggest crash issue. However, perhaps the problem is in the parser? fix #23518
* fixes commit hashes (#23520)ringabout2024-04-191-2/+2
|
* allow having {.noinit.} on a complex type avoid memsets to 0 for its … ↵heterodoxic2024-04-182-1/+4
| | | | | | | | | | | | | | | | | | | | | (#23388) …instantiations (C/C++ backend) AFAIK, #22802 expanded `noinit`'s utility by allowing the pragma to be attached to types (thanks @jmgomez !). I suggest broadening the scope a bit further: try to avoid `nimZeroMem`s on a type level beyond imported C/C++ types[^1], saving us from annotating the type instantiations with `noinit`. If this change is deemed acceptable, I will also adjust the docs, of course. Adding tests for this change seems a bit problematic, as the effect of this type annotation will be to work with uninitialized memory, which *might* match 0 patterns. [^1]: "complex value types" as already defined here: https://github.com/nim-lang/Nim/blob/94c599687796f4ee3872c8aa866827b9ed33f52b/compiler/cgen.nim#L470-L471
* Fix duplicated member declarations in structs for C++ backend (#23512)HexSegfaultCat2024-04-182-1/+28
| | | | | | | | | | | | | | | When forward declaration is used with pragmas `virtual` or `member`, the declaration in struct is added twice. It happens because of missing check for `sfWasForwarded` pragma. Current compiler generates the following C++ code: ```cpp struct tyObject_Foo__fFO9b6HU7kRnKB9aJA1RApKw { N_LIB_PRIVATE N_NOCONV(void, abc)(NI x_p1); N_LIB_PRIVATE N_NOCONV(virtual void, def)(NI y_p1); N_LIB_PRIVATE N_NOCONV(void, abc)(NI x_p1); N_LIB_PRIVATE N_NOCONV(virtual void, def)(NI y_p1); }; ```
* workaround #23435; real fix pending #23279 (#23436)ringabout2024-04-182-0/+14
| | | | | | | workaround #23435 related to https://github.com/nim-lang/Nim/issues/22852 see also #23279
* bundle atlas with sat (#23375)ringabout2024-04-181-1/+4
| | | | pending https://github.com/nim-lang/atlas/pull/119 pending AtlasStableCommit updates
* remove php code from jsgen (#23502)ringabout2024-04-181-14/+0
| | | | follow up https://github.com/nim-lang/Nim/pull/7606 https://github.com/nim-lang/Nim/pull/13466
* remove `|| []` from jsgen because string cannot be nil anymore (#23508)ringabout2024-04-181-3/+3
| | | introduced in https://github.com/nim-lang/Nim/pull/9411
* fixes #23492; fixes JS float range causes compiler crash (#23517)ringabout2024-04-181-1/+1
| | | | | | | | | | | | | | | fixes #23492 ```nim proc foo = var x: range[1.0 .. 5.0] = 2.0 case x of 1.0..2.0: echo 1 else: echo 3 foo() ```
* fixes #4695; closure iterators support for JS backend (#23493)ringabout2024-04-186-53/+64
| | | | | | | | | | | | | | | | | | | | | | | 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>
* fixes #23505; fixes injectdestructors errors on transformed addr (deref) ↵ringabout2024-04-182-1/+17
| | | | | refs (#23507) fixes #23505
* remove HEAD arraymancer dependency requirement in package CI (#23509)metagn2024-04-171-3/+3
| | | | | Was introduced to handle a break in #23392, according to https://github.com/nim-lang/Nim/pull/23503#issuecomment-2057266475 should not be needed anymore
* fixes #23494; Wrong type in object construction error message (#23504)ringabout2024-04-162-1/+7
| | | fixes #23494
* fixes #23499; don't skip `addr` when constructing `bracketExpr` (#23503)ringabout2024-04-152-1/+11
| | | | | | | | | | | fixes #23499 In the https://github.com/nim-lang/Nim/commit/8990626ca9715a3687b28331aee4ccf242997aa2 the effect of `skipAddr` changed to skip `nkAddr` and `nkHiddenAddr`. Some old code was not adapted. In the https://github.com/nim-lang/Nim/pull/23477, the magic `addr` function was handled in the semantic analysis phase, which causes it be skipped incorrectly
* 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
* [JS backend] improve `discard` statement; ridding of the awkward special ↵ringabout2024-04-132-2/+2
| | | | | | | | | | variable `_` (#23498) According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/Expression_statement, some expression statements need parentheses to make it unambiguous. `_` introduced in the https://github.com/nim-lang/Nim/pull/15789 is unnecessary. We can get rid of it by adding parentheses so that object literals are not ambiguous with block statements.
* 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-1110-71/+118
| | | | | | | | 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-1030-71/+80
|