Commit Graph

22824 Commits

Author SHA1 Message Date
Andreas Rumpf
c5455c1515 attempt to fix final issue with Nim's multi-threaded allocator (#25513)
(cherry picked from commit b41049988f)
2026-02-16 09:03:24 +01:00
ringabout
334f2d6a87 fixes #25457; make rawAlloc support alignment (#25476)
fixes https://github.com/nim-lang/Nim/issues/25457

Small chunks allocate memory in fixed-size cells. Each cell is
positioned at exact multiples of the cell size from the chunk's data
start, which makes it much harder to support alignment

```nim
sysAssert c.size == size, "rawAlloc 6"
if c.freeList == nil:
  sysAssert(c.acc.int + smallChunkOverhead() + size <= SmallChunkSize,
            "rawAlloc 7")
  result = cast[pointer](cast[int](addr(c.data)) +% c.acc.int)
  inc(c.acc, size)
```

See also https://github.com/nim-lang/Nim/pull/12926

While using big trunk, each allocation gets its own chunk

(cherry picked from commit 94008531c1)
2026-02-13 09:39:30 +01:00
ringabout
29125f0bc7 fixes #25494; [regression] Crash on enum ranges as default parameters in generic procs (#25496)
fixes #25494;

(cherry picked from commit ae5f864bff)
2026-02-10 17:22:52 +01:00
ringabout
becb06dd70 fixes #25488; Strings can be compared against nil (#25489)
fixes #25488
ref https://github.com/nim-lang/Nim/pull/20222

(cherry picked from commit 513c9aa69a)
2026-02-10 17:22:25 +01:00
Yuriy Glukhov
2ddeabceaf Fixes #25340 (#25389)
(cherry picked from commit 296b2789b5)
2026-02-10 17:20:32 +01:00
ringabout
9fa69d222f fixes #25482; ICE leaking temporary 3 slotTempInt (#25483)
fixes #25482

(cherry picked from commit a04f720217)
2026-02-10 17:20:21 +01:00
ringabout
d48fc130c1 fixes #24706; Warn on implicit range downsizing (#25451)
fixes #24706

(cherry picked from commit bfc2786718)
2026-02-02 07:59:57 +01:00
Tomohiro
c86e7a0ca9 fixes #25459; hashType returns different hash from instantiated generics with distinct types (#25471)
`hashType` proc returned the same hash value from different instanced
generics types like `D[int64]` and `D[F]`.
That caused the struct type with wrong field types.

object/tuple type size check code is generated when it is compiled with
`-d:checkAbi` option.

(cherry picked from commit 88e7adfcb7)
2026-02-02 07:57:46 +01:00
Tomohiro
8d553c5624 fixes #25231; print better error messages when generics instantiation… (#25460)
… has no params

(cherry picked from commit abf434a336)
2026-01-28 09:41:30 +01:00
Gianmarco
d9ed8f2717 Make it so that every feature can be used in panicoverride files (#25300)
Refer to #25298

(cherry picked from commit e7809364b3)
2026-01-26 09:13:58 +01:00
ringabout
35429f6252 fixes #25441; fixes #7355; deletes void args from the argument list (#25455)
fixes #25441; fixes #7355

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
(cherry picked from commit 81610095e6)
2026-01-26 09:13:27 +01:00
ringabout
7277d95b3c fixes #19831; add --styleCheck:warning (#25456)
fixes #19831

(cherry picked from commit f44700e638)
2026-01-26 09:13:17 +01:00
ringabout
ba8ff51f2d fixes #25074; Long integer literal truncated without warning (#25449)
fixes #25074

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
(cherry picked from commit ace09b3cab)
2026-01-26 09:13:06 +01:00
ringabout
a4982bd74d fixes #25446; [FieldDefect] with static: discard cast[pointer](default(pointer)) (#25448)
fixes #25446

supports this since `static: discard cast[pointer](nil)` works

(cherry picked from commit 39864980d1)
2026-01-26 09:12:59 +01:00
ringabout
196f444699 fixes #25400; Naked raised causes wrong exception effect (#25422)
fixes #25400

infers `Exception` for Naked raised

(cherry picked from commit 9a23ff36bd)
2026-01-26 09:12:51 +01:00
ringabout
67446d192d Remove URL from BipBuffer package entry (#25439)
ref https://github.com/MarcAzar/BipBuffer/pull/1

(cherry picked from commit 80b43ad6ce)
2026-01-26 09:12:35 +01:00
ringabout
97c160271c fixes #25419; lift magic types to typeclasses (#25421)
fixes #25419

(cherry picked from commit 40480fe348)
2026-01-15 14:47:22 +01:00
Jake Leahy
c022120ebb Raw switch for jsondoc (#24568)
Implements #21928

Adds a `--raw` (since thats what the original issue used, suggestions
welcome) switch which stops the jsondoc gen from rendering rst/markdown.

Implemented by making `genComment` check if it needs to return the raw
string or not. This required switching the related procs to using
`Option` to handle how `nil` values were returned before. The `nil`
returns were eventually ignored so just ignoring `none(T)` has the same
effect.

Doesn't support `runnableExamples` since jsondocs doesn't support them
either

(cherry picked from commit c1e381ae8d)
2026-01-12 08:51:47 +01:00
Copilot
e45bef46a1 Add test case for jsffi type mismatch error (#16726) (#25429)
Issue #16726 reported an internal compiler error (`semcall.nim(229, 18)
nArg != nil`) when calling `toJs` with invalid arguments. The bug has
been fixed in the current codebase but lacked a regression test.

```nim
import std/jsffi
let a = toJs(3)
let b = a.toJs(int)  # Now produces: Error: type mismatch
                      # Previously: internal error
```

**Changes:**
- Added `tests/js/t16726.nim` to verify proper type mismatch error is
reported instead of internal compiler error

<!-- START COPILOT ORIGINAL PROMPT -->

<details>

<summary>Original prompt</summary>

>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>internal error: semcall.nim(229, 18) nArg !=
nil</issue_title>
> <issue_description>### Example
> the code below should give a clean CT error, not an internal error
> ```nim
> import std/jsffi
> let a = toJs(3)
> let b = a.toJs(int)
> ```
>
> ### Current Output
> nim r -b:js main
> compiler/semcall.nim(229, 18) `nArg != nil`
>
> ### Expected Output
> proper CT error
>
> ### Additional Information
> 1.5.1 41965880ce
> </issue_description>
>
> <agent_instructions>adds a test case for it and verify it by `./koch
temp js -r test.nim` before committing</agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> <comment_new><author>@ringabout</author><body>
> related:
https://github.com/nim-lang/Nim/issues/15607</body></comment_new>
> </comments>
>

</details>

<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes nim-lang/Nim#16726

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
(cherry picked from commit 83d7d8c634)
2026-01-12 08:49:58 +01:00
ringabout
a21a1c99cd fixes #19983; implements bitmasked bitshifting for all backends (#25390)
replaces https://github.com/nim-lang/Nim/pull/11555

fixes https://github.com/nim-lang/Nim/issues/19983
fixes https://github.com/nim-lang/Nim/issues/13566

- [x] JS backend

---------

Co-authored-by: Arne Döring <arne.doering@gmx.net>
(cherry picked from commit f1b97caf92)
2026-01-12 08:48:55 +01:00
ringabout
f3f76cdc52 closes #23394; adds a test case (#25416)
closes #23394

(cherry picked from commit 89c8f0aa49)
2026-01-09 09:14:09 +01:00
ringabout
e6413f8fe4 remove duplicated module imports (#25411)
(cherry picked from commit a6c7989c7f)
2026-01-09 09:12:48 +01:00
ringabout
fa6be0fb6a hello 2026 (#25410)
(cherry picked from commit 1a651c17b3)
2026-01-09 09:12:37 +01:00
Ryan McConnell
f04fe4e4a3 memfiles.nim resizeFile fallback logic bug (#25408)
`e` is not cleared when falling back to `ftruncate`

(cherry picked from commit 4b615aca46)
2026-01-09 09:12:03 +01:00
Jacek Sieka
d1016a3bc9 pegs: get rid of spurious exception effects (#25399)
Pegs raise only their own error, but the forward declaration causes an
unwanted Exception effect

* use strformat which does compile-time analysis of the format string to
avoid exceptions
* also in parsecfg

(cherry picked from commit 92ad98f5d8)
2026-01-09 09:11:40 +01:00
Esteban C Borsani
0ae9f5e4df Add parseEnum support for triple quoted string and raw string enum values (#25401)
(cherry picked from commit ae8a1739f8)
2026-01-09 09:08:34 +01:00
Pierre Thibault
fda7c2e5bb Missleading sentence about array indexing (#25367)
I added some precision. The first time I read this sentence, I was
confused. This applies to the above example, but it cannot be
generalized, since every array has its own range of valid indexes.

I think this change make the documentation clearer.

---------

Co-authored-by: Andreas Rumpf <araq4k@proton.me>
(cherry picked from commit ee55ddcffd)
2026-01-09 09:04:33 +01:00
Jacek Sieka
237f50e0d9 reduce imports (#25398)
(cherry picked from commit 61970be479)
2026-01-09 09:03:51 +01:00
Jake Leahy
34e61d5ae6 Fix tupleLen not skipping aliases (#25392)
This code was failing to compile with `Error: unhandled exception:
semmagic.nim(247, 5) operand.kind == tyTuple tyAlias [AssertionDefect]`
```nim
import std/typetraits

type
  Bar[T] = T
  Foo = Bar[tuple[a: int]]

echo Foo.tupleLen
```

Fix was just making `tupleLen` skip alias types also

(cherry picked from commit 91d51923b9)
2026-01-09 08:49:48 +01:00
bptato
1dafcbd2a7 Fix std/hashes completely ignoring endianness (#25386)
This is a problem on big-endian CPUs because you end up with nimvm
computing something different than Nim proper, so e.g. a const table
won't work.

I also took the liberty to replace a redundant implementation of load4
in murmurHash.

(Thanks to barracuda156 for helping debug this.)

(cherry picked from commit a061f026a8)
2026-01-09 08:49:09 +01:00
ringabout
57e4b364d2 fixes #25387; embedsrc breaks with Line Continuation (#25388)
fixes #25387

https://stackoverflow.com/questions/30286253/how-to-escape-backslash-in-comment

- adding a whitespace or `\t` after `\` breaks the `goto` block
- `\* *\` doesn't support nesting, causing problems for using it in the
Nim comments

(cherry picked from commit a41bbf6901)
2026-01-09 08:49:03 +01:00
ringabout
6d32ceaebb fixes #25254; fixes #10395; Invalid pred in when swallowed (#25385)
fixes #25254
fixes #10395

(cherry picked from commit 5e53a70e62)
2026-01-09 08:48:56 +01:00
Yuriy Glukhov
72e24284ef Fixes #25319 (#25380)
This was a regression introduced in
https://github.com/nim-lang/Nim/pull/25070.

@janAkali, @Z9RO, can you verify please?

(cherry picked from commit 2dbdf08fc7)
2026-01-09 08:48:46 +01:00
elijahr
f4fd26d403 Fix sizeof(T) in typedesc templates called from generic type when clauses (#25374)
The `hasValuelessStatics` function in `semtypinst.nim` only checked for
`tyStatic`, missing `tyTypeDesc(tyGenericParam)`. This caused
`sizeof(T)` inside a typedesc template called from a generic type's
`when` clause to error with "'sizeof' requires '.importc' types to be
'.completeStruct'".

The fix adds a check for `tyTypeDesc` wrapping `tyGenericParam`,
recognizing it as an unresolved generic parameter that needs resolution
before evaluation.

Also documents the `completeStruct` pragma in the manual.

(cherry picked from commit b819472e74)
2026-01-09 08:48:29 +01:00
Amjad Ben Hedhili
a4ec5d6be2 [Docs] Remove horizontal scrolling on mobile (#25377)
* Also use more of the available width

(cherry picked from commit 7b12deecf4)
2026-01-09 08:48:22 +01:00
elijahr
75f818f385 fix #17630: Implement cycle detection for recursive concepts (#25353)
fixes #17630

## Recursive Concept Cycle Detection

- Track (conceptId, typeId) pairs during matching to detect cycles
- Changed marker from IntSet to HashSet[ConceptTypePair]
- Removed unused depthCount field
- Added recursive concepts documentation to manual
- Added tests for recursive concepts, distinct chains, and co-dependent
concepts

## Fix Flaky `tasyncclosestall` Test

The macOS ARM64 CI jobs were failing due to a flaky async socket test
(unrelated to concepts).

The test only accepted `EBADF` as a valid error code when closing a
socket with pending writes. However, depending on timing, the kernel may
report `ECONNRESET` or `EPIPE` instead:

- **EBADF**: Socket was closed locally before kernel detected remote
state
- **ECONNRESET**: Remote peer sent RST packet (detected first)
- **EPIPE**: Socket is no longer connected (broken pipe)

All three are valid disconnection errors. The fix accepts any of them,
making the test reliable across platforms.

---------

Co-authored-by: Andreas Rumpf <araq4k@proton.me>
(cherry picked from commit 1324183c38)
2026-01-09 08:47:57 +01:00
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