Skip to content

Compute lazy lambda serialization - #7870

Merged
dlang-bot merged 1 commit into
dlang:masterfrom
RazvanN7:Lambda_v2
Feb 20, 2018
Merged

dlang-bot merged 1 commit into
dlang:masterfrom
RazvanN7:Lambda_v2

Conversation

@RazvanN7

Copy link
Copy Markdown
Contributor

This is an optimization to compute the lambda serialization only when __traits(isSame) is used on lambda functions.

@dlang-bot

dlang-bot commented Feb 12, 2018 •

Copy link
Copy Markdown

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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 references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@RazvanN7
RazvanN7 force-pushed the Lambda_v2 branch 2 times, most recently from 93eee54 to 5fb1c17 Compare February 12, 2018 09:13
Comment thread src/dmd/lambdacomp.d Outdated
override void visit(TypeClass t)
{
buf.reset();
if (LOG)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

static if

Comment thread src/dmd/lambdacomp.d Outdated
override void visit(FuncLiteralDeclaration fld)
{
assert(fld.type.ty != Terror);
if (LOG)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

static if

@andralex andralex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JinShil

JinShil commented Feb 12, 2018

Copy link
Copy Markdown
Contributor

There aren't any tests and coverage is only 80%. Is that deliberate?

@RazvanN7

RazvanN7 commented Feb 13, 2018 •

Copy link
Copy Markdown
Contributor Author

@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.

@timotheecour

timotheecour commented Feb 13, 2018 •

Copy link
Copy Markdown
Contributor

@RazvanN7 speaking of __traits(isSame) and lambdas, there's a regression in git master:
https://issues.dlang.org/show_bug.cgi?id=18430 Issue 18430 - isSame is wrong for non global lambdas; obviously this PR couldn't have caused it since it's not merged but maybe you'd have some idea? (sorry for the drop in)

EDIT: just found out you already had a fix in progress #7885; thanks!

Comment thread src/dmd/lambdacomp.d
import dmd.tokens;
import dmd.visitor;

enum LOG = false;

Copy link
Copy Markdown
Contributor

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.

@RazvanN7 RazvanN7 Feb 14, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread src/dmd/traits.d Outdated
import core.stdc.string;
const(char)* getSerialization(FuncLiteralDeclaration fld)
{
import dmd.lambdacomp;

Copy link
Copy Markdown
Contributor

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.

Comment thread src/dmd/traits.d
if (l1 && l2)
{
import core.stdc.string;
const(char)* getSerialization(FuncLiteralDeclaration fld)

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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)*

Copy link
Copy Markdown
Contributor

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)

@RazvanN7 RazvanN7 Feb 14, 2018 •

Copy link
Copy Markdown
Contributor Author

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well, as its a new field and not used by GDC or LDC at the moment, you could do sth. like:

struct DString
{
  size_t length;
  char* head;
}

CC @ibuclaw @redstar @klickverbot

We have to start somewhere, but I don't want to block your PR with this. Sorry.

@timotheecour timotheecour Feb 14, 2018 •

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member

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.

@RazvanN7
RazvanN7 force-pushed the Lambda_v2 branch 2 times, most recently from f788974 to d330e9e Compare February 14, 2018 09:43
@RazvanN7 RazvanN7 changed the title Compute lazy lambda serialization [WIP]Compute lazy lambda serialization Feb 14, 2018
@RazvanN7

RazvanN7 commented Feb 14, 2018 •

Copy link
Copy Markdown
Contributor Author

I discovered some problems. Please do not merge.

Later edit: I solved the issue. Ready to merge.

@RazvanN7 RazvanN7 changed the title [WIP]Compute lazy lambda serialization Compute lazy lambda serialization Feb 15, 2018
Comment thread src/dmd/traits.d
if (l1 && l2)
{
import core.stdc.string;
const(char)* getSerialization(FuncLiteralDeclaration fld)

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merge:auto-merge Review:WIP Work In Progress - not ready for review or pulling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants