Commit Graph

22788 Commits

Author SHA1 Message Date
ringabout
919d0d5ea8 fixes #25369 (#25370)
fixes #25369

(cherry picked from commit 548b1c6ef8)
2025-12-18 20:53:04 +01:00
Andreas Rumpf
34c9606b41 system.nim: memory must be part of system so that its compilerprocs c… (#25365)
…an work for IC

(cherry picked from commit 80cf9a8ce8)
2025-12-18 20:52:46 +01:00
Ryan McConnell
a69ab81fa9 flush stdout when prompting for password (#25348)
Saw this misbehave on Linux. It was fine in Windows when I checked, but
I figured it can't hurt.

(cherry picked from commit 8747160a9a)
2025-12-18 20:52:38 +01:00
Andreas Rumpf
90b7517656 refs https://github.com/nim-lang/Nim/pull/25353 make tasyncclosestall… (#25366)
….nim less flaky

(cherry picked from commit 334ac3f588)
2025-12-18 20:52:17 +01:00
Jacek Sieka
244af30c58 Align treetab hash with equivalence (#25354)
In particular, hash `typ` for `nkType`, `nkNilLit` or they end up
generating collisions

<img width="989" height="612" alt="image"
src="https://github.com/user-attachments/assets/a5c6366f-1214-443e-98d5-52ce95fc3555"
/>

(cherry picked from commit 1527c13273)
2025-12-15 20:29:49 +01:00
ringabout
795b5665dc fixes markdown tests (#25347)
(cherry picked from commit 28ada7df94)
2025-12-15 20:28:51 +01:00
metagn
c8556ef5df consider generic param type as typedesc in tuple type expressions (#25316)
fixes #25312

Tuple expressions `(a, b, c)` can be either types or values depending on
if their elements are typedescs or values, this is checked by checking
if the type of the element is `tyTypeDesc`. However when an
`skGenericParam` symbol is semchecked by `semSym` it is given its own
`tyGenericParam` type rather than a `tyTypeDesc` type, this seems to be
necessary for signatures to allow wildcard generic params passed to
static constrained generic params (tested in #25315). The reason
`semSym` is called is that `semGeneric` for generic invocations calls
`matches` which sems its arguments like normal expressions.

To deal with this, an expression of type `tyGenericParam` and with a
`skGenericParam` sym is allowed as a type in the tuple expression. A
problem is that this might consider a value with a wildcard generic
param type as a type. But this is a very niche problem, and I'm not sure
how to check for this. `skGenericParam` symbols stay as idents when
semchecked so it can't be checked that the node is an `skGenericParam`
symbol. It could be checked that it's an ident but I don't know how
robust this is. And maybe there is another way to refer to a wildcard
generic param type instead of just its symbol, i.e. another kind of
node.

This also makes #5647 finally work but a test case for that can be added
after.

(cherry picked from commit 44d2472b08)
2025-12-10 10:31:59 +01:00
ringabout
6c8ab9f898 fixes #25329; Wrong type for second parameter of procedures "inc", "dec", "succ" and "pred" (#25337)
fixes #25329

(cherry picked from commit e1f2329e55)
2025-12-10 10:31:42 +01:00
elijahr
547416b806 Fixes #25341; Invalid C code for lifecycle hooks for distinct types based on generics (#25342)
(cherry picked from commit 099ee1ce4a)
2025-12-10 10:29:15 +01:00
Yuriy Glukhov
97c41c0f15 Fixes #25330 (#25336)
Fixed state optimizer. It did not replace deleted states in
`excLandingState`.

(cherry picked from commit 8f8814b495)
2025-12-05 15:29:45 +01:00
ringabout
feaa364038 fixes #25306; Dangling pointers in stack traces with -d:nimStackTraceOverride (#25313)
fixes #25306

```nim
type
  StackTraceEntry* = object ## In debug mode exceptions store the stack trace that led
                            ## to them. A `StackTraceEntry` is a single entry of the
                            ## stack trace.
    procname*: cstring      ## Name of the proc that is currently executing.
    line*: int              ## Line number of the proc that is currently executing.
    filename*: cstring      ## Filename of the proc that is currently executing.
    when NimStackTraceMsgs:
      frameMsg*: string     ## When a stacktrace is generated in a given frame and
                            ## rendered at a later time, we should ensure the stacktrace
                            ## data isn't invalidated; any pointer into PFrame is
                            ## subject to being invalidated so shouldn't be stored.
    when defined(nimStackTraceOverride):
      programCounter*: uint ## Program counter - will be used to get the rest of the info,
                            ## when `$` is called on this type. We can't use
                            ## "cuintptr_t" in here.
      procnameStr*, filenameStr*: string ## GC-ed alternatives to "procname" and "filename"
```

(cherry picked from commit 0ea5f2625c)
2025-12-05 15:29:35 +01:00
ringabout
05c8e1d85d fixes #25324; Channel incorrectly takes a sink argument in refc (#25328)
… it performs a deep copy internally

fixes #25324

notes that
> Enabling `-d:nimPreviewSlimSystem` removes the import of
`channels_builtin` in
in the `system` module, which is replaced by
[threading/channels](https://github.com/nim-lang/threading/blob/master/threading/channels.nim).

(cherry picked from commit 5d4829415a)
2025-12-05 15:29:27 +01:00
Ryan McConnell
90efe870c8 concept patch: inheritance (#25317)
adds some inheritance support

---------

Co-authored-by: Andreas Rumpf <araq4k@proton.me>
(cherry picked from commit 86bbc73b3a)
2025-12-05 15:29:15 +01:00
ringabout
860e827df6 fixes #22305; Combination of generic destructor and closure fails in certain cases (#25327)
fixes #22305

It seems that the generic type is cached somehow so that no hooks are
instantiated for the generic type. There are only hooks for the
instantiated type. When `lambdalifting` tries to create type bounds for
the generic type, it cannot either find the instantiated hooks or
instantiate the generic hooks since it lacks `SemContext`. It can use
hooks for the instantiated type in this case

(cherry picked from commit 1da0dc74d9)
2025-12-05 15:29:06 +01:00
Ryan
834c35a137 std: sysatomics: fix use of atomicCompareExchangeN for MSVC (#25325)
`InterlockedCompareExchange64 `(winnt.h) is used instead of gcc atomics
when compiling with MSVC on Windows, but the function signatures are
`InterlockedCompareExchange64(ptr int64, int64, int64)` and
`InterlockedCompareExchange32(ptr int32, int32, int32)` as opposed to
`(ptr T, ptr T, T)` for `__atomic_compare_exchange_n`.

Passing a pointer to the expected value (parameter two) instead of the
value itself causes the comparison to unconditionally fail, with stalls
in threaded code using atomic comparisons.

Fix the function signature for MSVC.

Signed-off-by: Ryan Walklin <ryan@testtoast.com>
(cherry picked from commit 2d0b62aa51)
2025-12-02 14:21:40 +01:00
Jacek Sieka
75f01bd49f Ensure channels don't leak exception effects (#25318)
The forward declarations cause `Exception` to be inferred - also,
`llrecv` is an internal implementation detail and the type of the
received item is controlled by generics, thus the ValueError raised
there seems out of place for the generic api.

(cherry picked from commit 91febf1f4c)
2025-12-02 14:21:33 +01:00
Yuriy Glukhov
800384176e Fixes #25261 (#25310)
Returning or yielding from a closureiter must restore "external"
exception, but `popCurrentException` from `blockLeaveActions` was
getting in the way. So now `blockLeaveActions` doesn't emit
`popCurrentException` for returns in closureiters. I'm not a fan of this
"abstraction leakage", but don't see a better solution yet. Any input is
much appreciated.

---------

Co-authored-by: Andreas Rumpf <araq4k@proton.me>
(cherry picked from commit 6656084004)
2025-11-27 19:03:50 +01:00
ringabout
dc8f1ab52d uses csources_v3 (#25273)
(cherry picked from commit a57b6d8406)
2025-11-22 14:23:19 +01:00
Peter Munch-Ellingsen
ffaabdf21e Fixes #25304 proper test for hlo recursion limit (#25305)
The `warnUser` message kind is probably not the right one, but I left it
as a placeholder. It should probably at least warn if not just straight
up throw an error, was very hard to figure out what went wrong without
any indication. The hard coded 300 should possibly also be changed to
`evalTemplateLimit` or the VM call recursion limit or something.

(cherry picked from commit 6543040d40)
2025-11-22 13:33:01 +01:00
Andreas Rumpf
431e01eaf2 system.nim refactorings for IC (#25295)
Generally useful refactoring as it produces better code.

(cherry picked from commit 0f7b378467)
2025-11-22 13:32:24 +01:00
ringabout
a5e73ff408 use nimKochBootstrap for niminst (#25293)
so that `nimony` won't be required for nightlies. It's annoying to build
`nimony` on each platform, e.g. `std/memfiles` which is used by `nimony`
is not supported by `nintendoswitch`

```
bin/nim compile -f --incremental:off --compileonly --gen_mapping --cc:gcc --skipUserCfg --os:nintendoswitch --cpu:arm64 -d:danger -d:gitHash:cd69f37f3a4fb46468b77b84ccf6aa3225c8895e compiler/nim.nim
```

```
/home/runner/work/nightlies/nightlies/nim/lib/pure/memfiles.nim(107, 40) Error: undeclared identifier: 'MAP_SHARED'
candidates (edit distance, scope distance); see '--spellSuggest':
 (4, 5): 'freeShared'
```

(cherry picked from commit 46d4079357)
2025-11-22 13:29:54 +01:00
Ryan McConnell
37fd04a0eb concept patch for tyGenericInvocation (#25288)
matching between some generic invocations and equivalent instantiations
did not have a code path

(cherry picked from commit 79ddb7d89e)
2025-11-22 13:29:38 +01:00
Zoom
dc1c3ed90e std: sysstr cleanup, add docs (#25180)
- Removed redundant `len` and `reserved` sets already performed by prior
`rawNewStringNoInit` calls.
- Reuse `appendChar`
- Removed never used `newOwnedString`
- Added internal `toOwnedCopy`
- Documents differences in impls of internal procs used for
`system.string.setLen`:
  + `strs_v2.setLengthStrV2`:
    - does not set the terminating zero byte when new length is 0
    - does not handle negative new length
  + `sysstr.setLengthStr`:
    - sets the terminating zero byte when new length is 0
    - bounds negative new length to 0

(cherry picked from commit b539adf829)
2025-11-21 15:13:51 +01:00
Zoom
8d475993f8 std: sysstr refactor (#25185)
Continuation of #25180. This one refactors the sequence routines.

Preparation for extending with new routines.

Mostly removes repeating code to simplify debugging.

Removes:
 - `incrSeqV2` superseded by `incrSeqV3`,
 - `setLengthSeq` superseded by `setLengthSeqV2`

Note comment on line 338, acknowledging that implementation of
`setLenUninit` from #25022 does zero the new memory in this branch,
having been copied from `setLengthSeqV2`. This PR does not fix this.

(cherry picked from commit 01c084077e)
2025-11-21 15:13:41 +01:00
ringabout
8914baae78 fixes #25007; implements setLenUninit for refc (#25022)
fixes #25007

```nim
proc setLengthSeqUninit(s: PGenericSeq, typ: PNimType, newLen: int, isTrivial: bool): PGenericSeq {.
    compilerRtl.} =
```

In this added function, only the line `zeroMem(dataPointer(result,
elemAlign, elemSize, newLen), (result.len-%newLen) *% elemSize)` is
removed from `proc setLengthSeqV2` when enlarging a sequence.

JS and VM versions simply use `setLen`.

(cherry picked from commit 611b8bbf67)
2025-11-21 13:28:13 +01:00
ringabout
fcf4f10c70 fixes #19728; setLen slow when shrinking seq due to zero-filling of released area (#24683)
fixes #19728

don't zero-filling memory for "trivial types" without destructor in
refc. I tested locally with internal apis.

(cherry picked from commit b421d0f8ee)
2025-11-21 08:57:40 +01:00
lit
5394c6814b fixes #25227; crash when codegen user-defined tuple iterate (#25228)
fixes #25227

(cherry picked from commit 39be9b981d)
2025-11-15 12:27:17 +01:00
ringabout
2ddda806a9 fixes #25284; .global initialization inside method hoisted to preInitProc (#25285)
fixes #25284

```nim
proc m2()  =
  let v {.global, used.}: string = f2(f2("123"))
```

transform lifted `.global`statements in the top level scope

(cherry picked from commit 9becd1453d)
2025-11-15 12:27:12 +01:00
Andreas Rumpf
8775ef62fe nimsuggest tester: remove PCRE dependency (#25279)
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
(cherry picked from commit 4c6d9b6068)
2025-11-15 12:26:44 +01:00
Andreas Rumpf
63398611e7 VM: refactoring [backport] (#25280)
Note to @narimiran backport because IC requires it.

(cherry picked from commit 5da72efbde)
2025-11-15 12:26:35 +01:00
ringabout
a6988458c4 updates to macos-15 (#25278)
ref https://github.com/actions/runner-images/issues/13046

(cherry picked from commit d5549a3c65)
2025-11-15 12:26:15 +01:00
lit
9346b138e1 fixes #19846; std/unicode.strip trailing big chars (#25274)
fixes #19846

(cherry picked from commit 2679b3221c)
2025-11-15 12:26:05 +01:00
Ryan McConnell
c75c85cbf8 silence mass dump of BareExcept when using unittest (#25260)
Seems better to change it to `CatchableError` instead?

(cherry picked from commit cc4c7377b2)
2025-11-15 12:25:56 +01:00
ringabout
38384d040a fixes #25265; fixes #23453; Unable to build Nim 2.2.6 tools from source (#25269)
fixes #25265;
fixes #23453

`(addr deref (ptr object))` generated weak typedesc before, which causes
problems for old GCC versions. As a bonus, by generating a typedesc for
`deref (ptr object)`, it also fixes #23453

(cherry picked from commit 92468e99f7)
2025-11-08 16:40:44 +01:00
metagn
605180fcfa js: replace push.apply with for loop for string add [backport] (#25267)
While `a.push.apply(a, b)` is better for performance than the previous
`a = a.concat(b)` due to the fact that it doesn't create a new array,
there is a pretty big problem with it: depending on the JS engine, if
the second array is too long, it can [cause a
crash](https://tanaikech.github.io/2020/04/20/limitation-of-array.prototype.push.apply-under-v8-for-google-apps-script/)
due to the function `push` taking too many arguments. This has
unfortunately been what the codegen produces since 1.4.0 (commit
707367e1ca).

So string addition is now moved to a compilerproc that just uses a `for`
loop. From what I can tell this is the most compatible and the fastest.
Only potential problem compared to `concat` etc is with aliasing, i.e.
adding an array to itself, but I'm guessing it's enough that the length
from before the iteration is used, since it can only grow. The test
checks for aliased nim strings but I don't know if there's an extra
protection for them.

(cherry picked from commit 839cbeb371)
2025-11-08 16:40:36 +01:00
narimiran
be6e195585 remove wrong test 2025-11-08 16:40:00 +01:00
Andreas Rumpf
873ab1f9ef VM: optimize 'return' slots; saves millions of node allocations for N… (#25266)
…imbus

(cherry picked from commit 809662a228)
2025-11-07 12:33:59 +01:00
ringabout
4efece995e fixes #25251; SIGBUS with iterator over const Table lookup - premature temporary destruction (#25255)
fixes #25251

enforce a copy if the arg is a deref of a lent pointer since the arg
could be a temporary that will go out of scope

(cherry picked from commit 6f73094263)
2025-11-07 12:33:53 +01:00
Jacek Sieka
40e1a34831 Add heaptrack support (#25257)
This PR, courtesy of @NagyZoltanPeter
(https://github.com/waku-org/nwaku/pull/3522) adds the ability to track
memory allocations in a program suitable for use with
[heaptrack](https://github.com/KDE/heaptrack).

By passing `-d:heaptrack --debugger:native` to compilation, calls to
heaptrack will be injected when memory is being allocated and released -
unlike `-d:useMalloc` this strategy also works with `refc` and the
default memory pool.

See https://github.com/KDE/heaptrack for usage examples. The resulting
binary needs to be run with `heaptrack` and with the shared
`libheaptrack_preload.so` in the `LD_LIBRARY_PATH`.

(cherry picked from commit 861ebc0f19)
2025-11-07 12:33:33 +01:00
ringabout
bd9cbc91ba fixes #25263; provides a new switch mangle:nim/cpp for debug name mangling (#25264)
fixes #25263

- [x] documentation and changelogs

(cherry picked from commit 1d08c4e241)
2025-11-07 12:33:17 +01:00
Andreas Rumpf
d7ae00349a produces vastly better error messages for implicit --import and --inc… (#25258)
…lude configuration options

(cherry picked from commit cfefd1d95b)
2025-11-05 11:36:39 +01:00
ringabout
61e98e9bf1 fixes #25252; Unexpected ambiguous call with fields over object with default fields (#25256)
fixes #25252

(cherry picked from commit d54b5f3ae1)
2025-11-05 11:36:17 +01:00
Yuriy Glukhov
7f6c0afa59 Respect noinit for generic types (#25250)
(cherry picked from commit 99a222d63d)
2025-11-05 11:34:12 +01:00
narimiran
6b89497b1e bump NimVersion to 2.2.7 2025-11-05 11:33:32 +01:00
narimiran
ab00c56904 bump NimVersion to 2.2.6 v2.2.6 2025-10-30 20:32:15 +01:00
Miran
6db962ebf5 bump the shipped version of Atlas (#25248)
(cherry picked from commit 3e9a66599a)
2025-10-30 20:31:16 +01:00
ringabout
05c76c7f1c fixes #24575; _GNU_SOURCE redefined (#25247)
fixes #24575

(cherry picked from commit ce6a34597d)
2025-10-30 20:31:06 +01:00
Yuriy Glukhov
365da2cb97 Fixes #25202 (#25244)
(cherry picked from commit 7af4e3eefd)
2025-10-28 13:50:59 +01:00
ringabout
3bbba9e0ff fixes #25008; Compiler internal error with static overload (#25234)
fixes #25008

It seems that `semOverloadedCall` evaluates the same node twice using
`tryConstExpr` in order for `efExplain` to print all the diagnostic
output. The problem is that `tryConstExpr` has side effects, i.e., it
changes the slot index of variables after VM execution.

(cherry picked from commit 130eac2f93)
2025-10-28 13:50:50 +01:00
ringabout
4eaecfe59e fixes #25027; nim doc uses doc comment from private field for public field (#25239)
fixes #25027

(cherry picked from commit b8ce11dd9d)
2025-10-27 08:51:12 +01:00