Skip to content

Translate _d_arraycatnTX to a template#14550

Merged
RazvanN7 merged 1 commit into
dlang:masterfrom
teodutu:template-_d_arraycatnTX
Apr 28, 2023
Merged

Translate _d_arraycatnTX to a template#14550
RazvanN7 merged 1 commit into
dlang:masterfrom
teodutu:template-_d_arraycatnTX

Conversation

@teodutu
Copy link
Copy Markdown
Member

@teodutu teodutu commented Oct 12, 2022

This brings the following changes:

  • Improves the existing template _d_arraycatnTX, to now concatenates both arrays and single elements
  • Changes the lowerings to _d_arraycatT to use the new template
  • Moves the lowering logic to _d_arraycatnTX to expressionsem.d
  • Removes the old non-template _d_arraycatnTX and _d_arraycatT hooks
  • Moves isRuntimeHook and removeHookTraceImpl to expression.d` so they can be called from both expressionsem.d and dinterpret.d

This continues #10064.

Signed-off-by: Teodor Dutu teodor.dutu@gmail.com

@teodutu teodutu requested a review from ibuclaw as a code owner October 12, 2022 12:59
@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request, @teodutu!

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 run digger -- build "master + dmd#14550"

@teodutu
Copy link
Copy Markdown
Member Author

teodutu commented Oct 12, 2022

This is currently blocked by https://issues.dlang.org/show_bug.cgi?id=23408. This causes dmd/test/runnable/test19688.d to fail.

@dkorpel
Copy link
Copy Markdown
Contributor

dkorpel commented Oct 13, 2022

This causes dmd/test/runnable/test19688.d to fail.

I suggest changing the test case from runnable to compilable, since the original bug report was about a compiler crash.
See my comment in the other PR: #14549 (comment)

@RazvanN7
Copy link
Copy Markdown
Contributor

@teodutu yes, move the test to compilable and if we decide to move on in the direction of #14549 we can move it back. There is no point to stay blocked by this.

@teodutu teodutu force-pushed the template-_d_arraycatnTX branch 4 times, most recently from 53909d1 to 39bb37a Compare October 15, 2022 16:39
Comment thread compiler/src/dmd/e2ir.d Outdated
{
//printf("[%s] CallExp.toElem('%s') %p, %s\n", ce.loc.toChars(), ce.toChars(), ce, ce.type.toChars());
/* Do this check during code gen rather than semantic() because concatenation is
* allowed in CTFE, and cannot distinguish that in semantic().
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.

Two major issues with this:

  • GDC and LDC have to implement this error check themselves (is there a testcase for it?)
  • -o- will not trigger this error

Copy link
Copy Markdown
Member Author

@teodutu teodutu Oct 21, 2022

Choose a reason for hiding this comment

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

GDC and LDC have to implement this error check themselves (is there a testcase for it?)

This check was previously in visitCat(), so this PR isn't making things worse. And the reason it's here is explained in the comment. Do you know of a better place where to verify this?

-o- will not trigger this error

Why would it? AFICT -o- simply skips the generation of the .o file. How is this connected to string concatenation with -betterC? This check is triggered by test/fail_compilation/test18312.d.

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.

-o- skips codegen, thus skips e2ir ?

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.

looks like you are right that this PR does not make the situation worse.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

-o- skips codegen, thus skips e2ir

And doing so also skips the rest of the backend. Therefore, the CatExp that would otherwise be leaked to the glue layer is ignored. Because code generation is omitted, the leak is silent as it doesn't cause any trouble.

@teodutu teodutu force-pushed the template-_d_arraycatnTX branch 2 times, most recently from eafbf95 to 98442f1 Compare October 21, 2022 19:38
@RazvanN7
Copy link
Copy Markdown
Contributor

RazvanN7 commented Nov 1, 2022

@teodutu any updates on this PR?

@teodutu
Copy link
Copy Markdown
Member Author

teodutu commented Nov 2, 2022

@RazvanN7 The buildkite failures come from building DMD. This tells me that the failures are likely coming from string concatenations that then call .ptr like this:

string res = str1 ~ str2;
foo(res.ptr);

For some reason, they didn't trigger errors before, but now they cause issues because res.ptr is not null-terminated. Debugging this is tedious because I can't reproduce the issue locally. Same for the failure on macOS 12

Copy link
Copy Markdown
Contributor

@RazvanN7 RazvanN7 left a comment

Choose a reason for hiding this comment

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

Looks good to me, although I don't understand why now we have more allocations for the profilegc tests.

@RazvanN7
Copy link
Copy Markdown
Contributor

@JohanEngelen @ibuclaw @dkorpel could you please take a look at this?

@teodutu teodutu force-pushed the template-_d_arraycatnTX branch 2 times, most recently from 4db8529 to f04d44b Compare November 29, 2022 11:45
Comment thread compiler/src/dmd/dinterpret.d Outdated
@teodutu teodutu force-pushed the template-_d_arraycatnTX branch from 2f651be to 29cd668 Compare April 14, 2023 09:46
@teodutu
Copy link
Copy Markdown
Member Author

teodutu commented Apr 14, 2023

@JohanEngelen @ibuclaw @dkorpel I've fixed the bugs created by moving the lowering to its own field inside CatExp. Can you take another look at this, please? The macOS 13 failures seem unrelated.

Comment thread compiler/src/dmd/expression.d Outdated
Comment thread compiler/src/dmd/e2ir.d
@@ -1725,50 +1725,10 @@ elem* toElem(Expression e, IRState *irs)
return el_long(TYint, 0);
}

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 above betterC check could be probably moved to the frontend. You could check sc.func.needsCodegen, however, that is a topic for a different PR.

Comment thread compiler/src/dmd/toir.d Outdated
Comment thread compiler/test/compilable/test19688.d
Comment thread compiler/test/runnable/test23710.d Outdated
Comment thread druntime/src/core/internal/array/concatenation.d
@teodutu teodutu force-pushed the template-_d_arraycatnTX branch from 29cd668 to 66b4d9c Compare April 14, 2023 10:30
Comment thread compiler/test/runnable/test23710.d Outdated
@teodutu teodutu force-pushed the template-_d_arraycatnTX branch from 66b4d9c to c525392 Compare April 15, 2023 06:47
@teodutu
Copy link
Copy Markdown
Member Author

teodutu commented Apr 15, 2023

@RazvanN7 @JohanEngelen, I have addressed your comments about test23710.d by adding STC.exptemp to the arrayliteral_on_stack that was created. Please have another look.

@teodutu
Copy link
Copy Markdown
Member Author

teodutu commented Apr 15, 2023

I have also enclosed _d_arraycatnTX within version (D_ProfileGC) as per #14914.

Copy link
Copy Markdown
Contributor

@RazvanN7 RazvanN7 left a comment

Choose a reason for hiding this comment

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

LGTM. cc @JohanEngelen any more comments?

Comment thread druntime/src/core/internal/array/concatenation.d Outdated
Comment thread compiler/src/dmd/expression.d Outdated
Comment thread compiler/src/dmd/expressionsem.d Outdated
Comment thread compiler/src/dmd/nogc.d Outdated
Comment thread compiler/test/unit/lexer/location_offset.d
Comment thread druntime/src/core/internal/array/concatenation.d
Comment thread druntime/src/core/internal/array/concatenation.d
Comment thread druntime/src/rt/tracegc.d
Comment thread compiler/src/dmd/expressionsem.d Outdated
Comment thread compiler/src/dmd/expressionsem.d Outdated
Comment thread druntime/src/core/internal/array/concatenation.d Outdated
@teodutu teodutu force-pushed the template-_d_arraycatnTX branch from c525392 to 9601ea8 Compare April 19, 2023 09:39
@RazvanN7
Copy link
Copy Markdown
Contributor

@dkorpel @JohanEngelen are there any other concerns?

This brings the following changes:
- Improves the existing template `_d_arraycatnTX`, to now concatenates
both arrays and single elements
- Changes the lowerings to `_d_arraycatT` to use the new template
- Moves the lowering logic to `_d_arraycatnTX` to expressionsem.d
- Adds a new field to `CatExp` called `lowering` to store the template
  lowering
- Removes the old non-template `_d_arraycatnTX` and `_d_arraycatT` hooks
- Moves `test19688.d` from `runnable/` to `compilable/` until
https://issues.dlang.org/show_bug.cgi?id=23408 is fixed

Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
@teodutu teodutu force-pushed the template-_d_arraycatnTX branch from 9601ea8 to 3c9bea4 Compare April 24, 2023 10:25
@RazvanN7 RazvanN7 added the Merge:72h no objection -> merge The PR will be merged if there are no objections raised. label Apr 24, 2023
Comment thread compiler/test/compilable/test19688.d
@JohanEngelen
Copy link
Copy Markdown
Contributor

I lack the knowledge to review in a lot of detail. Overall I am worried about template bloat due to these templatizations, so I'd appreciate if you can add an open issue about trying to implement it in such a way that reduces this bloat (e.g. have the template forward to a function that is the same for POD structs of the same size, etc.)

@RazvanN7
Copy link
Copy Markdown
Contributor

@JohanEngelen The follow-up project for @teodutu after he has finished templating the existing hooks is to implement optimizations for them.

@RazvanN7 RazvanN7 merged commit 1db1ba8 into dlang:master Apr 28, 2023
@dkorpel
Copy link
Copy Markdown
Contributor

dkorpel commented Apr 28, 2023

This PR broke frontend.h: #15141

@dkorpel dkorpel mentioned this pull request Apr 28, 2023
@FeepingCreature
Copy link
Copy Markdown
Contributor

This PR caused a regression: #24018

@ghost
Copy link
Copy Markdown

ghost commented Aug 9, 2023

And unfortunately #24078

@tim-dlang
Copy link
Copy Markdown
Contributor

There are two other regressions related to this:
https://issues.dlang.org/show_bug.cgi?id=24371
https://issues.dlang.org/show_bug.cgi?id=24378

nybzmr added a commit to nybzmr/dmd that referenced this pull request Mar 19, 2025
…RAYCATT, TRACEARRAYCATNTX and TRACEARRAYCATT
thewilsonator pushed a commit that referenced this pull request Mar 19, 2025
* Remove RTLSYM for Translation PR #15819: Removed NEWARRAYMITX, NEWARRAYMITX, TRACENEWARRAYMTX and TRACENEWARRAYMITX

* Remove RTLSYM for Translation PR #15299: Removed NEWARRAYT, NEWARRAYIT, TRACENEWARRAYT and TRACENEWARRAYIT

* Remove RTLSYM for Translation PR #14837: Removed NEWCLASS, TRACENEWCLASS

* Remove RTLSYM for Translation PR #14664: Removed NEWITEMT, NEWITEMIT, TRACENEWITEMT and TRACENEWITEMIT

* Remove RTLSYM for Translation PR #14550: Removed ARRAYCATNTX, ARRAYCATT, TRACEARRAYCATNTX and TRACEARRAYCATT

* Remove RTLSYM for Translation PR #14382: Removed ARRAYSETASSIGN

* Remove RTLSYM for Translation PR #14310: Removed ARRAYASSIGN

* Remove RTLSYM for Translation PR #13495: Removed ARRAYAPPENDT, ARRAYAPPENDCTX, TRACEARRAYAPPENDT and TRACEARRAYAPPENDCTX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merge:72h no objection -> merge The PR will be merged if there are no objections raised.

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

8 participants