Skip to content

Translate _d_arraysetlengthT to template - #10106

Merged
thewilsonator merged 4 commits into
dlang:masterfrom
Vild:ConvertArraySetLength
Jul 19, 2019
Merged

thewilsonator merged 4 commits into
dlang:masterfrom
Vild:ConvertArraySetLength

Conversation

@Vild

@Vild Vild commented Jun 28, 2019 •

Copy link
Copy Markdown
Contributor

druntime PR: dlang/druntime#2656

The exp.e1.type.toBasetype().nextOf().isZeroInit check is now inside of the runtime hook.

@dlang-bot

dlang-bot commented Jun 28, 2019 •

Copy link
Copy Markdown

Thanks for your pull request and interest in making D better, @Vild! 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 coverage diff by visiting the details link of the codecov check)
  • 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.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#10106"

Comment thread src/dmd/expressionsem.d Resolved
@Vild
Vild force-pushed the ConvertArraySetLength branch from 1d846a9 to 118b4a9 Compare June 29, 2019 22:16
@JinShil

JinShil commented Jul 2, 2019

Copy link
Copy Markdown
Contributor

@Vild The druntime PR is in, so I guess that automatically makes this our first merge candidate. Please rebase, or do whatever is necessary to make this pass this test suite. cc @jpf91

Comment thread src/dmd/expressionsem.d
Expression id = new IdentifierExp(ale.loc, Id.empty);
id = new DotIdExp(ale.loc, id, Id.object);
id = new DotIdExp(ale.loc, id, hook);
id = id.expressionSemantic(sc);

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.

BTW, maybe the code above can somehow be merged into verifyHookExists?

Expression id = verifyHookExist(exp.loc, *sc, hook, "resizing arrays", Id.object);
if (!id)
    return setError();

@jpf91 jpf91 Jul 2, 2019 •

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.

Maybe rename it though and also provide a way to get the hook without error reporting:

Expression id = findRuntimeHook(... bool printError);

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 don't think this PR is the correct place to change the the implementation of verifyHookExist.
It is already used for the already implemented hook lowerings, so I think it would be better to change it in another PR.

@Vild
Vild force-pushed the ConvertArraySetLength branch 2 times, most recently from afd3475 to 481f4a0 Compare July 3, 2019 18:17
@Vild
Vild force-pushed the ConvertArraySetLength branch from 481f4a0 to e309ec4 Compare July 4, 2019 02:24
@Vild

Vild commented Jul 4, 2019

Copy link
Copy Markdown
Contributor Author

This patch doesn't compile DCD currently because it uses -inline, so my dinterpret.d hack gets bypassed when the hook is inlined.

@JinShil

JinShil commented Jul 4, 2019

Copy link
Copy Markdown
Contributor

my dinterpret.d hack gets bypassed when the hook is inlined.

What, specifically, is the problem that the dinterpret hack is trying to avoid? Can an if (__ctfe) branch be added to the runtime lowering to achieve the same thing?

@Vild

Vild commented Jul 5, 2019 •

Copy link
Copy Markdown
Contributor Author

So the 'hack' is basically turning the _d_arraysetlengthT(arr, newLength) call back to arr.length = newLength, so it can run the correct dinterpret.d code path to handle the resize correctly.

The problem now was that I didn't test that the code worked with -inline, which caused a problem in my dinterpret.d hack because I use the visit(CallExp) function to be able to rewrite it back to arr.length=newLen.

I got it working by adding pragma(inline, false) to the runtime hooks, so now I will always be able to find the CallExp with the call to the hook.

But sadly now another problem arose, error: undefined reference to '_D2rt5array8capacity__T23_d_arraysetlengthTTraceHTAaTaZQBgFNaNbNeAyaiQeMNkKQzmZm', when compiling DCD with -profile=gc. So for some reason not all the template instantiations are exported.

@Vild

Vild commented Jul 9, 2019

Copy link
Copy Markdown
Contributor Author

It currently fails during the profilegc test:

./generated/linux/release/64/profilegc ./generated/linux/release/64/myprofilegc.log
diff myprofilegc.log.linux.64.exp ./generated/linux/release/64/myprofilegc.log
5,6d4
<              48	              1	float[] D main src/profilegc.d:42
<              48	              1	int[] D main src/profilegc.d:41

I cannot reproduce this locally, so I'm not sure what to do.

@JinShil

JinShil commented Jul 10, 2019 •

Copy link
Copy Markdown
Contributor

I cannot reproduce this locally

Try testing both debug and release builds.

@Vild

Vild commented Jul 11, 2019

Copy link
Copy Markdown
Contributor Author

Try testing both debug and release builds.

That was the problem, I only tested it with debug and it got triggered only on release builds (-release -O).
The call to accumulate gets culled away because it is pure and the return value isn't used (it's void): https://github.com/dlang/druntime/blob/master/src/rt/array/capacity.d#L287
So I guess I need to make sure that nothing gets culled inside of a tracehook, or somehow change the hook so it isn't pure.

@thewilsonator

Copy link
Copy Markdown
Contributor

Is this good to go?

@Vild

Vild commented Jul 16, 2019

Copy link
Copy Markdown
Contributor Author

Is this good to go?

Not fully yet, I need to fix the *Trace detection for the ctfe intercept

@Vild
Vild force-pushed the ConvertArraySetLength branch from a130014 to 0240596 Compare July 16, 2019 15:44
@Vild

Vild commented Jul 16, 2019

Copy link
Copy Markdown
Contributor Author

@thewilsonator It is done now :)

Comment thread src/dmd/expression.d Resolved
Comment thread src/dmd/dinterpret.d Resolved
Comment thread src/dmd/id.d Resolved
Comment thread src/dmd/dinterpret.d Resolved
Comment thread src/dmd/expression.d Resolved
Comment thread src/dmd/nogc.d Resolved
@Vild
Vild force-pushed the ConvertArraySetLength branch from 0240596 to 53bbd90 Compare July 17, 2019 14:28
Comment thread src/dmd/dinterpret.d Resolved
Comment thread src/dmd/dinterpret.d Resolved
@Vild
Vild force-pushed the ConvertArraySetLength branch from 746e39b to d1bf9bf Compare July 18, 2019 14:01
@Vild

Vild commented Jul 18, 2019

Copy link
Copy Markdown
Contributor Author

Any more changes needed?

@JinShil JinShil left a comment

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.

The workarounds bug me, but they are isolated and I'm not able to come up with anything better.

@thewilsonator
thewilsonator merged commit 5605225 into dlang:master Jul 19, 2019
@Vild
Vild deleted the ConvertArraySetLength branch July 19, 2019 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants