Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Fix Issue 19830 - core.memory.__delete destructs arrays of structs in the wrong order #2585

Merged
merged 1 commit into from Apr 26, 2019
Merged

Conversation

JinShil
Copy link
Contributor

@JinShil JinShil commented Apr 26, 2019

This issue was discovered while working on dlang/dmd#9666

This test https://github.com/dlang/dmd/blob/b0007c1193dfb72bcfa8cef3f420fee68564ce49/test/runnable/sdtor.d#L186-L208 does not pass when delete is replaced with __delete. This PR fixes that.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @JinShil! 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 annotated coverage diff directly on GitHub with CodeCov's browser extension
  • 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

Auto-close Bugzilla Severity Description
19830 normal core.memory.__delete destructs arrays of structs in the wrong order

Testing this PR locally

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

dub fetch digger
dub run digger -- build "stable + druntime#2585"

@dlang-bot dlang-bot added the Bug Fix Include reference to corresponding bugzilla issue label Apr 26, 2019
@thewilsonator
Copy link
Contributor

Thanks!

@@ -1067,7 +1067,7 @@ void __delete(T)(ref T x) @system
{
static if (is(E == struct))
{
foreach (ref e; x)
foreach_reverse (ref e; x)
Copy link
Member

@rainers rainers Apr 26, 2019

Choose a reason for hiding this comment

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

See https://github.com/dlang/druntime/blob/master/src/rt/lifetime.d#L1157 for what currently happens with delete: finalizers are only called if it is a runtime allocated array (debatable), pointer offset is corrected for large arrays (GC.free is wrong otherwise), block cache is invalidated (not doing so might make later operations unsafe).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems to be an existing issue with __delete's impementation, but out of scope of this PR. Can you just file a bug report, so it can be dealt with properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably we should just have __delete call _d_delarray_t.

Copy link
Member

Choose a reason for hiding this comment

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

Can't do that as these C functions are supposed to go once the deprecation is over.

Copy link
Member

Choose a reason for hiding this comment

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

That seems to be an existing issue with __delete's impementation, but out of scope of this PR.

Fine with me.

Can you just file a bug report, so it can be dealt with properly?

https://issues.dlang.org/show_bug.cgi?id=13558

Probably we should just have __delete call _d_delarray_t.

That's what I thought, too.

Copy link
Contributor Author

@JinShil JinShil Apr 26, 2019

Choose a reason for hiding this comment

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

I think what @rainers is saying is the implementation is still needed; it just doesn't get called directly by the compiler. We either need to move the implementation into __delete or have __delete call it. I suppose we could also convert _d_delarray_t into a template to get rid of the dependency on TypeInfo.

Copy link
Member

Choose a reason for hiding this comment

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

I think Andrei would want us to move the implementation into __delete as the general idea is to move into a D without any runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll look into that soon.

@dlang-bot dlang-bot merged commit b61d29a into dlang:stable Apr 26, 2019
@JinShil JinShil deleted the fix_19830 branch April 26, 2019 15:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Fix Include reference to corresponding bugzilla issue
Projects
None yet
5 participants