Commit Graph

9777 Commits

Author SHA1 Message Date
ringabout
e4522dc87f remove internalNew from system (#23475) 2024-04-04 12:53:30 +02:00
ringabout
9e1b170a09 fixes #16771; lower swap for JS backend (#23473)
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.
2024-04-03 16:59:35 +02:00
lit
dee55f587f Update syncio.nim, fixes "open by FileHandle" doesn't work on Windows (#23456)
## 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.
2024-04-03 09:32:26 +02:00
ringabout
a1602b0d85 dynlib keeps exported functions alive in emscripten (#23469)
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.
2024-04-02 18:18:03 +02:00
Gianmarco
afc30a3b93 Fix compile time errors when using tables on 8/16-bits systems. (#23450)
Refer to the discussion in #23439.
2024-03-28 10:54:29 +01:00
Gianmarco
4c38569229 Change unicode lookup tables to have int32 elements to support platforms 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.
2024-03-25 10:59:48 +01:00
Jaremy Creechley
280f877145 fix atomicarc increment (#23427)
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?
2024-03-25 10:59:18 +01:00
Andreas Rumpf
6c4c60eade Adds support for custom ASTs in the Nim parser (#23417) 2024-03-18 20:27:00 +01:00
soonsouth
b387bc49b5 chore: fix some typos (#23412)
Signed-off-by: soonsouth <cuibuwei@163.com>
2024-03-16 08:35:18 +08:00
Chancy K
c2c00776e3 fix BigInt conversion, xOffset/yOffset to int from int64 (#23404)
Problem described here: https://github.com/karaxnim/karax/issues/284

Co-authored-by: Chancy Kennedy <chancy@conciergecloset.com>
2024-03-15 10:13:40 +08:00
握猫猫
51837e8127 Fix #23381, Use sink and lent to avoid Future[object] making a copy (#23389)
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
2024-03-14 11:24:39 +01:00
ringabout
1e20165a15 fixes #22166; adds sideeffects for close and setFilePos (#23380)
fixes #22166
2024-03-09 11:43:00 +01:00
litlighilit
6e875cd7c2 fix isAbsolute broken when nodejs on Windows (#23365)
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.
2024-03-04 09:58:33 +01:00
ringabout
248850a0ce ref #23333; fixes AF_INET6 value on Linux (#23334)
ref #23333
2024-03-03 17:52:56 +01:00
litlighilit
79bd6fe084 Update browsers.nim, deprecate unimplemented openDefaultBrowser() (#23332)
For this
[proc](773c066634/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>
2024-03-03 17:27:27 +01:00
Jacek Sieka
a1e41930f8 strformat: detect format string errors at compile-time (#23356)
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>
2024-03-03 15:40:53 +01:00
Andreas Rumpf
59c65009a5 ORC: added -d:nimOrcStats switch and related API (#23272) 2024-02-21 16:58:30 +01:00
Tomohiro
d6f0f1aca7 Remove count field from Deque (#23318)
This PR removes `count` field from `Deque` and get `count` from `tail -
head`.
2024-02-20 07:31:09 +01:00
ringabout
dfd778d056 fixes #23304; uses snprintf instead of sprintf (#23322)
fixes #23304
2024-02-20 07:28:45 +01:00
ringabout
35ec9c31bd fixes refc with non-var destructor; cancel warnings (#23156)
fixes https://forum.nim-lang.org/t/10807
2024-02-13 08:11:49 +01:00
Tomohiro
ce68e11641 Remove mask field from Deque (#23299)
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>
2024-02-11 00:39:32 +01:00
Antonis Geralis
c234a2a661 Add items and contains to heapqueue (#23296)
The implementation of these functions are trivial yet they were missing
from the module.
2024-02-09 13:19:36 +01:00
Tomohiro
befb383ac8 fixes #23275; Add == for Deque (#23276) 2024-02-08 22:18:52 +01:00
ringabout
a1d820367f follow up #22380; fixes incorrect usages of newWideCString (#23278)
follow up #22380
2024-02-05 12:14:21 +01:00
litlighilit
dd753b3383 Docs-improve: os.getCurrentCompilerExe replace with clearer short-desc (#23270)
The doc for `getCurrentCompilerExe` was originally added at [this
commit](c4e3c4ca2d),
saying "`getAppFilename` at CT", and modified as "This is
`getAppFilename()`_ at compile time..." since
[this](0c2c2dca2a (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>
2024-02-02 20:11:49 +08:00
Angel Ezquerra
857b35c602 Additional speed ups of complex.pow (#23264)
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>
2024-01-29 09:05:05 +01:00
litlighilit
abcf45e174 Update cmdline.nim, fix broken (dragged) doc-reference for getAppFile… (#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`
2024-01-28 20:38:37 +08:00
ringabout
e3350cbe6f clean up goto exceptions; remove the setjmp.h dep (#23259) 2024-01-27 07:57:07 +01:00
rockcavera
9c155eaccc Fix system.currentSourcePath() documentation [backport 2.0] (#23243)
The documentation links for `parentDir()` and `getCurrentDir()` are
broken as they are no longer part of `std/os`. Link changed to
`std/private/ospaths2`.
2024-01-23 22:48:18 +01:00
ringabout
d3f5056bde remove unreachable code (#23244) 2024-01-22 16:47:21 +08:00
ringabout
301822e189 fixes a broken link in std/algorithm (#23246)
https://nim-lang.github.io/Nim/manual.html#procedures-do-notation
2024-01-22 16:45:56 +08:00
Angel Ezquerra
83f2708909 Speed up complex.pow when the exponent is 2.0 or 0.5 (#23237)
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.
2024-01-20 06:39:49 +01:00
Bung
01097fc1fc fix mime types data (#23226)
generated via https://github.com/bung87/mimetypes_gen

source data:
http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co
2024-01-19 13:11:01 +01:00
Angel Ezquerra
38f9ee0e58 Make std/math classify work without --passc:-fast-math. (#23211)
By using the existing isNaN function we can make std/math's classify
function work even if `--passc:-fast-math` is used.
2024-01-18 21:59:16 +01:00
ringabout
8a38880ef7 workaround arrayWith issues (#23230)
I'm working on it, but it's quite tricky. I will fix it soon
2024-01-18 21:13:39 +01:00
Angel Ezquerra
2425f4559c Add ^ operator support for Rational numbers (#23219)
Since pow() cannot be supported for rationals, we support negative
integer exponents instead.
2024-01-18 14:32:22 +01:00
ringabout
3379d26629 fixes #23223; prevents insert self-assignment (#23225)
fixes #23223
2024-01-18 14:20:54 +01:00
ringabout
bd72c4c729 remove unnecessary workaround from arrayWith (#23208)
The problem was fixed by https://github.com/nim-lang/Nim/pull/23195
2024-01-15 17:06:43 +08:00
ringabout
30cb6826c0 patches for #23129 (#23198)
fixes it in the normal situation
2024-01-11 15:38:23 +01:00
ringabout
29ac3c9986 fixes #22923; fixes =dup issues (#23182)
fixes #22923
2024-01-11 11:23:42 +01:00
Zoom
8d1c722d2d Docs:strutils. Expand multiReplace docs, add runnableExamples (#23181)
- 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.
2024-01-08 08:23:24 +01:00
ringabout
3dee1a3e4c fixes #23139; Cannot get repr of range type of enum (#23164)
fixes #23139
2024-01-05 11:07:27 +01:00
ASVIEST
20d79c9fb0 Deprecate asm stmt for js target (#23149)
why ?

- We already have an emit that does the same thing
- The name asm itself is a bit confusing, you might think it's an alias
for asm.js or something else.
- The asm keyword is used differently on different compiler targets (it
makes it inexpressive).
- Does anyone (other than some compiler libraries) use asm instead of
emit ? If yes, it's a bit strange to use asm somewhere and emit
somewhere. By making the asm keyword for js target deprecated, there
would be even less use of the asm keyword for js target, reducing the
amount of confusion.
- New users might accidentally use a non-universal approach via the asm
keyword instead of emit, and then when they learn about asm, try to
figure out what the differences are.

see https://forum.nim-lang.org/t/10821

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-01-02 07:49:54 +01:00
ringabout
9659da903f fixes wrong indentation (#23145)
4 spaces => 2 spaces
2023-12-31 17:25:14 +01:00
Ikko Eltociear Ashimine
b92163180d Fix typo in pegs.nim (#23143)
wether -> whether
2023-12-30 17:05:55 +08:00
Gianmarco
15c7b76c66 Fix cmpRunesIgnoreCase on system where sizeof(int) < 4. Fixes #23125. (#23138)
Fixes an issue where importing the `strutils` module, or any other
importing the `strutils` module, ends up with a compile time error on
platforms where ints are less then 32-bit wide.

The fix follows the suggestions made in #23125.
2023-12-28 23:41:58 +01:00
ringabout
53855a9fa3 make -d:debugHeapLinks compile again (#23126)
I have made `realloc` absorb unused adjacent memory, which improves the
performance. I'm investigating whether `deallocOsPages` can be used to
improve memory comsumption.
2023-12-24 15:30:35 +01:00
metagn
fc49c6e3ba fix spurious indent and newlines in rendering of nkRecList (#23121)
Rendering of `nkRecList` produces an indent and adds a new line at the
end. However for things like case object `of`/`else` branches or `when`
branches this is already done, so this produces 2 indents and an extra
new line. Instead, just add an indent in the place where the indent that
`nkRecList` produces is needed, for the rendering of the final node of
`nkObjectTy`. There doesn't seem to be a need to add the newline.

Before:

```nim
case x*: bool
of true:
    y*: int

of false:
  nil
```

After:

```nim
case x*: bool
of true:
  y*: int
of false:
  nil
```
2023-12-24 15:22:10 +01:00
Eric N. Vander Weele
6fee2240cd Add toSinglyLinkedRing and toDoublyLinkedRing to std/lists (#22952)
Allow for conversion from `openArray`s, similar to `toSinglyLinkedList`
and `toDoublyLinkedList`.
2023-12-24 15:21:22 +01:00
ringabout
0f54554213 allow non var deinit for locks and conds: alternative way (#23099)
alternative to https://github.com/nim-lang/Nim/pull/23092
2023-12-19 09:47:39 +01:00