Skip to content

[stable] Try to fix #21331#21343

Merged
thewilsonator merged 4 commits intodlang:stablefrom
kinke:fix21331
Jun 4, 2025
Merged

[stable] Try to fix #21331#21343
thewilsonator merged 4 commits intodlang:stablefrom
kinke:fix21331

Conversation

@kinke
Copy link
Copy Markdown
Contributor

@kinke kinke commented May 5, 2025

See #17102 (comment) and following.

@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request and interest in making D better, @kinke! 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 run digger -- build "stable + dmd#21343"

nm ${objfile} | grep -E '16__lambda_L13_C17.+15__lambda_L5_C19'
nm ${objfile} | grep -E '16__lambda_L13_C17.+17__lambda_L5_C19_1'
nm ${objfile} | grep -E '18__lambda_L13_C17_1.+15__lambda_L5_C19'
nm ${objfile} | grep -E '18__lambda_L13_C17_1.+17__lambda_L5_C19_1'
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 gave up on a testcase for the actual issue, wrt. empty tuples in parameter UDAs being 'optimized' later and affecting toPrettyChars().

Instead, I went with this - v2.111 produces these symbols:

_D9test21331__T1SSQq3barFZ16__lambda_L13_C17ZQBe3fooMFZ__T15__lambda_L5_C19TiZQuFNaNbNiNfiZi
_D9test21331__T1SSQq3barFZ16__lambda_L13_C17ZQBe3fooMFZ__T17__lambda_L5_C19_1TiZQwFNaNbNiNfiZi
_D9test21331__T1SSQq3barFZ18__lambda_L13_C17_1ZQBg3fooMFZ__T17__lambda_L5_C19_2TiZQwFNaNbNiNfiZi
_D9test21331__T1SSQq3barFZ18__lambda_L13_C17_1ZQBg3fooMFZ__T17__lambda_L5_C19_3TiZQwFNaNbNiNfiZi

I.e., the inner lambda got renamed to _2 and _3 when the outer one was renamed to _1. Using the parent mangle avoids this and makes the inner one start without suffix again.

@kinke kinke marked this pull request as ready for review May 5, 2025 17:37
func.localsymtab = new DsymbolTable();
}
symtab = func.localsymtab;
parentMangle = cast(string) mangleExact(func).toDString();
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.

This one is cached (in FuncDeclaration.mangleString).

kinke added a commit to kinke/ldc that referenced this pull request May 5, 2025
@kinke
Copy link
Copy Markdown
Contributor Author

kinke commented May 5, 2025

Also passes LDC CI, and the LDC with this patch doesn't hit #21331 for that Symmetry code base anymore.

kinke added a commit that referenced this pull request May 12, 2025
Cherry-picked from #21343.
@yanok
Copy link
Copy Markdown

yanok commented May 14, 2025

Is merging blocked on failed CI tasks? They seem to be irrelevant. Can we rebase and retry?

@kinke
Copy link
Copy Markdown
Contributor Author

kinke commented May 14, 2025

Yeah those failures are obviously unrelated and fixed in the meantime.

The only thing I'm unsure about is whether getting the mangle of the parent might have unexpected side effects, like extra/earlier semantic analysis for the parent.

yanok pushed a commit to yanok/ldc that referenced this pull request May 31, 2025
@kinke
Copy link
Copy Markdown
Contributor Author

kinke commented Jun 2, 2025

I guess what could happen is that parent function mangles are now generated earlier, potentially before semantic analysis of the parent is completed. And as they are cached in FuncDeclaration.mangleString, the final mangle might be based on incomplete attribute inference.

The first variant, using the class-ref identity of the parent, seems safer in that regard. So I rather tend towards the original variant.

@thewilsonator
Copy link
Copy Markdown
Contributor

This good to go?

@kinke
Copy link
Copy Markdown
Contributor Author

kinke commented Jun 3, 2025

No; I was hoping @yanok would give some feedback wrt. reverting to the original variant.

@yanok
Copy link
Copy Markdown

yanok commented Jun 3, 2025

I guess what could happen is that parent function mangles are now generated earlier, potentially before semantic analysis of the parent is completed. And as they are cached in FuncDeclaration.mangleString, the final mangle might be based on incomplete attribute inference.

Yes, that might be the case. But did we see anything like this in the wild? With a proper dependency tracking I believe asking for a mangle should trigger all the inference and complain if it has to be changed later... but that's not the case with the current implementation...

The first variant, using the class-ref identity of the parent, seems safer in that regard. So I rather tend towards the original variant.

I had some concerns about multiple TemplateInstance instances for the same template with the same arguments. But of course the code is smart enough to only analyze the same instantiation once, so that's not an issue.

@yanok
Copy link
Copy Markdown

yanok commented Jun 3, 2025

I'm going to test building Weka code with the first version of the fix today, will post an update here.

@yanok
Copy link
Copy Markdown

yanok commented Jun 3, 2025

Yes, that might be the case. But did we see anything like this in the wild?

To answer my own question: yes, I do indeed see mangles of symbols loosing attributes wrt to unpatched ldc version, so the version with parent's mangle has undesired side-effects indeed.

Still verifying the version with the ref comparison, the first results are good.

@yanok
Copy link
Copy Markdown

yanok commented Jun 4, 2025

I did testing with the ref comparison (the version in the first commit), so far so good. So I guess that's the version we want to proceed with.

In the long run, we probably want to shift the uniqueness logic from generateIdWithLoc to the callers: there are only a handful of places there adding suffixes to ids is the desirable behavior: static foreach, foreach unrolling, anything else?

@kinke
Copy link
Copy Markdown
Contributor Author

kinke commented Jun 4, 2025

Perfect Ilya, thx a lot for testing! So I guess this is ready now; the commits are to be squashed (I left the 2nd variant in, just so that it's in the history of this PR).

In the long run, we probably want to shift the uniqueness logic from generateIdWithLoc to the callers: there are only a handful of places there adding suffixes to ids is the desirable behavior: static foreach, foreach unrolling, anything else?

Yeah I guess it's only statically unrolled loops which require the suffices for all nested lambdas.

@thewilsonator thewilsonator merged commit 12d01d0 into dlang:stable Jun 4, 2025
74 checks passed
@kinke kinke deleted the fix21331 branch June 4, 2025 15:45
kinke added a commit to kinke/ldc that referenced this pull request Jun 4, 2025
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.

4 participants