Skip to content
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

make function symbols store function parameters, needed for UFCS. #182

Merged
merged 3 commits into from
Oct 10, 2022

Conversation

vushu
Copy link
Contributor

@vushu vushu commented Oct 9, 2022

To not rely on callTips and properly support UFCS, we need functions to store their applicable argument symbols, this PR adds does this.

Copy link
Member

@WebFreak001 WebFreak001 left a comment

Choose a reason for hiding this comment

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

seems useful, but need to check again why you always set includeParameterSymbols there. Do you actually always need it or is that a left-over from debugging? In the cases where we want it we can simply set the value to true in the constructor, instead of forcing it to users. Alternatively if you can measure that there is no to little overhead in always including them (and posting your results on that) we can simply remove the boolean like I suggested in the first comment.

@@ -152,6 +152,7 @@ final class FirstPass : ASTVisitor
pushFunctionScope(dec.functionBody, semanticAllocator,
dec.name.index + dec.name.text.length);
scope (exit) popScope();
includeParameterSymbols = true;
Copy link
Member

Choose a reason for hiding this comment

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

this should not be here (it effectively now makes the constructor parameter useless, as parameters would always be included)

If it's never a problem, consider instead removing the symbol completely, deprecating the ctor and stripping all the ifs that checked on it

@@ -981,6 +983,9 @@ private:
addTypeToLookups(parameter.typeLookups, p.type);
parameter.parent = currentSymbol;
currentSymbol.acSymbol.argNames.insert(parameter.acSymbol.name);

currentSymbol.acSymbol.functionArguments ~= parameter.acSymbol;
Copy link
Member

Choose a reason for hiding this comment

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

mixed tabs and spaces

UnrolledList!(istring) argNames;

private uint _location;

/**
* Function argument symbols
Copy link
Member

Choose a reason for hiding this comment

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

mixed tabs and spaces

@vushu
Copy link
Contributor Author

vushu commented Oct 9, 2022

@WebFreak001 indeed looks like we probably can remove the includeParameterSymbols if it always should be true.

I have looked into the changes and ran the default tests in DCD before and after the changes.

before the change:

one run:

real	0m12.235s
user	0m0.905s
sys	0m0.388s

10 runs:

real	2m1.003s
user	0m8.368s
sys	0m3.226s

after the change:

one run:

real	0m12.323s
user	0m0.970s
sys	0m0.397s

10 runs:

real	2m3.326s
user	0m9.289s
sys	0m4.732s

Doesn't seem like it affects too much.

/**
* Function argument symbols
*/
DSymbol*[] functionArguments;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need to be an array of pointers?

Copy link
Contributor Author

@vushu vushu Oct 9, 2022

Choose a reason for hiding this comment

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

I guess so since DSymbol isn't copyable unless we change that.

struct DSymbol
{
	// Copying is disabled
	@disable this();
	@disable this(this);
,,,

Copy link
Member

Choose a reason for hiding this comment

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

usually all the DSymbol references are done by pointers, but it might be effective to use them inline in arrays (e.g. move them into the array)

We already know the count of items that get put into array before putting them there anyway, so we can already preallocate all the space and directly construct them in-place.

@WebFreak001
Copy link
Member

@WebFreak001 indeed looks like we probably can remove the includeParameterSymbols if it always should be true.

I have looked into the changes and ran the default tests in DCD before and after the changes.

before the change:

one run:

real	0m12.235s
user	0m0.905s
sys	0m0.388s

10 runs:

real	2m1.003s
user	0m8.368s
sys	0m3.226s

after the change:

one run:

real	0m12.323s
user	0m0.970s
sys	0m0.397s

10 runs:

real	2m3.326s
user	0m9.289s
sys	0m4.732s

Doesn't seem like it affects too much.

performance wise it looks ok.

Did you also check memory impact opening a Phobos or DMD source file and checking process memory usage completing a single symbol? That would be particularly interesting I think.

Otherwise LGTM to me now.

@@ -62,11 +62,10 @@ final class FirstPass : ASTVisitor
* symbolFile = path to the file being converted
* symbolAllocator = allocator used for the auto-complete symbols
* semanticAllocator = allocator used for semantic symbols
* includeParameterSymbols = include parameter symbols as children of
* function decalarations and constructors
Copy link
Member

@WebFreak001 WebFreak001 Oct 9, 2022

Choose a reason for hiding this comment

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

this line here (below the deleted one) was also part of the deleted comment, also delete this line.

@vushu
Copy link
Contributor Author

vushu commented Oct 10, 2022

@WebFreak001, Right good point. I made a test where I measure the memory after a completion:

client test:
./dcd-client -c191 -I"/usr/include/dmd/phobos" test.d

test.d:

import std.algorithm;
import std.container;
import std.array;
import std.algorithm.iteration;
import std.regex;
import std.functional;
import std.string;
import std.stdio;
void main()
{
    s
}

where cursor is on s

I have measured the memory using pmap

dcd-server memory usage:

before change
total 1186852K

after change
total 1191868K

so an increase of 5mb

Test opening dmd/compiler/src/dmd/cppmangle.d, then make it complete on the letter s

before change
total 1069360K

after change:
total 1114172K

so an increase of 44mb

The data increase is expected since we store more information now. On big files like cppmangle.d which today
has 2578 lines of code the memory usage will be more significantly, but I think that is expected when opening such big files.

@WebFreak001 WebFreak001 changed the title make funtion symbols store function arguments, needed for UFCS. make function symbols store function parameters, needed for UFCS. Oct 10, 2022
@WebFreak001 WebFreak001 merged commit 8a24727 into dlang-community:master Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants