-
-
Notifications
You must be signed in to change notification settings - Fork 650
Compute lazy lambda serialization #7870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
{ | ||
buf.reset(); | ||
if (LOG) |
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.
static if
src/dmd/lambdacomp.d
Outdated
@@ -83,6 +86,8 @@ public: | |||
override void visit(FuncLiteralDeclaration fld) | |||
{ | |||
assert(fld.type.ty != Terror); | |||
if (LOG) |
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.
static if
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.
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! |
@@ -34,6 +35,8 @@ import dmd.statement; | |||
import dmd.tokens; | |||
import dmd.visitor; | |||
|
|||
enum LOG = false; |
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.
Out of interest: why not version= LOG
? This is commonly used pattern in DRuntime.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: local imports should be selective.
@@ -1453,8 +1453,24 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc) | |||
|
|||
if (l1 && l2) | |||
{ | |||
import core.stdc.string; | |||
const(char)* getSerialization(FuncLiteralDeclaration fld) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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. |
@@ -1453,8 +1453,24 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc) | |||
|
|||
if (l1 && l2) | |||
{ | |||
import core.stdc.string; | |||
const(char)* getSerialization(FuncLiteralDeclaration fld) |
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.
@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.