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

Drop debug info instead of panicking if we exceed LLVM's capability to represent it #133194

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

khuey
Copy link
Contributor

@khuey khuey commented Nov 19, 2024

Recapping a bit of history here:

In #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 #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 #132613 I added discriminators to DILocations that would otherwise be the same to repair #1319441. 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 #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 #132900

r? @jieyouxu

Footnotes

  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).

@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 19, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 19, 2024

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks. This is certainly... interesting. I have two questions.

Comment on lines 197 to 199
tracing::warn!(
"Debug information was lost because LLVM discriminator limits were exceeded"
);
Copy link
Member

Choose a reason for hiding this comment

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

Question: this is a tracing::warn that is for rustc developers. But shouldn't this be a user-visible warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. It's not particularly actionable to users and we don't warn in all the other cases where we don't emit debug info.

Copy link
Member

@jieyouxu jieyouxu Nov 19, 2024

Choose a reason for hiding this comment

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

we don't warn in all the other cases where we don't emit debuginfo.

I feel like as a user I would want to have such a warning, but maybe that can get very noisy. Anyway, if we do want to warn when not emitting debuginfo then we should do so consistently, so not for this PR.

EDIT: asked in https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Warning.20if.20not.20emitting.20debuginfo.3F, but not a blocker for this PR.

@jieyouxu jieyouxu 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 19, 2024
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Otherwise this LGTM, thanks. r=me once PR CI is green.

@jieyouxu
Copy link
Member

@bors delegate+ rollup=iffy

@bors
Copy link
Contributor

bors commented Nov 19, 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

@jieyouxu jieyouxu added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Nov 19, 2024
@rust-log-analyzer

This comment has been minimized.

@jieyouxu
Copy link
Member

jieyouxu commented Nov 19, 2024

I think tests are not build with debug logging (for good reason), so you cannot include that in the stderr snapshot. I would consider it sufficient to have a test be //@ check-pass, i.e. a test that would've ICE'd without this PR.

…de macros.

The test relies on the fact that inlining more than 2^12 calls at the same
callsite will trigger a panic (and after the following commit, a warning) due to
LLVM limitations but with collapse_debuginfo the callsites should not be the
same.
… debug info for the function instead of panicking.

The maximum discriminator value LLVM can currently encode is 2^12. If macro use
results in more than 2^12 calls to the same function attributed to the same
callsite, and those calls are MIR-inlined, we will require more than the maximum
discriminator value to completely represent the debug information. Once we reach
that point drop the debug info instead.
@khuey
Copy link
Contributor Author

khuey commented Nov 19, 2024

Alright, I dropped the warning and adjusted the test accordingly.

@bors r=@jieyouxu

@bors
Copy link
Contributor

bors commented Nov 19, 2024

📌 Commit f5b023b 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 19, 2024
@cuviper
Copy link
Member

cuviper commented Nov 19, 2024

Nominating a backport to follow #132613 -- it seems we should consider these as a pair, backporting both or neither.

@rustbot label beta-nominated

@rustbot rustbot added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 19, 2024
@bors
Copy link
Contributor

bors commented Nov 20, 2024

⌛ Testing commit f5b023b with merge bcfea1f...

@bors
Copy link
Contributor

bors commented Nov 20, 2024

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

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

Finished benchmarking commit (bcfea1f): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 2
Improvements ✅
(secondary)
-0.4% [-0.7%, -0.4%] 8
All ❌✅ (primary) -1.1% [-1.1%, -1.1%] 2

Max RSS (memory usage)

Results (secondary 3.3%)

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)
3.3% [3.3%, 3.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

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

Binary size

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

Bootstrap: 793.735s -> 793.573s (-0.02%)
Artifact size: 335.41 MiB -> 335.42 MiB (0.00%)

@apiraino
Copy link
Contributor

Beta backport declined as per compiler team on Zulip, since we also declined #132613

@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
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) 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.

ICE: Failed to encode discriminator in DILocation
8 participants