-
-
Notifications
You must be signed in to change notification settings - Fork 411
Refactor object.d: Move destroy and friends to new file, lifetime.d
#2399
Conversation
|
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 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 referencesYour 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 locallyIf 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#2399" |
|
|
Thanks, @thewilsonator |
|
No problems. |
|
The auto-tester was failing, so I tried to modify some of the makefiles. Now circleci is failing. I don't know why. If someone has an idea, please let me know. |
| endif | ||
|
|
||
| # macro that returns the module name given the src path | ||
| moduleName=$(subst rt.invariant,invariant,$(subst object_,object,$(subst /,.,$(1)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a string replacement from a bygone era, so I removed it. But I'm not even sure if I did it correctly because I generally don't work with makefiles, and dread it every time I have to.
|
What is this all about, and why is it affecting this PR? EDIT: Nevermind. I see it's actually complaining about the sanitized json diff. Looks like this needs a change to the DMD repository. EDIT: This PR now needs dlang/dmd#9049 |
|
WARNING: This PR causes a huge change in the documentation; see DAutoTest, but I can't see the usual diffs to determine what the changes are. I browsed the documentation and couldn't find any issues, but that doesn't mean there aren't any. EDIT: Looks like |
|
I don't understand what's failing in DAutoTest. @CyberShadow could you take a quick look? Or @adamdruppe, is that your code? EDIT: Nevermind. I think the real error was further down in the wall of output text. I think I figured it out. |
|
Ok, this is looking good now. Please notice the changes in the documentation. There's a new There was a concern in #2222 about this negatively affecting build times. I couldn't see any measurable difference when building phobos (at least with all the statistical noise). Reviewers are advised to independently verify. |
|
If this is accepted, I'll do some of the others. I'm thinking... object_/array.d - dynamic array support |
src/object_/lifetime.d
Outdated
| * Contains utilities for managing lifetimes. | ||
| * | ||
| * This module is not intended to be imported or used directly. It is | ||
| * publicly imported by object.d, and should be accessed through there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "should be accessed through there" mean? Would it be more accurate to say that the declarations in this module are automatically available in all D modules, like those in object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module is not intended to be imported or used directly. It...
"It" refers to "This module".
It is publicly imported by object.d, and should be accessed through there.
"there" refers to "object.d"
This is natural English for me (using pronouns to refer to previously mentioned things). If you'd like me to change it, please send me copy-pastable text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm trying to say is that it might not be obvious to users that they don't have to import anything in order to use the symbols from that module. E.g. someone googles for "dlang destroy object", finds this page on dlang.org, sees that it's in a module, and tries importing it. Heck, at that point the user might not even know that even object doesn't need to be imported.
"accessed through there" also can be interpreted that something needs to be done by the user to achieve this, specifically something involving what "there" refers to (the object module).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave it another go to address your concerns. I don't know if it's good enough. Please send me something better it's not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better :)
mak/DOCS
Outdated
| $(DOCDIR)\object.html \ | ||
| \ | ||
| $(DOCDIR)\object__lifetime.html \ | ||
| \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces where should be tabs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this location, but make can be fussy about tabs vs spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
Why |
There were concerns in #2222 about placing lifetime.d in the root and preventing users from being able to use lifetime.d as their own top level package. I'm actually not sure about that. @wilzbach, care to clarify?
Actually, I just realized what @schveiguy was saying in #2222. I think I should have done |
So, |
I think we could make that work, but I'd like to keep all the publicly imported parts of object.d together as a group and segregated from the other |
|
So we're gonna publicly import |
If |
|
why does destroy need to be implicitly available? is it possible to deprecate that public import with time? |
I don't know, but now that it is, it'll take a deprecation cycle and a lot of persuasions to change.
I suppose, if you can convince the right people. There are a lot of architecture problems with druntime. |
|
Damn! If you see the autotester, it's building with 2.079 which doesn't yet have the fix from https://issues.dlang.org/show_bug.cgi?id=19014. I'm sure what to do about that yet. 2.083 (the version on my local machine) also seems to still have the problem. When I build from HEAD everything works fine. @RazvanN7 @wilzbach wasn't that fix supposed to be released already? EDIT: Looks like the fix is coming 2.084: https://dlang.org/changelog/pending.html |
|
so note that none my my code are ran as part of the tests. it is just that the phobos makefile has a build rule with a similar name to my site. |
|
Currently version(D_Doc)
{
/**
Destroys the given object and optionally resets to initial state. It's used to
_destroy an object, calling its destructor or finalizer so it no longer
references any other objects. It does $(I not) initiate a GC cycle or free
any GC memory.
If `initialize` is supplied `false`, the object is considered invalid after
destruction, and should not be referenced.
*/
void destroy(bool initialize = true, T)(ref T obj)
if (!is(T == class) && !is(T == interface))
{
import lifetime = core.internal.object.lifetime;
lifetime.destroy!(initialize)(obj);
}
/// ditto
void destroy(bool initialize = true, T)(T obj)
if (is(T == class) || is(T == interface))
{
import lifetime = core.internal.object.lifetime;
lifetime.destroy!(initialize)(obj);
}
}
else
{
public import core.internal.object.lifetime : destroy;
} |
| /** | ||
| * Contains utilities for managing lifetimes. | ||
| * | ||
| * This module is not intended to be imported or used directly. It is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All public symbols should be package, then the user cannot use this module directly. Assuming that works since object doesn't live in a package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I make them package then they won't be visible outside of core.internal.object, right? If that's the case, then I won't be able to publicly import them into object.d.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This goes along with my original idea in #2222 to put them all in the root, rename object.d to package.d and then modify the compiler to look for package.d (or the root of the runtime) instead of object.d. Then the symbols can all be made package.
There were concerns about not being able to use lifetime.d in one's own file hierarchy. But, honestly, I don't understand that, because they would be under a different folder and users should never import the runtime's lifetime.d anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to specify a symbol along with package, i.e. package(core) which would make it accessible to the whole core package and all its sub packages. But since object lives outside any package, that might not work anyway.
Yes, I'm aware and working on that. My current workaround is https://github.com/dlang/druntime/pull/2399/files#diff-a68e58fcf0de5aa198fcaceafe4e8cf9R6 That's a statement in object.d's documentation comment that reads... ... if I can only get the link to work right (If you know the correct DDoc syntax for the link, please do tell). You can see it rendered here. I don't really want to do your I also tried There's actually an issue report already documenting that this isn't working right: https://issues.dlang.org/show_bug.cgi?id=10665 I'm going to try to fix that tonight. If I'm successful, the problem will just go away and we'll all have one less annoyance to deal with in our own code. |
|
Due to Issue 19014 This needs the autotester upgraded to 2.084 before it can move forward. Closing until that becomes reality. |
Reboot of #2222 in an attempt to help with #2398