Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive

Comments

Fix linker error in destroy under -betterC#2204

Merged
dlang-bot merged 1 commit intodlang:masterfrom
JinShil:fix_destroy_link_error
Jun 10, 2018
Merged

Fix linker error in destroy under -betterC#2204
dlang-bot merged 1 commit intodlang:masterfrom
JinShil:fix_destroy_link_error

Conversation

@JinShil
Copy link
Contributor

@JinShil JinShil commented Jun 2, 2018

This is a followup to #2178

My fix was insufficient. Although it fixed the compiler error, there was still a linker error. Because we were copying two arrays, it was making a runtime call to _d_arraycopy. Since the runtime is not linked in -betterC, it resulted in an unresolved reference error at link time.

See the implementation of _d_arraycopy at

void[] _d_arraycopy(size_t size, void[] from, void[] to)
. It basically just forwards to memcpy, so the array copy code was simply replaced with a direct call to memcpy.

The test case was also updated to compile and link.

Sorry for the mistake.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @JinShil!

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 fetch digger
dub run digger -- build "master + druntime#2204"

@JinShil JinShil added the Vision Vision Plan https://wiki.dlang.org/Vision/2018H1 label Jun 2, 2018
@n8sh
Copy link
Member

n8sh commented Jun 2, 2018

If dest[] = src[] doesn't work in betterC, that should be fixed rather than applying a bandaid here.

@JinShil
Copy link
Contributor Author

JinShil commented Jun 2, 2018

It is possible to make dest[] = src[] work in -betterC, but that is an enormous undertaking. It requires rewriting the array lowerings in the compiler to templates (similar to what was done for __equals). I've been working on it, but is extremely difficult and filled with all kinds of problems.

For example, did you know you can set the length property of an array in @safe nothrow pure code, but it gets lowered to a runtime hook which is neither @safe, nothrow, nor pure? The compiler is lying to us. I attempted it already, but I discovered it required all the code in https://github.com/dlang/druntime/blob/098a08a9593a8e265a9b02da55bda53393f3d5c1/src/rt/lifetime.d to be rewritten. That is a long-term project and one, which if not done carefully, could cause quite a few problems. It's going to take years to get that done, but in the meantime users are expecting features like this to work.

@n8sh
Copy link
Member

n8sh commented Jun 2, 2018

@JinShil Of course you're right.

I was also writing under the mistaken assumption that slice copying not working in betterC was a recent regression rather than a longstanding limitation, since the documentation claims that array slicing is supported in -betterC.

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

Though of course it would be great if betterC would support array copying out of the box, but well let's got step by step.

@dlang-bot dlang-bot merged commit 706081f into dlang:master Jun 10, 2018
@JinShil JinShil deleted the fix_destroy_link_error branch July 11, 2018 01:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Vision Vision Plan https://wiki.dlang.org/Vision/2018H1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants