Skip to content

Refactored arraysetlengthT and arraysetlengthiT into a Single arraysetlengthT Template #21151

Merged
thewilsonator merged 1 commit intodlang:masterfrom
shivangshukla7020:template
May 1, 2025
Merged

Refactored arraysetlengthT and arraysetlengthiT into a Single arraysetlengthT Template #21151
thewilsonator merged 1 commit intodlang:masterfrom
shivangshukla7020:template

Conversation

@shivangshukla7020
Copy link
Copy Markdown
Contributor

Changes Introduced

This PR merges arraysetlengthT and arraysetlengthiT into a single template, improving compile-time specialization and reducing redundancy. The key updates include:

  • Unified arraysetlengthT and arraysetlengthiT into a single template, distinguishing them based on initialization behavior.
  • Optimized memory handling for zero-initialized (arraysetlengthT) and non-zero-initialized (arraysetlengthiT) cases.
  • Used emplace for non-trivial types instead of memcpy to ensure correct postblit behavior.
  • Integrated gc_expandArrayUsed for in-place array expansion where applicable.
  • Added D_ProfileGC support via _d_HookTraceImpl.

This refactoring improves performance by removing TypeInfo lookups and enabling better compile-time specialization.

@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request and interest in making D better, @shivangshukla7020! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#21151"

Copy link
Copy Markdown
Member

@teodutu teodutu left a comment

Choose a reason for hiding this comment

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

Overall this is looking good. I made some small suggestions.

@shivangshukla7020 shivangshukla7020 force-pushed the template branch 2 times, most recently from 09df08b to 0e0cd9c Compare April 21, 2025 11:00
@shivangshukla7020 shivangshukla7020 force-pushed the template branch 3 times, most recently from 30a3d1b to 2ab5424 Compare April 23, 2025 19:05
@shivangshukla7020 shivangshukla7020 force-pushed the template branch 3 times, most recently from f329524 to 136317e Compare April 24, 2025 06:43
Copy link
Copy Markdown
Member

@teodutu teodutu left a comment

Choose a reason for hiding this comment

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

The compiler code looks OK, but the runtime checks for __traits(compiles might be superfluous.

Copy link
Copy Markdown
Member

@teodutu teodutu left a comment

Choose a reason for hiding this comment

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

It's looking good now. Since you have 73 commits here, it would be easier for eventual regressions to squash them into a single one before merging.

@thewilsonator
Copy link
Copy Markdown
Contributor

Plese rebase and resolve the merge conflicts

@shivangshukla7020
Copy link
Copy Markdown
Contributor Author

shivangshukla7020 commented May 1, 2025

Plese rebase and resolve the merge conflicts

Done

Copy link
Copy Markdown
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

Thanks

@thewilsonator thewilsonator merged commit 94bad47 into dlang:master May 1, 2025
42 checks passed
@bangbangsheshotmedown
Copy link
Copy Markdown
Contributor

runtime hook change should probably require a change log entry

@teodutu
Copy link
Copy Markdown
Member

teodutu commented May 1, 2025

runtime hook change should probably require a change log entry

Oh yeah you're right, I forgot to mention this. @shivangshukla7020 please raise another PR where you add a file to this folder (check those already existing for formatting): https://github.com/dlang/dmd/tree/master/changelog

@shivangshukla7020
Copy link
Copy Markdown
Contributor Author

Okay, I'll update and add the changelog accordingly

@CyberShadow
Copy link
Copy Markdown
Member

This pull request introduced a regression: #21832

@ibuclaw
Copy link
Copy Markdown
Member

ibuclaw commented Nov 20, 2025

This PR caused a build regression

core/internal/array/capacity.d:251:23: error: none of the overloads of template ‘core.checkedint.mulu’ are callable using argument types ‘!()(ulong, ulong, ubyte)’
  251 |         newsize = mulu(sizeelem, newlength, overflow);
      |                       ^
core/checkedint.d:761:6: note: Candidates are: ‘mulu()(uint x, uint y, ref bool overflow)’
  761 | uint mulu()(uint x, uint y, ref bool overflow)
      |      ^
core/checkedint.d:792:7: note:                 ‘mulu()(ulong x, uint y, ref bool overflow)’
  792 | ulong mulu()(ulong x, uint y, ref bool overflow)
      |       ^
core/checkedint.d:803:7: note:                 ‘mulu()(ulong x, ulong y, ref bool overflow)’
  803 | ulong mulu()(ulong x, ulong y, ref bool overflow)
      |       ^

Comment on lines +225 to +252
ubyte overflow = 0;

size_t newsize = void;

version (D_InlineAsm_X86)
{
asm pure nothrow @nogc
{
mov EAX, sizeelem;
mul newlength; // EDX:EAX = EAX * newlength
mov newsize, EAX;
setc overflow;
}
}
else version (D_InlineAsm_X86_64)
{
asm pure nothrow @nogc
{
auto ti = typeid(Tarr);
mov RAX, sizeelem;
mul newlength; // RDX:RAX = RAX * newlength
mov newsize, RAX;
setc overflow;
}
}
else
{
newsize = mulu(sizeelem, newlength, overflow);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

... here, overflow has wrong type.

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.

7 participants