Skip to content

fixes #18238; Nested object construction can zero same memory multiple times for --mm:refc#25834

Open
ringabout wants to merge 1 commit into
develfrom
pr_shf
Open

fixes #18238; Nested object construction can zero same memory multiple times for --mm:refc#25834
ringabout wants to merge 1 commit into
develfrom
pr_shf

Conversation

@ringabout
Copy link
Copy Markdown
Member

@ringabout ringabout commented May 21, 2026

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.
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

Copilot AI review requested due to automatic review settings May 21, 2026 15:08
@ringabout ringabout changed the title fixes #18238; Nested object construction can zero same memory multiple times fixes #18238; Nested object construction can zero same memory multiple times for --mm:refc May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the C backend’s object-construction codegen (genObjConstr) to reduce redundant zero-initialization during nested object construction, targeting the --mm:refc case described in issue #18238.

Changes:

  • Refines the needsZeroMem condition in compiler/ccgexprs.nim to avoid unconditional zeroing based solely on the selected GC, and instead incorporate containsGarbageCollectedRef(t) plus the optSeqDestructors setting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread compiler/ccgexprs.nim
Comment thread compiler/ccgexprs.nim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested object construction can zero same memory multiple times

2 participants