Compute lazy lambda serialization#7870
Conversation
|
Thanks for your pull request and interest in making D better, @RazvanN7! 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. |
93eee54 to
5fb1c17
Compare
src/dmd/lambdacomp.d
Outdated
| override void visit(TypeClass t) | ||
| { | ||
| buf.reset(); | ||
| if (LOG) |
src/dmd/lambdacomp.d
Outdated
| override void visit(FuncLiteralDeclaration fld) | ||
| { | ||
| assert(fld.type.ty != Terror); | ||
| if (LOG) |
|
There aren't any tests and coverage is only 80%. Is that deliberate? |
|
@JinShil This PR does not introduce any new functionality, but optimizes the lambda comparison. The code is not covered because the struct and class cases are identical and I only added examples for one of them. I will add another few tests so that coverage is 100%. P.S. : Everything is covered now. |
|
@RazvanN7 speaking of __traits(isSame) and lambdas, there's a regression in git master: EDIT: just found out you already had a fix in progress #7885; thanks! |
| import dmd.tokens; | ||
| import dmd.visitor; | ||
|
|
||
| enum LOG = false; |
There was a problem hiding this comment.
Out of interest: why not version= LOG? This is commonly used pattern in DRuntime.
There was a problem hiding this comment.
This is the pattern used in dmd from what I could obeserve :
https://github.com/dlang/dmd/blob/master/src/dmd/mtype.d#L61
https://github.com/dlang/dmd/blob/master/src/dmd/expression.d#L67
https://github.com/dlang/dmd/blob/master/src/dmd/expressionsem.d#L73
And the list could continue.
src/dmd/traits.d
Outdated
| import core.stdc.string; | ||
| const(char)* getSerialization(FuncLiteralDeclaration fld) | ||
| { | ||
| import dmd.lambdacomp; |
There was a problem hiding this comment.
Nit: local imports should be selective.
| if (l1 && l2) | ||
| { | ||
| import core.stdc.string; | ||
| const(char)* getSerialization(FuncLiteralDeclaration fld) |
There was a problem hiding this comment.
Why don't you return string here? Comparing D strings is more efficient (no \0 checking)
You already know the length of the buffer - no need to throw this valuable information away.
There was a problem hiding this comment.
I know it's easier with strings, but the serialization field is is const(char)* and I really haven't seen AST members declared as strings. All of them are const(char)*
There was a problem hiding this comment.
Quoting a conversation with Walter here:
On 12/5/2017 11:20 AM, Andrei Alexandrescu wrote:
Hi Walter, Seb noticed that the dmd code is going through unpleasant hoops caused by C-style strings. Do you think incrementally switching to D-style strings would improve the compiler? -- Andrei
Yes, but we have to be mindful of gdc and ldc both relying on the C++ interface to use dmd, and D strings don't work on that interface.
I've already converted a bunch of internal stuff to D strings where the interface to the back end was not involved.
(we can even convert the C++ interfaces, but that's significantly more effort)
There was a problem hiding this comment.
So how do we proceed here? That was my problem also: I may turn the field into a string, but what should I do regarding the header file?
There was a problem hiding this comment.
how about this:
extern(C++) Dstring funLib(Dstring input);see full working example here showing using such API from C++ with the function defined in D.
https://github.com/timotheecour/dtools/blob/master/tests/d01_dmd_string/
EDIT: see #7893
There was a problem hiding this comment.
@timotheecour #7893 is a good step in the right direction, we need to start using D strings in the compiler. That would be an effort separated from this.
f788974 to
d330e9e
Compare
|
I discovered some problems. Please do not merge. Later edit: I solved the issue. Ready to merge. |
| if (l1 && l2) | ||
| { | ||
| import core.stdc.string; | ||
| const(char)* getSerialization(FuncLiteralDeclaration fld) |
There was a problem hiding this comment.
@timotheecour #7893 is a good step in the right direction, we need to start using D strings in the compiler. That would be an effort separated from this.
This is an optimization to compute the lambda serialization only when __traits(isSame) is used on lambda functions.