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

Advance deprecation of delete expressions, class allocators, class deallocators: Error #9666

Closed
wants to merge 1 commit into from
Closed

Conversation

JinShil
Copy link
Contributor

@JinShil JinShil commented Apr 21, 2019

Documentation update: dlang/dlang.org#2631

@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

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 + dmd#9666"

@wilzbach
Copy link
Member

home/braddr/sandbox/at-client/pull-3607611-Linux_32_64/dmd/generated/linux/release/32/dmd -conf= -m64 -Irunnable  -fPIC  -odgenerated/runnable -ofgenerated/runnable/test23_0  runnable/test23.d 
runnable/test23.d(709): Deprecation: class allocators have been deprecated, consider moving the allocation strategy outside of the class
runnable/test23.d(717): Deprecation: class deallocators have been deprecated, consider moving the deallocation strategy outside of the class
runnable/test23.d(741): Deprecation: class allocators have been deprecated, consider moving the allocation strategy outside of the class
runnable/test23.d(749): Deprecation: class deallocators have been deprecated, consider moving the deallocation strategy outside of the class
runnable/test23.d(728): Error: The `delete` keyword has been deprecated.  Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead.


==============================
Test runnable/test23.d failed: expected rc == 0, exited with rc == 1

Makefile:153: recipe for target 'generated/runnable/test23.d.out' failed
make[2]: *** [generated/runnable/test23.d.out] Error 1

There's also at least one test in druntime that needs to be disabled before this can pass.

@JinShil
Copy link
Contributor Author

JinShil commented Apr 21, 2019

There's also at least one test in druntime that needs to be disabled before this can pass.

Please elaborate. I replaced delete with destroy and test23.d passes (though there are other tests that don't pass with such a fix).

@wilzbach
Copy link
Member

I'm talking about the unittests in here: https://github.com/dlang/druntime/blob/master/src/rt/lifetime.d which test the implementation of delete.

I think they need to be disabled first for this PR to pass.

@JinShil
Copy link
Contributor Author

JinShil commented Apr 21, 2019

I think they need to be disabled first for this PR to pass.

Ok, I'll get to it. It looks like this is going to be a much bigger job than I anticipated. It'd probably be a good idea to mark this WIP until I work through all of the issues.

@wilzbach wilzbach added the WIP Work In Progress - not ready for review or pulling label Apr 21, 2019
@rainers
Copy link
Member

rainers commented Apr 21, 2019

I'm not a big fan of deprecation or removal of delete. As far as I know the rationale was that it looks innocent syntactically, but is unsafe. The same can be said about other constructs of the language, e.g. pointer offsetting.

On the other hand, it is quite inconvenient to get the call to GC.free correct. Even experienced D programmers don't know how to do it (see e.g. https://issues.dlang.org/show_bug.cgi?id=13558, also slightly related: https://issues.dlang.org/show_bug.cgi?id=19539). You should not have to know to begin with, as it will lock the user code with the internal implementation.

This can be solved by a library function that knows about all the special cases, but I think it should exist before removal. The pair of destroy and delete library functions is unlikely to be accessible to the compiler, while delete has defined semantics. With the help of escape analysis it might even proove its usage to be safe.

tldr: If delete is removed, a library function should be provided that actually frees the memory. I'd prefer de-deprecation, though.

@wilzbach
Copy link
Member

@rainers: there's __delete in core.memory which is supposed to be a 1:1 replacement of delete.

@rainers
Copy link
Member

rainers commented Apr 21, 2019

@rainers: there's __delete in core.memory which is supposed to be a 1:1 replacement of delete.

Thanks, I didn't know these. And the implementation is just as wrong as in the bug report given above.

@JinShil JinShil changed the title Advance deprecation of delete expressions: Error Advance deprecation of delete expressions, class allocators, class deallocators: Error Apr 23, 2019
@JinShil
Copy link
Contributor Author

JinShil commented Apr 23, 2019

Many of the tests were using delete to test class deallocators, so I had to advance the deprecation of delete, class allocators, and class deallocators simultaneously to make this work and pass the test suite.

@JinShil
Copy link
Contributor Author

JinShil commented May 3, 2019

../../druntime/import/object.d(642): Error: rt_finalize cannot be interpreted at compile time, because it has no available source code
Error: expression <error> is not constant
runnable/interpret.d(3207): while evaluating: static assert(test6907())

Apparently delete is currently implemented at compile-time. See https://issues.dlang.org/show_bug.cgi?id=6907

But, I don't know if it's possible to implement __delete at compile-time. The following code illustrates the problem.

class C { ~this() { ++dtor1; } }
{ Object o = new C(); __delete(o); assert(dtor1 == 4); }

Since __delete is called with a type of Object, the following if statement will return false because T is Object instead of C:

static if (__traits(hasMember, T, "__xdtor"))
     obj.__xdtor();

typeid() isn't implemented for CTFE and CTFE can't perform casts like ClassInfo** c = cast(ClassInfo**)(&obj). So, I'm stuck. I don't know how to get the destructor of C when C is given to me as Object.

@jacob-carlborg
Copy link
Contributor

typeid() isn't implemented for CTFE

You can always try to implement that 😉.

@JinShil
Copy link
Contributor Author

JinShil commented May 14, 2019

I'm closing this for now. Removing delete is going to require a significant amount of work.

@JinShil JinShil closed this May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work In Progress - not ready for review or pulling
Projects
None yet
5 participants