Commit Graph

22806 Commits

Author SHA1 Message Date
Andreas Rumpf
a866bf2a39 VM: optimize 'return' slots; saves millions of node allocations for N… (#25266)
…imbus
2025-11-07 13:53:24 +01:00
ringabout
6d3254a86f 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
2025-11-07 13:53:24 +01:00
Jacek Sieka
155b06a4f5 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`.
2025-11-07 13:53:24 +01:00
ringabout
116c220e3f fixes #25263; provides a new switch mangle:nim/cpp for debug name mangling (#25264)
fixes #25263

- [x] documentation and changelogs
2025-11-07 13:53:24 +01:00
demotomohiro
43ff7b1dc4 loads modules imported by system module and create module sym before decode 2025-11-06 04:50:21 +09:00
demotomohiro
54aa552fb6 refers imported symbols like Nimony 2025-11-06 04:50:21 +09:00
demotomohiro
ab13900fad saves/loads PSym.ast, constraint and instantiatedFrom 2025-11-06 04:50:21 +09:00
demotomohiro
5f3be1e991 makes tencode_node2node.nim faster 2025-11-06 04:50:21 +09:00
demotomohiro
f3178e4515 saves/loads flags of nkIdent node 2025-11-06 04:50:21 +09:00
demotomohiro
9f73412e93 saves/loads float Inf, NaN and NegInf literals 2025-11-06 04:50:21 +09:00
demotomohiro
91db9ac8f5 uses ItemId instead of PSym or PType for the set of decoded syms and types 2025-11-06 04:50:21 +09:00
demotomohiro
3c599ed7db adds expression test code 2025-11-06 04:50:20 +09:00
demotomohiro
66d7a8e0b4 adds generics test code and fixes bug 2025-11-06 04:50:20 +09:00
demotomohiro
467a27948c adds pragma test code 2025-11-06 04:50:20 +09:00
demotomohiro
6a74316c0e fixes assertion defect when encoding empty object type definition 2025-11-06 04:50:20 +09:00
demotomohiro
10885d4dce adds statements test code 2025-11-06 04:50:20 +09:00
demotomohiro
3ceb223089 adds more procedure test code 2025-11-06 04:50:20 +09:00
demotomohiro
b50c453b14 adds procedure test code and fix bugs 2025-11-06 04:50:19 +09:00
demotomohiro
6f237be686 saves/loads symbol magic, options and offset 2025-11-06 04:50:19 +09:00
demotomohiro
8a4d921d6b saves/loads PNode and PSym line info 2025-11-06 04:50:19 +09:00
demotomohiro
51eccea910 saves/loads PSym guard, bitsize and alignment 2025-11-06 04:50:19 +09:00
demotomohiro
5eeede3a43 uses PSym.item and PType.item as id in NIF 2025-11-06 04:50:19 +09:00
demotomohiro
25ca7ccc79 encodes/decodes itemId.module 2025-11-06 04:50:19 +09:00
demotomohiro
e9127b2567 adds Nim's AST to/from NIF 2025-11-06 04:50:19 +09:00
Andreas Rumpf
cfefd1d95b produces vastly better error messages for implicit --import and --inc… (#25258)
…lude configuration options
2025-11-04 17:54:23 +01:00
ringabout
d54b5f3ae1 fixes #25252; Unexpected ambiguous call with fields over object with default fields (#25256)
fixes #25252
2025-11-04 20:08:07 +08:00
Tomohiro
5079074b1a uses newer Nimony (#25249)
Old Nimony has unfixed issue
https://github.com/nim-lang/nimony/issues/1313.
So https://github.com/nim-lang/Nim/pull/25243 doesn't work correctly
with float literal `-0.0`.
This PR updates the Nimony that fixed the issue.
2025-10-31 16:59:38 +01:00
Yuriy Glukhov
99a222d63d Respect noinit for generic types (#25250) 2025-10-31 16:59:24 +01:00
Miran
3e9a66599a bump the shipped version of Atlas (#25248) 2025-10-30 20:30:28 +01:00
ringabout
ce6a34597d fixes #24575; _GNU_SOURCE redefined (#25247)
fixes #24575
2025-10-28 18:39:50 +01:00
Yuriy Glukhov
7af4e3eefd Fixes #25202 (#25244) 2025-10-28 12:48:22 +01:00
ringabout
130eac2f93 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.
2025-10-28 11:47:20 +01:00
ringabout
b8ce11dd9d fixes #25027; nim doc uses doc comment from private field for public field (#25239)
fixes #25027
2025-10-23 19:19:27 +02:00
ringabout
b7c02e9bad fixes #25240; forbids modifying a Deque changed while iterating over it (#25242)
fixes #25240

> Deque items behavior is not the same on 2.0.16 and 2.2.0

The behavior seems to be caused by the temp introduced for the parameter
`deq.len`, which prevents it from being evaluated multiple times
2025-10-23 19:18:57 +02:00
Ryan McConnell
544c26c0b8 add srcDir variable to nim.cfg (#24919)
There might be a way to do this but I couldn't find anything about it.
This is a very simple thing that goes a long way in certain situations.
Trying to avoid needing to switch to nimscript just to get:
```nim
# config.nims
import os
let srcDir = currentSourcePath.parentDir()
switch("define", &"ProjPath:\"{srcDir}\"")
```
with this change just needs:
```
# nim.cfg
d %= "ProjPath=$srcDir"
```
2025-10-23 09:05:05 +02:00
ringabout
c449c72498 fixes #25236; broken assignment hooks of union inside variant object in orc (#25238)
fixes #25236
2025-10-21 16:59:22 +02:00
ringabout
1eae14a3be fixes #25226; VM repr raises RangeDefect for long string under refc (#25230)
fixes #25226

`int16` seems to be too small for a reasonable VM program
2025-10-17 17:32:28 +02:00
ringabout
5abd21dfa5 fixes #25123; fixes #11862; Case object from compileTime proc unable to be passed as static param (#25224)
fixes #25123; fixes #11862

follow up https://github.com/nim-lang/Nim/pull/24442
ref https://github.com/nim-lang/Nim/pull/24441

> To fix this, fields from inactive branches are now detected in
semmacrosanity.annotateType (called in fixupTypeAfterEval) and marked to
prevent the codegen of their assignments. In
https://github.com/nim-lang/Nim/pull/24441 these fields were excluded
from the resulting node, but this causes issues when the node is
directly supposed to go back into the VM, for example as const values. I
don't know if this is the only case where this happens, so I wasn't sure
about how to keep that implementation working.

Object variants fields coming from inactive branches from VM are now
flagged `nfPreventCg`. We can ignore them, as done by the C backends.
2025-10-16 18:22:46 +02:00
ringabout
f009ea6c3e fixes #25208; generates a copy for opcLdConst in the assignments (#25211)
fixes #25208


```nim
type Conf = object
  val: int

const defaultConf = Conf(val: 123)
static:
  var conf: Conf
  conf = defaultConf
```

```nim
# opcLdConst is now always valid. We produce the necessary copy in the
# assignments now:
```

A `opcLdConst` is generated for `defaultConf` in `conf = defaultConf`.
According to the comment above, we need to handle the copy for
assignments of `opcLdConst`
2025-10-16 18:22:06 +02:00
lit
8f3bdb6951 fixes #25222; cast[char](i) not trunc on JS (#25223)
fixes #25222
2025-10-16 18:21:37 +02:00
ringabout
31d64b57d5 fixes #25046; Infinite loop with anonymous iterator (#25221)
fixes #25046

```nim
proc makeiter(v: string): iterator(): string =
  return iterator(): string =
    yield v

# loops
for c in makeiter("test")():
  echo "loops ", c
```
becomes

```nim
var temp = makeiter("test")
for c in temp():
  echo "loops ", c
```
for closures that might have side effects
2025-10-15 12:11:15 +02:00
ringabout
2be0721236 fixes vtable documentation in tut2 (#24304)
ref https://forum.nim-lang.org/t/12537#77311
2025-10-15 08:22:27 +02:00
ringabout
f191ba8ddd fixes #25048; Closure environment wrongly marked as cyclic (#25220)
fixes  #25048

```nim
proc canFormAcycleAux =
  of tyObject:
    # Inheritance can introduce cyclic types, however this is not relevant
    # as the type that is passed to 'new' is statically known!
    # er but we use it also for the write barrier ...
    if tfFinal notin t.flags:
      # damn inheritance may introduce cycles:
      result = true
```

It seems that all objects without `tfFinal` in their flags are
registering cycles. It doesn't seem that `Env` can be a cyclic type
because of inheritance since it is not going to be inherited after all
by another `Env` object type
2025-10-15 07:24:48 +02:00
ringabout
fb4a82f5cc fixes #25210; VM error when passing object field ref to proc(var T): var T (#25213)
fixes #25210
no longer transform `addr(obj.field[])` into `obj.field` to keep the
addressing needed for VM
2025-10-15 07:21:08 +02:00
ringabout
c0fa86872b fixes nightlies due to UB errors; increase maxCPU hard limits (#25219)
ref https://github.com/nim-lang/Nim/pull/25217

The issues is actually that there is a hard limit for max cpus in
niminst: https://github.com/nim-lang/Nim/pull/25219, which set to 20
while there is a 21 cpus now
2025-10-13 13:47:06 +02:00
Juan Carlos
1ef81f4190 Fix Bisect (#25218)
- Nim requires `SSL_library_init`, OpenSSL 3.x removed
`SSL_library_init`, Windows defaults to OpenSSL 3.x, then install
OpenSSL 1.x on Windows.
- Keep `jiro4989/setup-nim-action` at `v1`, because `v2` uses a YAML
"hardcoded" matrix of Nim versions, but this Bisect "dynamically" finds
the Nim version with a bug, therefore we cant hardcode Nim versions in
the YAML, the Bisect programmatically installs required Nim versions as
it goes bisecting commit-by-commit.
- Update `actions/checkout` from `v4` to `v5`.
- Add support for Nim `2.2.4`.

@ringabout
2025-10-11 11:23:40 +08:00
ringabout
3962264c35 nightlies regressions: CPU order matters for C sources? (#25217)
ref https://github.com/nim-lang/Nim/pull/25056


https://github.com/nim-lang/nightlies/actions/runs/18053288396/job/51378922406#step:12:1572

```
bin/nim compile -f --incremental:off --compileonly --gen_mapping --cc:gcc --skipUserCfg --os:windows --cpu:loongarch64 -d:danger -d:gitHash:f4497c61584dca8acd489ceb7ba862b150f5cf55 compiler/nim.nim
```

`loongarch64` is applied to all the platforms wrongly. Presumably it was
caused by the order?
2025-10-10 19:11:58 +02:00
ringabout
7c65d9e747 fixes #25204; Uninitialized variable usage in resize__system_u... in @psystem.nim.c in ORC (#25209)
fixes #25204

```nim
  of mUnaryMinusI..mAbsI: unaryArithOverflow(p, e, d, op)
  of mAddI..mPred: binaryArithOverflow(p, e, d, op)
```
Arithmetic operations may raise exceptions. So we cannot entrust the
optimizer to skip `result` initialization in this situation, as
complained righteously by `gcc` and `clang`: `warning: ‘result’ may be
used uninitialized [-Wmaybe-uninitialize]`.

With this PR, `clang -c -Wuninitialized -O1 @psystem.nim.c` no longer
gives warnings
2025-10-08 19:10:09 +02:00
Andreas Rumpf
c4c51d7e78 unittest: show proper stack trace for 'check' (#25212) 2025-10-08 19:09:45 +02:00
Gleb
440b55a44a fix spawn not used on linux (#25206)
Subj, among other things slows down the compilation of large projects on
linux significantly.
2025-10-06 22:22:32 +02:00