Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored arraysetlengthT and arraysetlengthiT into a Single arraysetlengthT Template #21151

Open
wants to merge 45 commits into
base: master
Choose a base branch
from

Conversation

shivangshukla7020
Copy link
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
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
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.

}

version (D_ProfileGC)
size_t oldsize = arr.length * sizeelem;
bool isshared = is(T == shared T);
Copy link
Member

Choose a reason for hiding this comment

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

You can optimise this a little bit. Now a new template instance would be emitted for each array type like A[], const A[] etc, but you only need the unqualified type (UnqT). So draw inspiration from here [1] and unqualify the type in the compiler and pass isshared as an argument to reduce the number of generated type instances.

[1]

auto tiargs = new Objects();
/*
* Remove `inout`, `const`, `immutable` and `shared` to reduce the
* number of generated `_d_newitemT` instances.
*/
auto t = ne.type.nextOf.unqualify(MODFlags.wild | MODFlags.const_ |
MODFlags.immutable_ | MODFlags.shared_);
tiargs.push(t);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ll update it to follow that approach and avoid unnecessary template instantiations .

@@ -3764,14 +3764,17 @@ extern (C++) final class SliceExp : UnaExp
*/
extern (C++) final class ArrayLengthExp : UnaExp
{
Expression lowering; // Field to store the lowered expression
Copy link
Member

Choose a reason for hiding this comment

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

You don't need this field. expressionsem.d creates a LoweredAssignExp which already contains the lowering. No need to duplicate it here.

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.

4 participants