Translate _d_delstruct to template#13398
Conversation
|
Thanks for your pull request and interest in making D better, @teodutu! 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 run digger -- build "master + dmd#13398" |
src/dmd/e2ir.d
Outdated
| * expression. This is how e2ir.d gets here. | ||
| * Since the lowering has already been made, the DeleteExp can | ||
| * be ignored here. | ||
| */ |
There was a problem hiding this comment.
How is this going to affect the traceGC hooks? If you look below, there is a call to toTraceGC which basically calls a wrapper of the hook if the gc_profile command line flag is passed. It seems that in this case, the wrapper call is ignored.
3d0c446 to
94803a6
Compare
94803a6 to
15a898b
Compare
683ce63 to
32a4d4f
Compare
src/dmd/expressionsem.d
Outdated
| * `_d_delstruct` in order to keep checking for dtor errors as | ||
| * well as generate code for the call to `_d_delstruct`. | ||
| */ | ||
| e = Expression.combine(exp, e); |
There was a problem hiding this comment.
Why do we still need the original expression and pass it all the way to e2ir? Can't we simply check here if the dtor is callable in the current context and output an error if not?
There was a problem hiding this comment.
I tried to do this, but certain errors are output from different contexts, which are difficult to replicate here.
Here's an example: this snippet [1] may be output an error if the dtor throws. In order to verify this, canThrow is called here [2]. _d_delstruct(s) is nothrow so that it's not mentioned in errors such as this one [3].
I agree that returning both expressions is inelegant, but I don't see a way to avoid the situation above without duplicating the logic from semantic3.d in expressionsem.d.
[1]
Lines 747 to 750 in 93108bb
[2]
Lines 113 to 114 in 93108bb
[3]
Lines 58 to 64 in 93108bb
32a4d4f to
9b25792
Compare
Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
Such calls are returned from expressionsem.d together with their corresponding DeleteExp, as part of a CommaExp. Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
Signed-off-by: teo <teodor.dutu@gmail.com>
9b25792 to
45e22ef
Compare
RazvanN7
left a comment
There was a problem hiding this comment.
Does not need to recreate the DeleteExp.
src/dmd/canthrow.d
Outdated
| // In expressionsem.d `delete s` was lowered to `_d_delstruct(s)`. | ||
| // The following code rewrites it back to the original expresion | ||
| // in order to properly output `nothrow` errors. | ||
| auto de = new DeleteExp(ce.loc, (*ce.arguments)[0], false); |
There was a problem hiding this comment.
Creating a DeleteExp is superfluous here. This is wasteful because allocation is costly. You can simply check if the dtor of of the aggregate type (if it exists) throws: this is essentially what the DeleteExp visiting method does.
There was a problem hiding this comment.
I was trying to not duplicate the code in visit(DeleteExp), but I see your point.
src/dmd/dinterpret.d
Outdated
| // interpret that expression. | ||
| assert(e.arguments.dim == 1); | ||
|
|
||
| auto de = new DeleteExp(e.loc, (*e.arguments)[0], false); |
src/dmd/nogc.d
Outdated
| // In expressionsem.d `delete s` was lowered to `_d_delstruct(s)`. | ||
| // The following code rewrites it back to the original expresion in | ||
| // order to properly output `nogc` errors. | ||
| auto de = new DeleteExp(e.loc, (*e.arguments)[0], false); |
…`nogc` and `nothrow` Signed-off-by: teo <teodor.dutu@gmail.com>
Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
|
Great work, @teodutu ! Thanks for this. Let's wait a bit to see if someone else has anything to comment and then we'll merge. |
These hooks have been converted to templates and their lowerings changed to use those templates: - dlang/dmd#13116 - dlang/dmd#13495 - dlang/dmd#13398 Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
These hooks have been converted to templates and their lowerings changed to use those templates: - dlang/dmd#13116 - dlang/dmd#13495 - dlang/dmd#13398 Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
These hooks have been converted to templates and their lowerings changed to use those templates: - dlang/dmd#13116 - dlang/dmd#13495 - dlang/dmd#13398 Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
These hooks have been converted to templates and their lowerings changed to use those templates: - dlang/dmd#13116 - dlang/dmd#13495 - dlang/dmd#13398 Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
This PR translates the lowering of expressions like
delete pto a template version of_d_delstructthat no longer uses the secondTypeInfo_Structparameter. The PR where this new template hook was implemented is this: dlang/druntime#3639