Commit Graph

9881 Commits

Author SHA1 Message Date
tocariimaa
d51d88700b Implement removeHandler in std/logging module (fixes #23757) (#24143)
Since the module allows for a handler to be added multiple times, for
the sake of consistency, `removeHandler` only removes the first found
instance of the handler in the `handlers` seq. So for n calls of
`addHandler` using the same handler, n calls of `removeHandler` are
required.

fixes #23757

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-09-20 17:32:23 +02:00
tocariimaa
84f5060e94 Create IPPROTO_NONE alias & Add test for Unix socket (#24139)
closes #24116
2024-09-19 07:19:59 +02:00
metagn
6cc50ec316 fix system for nimscript config files on js backend (#24135)
fixes #21441

When compiling for JS, nimscript config files have both `defined(js)`
and `defined(nimscript)` be true at the same time. This is required so
that the nimscript config file knows the current compilation is for the
JS backend. However the system module doesn't account for this in some
cases, defining JS-specific code or not defining nimscript-specific code
when compiling such nimscript files. To fix this, have the `nimscript`
define take priority over the `js` one.
2024-09-19 00:35:29 +02:00
ringabout
c759d7abd1 fixes rst parsing Markdown CodeblockFields blocking the loop (#24128)
```nim
import packages/docutils/[rst, rstgen]

let message = """```llvm-profdata"""

echo rstgen.rstToHtml(message, {roSupportMarkdown}, nil)
```
2024-09-18 17:35:46 +02:00
metagn
04ccd2f4f0 revert second argument of inc not being generic (#24129)
refs #22328, fixes regression in
https://forum.nim-lang.org/t/12465#76998
2024-09-17 21:28:54 +02:00
ringabout
21a161a535 remove nimfrs and varslot (#24126)
was introduced for debugger
b63f322a46 (diff-abd3a10386cf1ae32bfd3ffae82335a1938cc6c6d92be0ee492fcb44b9f2b552)


b63f322a46/lib/system/debugger.nim
2024-09-17 14:01:21 +02:00
metagn
21771765a2 add posix uint changes to changelog + fix Nlink, Dev on FreeBSD (#24088)
refs #24078, refs #24076

Since these changes are potentially breaking, add them to changelog,
also add Nlink as mentioned in
https://github.com/nim-lang/Nim/issues/24076#issuecomment-2337666555.
2024-09-09 14:44:49 +02:00
ringabout
3a55bae53f enable closures tests for JS & implement finished for JS (#23521) 2024-09-09 14:20:40 +02:00
Tobias Dély
8b895afcb5 fix: InotifyEvent.name should be UncheckedArray[char] (#23413) 2024-09-09 11:45:58 +02:00
metagn
7de4ace949 fix int32's that should be uint32 on BSD & OSX (#24078)
fixes #24076

As described in #24076, misannotating these types causes codegen errors.
Sources for the types are https://github.com/openbsd/src/blob/master/sys
for BSD and https://opensource.apple.com/source/Libinfo/Libinfo-391/ and
[_types.h](https://opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/_types.h.auto.html)
for OSX.
2024-09-09 09:46:47 +02:00
bptato
29a7d60acb Fix ioselectors_kqueue raising wrong exceptions (#24079)
kqueue will remove pipes automatically if their read end is closed.
Unfortunately this means that trying to unregister it (which is
necessary to clean up resources & for consistency with other ioselectors
implementations) will set an ENOENT error, which currently raises an
exception.

(ETA: in other words, it is currently impossible to call unregister on a
pipe fd without potentially getting the selector into an invalid state
on platforms with kqueue.)

Avoid this issue by ignoring ENOENT errors returned from kqueue.

(Tested on FreeBSD. I added a test case to the tioselectors file; the
seemingly unrelated change is to fix a race condition that doesn't
appear on Linux, so that it would run my code too.)
2024-09-08 22:50:10 +02:00
metagn
cd22560af5 fix string literal assignment with different lengths on ARC (#24083)
fixes #24080
2024-09-08 20:17:26 +02:00
metagn
d77ea07837 expose rangeBase typetrait, fix enum conversion warning (#24056)
refs #21682, refs #24038

The `rangeBase` typetrait added in #21682 which gives the base type of a
range type is now added publicly to `typetraits`. Previously it was only
privately used in `repr_v2` and in `enumutils` since #24052
(coincidentally I didn't see this until now). This is part of an effort
to make range types easier to work with in generics, as mentioned in
#24038. Its use combined with #24037 is also tested.

The condition for the "enum to enum conversion" warning is now also
restricted to conversions between different enum base types, i.e.
conversion between an enum type and a range type of itself doesn't give
a warning. I put this in this PR since the test gave the warning and so
works as a regression test.
2024-09-06 11:18:20 +02:00
lit
e265b3dfdd Make math.isNaN,copySign,etc available on objc (#24025)
fixes #23922

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2024-09-05 14:21:30 +08:00
c-blake
6908fb4011 Make $ on 0-length MemSlice produce Nim "" as per DMisener idea (#24015)
in https://forum.nim-lang.org/t/12463 which seems reasonable enough to
me.

stdlib has several dozens of places doing result.setLen now, but if
`experimental:strictDefs` move sot on by default and there is no easy
way to locally suppress the warning we can revisit this.
2024-09-04 17:01:55 +08:00
metagn
080b0a03bd streams: implement readStr for VM, document VM limitations (#24058)
fixes #24054

`readData` is not implemented for the VM as mentioned in the issue, but
`readDataStr` is, so that is used for `readStr` instead on the VM. We
could also just use it in general since it falls back to `readData`
anyway but it's kept the same otherwise for now.

Also where and why streams in general don't work in VM is now documented
on the top level `streams` module documentation.
2024-09-04 09:25:01 +02:00
ringabout
c948ab9b85 fixes symbolName for range enums (#24052) 2024-09-03 16:35:04 +02:00
握猫猫
5e8cd318ef Fix linux start process errorCode always 0 (#24001)
#23992 The test case provided does not cover the Windows situation, I
fixed it in this new PR.

Fixed an issue where errorCode was always 0 when startProcess didn't use
the poEvalCommand flag.

Tthe sleep command might not be available in all Windows installations,
so I skipped the relevant test.

Added a test case, tested on my fedora and windows systems.
2024-08-28 20:52:00 +02:00
metagn
770f8d5513 opensym for templates + move behavior of opensymchoice to itself (#24007)
fixes #15314, fixes #24002

The OpenSym behavior first added to generics in #23091 now also applies
to templates, since templates can also capture symbols that are meant to
be replaced by local symbols if the context imports symbols with the
same name, as in the issue #24002. The experimental switch
`templateOpenSym` is added to enable this behavior for templates only,
and the experimental switch `openSym` is added to enable it for both
templates and generics, and the documentation now mainly mentions this
switch.

Additionally the logic for `nkOpenSymChoice` nodes that were previously
wrapped in `nkOpenSym` now apply to all `nkOpenSymChoice` nodes, and so
these nodes aren't wrapped in `nkOpenSym` anymore. This means
`nkOpenSym` can only have children of kind `nkSym` again, so it is more
in line with the structure of symchoice nodes. As for why they aren't
merged with `nkOpenSymChoice` nodes yet, we need some way to signal that
the node shouldn't become ambiguous if other options exist at
instantiation time, we already captured a symbol at the beginning and
another symbol can only replace it if it's closer in scope and
unambiguous.
2024-08-28 20:51:13 +02:00
metagn
d3af51e3ce remove fauxMatch for tyFromExpr, remove tyProxy and tyUnknown aliases (#24018)
updated version of #22193

After #22029 and the followups #23983 and #24005 which fixed issues with
it, `tyFromExpr` no longer match any proc params in generic type bodies
but delay all non-matching calls until the type is instantiated.
Previously the mechanism `fauxMatch` was used to pretend that any
failing match against `tyFromExpr` actually matched, but prevented the
instantiation of the type until later.

Since this mechanism is not needed anymore for `tyFromExpr`, it is now
only used for `tyError` to prevent cascading errors and changed to a
bool field for simplicity. A change in `semtypes` was also needed to
prevent calling `fitNode` on default param values resolving to type
`tyFromExpr` in generic procs for params with non-generic types, as this
would try to coerce the expression into a concrete type when it can't be
instantiated yet.

The aliases `tyProxy` and `tyUnknown` for `tyError` and `tyFromExpr` are
also removed for uniformity.
2024-08-28 20:46:36 +02:00
ringabout
ea7c2a4409 fixes #14623; Top-level volatileLoad/volatileStore leads to invalid codegen (#24020)
fixes #14623
2024-08-28 20:44:06 +02:00
Miran
4c250d69a8 bump NimVersion to 2.1.99 (2.0.2 RC2) (#24016) 2024-08-27 02:49:46 +02:00
metagn
09dcff71c8 generate symchoice for ambiguous types in templates & generics + handle types in symchoices (#23997)
fixes #23898, supersedes #23966 and #23990

Since #20631 ambiguous type symbols in templates are rejected outright,
now we generate a symchoice for type nodes if they're ambiguous, a
generalization of what was done in #22375. This is done for generics as
well. Symchoices also handle type symbols better now, ensuring their
type is a `typedesc` type; this probably isn't necessary for everything
to work but it makes the logic more robust.

Similar to #23989, we have to prepare for the fact that ambiguous type
symbols behave differently than normal type symbols and either error
normally or relegate to other routine symbols if the symbol is being
called. Generating a symchoice emulates this behavior, `semExpr` will
find the type symbol first, but since the symchoice has other symbols,
it will count as an ambiguous type symbol.

I know it seems spammy to carry around an ambiguity flag everywhere, but
in the future when we have something like #23104 we could just always
generate a symchoice, and the symchoice itself would carry the info of
whether the first symbol was ambiguous. But this could harm compiler
performance/memory use, it might be better to generate it only when we
have to, which in the case of type symbols is only when they're
ambiguous.
2024-08-25 22:24:20 +02:00
ringabout
0d53b6e027 fixes #23915; std/random produces different results on c/js (#24003)
fixes #23915
2024-08-25 22:23:30 +02:00
Alfred Morgan
cb7bcae7f7 fixes #23956; bindUnix loses the last character on OpenBSD (#23961)
uses calculation as shown in
https://man7.org/linux/man-pages/man7/unix.7.html
> offsetof(struct sockaddr_un, sun_path) + strlen(sun_path) + 1
2024-08-22 10:31:35 +02:00
ringabout
832ba815d1 Revert "Fixed an issue where errorCode was always 0 when startProcess did…" (#23995)
Reverts nim-lang/Nim#23992
2024-08-21 20:53:38 +08:00
握猫猫
12b90d7c07 Fixed an issue where errorCode was always 0 when startProcess did… (#23992)
…n't use the `poEvalCommand` flag

https://forum.nim-lang.org/t/12310

Added a test case, tested on my fedora system.
2024-08-21 11:44:53 +02:00
ringabout
dda638c1ba fixes #23945; type checking for whenvm expresssions (#23970)
fixes #23945
2024-08-20 20:41:07 +08:00
ringabout
253fafb305 fixes docgen regression: don't add newLine for code if it's the first line (#23154)
Before (devel)


![image](https://github.com/nim-lang/Nim/assets/43030857/cde37109-027a-46c1-a37e-1d6062e6c609)

After (this PR and stable)


![image](https://github.com/nim-lang/Nim/assets/43030857/3366877c-7223-4749-a584-fe93f731281f)

It now keeps the same behavior as before
2024-08-17 20:02:36 +08:00
Archar Gelod
2a046e6487 better examples for std/inotify (#23415)
Previous example wouldn't run unless `std/posix` was imported and it
wasn't mentioned anywhere in the docs.

Other changes in the example:
- replaced magic number with constant `MaxWatches` .
- changed seq buffer to array, because length is already constant +
pointer is a bit nicer: `addr seq[0]` vs `addr arr`
- added example for getting a `cstring` name value from `InotifyEvent`
struct with explicit cast.
- added a bit more description to `inotify_init1` (copied from `man
inotify(7)`)

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2024-08-14 22:35:40 +08:00
Mark Leyva
c5b206d4ac fix #23817; Use __builtin_saddl_overflow variants for arm-none-eabi-gcc. (#23835)
Provides a fix for #23817. 

With target `arm-none-eabi`, GCC defines `int32_t` to `long int`. Nim
uses `__builtin_sadd_overflow` for 32-bit targets, but this emits
warnings on GCC releases 13 and under, while generating an error on GCC
14. More info regarding this
[here](https://gcc.gnu.org/gcc-14/porting_to.html#c) and
[here](https://gcc.gnu.org/pipermail/gcc-cvs/2023-December/394351.html).

The proposed PR attempts to address this issue for these targets by
defining the `nimAddInt`, `nimSubInt`, and `nimMulInt` macros to use the
appropriate compiler intrinsics for this platform.

As for as we know, the LLVM toolchain for bare metal Arm does not define
`int32_t` as `long int` and has no need for this patch. Thus, we only
define the above macros for GCC targeting `arm-non-eabi`.
2024-08-12 18:10:33 +02:00
Juan M Gómez
630c304a2d Adds SEQ_DECL_SIZE 1 back under clang and a test (#23942) 2024-08-12 18:10:17 +02:00
metagn
0c890ff9a7 opensym as node kind + fixed experimental switch (#23892)
refs https://github.com/nim-lang/Nim/pull/23873#discussion_r1687995060,
fixes #23386, fixes #23385, supersedes #23572

Turns the `nfOpenSym` node flag implemented in #23091 and extended in
#23102 and #23873, into a node kind `nkOpenSym` that forms a unary node
containing either `nkSym` or `nkOpenSymChoice`. Since this affects
macros working on generic proc AST, the node kind is now only generated
when the experimental switch `genericsOpenSym` is enabled, and a new
node flag `nfDisabledOpenSym` is set to the `nkSym` or `nkOpenSymChoice`
when the switch is not enabled so that we can give a warning.

Now that the experimental switch has more reasonable semantics, we
define `nimHasGenericsOpenSym2`.
2024-08-12 15:33:26 +02:00
Tomohiro
7a0069a134 fixes #23913; empty SEQ_DECL_SIZE (#23940) 2024-08-12 15:19:42 +02:00
lit
e0e698be9a impr: std/cpuinfo: use documented impl ; support JS (#23911)
Currently `cpuinfo.countProcessor` uses hard-coded `HW_AVAILCPU=25` for
both MacOS and BSD;

However,

[There is no HW_AVAILCPU on FreeBSD, NetBSD, and OpenBSD](
https://bugs.webkit.org/show_bug.cgi?id=132542)

Also, `HW_AVAILCPU` is undocmented in MacOS,
while `sysctlbyname("hw.logicalcpu",...)` is documented and used
by many other languages' implementations, like
[Haskell](https://gitlab.haskell.org/ghc/ghc/-/blob/master/rts/posix/OSThreads.c?ref_type=heads#L376)

---

This PR:

- use `importc` value instead of hard-coded values for `HW_*` macros.
- use "hw.logicialcpu" over undocumented HW_AVAILCPU.
- reduce 2 elements of `mib` array when calling `sysctl` as they're no
use.
2024-08-11 17:32:58 +02:00
Antonis Geralis
c0aa951ee0 Fixed nimscript docs (#23938) 2024-08-11 10:35:09 +08:00
Tomohiro
12b9680291 Add a document to toOpenArray proc (#23905) 2024-08-01 12:27:10 +08:00
ringabout
39629a1adc fixes JS semicolon omissions (#23896) 2024-07-26 20:45:52 +02:00
lit
03973dca30 doc,test(times): followup #23861 (#23881)
followup #23861
2024-07-23 09:56:36 +08:00
SirOlaf
881fbb8f81 Allocator: Always place free cells into the active chunk and add documentation (#23871)
Lets single threaded applications benefit from tracking foreign cells as
well.
After this, `SmallChunk` technically doesn't need to act as a linked
list anymore I think, gotta investigate that more though.
The likelihood of overflowing `chunk.free` also rises, so to work around
that it might make sense to check `foreignCells` instead of adjusting
free space or replace free with a counter for the local capacity.

For Nim compile I can observe a ~10mb reduction, and smaller ones for
other projects.
2024-07-22 16:36:46 +02:00
Ward
c83a9c4c5c fixes #23838: Compilation by MinGW for cpu=i386 with time_t bug (#23876)
Change Time type in std/time_t to `distinct clong` instead of `distinct
int32`
2024-07-22 14:23:18 +02:00
Buldram
2d2a7f2347 Fix out-of-bounds slicing in std/varints (#23868)
Corrects a slicing mistake in the `std/varints` implementation which
caused it to fail when writing large numbers into buffers smaller than
10..13-bytes, now 9-byte buffers are sufficient as the documentation
states.
2024-07-22 07:11:14 +02:00
SirOlaf
fd1e62a7e2 Allocator: Track number of foreign cells a small chunk has access to (#23856)
Ref: https://github.com/nim-lang/Nim/issues/23788

There was a small leak in the above issue even after fixing the
segfault. The sizes of `free` and `acc` were changed to 32bit because
adding the `foreignCells` field will drastically increase the memory
usage for programs that hold onto memory for a long time if they stay as
64bit.
2024-07-20 05:40:00 +02:00
c-blake
24f5dfbed2 Add '.' (period, dot, ..) to FormatLiterals so that ss.fff can work. (#23861)
Honestly, to me the entire design of a (highly!) restricted set of
`FormatLiterals` characters seems antithetical to the very idea of a
format string template. Fixing that is a much larger change, though.

So, this PR just adds `'.'` so that the standard (both input & output!)
notation for decimal numbers in Nim can be used for the seconds part of
a time format in `lib/pure/times.format(.., f)`. It should only make
legal what was illegal and should be harmless since `'.'` is not used in
any special way otherwise.
2024-07-19 12:38:02 +02:00
lit
6aa54d533b doc: times.nim: DD -> dd (#23857)
`YYYY-MM-dd` was mistaken as `YYYY-MM-DD`.
2024-07-18 13:59:48 +02:00
ringabout
9de74b7097 fixes #23844; Nim devel nightly i386 build failing (#23849)
fixes #23844
follow up https://github.com/nim-lang/Nim/pull/23834

```nim
type
  Timespec* {.importc: "struct timespec",
               header: "<time.h>", final, pure.} = object ## struct timespec
    tv_sec*: Time  ## Seconds.
    tv_nsec*: clong  ## Nanoseconds.
```
2024-07-17 10:50:33 +02:00
Antonis Geralis
ad5b5e3ec0 Add warnings about exec usage. (#23820)
Related to https://github.com/nim-lang/Nim/issues/23819 and also found
in discord
https://discord.com/channels/371759389889003530/371759389889003532/1260845467147829372
Since nothing can be done, besides deprecating the function, a warning
is a better option.

---------

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
2024-07-17 08:45:52 +02:00
c-blake
c11b3f3fc7 Silence hint:performance message when using very basic http client (#23832)
code such as:
```Nim
import std/httpclient # nim c --hint:performance:on
echo newHttpClient(proxy=nil,
  headers=newHttpHeaders({"Accept": "*/*"})).getContent("x")
```
(Fix was suggested by @ringabout in a private channel.)

Seems useful since `httpclient` is so basic/probably pervasive with many
hundreds of `import`s across the NimbleVerse.
2024-07-15 14:11:06 +02:00
Mark Leyva
a5186a9d8b Use monotonic timestamp to calculate timeouts refs #23826 (#23834)
Related to #23826. This address issues raised
[here](https://github.com/nim-lang/Nim/pull/23826#issuecomment-2226877361)
by using a monotonic timestamp to calculate timeouts and increasing the
max sleep time to 50ms.
2024-07-15 14:10:31 +02:00
Miran
f6aeca5765 bump NimVersion to 2.1.9 (#23831)
This is a 2.2 RC1.
2024-07-12 21:06:29 +02:00