Skip to content

Comments

Allow using Unique with interfaces#4764

Merged
wilzbach merged 5 commits intodlang:masterfrom
tmccombs:unique-interface
Jul 21, 2017
Merged

Allow using Unique with interfaces#4764
wilzbach merged 5 commits intodlang:masterfrom
tmccombs:unique-interface

Conversation

@tmccombs
Copy link
Contributor

@tmccombs tmccombs commented Sep 5, 2016

No description provided.

@burner
Copy link
Member

burner commented Sep 5, 2016

The docs needs updating. They should mention interfaces

std/typecons.d Outdated
transfer can be explicit, by calling $(D release), or implicit, when
returning Unique from a function. The resource can be a polymorphic
class object, in which case Unique behaves polymorphically too.
class object or instance of an interface, in which case Unique behaves polymorphically too.
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it read "or an instance"

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 the "polymorphic" here applies to both "class object" and "instance of an interface", so it's okay.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks

@burner
Copy link
Member

burner commented Sep 6, 2016

I was just about to merge this than I saw https://github.com/dlang/phobos/pull/4764/files#diff-4e008aedb3026d4a84f58323e53bf017R220 (Line 220)

I think that is a better way to test the dtor call.

@JackStouffer
Copy link
Contributor

Ping @tmccombs

{
/** Represents a reference to $(D T). Resolves to $(D T*) if $(D T) is a value type. */
static if (is(T:Object))
static if (is(T == class) || is(T == interface))
Copy link
Member

Choose a reason for hiding this comment

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

Does this work with extern(C++) or extern(Windows) classes & interfaces? If not we should not allow them.

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'm not sure.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ZombineDev Good luck detecting them. This is something that @bbasile has been working on.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know about extern(Windows) - isn't that similar to extern(C) which wouldn't work with classes (I really haven't done much with Windows and D, and Windows linking is way more complicated in general than *nix)? However, as for something like extern(C++) or COM interfaces, wouldn't checking

is(T : Object) && (is(T == class) || is(T == interface))

do the trick?

Copy link
Member

Choose a reason for hiding this comment

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

That is, if the idea is to exclude them anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jmdavis the problem is that Object is a class, so if T is an interface it won't extend Object.

Copy link
Contributor Author

@tmccombs tmccombs Mar 17, 2017

Choose a reason for hiding this comment

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

I don't know a lot about extern(c++) or extern(Windows), but from reading http://dlang.org/spec/interfaceToC.html, it seems like extern(Windows) isn't really relevant since it is more about function calling conventions, and from http://dlang.org/spec/cpp_interface.html it seems like this might work with C++ classes. Although it isn't really clear if it is safe to call destroy on a C++ class. Of course, Unique certainly won't clean up the memory for a C++ class, but that is true regardless of if RefT is T or T*

Copy link
Member

Choose a reason for hiding this comment

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

IMO this shouldn't be stalled on whether it works with extern(C++)/extern(Windows) classes & interfaces. If they didn't work before then this PR doesn't change the status quo.

@MartinNowak MartinNowak removed this from the 2.075.0 milestone Jun 25, 2017
Copy link
Member

@MetaLang MetaLang left a comment

Choose a reason for hiding this comment

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

LGTM. Let's get this merged.

Does anyone know what's up with vibe.d? It doesn't look related but I'd rather not merge with a failing Jenkins build.

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.

IMO this shouldn't be stalled on whether it works with extern(C++)/extern(Windows) classes & interfaces. If they didn't work before then this PR doesn't change the status quo.

I agree!

assert(!ub2.isEmpty);
}

@system unittest
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW: @JackStouffer has been working on getting rid of these superfluous debug statements

Copy link
Member

Choose a reason for hiding this comment

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

Good. I was going to request that they be removed but it's easy to submit a PR removing them all at once so I didn't bother.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, it seems it was common style in this module

@wilzbach
Copy link
Contributor

Does anyone know what's up with vibe.d? It doesn't look related but I'd rather not merge with a failing Jenkins build.

I restarted it - hopefully everything should be auto-merged soon :)

@MetaLang
Copy link
Member

I restarted it

For future reference, how does one do that?

@wilzbach
Copy link
Contributor

For future reference, how does one do that?

The Jenkins auto-tester now supports login via GitHub, but it's in testing stage at the moment:
dlang/ci#36

@braddr
Copy link
Member

braddr commented Jul 21, 2017

another case of an ancient pull with more than github allows # of status updates, so won't ever report as successful, but it is. I'm going to hit the merge anyway button.

@wilzbach
Copy link
Contributor

another case of an ancient pull with more than github allows # of status updates, so won't ever report as successful, but it is. I'm going to hit the merge anyway button

Thanks for looking out! Btw do you have any ideas on preventing this? Seems like admin overwride is the only option when a PR has been built X times?

@wilzbach wilzbach merged commit 4aaffed into dlang:master Jul 21, 2017
@braddr
Copy link
Member

braddr commented Jul 21, 2017

A couple thoughts, none of which work really well. Basically count the number of status update sent and after some threshold (maybe 900?):

  1. switch to a much more conservative timing of sending status update -- only slows down the problem, but might be effective enough

  2. change the status name (I forget what the api calls it) so that a new block of 1000 updates is available. But that doesn't work with the required setting. You could maybe use the last remaining blocks in the required main status name to do just success/failed/pending transitions, but again, only delays the consumption of the max 1000 entries.

  3. post a final update of state pending with text that says that future updates are only available through the details link.

The real answer is that letting pull requests sit around long enough to accumulate that many updates is the problem, not that there's a limit.

@wilzbach wilzbach mentioned this pull request Jul 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants