-
-
Notifications
You must be signed in to change notification settings - Fork 411
implement druntime side of DIP1008 #1804
Conversation
| * into a call to: | ||
| * _d_throwc(h); | ||
| */ | ||
| extern(C) void _d_throwc(Throwable h) |
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.
Your also forgetting to update dwarfeh?
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 forgot to check it in. Done.
src/object.d
Outdated
| string toString() const; | ||
| } | ||
|
|
||
| private uint _refcount; // 0 : allocated by GC |
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.
Just a thought. Would there be a way to use a different vptr for reference-counted Throwable's? If so, you could use virtual functions instead of adding a _refcount to every Throwable object. Not sure if this design is better or worse (or if it's even feasible to implement) but it's something to consider I think.
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 thought about this more and realized that in order to do this, you would have to create 2 vtables for EVERY CLASS that inherits from throwable, one for RC objects and one for GC objects. A solution like this could be worth looking into for a general solution to RC objects, however, I don't think is appropriate for this feature.
|
Since this change would require adding "scope" to Throwable objects in all catch clauses, what do you think about adding a method to It would be even better if you could guard this function only allowing it to be called on "scoped" objects, but I've never heard of such a feature. Anyway, this type of function would allow catch clauses to easily escape exceptions and prevents the need to copy exceptions that are already GC. |
|
I removed the |
6c5f7bb to
95fa6f8
Compare
|
This is failing because dinterpret.d is using direct access to members rather than symbolic :-( |
|
Blocked by dlang/dmd#6689 |
|
dlang/dmd#6689 was merged 14 days ago, is there something else blocking this? |
75d9d39 to
29115fc
Compare
MartinNowak
left a comment
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.
The preliminary review of DIP1008 went pretty bad, why are we still going ahead with this before reaching a conclusion?
Those legacy C runtime interfaces have turned out to be a huge pain, because they are holes for attribute checks and cause lots of code breakage when we start to check 'em.
Please move _d_new/deleteThrowable to templated functions in object.d (possibly with an implementation in core.internal if it's too big) in order to not introduce new attribute holes holes for MyException.this and MyException.~this.
The objections were not technically well founded, none were on the grounds that it wouldn't work, and nobody solidly proposed anything better. This is a low risk change, it's minimally disruptive, and so can be removed/altered if it doesn't work out.
I'm not sure how that would improve things. |
|
Thanks for your pull request, @WalterBright! 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. |
Yeah, I think as a reasonable barrier, we should not be accepting any new runtime functions for compiler generated code that are plain extern(C). However I am on the sideline with this particular function as it doesn't require RTTI. Otherwise I would strongly agree. |
5fadf0c to
7fab571
Compare
9cb53d1 to
8f1bb25
Compare
Burgos
left a comment
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.
Would it be possible to add unittests here, without involving the compiler?
| private uint _refcount; // 0 : allocated by GC | ||
| // 1 : allocated by _d_newThrowable() | ||
| // 2.. : reference count + 1 | ||
| @system @nogc final pure nothrow ref uint refcount() return scope { return _refcount; } |
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 needs ddoc syntax, as this is a public method.
| } | ||
|
|
||
| /********************************************** | ||
| * Allocate an exception of type `ci` from the exception pool. |
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.
from the exception pool - There is no pool in this implementation, isn't 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.
Right. But there could be - without changing the interface.
8f1bb25 to
6d5f425
Compare
I'll summarize the concerns raised:
My responses to these concerns are as follows:
There would be a higher level note that is much more important. The preliminary review opened on May 19, and last comment was made on June 18. There has been no work on anything related to this following that - no alternative DIP, no proposed improvements to the DIP, and no compiler PRs. From a practical perspective it's safe to assume we won't have any competing DIP on our hands anytime soon. This DIP makes strong progress at a core issue. We can't afford to wait more for the perfect solution. At this point my main concern is avoiding lock-in, i.e. I want the implementation to be encapsulated enough to allow us to improve it later without disrupting user code. Let's see through the technical issues that will get this PR in so we can experiment with it. It's opt-in so no harm done. Thanks. |
6d5f425 to
14f2812
Compare
As @andralex said, this whole thing is opt-in anyway, so if it doesn't work out we can redo it without breaking things. (And it's not like it's a huge, disruptive change, it's surprisingly small.) But we won't find out the problems unless we try it. It needs to get pulled. |
|
@MartinNowak I'll override your request for changes under the assumptions: (a) the migration of functions to templates can be done subsequently, and (b) the feature is opt-in and allows us to experiment and work the kinks out before making a decision. |
Per comment - feel free to undo the pull if there are strong concerns.
|
Yes let's see how this ends up.
The idea was to transition catch parameters to
Does it depend on a dmd switch?
_d_delclass/_d_deleteThrowable finalized the deleted object but don't use the static type to infer the attributes of the finalizer. Since
Well, it's questionable whether chained exceptions are that useful. Providing a mechanism to disable chaining, or to access the current exception in flight might be alternatives here. Would be nice if we had a way to throw struct values that are implicitly convertible to void foo()
{
throw refCounted!Exception();
}
void bar()
{
try {}
catch (scope Exception e)
{
// RefCounted!Exception destroyed here unless rethrown
}
} |
see dlang/dmd#6681 which is blocking this