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

Add discriminators to DILocations when multiple functions are inlined into a single point. #132613

Merged
merged 1 commit into from
Nov 9, 2024

Conversation

khuey
Copy link
Contributor

@khuey khuey commented Nov 4, 2024

LLVM does not expect to ever see multiple dbg_declares for the same variable at the same location with different values. proc-macros make it possible for arbitrary code, including multiple calls that get inlined, to happen at any given location in the source code. Add discriminators when that happens so these locations are different to LLVM.

This may interfere with the AddDiscriminators pass in LLVM, which is added by the unstable flag -Zdebug-info-for-profiling.

Fixes #131944

@rustbot
Copy link
Collaborator

rustbot commented Nov 4, 2024

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 4, 2024
@rust-log-analyzer

This comment has been minimized.

@workingjubilee
Copy link
Member

@bors try

@bors
Copy link
Contributor

bors commented Nov 5, 2024

⌛ Trying commit c4b99a1 with merge 6bc6e20...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 5, 2024
Add discriminators to DILocations when multiple functions are inlined into a single point.

LLVM does not expect to ever see multiple dbg_declares for the same variable at the same location with different values. proc-macros make it possible for arbitrary code, including multiple calls that get inlined, to happen at any given location in the source code. Add discriminators when that happens so these locations are different to LLVM.

This may interfere with the AddDiscriminators pass in LLVM, which is added by the unstable flag -Zdebug-info-for-profiling.

Fixes rust-lang#131944
@bors
Copy link
Contributor

bors commented Nov 5, 2024

☀️ Try build successful - checks-actions
Build commit: 6bc6e20 (6bc6e203f22db68ac5d1affcbc364737fad0f0d6)

@jieyouxu
Copy link
Member

jieyouxu commented Nov 5, 2024

@bors try

@bors
Copy link
Contributor

bors commented Nov 5, 2024

⌛ Trying commit c4b99a1 with merge 9517283...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 5, 2024
Add discriminators to DILocations when multiple functions are inlined into a single point.

LLVM does not expect to ever see multiple dbg_declares for the same variable at the same location with different values. proc-macros make it possible for arbitrary code, including multiple calls that get inlined, to happen at any given location in the source code. Add discriminators when that happens so these locations are different to LLVM.

This may interfere with the AddDiscriminators pass in LLVM, which is added by the unstable flag -Zdebug-info-for-profiling.

Fixes rust-lang#131944

try-job: x86_64-msvc
try-job: i686-msvc
@lqd

This comment was marked as resolved.

@jieyouxu

This comment was marked as resolved.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Nov 5, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 5, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Nov 5, 2024

(I edited the PR description to include a few "selected" try-jobs which should bring about reasonable target variance, rest is probably full build)

@workingjubilee
Copy link
Member

@bors try

@bors
Copy link
Contributor

bors commented Nov 7, 2024

⌛ Trying commit b7b6b06 with merge 225656d...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 7, 2024
Add discriminators to DILocations when multiple functions are inlined into a single point.

LLVM does not expect to ever see multiple dbg_declares for the same variable at the same location with different values. proc-macros make it possible for arbitrary code, including multiple calls that get inlined, to happen at any given location in the source code. Add discriminators when that happens so these locations are different to LLVM.

This may interfere with the AddDiscriminators pass in LLVM, which is added by the unstable flag -Zdebug-info-for-profiling.

Fixes rust-lang#131944

try-job: x86_64-msvc
try-job: i686-msvc
try-job: x86_64-mingw
try-job: aarch64-apple
try-job: test-various
try-job: dist-various-1
try-job: armhf-gnu
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Nov 7, 2024

💔 Test failed - checks-actions

@jieyouxu
Copy link
Member

jieyouxu commented Nov 7, 2024

@bors try

@bors
Copy link
Contributor

bors commented Nov 7, 2024

⌛ Trying commit 29f30c3 with merge 49e1343...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 7, 2024
Add discriminators to DILocations when multiple functions are inlined into a single point.

LLVM does not expect to ever see multiple dbg_declares for the same variable at the same location with different values. proc-macros make it possible for arbitrary code, including multiple calls that get inlined, to happen at any given location in the source code. Add discriminators when that happens so these locations are different to LLVM.

This may interfere with the AddDiscriminators pass in LLVM, which is added by the unstable flag -Zdebug-info-for-profiling.

Fixes rust-lang#131944

try-job: x86_64-msvc
try-job: i686-msvc
try-job: x86_64-mingw
try-job: aarch64-apple
try-job: test-various
try-job: dist-various-1
try-job: armhf-gnu
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Nov 7, 2024

💔 Test failed - checks-actions

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Nov 9, 2024
@cuviper
Copy link
Member

cuviper commented Nov 9, 2024

Nominating since #131944 was rated critical -- although it doesn't seem like anyone else has had trouble with it.

@rustbot label beta-nominated

@rustbot rustbot added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 9, 2024
@workingjubilee
Copy link
Member

@bors rollup=never

@bors
Copy link
Contributor

bors commented Nov 9, 2024

☔ The latest upstream changes (presumably #132584) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 9, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Nov 9, 2024

Unfortunately needs a rebase, r=me after that.

@bors delegate

@jieyouxu
Copy link
Member

jieyouxu commented Nov 9, 2024

Er maybe @bors delegate+

@bors
Copy link
Contributor

bors commented Nov 9, 2024

✌️ @khuey, you can now approve this pull request!

If @jieyouxu told you to "r=me" after making some further change, please make that change, then do @bors r=@jieyouxu

… into a single point.

LLVM does not expect to ever see multiple dbg_declares for the same variable at the same
location with different values. proc-macros make it possible for arbitrary code,
including multiple calls that get inlined, to happen at any given location in the source
code. Add discriminators when that happens so these locations are different to LLVM.

This may interfere with the AddDiscriminators pass in LLVM, which is added by the
unstable flag -Zdebug-info-for-profiling.

Fixes rust-lang#131944
@jieyouxu
Copy link
Member

jieyouxu commented Nov 9, 2024

@bors r+ rollup=never p=1 (fixes a P-critical, but also make it easier to bisect)

@bors
Copy link
Contributor

bors commented Nov 9, 2024

📌 Commit 1dc1061 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 9, 2024
@bors
Copy link
Contributor

bors commented Nov 9, 2024

⌛ Testing commit 1dc1061 with merge b026d85...

@bors
Copy link
Contributor

bors commented Nov 9, 2024

☀️ Test successful - checks-actions
Approved by: jieyouxu
Pushing b026d85 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 9, 2024
@bors bors merged commit b026d85 into rust-lang:master Nov 9, 2024
7 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 9, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b026d85): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -1.7%, secondary -3.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.7% [-2.0%, -1.4%] 2
Improvements ✅
(secondary)
-3.2% [-4.5%, -1.9%] 2
All ❌✅ (primary) -1.7% [-2.0%, -1.4%] 2

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results (primary 0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.0% [0.0%, 0.0%] 31
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [0.0%, 0.0%] 31

Bootstrap: 781.253s -> 780.559s (-0.09%)
Artifact size: 335.38 MiB -> 335.38 MiB (0.00%)

mati865 pushed a commit to mati865/rust that referenced this pull request Nov 12, 2024
Add discriminators to DILocations when multiple functions are inlined into a single point.

LLVM does not expect to ever see multiple dbg_declares for the same variable at the same location with different values. proc-macros make it possible for arbitrary code, including multiple calls that get inlined, to happen at any given location in the source code. Add discriminators when that happens so these locations are different to LLVM.

This may interfere with the AddDiscriminators pass in LLVM, which is added by the unstable flag -Zdebug-info-for-profiling.
@apiraino
Copy link
Contributor

Beta backport visited during triage meeting on Zulip.

We're not completely clear about the value added by backporting this. Is this regression really critical? Also the patch fixing this is a bit suspect of causing another ICE (#132900).

So let's postpone the backport decision for a week (release in 2 weeks from now) waiting to have more info.

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 20, 2024
Drop debug info instead of panicking if we exceed LLVM's capability to represent it

Recapping a bit of history here:

In rust-lang#128861 I made debug info correctly represent parameters to inline functions by removing a fake lexical block that had been inserted to suppress LLVM assertions and by deduplicating those parameters.

LLVM, however, expects to see a single parameter _with distinct locations_, particularly distinct inlinedAt values on the DILocations. This generally worked because no matter how deep the chain of inlines it takes two different call sites in the original function to result in the same function being present multiple times, and a function call requires a non-zero number of characters, but macros threw a wrench in that in rust-lang#131944. At the time I thought the issue there was limited to proc-macros, where an arbitrary amount of code can be generated at a single point in the source text.

In rust-lang#132613 I added discriminators to DILocations that would otherwise be the same to repair rust-lang#131944[^1]. This works, but LLVM's capacity for discriminators is not infinite (LLVM actually only allocates 12 bits for this internally). At the time I thought it would be very rare for anyone to hit the limit, but rust-lang#132900 proved me wrong. In the relatively-minimized test case it also became clear to me that the issue affects regular macros too, because the call to the inlined function will (without collapse_debuginfo on the macro) be attributed to the (repeated, if the macro is used more than once) textual callsite in the macro definition.

This PR fixes the panic by dropping debug info when we exceed LLVM's maximum discriminator value. There's also a preceding commit for a related but distinct issue: macros that use collapse_debuginfo should in fact have their inlinedAts collapsed to the macro callsite and thus not need discriminators at all (and not panic/warn accordingly when the discriminator limit is exhausted).

Fixes rust-lang#132900

r? `@jieyouxu`

[^1]: Editor's note: `fix` is a magic keyword in PR description that apparently will close the linked issue (it's closed already in this case, but still).
@apiraino
Copy link
Contributor

Beta backport declined as per compiler team on Zulip.

@rustbot label -beta-nominated

@rustbot rustbot removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Regression] LLVM asserts "conflicting locations for variable" since 1.82