summary refs log tree commit diff stats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* allow non var deinit for locks and conds: alternative way (#23099)ringabout2023-12-193-17/+17
| | | alternative to https://github.com/nim-lang/Nim/pull/23092
* Fix grammar (#23090)Stephen2023-12-181-1/+1
|
* Show the name of the unexpected exception that was thrown in `std/unittest` ↵Jake Leahy2023-12-171-1/+2
| | | | | (#23087) Show name of error that wasn't expected in an `expect` block
* Mark `macros.error` as `.noreturn.` (#23081)Jake Leahy2023-12-171-1/+6
| | | | | | | | | | | | | | | Closes #14329 Marks `macros.error` as `.noreturn` so that it can be used in expressions. This also fixes the issue that occurred in #19659 where a stmt that could be an expression (Due to having `discardable` procs at the end of other branches) would believe a `noreturn` proc is returning the same type e.g. ```nim proc bar(): int {.discardable.} = discard if true: bar() else: quit(0) # Says that quit is of type `int` and needs to be used/discarded except it actually has no return type ```
* fixes yet another strictdefs bug (#23069)ringabout2023-12-151-0/+3
|
* rationals: support Rational[SomeUnsignedInt] (#23046)shirleyquirk2023-12-151-6/+6
| | | | | | | | fixes #22227 rationale: - `3u - 4u` is supported why not`3u.toRational - 4u.toRational` - all of rationals' api is on SomeInteger, looks like unsigned is declared as supported - math on unsigned rationals is meaningful and useful.
* Param match relax (#23033)Ryan McConnell2023-12-151-2/+3
| | | | | | | | | | | #23032 --------- Co-authored-by: Nikolay Nikolov <nickysn@gmail.com> Co-authored-by: Pylgos <43234674+Pylgos@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Jason Beetham <beefers331@gmail.com>
* fixes #23060; `editDistance` wrongly compare the length of rune strings (#23062)ringabout2023-12-131-1/+1
| | | fixes #23060
* Don't recurse into inner functions during asyncjs transform (#23036)Jake Leahy2023-12-061-0/+2
| | | Closes #13341
* strutils.multiReplace: Making order of replacement explicit (#23022)Joachim Hereth2023-12-021-2/+3
| | | | | | | | | | | | | | | | | | | | | | In the docs for strutils.multiReplace: Making it more explicit that left to right comes before the order in the replacements arg (but that the latter matters too). E.g. ``` echo "ab".multiReplace(@[("a", "1"), ("ax", "2")]) echo "ab".multiReplace(@[("ab", "2"), ("a", "1")]) ``` gives ``` 1b 2 ``` resolves #23016
* related #22534; fixes documentation rendering of custom number literal ↵Erich Reitz2023-12-011-11/+12
| | | | | | | | | | | | | | | routine declaration (#23015) I'm not sure if this is a complete fix, as it does not match the expected output given in the issue. The expected output given in the issue highlights the identifier after the `'` the same color as numeric literals (blue), and this change does not address that. I think that would involve simplifying `nimNumberPostfix`. However, this fixes the issue where the routine declaration was rendered as a string. New rendering: ![Screenshot from 2023-11-30 22-17-17](https://github.com/nim-lang/Nim/assets/80008541/b604ce27-a4ad-496b-82c3-0b568d99a8bf)
* fixes #22852; real bugfix is tied to bug #22672 (#23013)Andreas Rumpf2023-11-301-1/+4
|
* fixes #23006; newSeqUninit -> CT Error; imitate `newStringUninit` (#23007)ringabout2023-11-301-1/+4
| | | fixes #23006
* enable vtable implementation for C++ and make it an experimental feature ↵ringabout2023-11-302-3/+6
| | | | | | | | | | | (#23004) follow up https://github.com/nim-lang/Nim/pull/22991 - [x] turning it into an experimental feature --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* table.`mgetOrPut` without default val (#22994)inv20042023-11-302-4/+65
| | | | | | | | | | | RFC: https://github.com/nim-lang/RFCs/issues/539 - ~~mgetOrPutDefaultImpl template into `tableimpl.nim` to avoid macros~~ - mgetOrPut for `Table`, `TableRef`, `OrderedTable`, `OrderedTableRef` - `tests/stdlib/tmget.nim` tests update --------- Co-authored-by: inv2004 <>
* Silence several Hint[Performance] warnings (#23003)c-blake2023-11-294-6/+5
| | | | With `--mm:arc` one gets the "implicit copy; if possible, rearrange your program's control flow" `Performance` warnings without these `move`s.
* rework the vtable implementation embedding the vtable array directly with ↵ringabout2023-11-282-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | new strictions on methods (#22991) **TODO** - [x] fixes changelog With the new option `nimPreviewVtables`, `methods` are confined in the same module where the type of the first parameter is defined - [x] make it opt in after CI checks its feasibility ## In the following-up PRs - [ ] in the following PRs, refactor code into a more efficient one - [ ] cpp needs special treatments since it cannot embed array in light of the preceding limits: ref https://github.com/nim-lang/Nim/pull/20977#discussion_r1035528927; we can support cpp backends with vtable implementations later on the comprise that uses indirect vtable access --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fix: std/marshal unmarshaling of ref objects (#22983)John Viega2023-11-261-1/+2
| | | | | | | | | | | | | | | | | | | Fixes #16496 ![Marshal doesn't properly unmarshal *most* ref objects; the exceptions being nil ones](https://github-production-user-asset-6210df.s3.amazonaws.com/4764481/285471431-a39ee2c5-5670-4b12-aa10-7a10ba6b5b96.gif) Test case added. Note that this test (t9754) does pass locally, but there are tons of failures by default on OS X arm64, mostly around the bohem GC, so it's pretty spammy, and could easily have missed something. If there are better instructions please do let me know. --------- Co-authored-by: John Viega <viega@Johns-MacBook-Pro.local> Co-authored-by: John Viega <viega@Johns-MBP.localdomain> Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* remove unnecessary side-effects from base64.encode(mime) (#22986)tersec2023-11-251-12/+4
| | | Fixes https://github.com/nim-lang/Nim/issues/22985
* fixes #22286; enforce Non-var T destructors by `nimPreviewNonVarDestructor` ↵ringabout2023-11-251-9/+14
| | | | | | | | | | | | | | | | | | (#22975) fixes #22286 ref https://forum.nim-lang.org/t/10642 For backwards compatibilities, we might need to keep the changes under a preview compiler flag. Let's see how many packags it break. **TODO** in the following PRs - [ ] Turn the `var T` destructors warning into an error with `nimPreviewNonVarDestructor` --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* let `InotifyEvent` type `sizeof`-able (#22958)Derek2023-11-181-1/+2
| | | | Since the `InotifyEvent`s are receive through `read()`, user need the size of the type.
* Fix OSError `errorCode` field is not assigned a value (#22954)握猫猫2023-11-175-48/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | In this PR, the following changes were made: 1. Replaced `raise newException(OSError, osErrorMsg(errno))` in batches with `raiseOSError(errcode)`. 2. Replaced `newException(OSError, osErrorMsg(errno))` in batches with `newOSError(errcode)`. There are still some places that have not been replaced. After checking, they are not system errors in the traditional sense. ```nim proc dlclose(lib: LibHandle) = raise newException(OSError, "dlclose not implemented on Nintendo Switch!") ``` ```nim if not fileExists(result) and not dirExists(result): # consider using: `raiseOSError(osLastError(), result)` raise newException(OSError, "file '" & result & "' does not exist") ``` ```nim proc paramStr*(i: int): string = raise newException(OSError, "paramStr is not implemented on Genode") ```
* 'j' format specifier docs (#22928)Angel Ezquerra2023-11-172-5/+11
| | | | | | | | | | | | This is a small improvement on top of PR #22924, which documents the new 'j' format specifier for Complex numbers. In addition to that it moves the handling of the j specifier into the function that actually implements it (formatValueAsComplexNumber), which seems a little cleaner. --------- Co-authored-by: Angel Ezquerra <angel_ezquerra@keysight.com> Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
* fixes #22932; treats closure iterators as pointers (#22934)ringabout2023-11-141-2/+2
| | | | | | | | fixes #22932 follow up https://github.com/nim-lang/Nim/pull/21629 --------- Co-authored-by: Nickolay Bukreyev <SirNickolas@users.noreply.github.com>
* Add strformat support for Complex numbers (#22924)Angel Ezquerra2023-11-101-1/+36
| | | | | | | | | | | | | | | | | | | | | Before this change strformat used the generic formatValue function for Complex numbers. This meant that it was not possible to control the format of the real and imaginary components of the complex numbers. With this change this now works: ```nim import std/[complex, strformat] let c = complex(1.05000001, -2.000003) echo &"{c:g}" # You now get: (1.05, -2) # while before you'd get a ValueError exception (invalid type in format string for string, expected 's', but got g) ``` The only small drawback of this change is that I had to import complex from strformat. I hope that is not a problem. --------- Co-authored-by: Angel Ezquerra <angel_ezquerra@keysight.com>
* reserve `sysFatal` for `Defect` (#22158)Jacek Sieka2023-11-064-18/+15
| | | | | | | | Per manual, `panics:on` affects _only_ `Defect`:s - thus `sysFatal` should not redirect any other exceptions. Also, when `sysFatal` is used in `nimPanics` mode, it should use regular exception handling pipeline to ensure exception hooks are called consistently for all raised defects.
* fixes #22898; fix #22883 differently (#22900)ringabout2023-11-054-4/+10
| | | | | | fixes #22898 In these cases, the tables/sets are clears or elements are deleted from them. It's reasonable to suppress warnings because the value is not accessed anymore, which means it's safe to ignore the warnings.
* fixes #22860; suppress `AnyEnumConv` warning when iterating over set (#22904)ringabout2023-11-041-1/+4
| | | fixes #22860
* Fix `IndexDefect` errors in httpclient on invalid/weird headers (#22886)Yardanico2023-11-012-11/+26
| | | | | | | | | | | | | | | | | | | | | Continuation of https://github.com/nim-lang/Nim/pull/19262 Fixes https://github.com/nim-lang/Nim/issues/19261 The parsing code is still too lenient (e.g. it will happily parse header names with spaces in them, which is outright invalid by the spec), but I didn't want to touch it beyond the simple changes to make sure that `std/httpclient` won't throw `IndexDefect`s like it does now on those cases: - Multiline header values - No colon after the header name - No value after the header name + colon One question remains - should I keep `toCaseInsensitive` exported in `httpcore` or just copy-paste the implementation? --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22883; replace `default(typeof(` with `reset`; suppress `Unsaf… ↵ringabout2023-11-014-7/+11
| | | | | | | | | | | | | | | | | | | | | | | (#22895) fixes #22883 …eDefault` warnings avoid issues mentioned by https://forum.nim-lang.org namely, it allocated unnecessary stack objects in the loop ```c while (1) { tyObject_N__8DSNqSGSHBKOhI8CqSgAow T5_; nimZeroMem((void *)(&T5_), sizeof(tyObject_N__8DSNqSGSHBKOhI8CqSgAow)); eqsink___test4954_u450((&(*t_p0).data.p->data[i].Field1), T5_); } ``` It might be more efficient in some cases follow up https://github.com/nim-lang/Nim/pull/21821
* complete std prefixes for stdlib (#22887)ringabout2023-10-30137-263/+265
| | | | follow up https://github.com/nim-lang/Nim/pull/22851 follow up https://github.com/nim-lang/Nim/pull/22873
* NIR: VM + refactorings (#22835)Andreas Rumpf2023-10-291-2/+2
|
* Fix #22862 - change the httpclient user-agent to be valid spec-wise (#22882)Yardanico2023-10-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Per https://datatracker.ietf.org/doc/html/rfc9110#name-user-agent a User-Agent is defined as follows: ``` User-Agent = product *( RWS ( product / comment ) ) ``` Where ``` product = token ["/" product-version] product-version = token ``` In this case, `token` is defined in RFC 7230 - https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6: ``` token = 1*tchar tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA ; any VCHAR, except delimiters ``` or, in the original RFC 2616 - https://datatracker.ietf.org/doc/html/rfc2616#section-2.2 (next page): ``` token = 1*<any CHAR except CTLs or separators> separators = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HT ``` which means that a `token` cannot have whitespace. Not sure if this should be in the breaking changelog section - theoretically, some clients might've relied on the old Nim user-agent? For some extra info, some other languages seem to have adopted the same hyphen user agent to specify the language + module, e.g.: - https://github.com/python/cpython/blob/main/Lib/urllib/request.py#L1679 (`Python-urllib/<version>`) Fixes #22862.
* fixes #22868; fixes `std/nre` leaks under ARC/ORC (#22872)ringabout2023-10-271-0/+2
| | | fixes #22868
* deprecate htmlparser (#22870)ringabout2023-10-261-0/+2
| | | | | | | | | ref https://github.com/nim-lang/Nim/pull/22848 see also https://github.com/nim-lang/htmlparser will build the documentation later when everything else is settled --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22856; enables `-d:nimStrictDelete` (#22858)ringabout2023-10-241-5/+1
| | | | | | | | fixes #22856 `-d:nimStrictDelete` is introduced in 1.6.0, which promised to be enabled in the coming versions. To keep backwards incompatibilities, it also extends the feature of `-d:nimAuditDelete`, which now mimics the old behaviors.
* fixes `system.delete` that raises defects (#22857)ringabout2023-10-231-1/+1
|
* fix use after free (#22854)握猫猫2023-10-231-2/+2
| | | | | | 1. `freeAddrInfo` is called prematurely, the variable `myAddr` is still in use 2. Use defer syntax to ensure that `freeAddrInfo` is also called on exceptions
* explicitly import using `std/` in `tempfiles.nim` (#22851)Vindaar2023-10-201-1/+1
| | | | | At least on modern Nim `tempfiles` is not usable if the user has https://github.com/oprypin/nim-random installed, because the compiler picks the nimble path over the stdlib path (apparently).
* fixes #22844; uses arrays to store holeyenums for iterations; much more ↵ringabout2023-10-201-1/+1
| | | | | efficient than sets and reasonable for holeyenums (#22845) fixes #22844
* fix #22834 (#22843)rockcavera2023-10-201-9/+38
| | | | | | | fix #22834 Edit: also fixes `result.addrList` when IPv6, which previously only performed a `result.addrList = cstringArrayToSeq(s.h_addr_list)` which does not provide the textual representation of an IPv6
* fixes #22836; Unnecessary warning on 'options.none' with 'strictDefs'… ↵ringabout2023-10-181-1/+1
| | | | | | | (#22837) … enabled fixes #22836
* the compiler can be compiled with vcc (#22832)Juan M Gómez2023-10-161-1/+1
|
* NIR: store sizes, alignments and offsets in the type graph; beginning… ↵Andreas Rumpf2023-10-162-1/+4
| | | | | (#22822) …s of a patent-pending new VM
* NIR: progress (#22817)Andreas Rumpf2023-10-121-0/+3
| | | | | | Done: - [x] Implement conversions to openArray/varargs. - [x] Implement index/range checking.
* NIR: Nim intermediate representation (#22777)Andreas Rumpf2023-10-117-30/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Theoretical Benefits / Plans: - Typed assembler-like language. - Allows for a CPS transformation. - Can replace the existing C backend by a new C backend. - Can replace the VM. - Can do more effective "not nil" checking and static array bounds checking. - Can be used instead of the DFA. - Easily translatable to LLVM. - Reasonably easy to produce native code from. - Tiny memory consumption. No pointers, no cry. **In very early stages of development.** Todo: - [x] Map Nim types to IR types. - [ ] Map Nim AST to IR instructions: - [x] Map bitsets to bitops. - [ ] Implement string cases. - [ ] Implement range and index checks. - [x] Implement `default(T)` builtin. - [x] Implement multi string concat. - [ ] Write some analysis passes. - [ ] Write a backend. - [x] Integrate into the compilation pipeline.
* fixes #22790; use cast suppress AnyEnumConv warnings for enums withou… ↵ringabout2023-10-111-4/+13
| | | | | | | (#22813) …t holes fixes #22790
* use lent for the return value of index accesses of tables (#22812)ringabout2023-10-111-2/+2
| | | ref https://forum.nim-lang.org/t/10525
* Add getCursorPos() to std/terminal (#22749)Matt Rixman2023-10-081-1/+47
| | | | | | | | | | | This would be handy for making terminal apps which display content below the prompt (e.g. `fzf` does this). Need to test it on windows before I remove "draft" status. --------- Co-authored-by: Matt Rixman <MatrixManAtYrService@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* remove the O(n*n) `addUnique` one from std (#22799)ringabout2023-10-061-12/+0
| | | | It's not used in the compiler, besides, it doesn't seem to be a common operation. Follows the discussion on the Discord.