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

RustWrapper: work around unification of diagnostic handlers #83425

Merged
merged 1 commit into from
Apr 23, 2021

Conversation

durin42
Copy link
Contributor

@durin42 durin42 commented Mar 23, 2021

This lets me build against llvm/main as of March 23rd, 2021. I'm not
entirely sure this is correct, but it appears to be functionally
identical to what was done in LLVM: existing callsites of
setInlineAsmDiagnosticHandler were moved to SetDiagnosticHandler() on
the context object, which we already set up in both places that we
called setInlineAsmDiagnosticHandler().

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 23, 2021
@tmandry
Copy link
Member

tmandry commented Mar 23, 2021

r? @nikic

@rust-highfive rust-highfive assigned nikic and unassigned estebank Mar 23, 2021
@nagisa
Copy link
Member

nagisa commented Mar 24, 2021

From what I can tell this will lose information about location of the error – the inline_asm_handler appears to be spending additional effort to unpack the span and whatnot, and the regular diagnostic_handler is not doing so.

@durin42
Copy link
Contributor Author

durin42 commented Mar 24, 2021

I just spent a few minutes trying to trace how the inline_asm_handler works, but I'm honestly entirely lost at this point. The old (asm) handler gets a cookie argument that the new one doesn't, so it's not even obvious to me that things can be ported over without loss?

I'm also not sure what that cookie argument does: I got as far as seeing that it goes in InlineAsmError, and then gets used as a position in a span, so I strongly suspect that we're just SOL on showing spans on the newer LLVM. Happy to be proven wrong, naturally, but I don't see the span information unless it's hiding in the CodegenContext or DiagnosticInfo types (but that's somewhat beyond my skill - I can try and figure it out, I guess, but that'll have to wait a while).

I suppose I can drop a TODO that the diagnostic_handler should try and grovel around for some span information?

@nagisa
Copy link
Member

nagisa commented Mar 24, 2021

It would be fairly unfortunate if the span situation ends up not being looked at before the bump to LLVM 13, which I feel will almost definitely happen if this PR lands in its current form.

FWIW this area of code in clang seems relevant: https://github.com/llvm/llvm-project/blob/3cb2346982399892eae36e660ffa7e77a27ee067/clang/lib/CodeGen/CodeGenAction.cpp#L508-L529 – it also has something to do with a cookie and whatnot. But implementing something like this might involve adding more bindings to RustWrapper or similar.

durin42 added a commit to durin42/rust that referenced this pull request Mar 24, 2021
THis came up in the review of rust-lang#83425: it's hard to imagine a use of
LLVM_VERSION_LE() or LLVM_VERSION_EQ() that's not asking for trouble
when a point release gets created, so let's just discard them to prevent
the issue.
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Mar 25, 2021
… r=cuviper

LLVMWrapper: attractive nuisance macros

This came up in the review of rust-lang#83425: it's hard to imagine a use of
LLVM_VERSION_LE() or LLVM_VERSION_EQ() that's not asking for trouble
when a point release gets created, so let's just discard them to prevent
the issue.
@Amanieu
Copy link
Member

Amanieu commented Mar 25, 2021

Note that a lot of the asm tests aren't being run in CI because they require LLVM 10. These tests will fail when run by bors if source location support is missing.

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 12, 2021
@Dylan-DPC-zz
Copy link

@nikic any updates on this? thanks

@durin42
Copy link
Contributor Author

durin42 commented Apr 12, 2021

@Dylan-DPC I believe right now this is blocked on someone (probably me, but I was on vacation for over a week and just got back) fixing up some of the diagnostic handler stuff to be correctly implemented on LLVM HEAD. I hope to have time for that this week.

@Dylan-DPC-zz Dylan-DPC-zz 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 Apr 12, 2021
@durin42
Copy link
Contributor Author

durin42 commented Apr 22, 2021

Alright, I just spent some time with this, and I think it's already good: the only two callsites of LLVMRustSetInlineAsmDiagnosticHandler also call LLVMContextSetDiagnosticHandler, and diagnostic_handler in compiler/rustc_codegen_llvm/src/back/write.rs already checks for InlineAsm diagnostics, so it looks like all the adaptation has already been done. Can anyone point out a way that I'm wrong, or does that look roughly correct?

At this point I'm back to thinking this change is ready: the fixes I was expecting to need to make seem to have been mostly done in 5541f68, or other revisions that touch compiler/rustc_codegen_llvm/src/back/write.rs.

@nagisa
Copy link
Member

nagisa commented Apr 22, 2021

Can you squash the two commits?

Given the Amanieu's explanation I think I'm comfortable adding whatever support necessary for >= 13.0 as tests failing will definitely make us take another look if anything is wrong there.

This lets me build against llvm/main as of March 23rd, 2021. I'm not
entirely sure this is _correct_, but it appears to be functionally
identical to what was done in LLVM: existing callsites of
setInlineAsmDiagnosticHandler were moved to SetDiagnosticHandler() on
the context object, which we already set up in both places that we
called setInlineAsmDiagnosticHandler().
@durin42
Copy link
Contributor Author

durin42 commented Apr 22, 2021

Squashed!

(In my local test that I did just now, I believe this patch is the only thing required to get rustc to build against LLVM HEAD as of today!)

@nagisa
Copy link
Member

nagisa commented Apr 22, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Apr 22, 2021

📌 Commit fc2a74c has been approved by nagisa

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 22, 2021
@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 Apr 22, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 22, 2021
RustWrapper: work around unification of diagnostic handlers

This lets me build against llvm/main as of March 23rd, 2021. I'm not
entirely sure this is _correct_, but it appears to be functionally
identical to what was done in LLVM: existing callsites of
setInlineAsmDiagnosticHandler were moved to SetDiagnosticHandler() on
the context object, which we already set up in both places that we
called setInlineAsmDiagnosticHandler().
@bors
Copy link
Contributor

bors commented Apr 23, 2021

⌛ Testing commit fc2a74c with merge 236580b...

@bors
Copy link
Contributor

bors commented Apr 23, 2021

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing 236580b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 23, 2021
@bors bors merged commit 236580b into rust-lang:master Apr 23, 2021
@rustbot rustbot added this to the 1.53.0 milestone Apr 23, 2021
@durin42 durin42 deleted the llvm-update branch August 24, 2021 14:07
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.