Files
Nim/compiler
ringabout 4497d89267 fixes #18238; Nested object construction can zero same memory multiple times for --mm:refc (#25834)
fixes #18238

This pull request makes a targeted change to the object construction
logic in the `genObjConstr` procedure. The main update refines the
conditions under which memory zeroing is required during object
construction, making the behavior more accurate for different garbage
collection and destructor options.

Key logic update:

- Improved the `needsZeroMem` condition in `genObjConstr` to check for
the presence of garbage-collected references and the `optSeqDestructors`
option, instead of relying solely on the selected garbage collector and
field flags. This ensures memory is zeroed only when necessary,
potentially improving performance and correctness.


```c
T1_ = NIM_NIL;
T1_ = ((tyObject_E__uEKympBdEK4SY9anUbpNaLQ*) newObj((&NTIrefe__bJ9cSuxv8xHYxmdolQqFkUw_), sizeof(tyObject_E__uEKympBdEK4SY9anUbpNaLQ)));
nimZeroMem(((void*) ((&(*T1_).z.z.z.z))), sizeof(tyObject_A__G2lWlL9cFqoiWWwZmWqfJ9bA));
(*T1_).z.z.z.z.y = ((NI) 5);
asgnRef(((void**) ((&z1__test8_u12))), T1_);
asgnRef(((void**) ((&z2__test8_u55))), new__test8_u13());
(*z2__test8_u55).z.z.z.z.y = ((NI) 5);
T2_ = NIM_NIL;
T2_ = ((tyObject_E__uEKympBdEK4SY9anUbpNaLQ*) newObj((&NTIrefe__bJ9cSuxv8xHYxmdolQqFkUw_), sizeof(tyObject_E__uEKympBdEK4SY9anUbpNaLQ)));
asgnRef(((void**) ((&z3__test8_u56))), T2_);
(*z3__test8_u56).z.z.z.z.y = ((NI) 5);
```


The original test case has already been fixed for `ORC`, now extends it
to `refc`: if a constructor is fully initialized, it does not need a
zero-fill step
2026-06-08 08:54:15 +02:00
..
2023-12-15 10:20:57 +01:00
2025-12-01 22:59:12 +01:00
2026-02-10 13:21:35 +01:00
2026-04-02 07:19:43 +02:00
2025-12-11 18:22:38 +01:00
2026-03-16 16:56:18 +01:00
2025-12-31 13:33:57 +01:00
2017-01-07 22:35:09 +01:00
2026-02-10 13:21:35 +01:00
2025-12-11 18:22:38 +01:00
2025-12-11 18:22:38 +01:00
2026-06-07 19:55:56 +02:00
2025-11-25 12:49:23 +01:00
2026-04-02 07:19:43 +02:00
2024-12-27 19:42:18 +01:00
2026-04-02 07:19:43 +02:00
2025-12-11 18:22:38 +01:00
2026-04-02 07:19:43 +02:00
2025-12-11 18:22:38 +01:00
2021-01-12 09:36:51 +01:00
2026-01-09 13:10:04 +01:00
2026-02-10 13:21:35 +01:00
2025-12-11 18:22:38 +01:00
2025-12-11 18:22:38 +01:00
2026-01-24 06:07:41 +01:00
2026-02-10 13:21:35 +01:00
2023-07-02 22:36:05 +02:00
2023-11-06 18:33:28 +01:00
2026-02-10 13:21:35 +01:00
2026-05-12 23:20:10 +02:00
2025-12-11 18:22:38 +01:00
2025-12-11 18:22:38 +01:00
2025-12-11 18:22:38 +01:00
2025-12-11 18:22:38 +01:00
2026-05-29 08:08:42 +02:00
2025-12-11 18:22:38 +01:00
2024-03-16 08:35:18 +08:00
2025-12-29 13:52:22 +01:00
2025-12-31 13:33:57 +01:00
2026-02-10 13:21:35 +01:00
2023-12-25 07:12:54 +01:00

Nim Compiler

  • This directory contains the Nim compiler written in Nim.
  • Note that this code has been translated from a bootstrapping version written in Pascal.
  • So the code is not a poster child of good Nim code.

See Internals of the Nim Compiler for more information.