Stream: t-compiler/rust-analyzer

Topic: Proc macro unreachable code / use-after-free


Mario Carneiro (Jun 02 2021 at 11:07, on Zulip):

I'll report a bug if I can isolate it, but just in case, is anyone else seeing errors in proc-macros as of the latest release? I'm getting proc-macro panicked: use-after-free in `proc_macro` handle and proc-macro panicked: internal error: entered unreachable code, for my own proc macros (whose implementation has not changed in a while, although I suspect that on earlier versions of r-a they just weren't being run).

Laurențiu (Jun 02 2021 at 11:07, on Zulip):

https://github.com/rust-analyzer/rust-analyzer/issues/8929

Laurențiu (Jun 02 2021 at 11:08, on Zulip):

It's an (or a series of) ABI changes in nightly

Mario Carneiro (Jun 02 2021 at 11:08, on Zulip):

thanks!

Laurențiu (Jun 02 2021 at 11:09, on Zulip):

You can try downgrading to a nightly from before May 10th or so, or use stable

Mario Carneiro (Jun 02 2021 at 11:11, on Zulip):

I see references to that on the issue, is this a bug in the nightly ABI or a change that requires recompiling everything to use the same updated ABI?

Laurențiu (Jun 02 2021 at 11:14, on Zulip):

We don't want to reuse the rustc implementation (even if it were possible, I don't know), so we ship a copy of the code that runs on the proc macro side with some appropriate shims on the RA

Laurențiu (Jun 02 2021 at 11:14, on Zulip):

If the ABI changes, we need to update our bundled code, and to update our shims in RA to support anything new that's in there

bjorn3 (Jun 02 2021 at 11:14, on Zulip):

Laurențiu said:

We don't want to reuse the rustc implementation (even if it were possible, I don't know)

The rustc implementation is only accessible behind a feature flag.

Laurențiu (Jun 02 2021 at 11:15, on Zulip):

But we can't support both the stable and the nightly ABI at once

Laurențiu (Jun 02 2021 at 11:16, on Zulip):

There's https://github.com/rust-analyzer/rust-analyzer/pull/9047, but it might need more changes

Mario Carneiro (Jun 02 2021 at 11:19, on Zulip):

oh wow, ABI changes sound really painful. I guess this happens on every change and persists for 12 weeks

Mario Carneiro (Jun 02 2021 at 11:20, on Zulip):

is it possible to detect that you are running on nightly?

Laurențiu (Jun 02 2021 at 11:20, on Zulip):

Yeah, but it's not implemented

Florian Diebold (Jun 02 2021 at 11:21, on Zulip):

hmm don't we already read the proc macro ABI version or something like that?

Laurențiu (Jun 02 2021 at 11:23, on Zulip):

Yeah, but only to check the rustc version against our rustc IIRC

Laurențiu (Jun 02 2021 at 11:23, on Zulip):

We don't figure "oh, it's a nightly and we know these to be broken, so let's disable proc macros for now"

cynecx (Jun 02 2021 at 12:09, on Zulip):

wait. the proc macro abi is “versionised”? or are we talking about comparing rustc versions?

cynecx (Jun 02 2021 at 12:11, on Zulip):

having some kind of proc macro abi versioning would be nice

Jonas Schievink [he/him] (Jun 02 2021 at 12:11, on Zulip):

we look at the rustc version stored in the proc macro's dylib

Laurențiu (Jun 02 2021 at 12:16, on Zulip):

The ABI itself is not versioned

Laurențiu (Jun 02 2021 at 12:16, on Zulip):

And we don't support multiple versions of it, though that would be nice

Jonas Schievink [he/him] (Jun 02 2021 at 12:20, on Zulip):

I think the ideal solution would be to ship the required code as part of the rustup toolchain, that way it auto-updates and is always compatible with the compiler in use

bjorn3 (Jun 02 2021 at 12:22, on Zulip):

The problem with that is that every time the proc macro abi changes, the api that needs to be implemented by rust-analyzer changes too.

Laurențiu (Jun 02 2021 at 12:23, on Zulip):

Yeah, like in https://github.com/rust-analyzer/rust-analyzer/issues/9049 and https://github.com/rust-analyzer/rust-analyzer/pull/9047/files#diff-33c902ac596e0d7ed8a6c15d046920d3cdb70bcabab1461c8bb46a294a97cf3cR524-R526

Jonas Schievink [he/him] (Jun 02 2021 at 12:25, on Zulip):

If we compile that code ourselves, that means we'll get notified when ABI breakage happens, so that seems strictly better than the current state

Jonas Schievink [he/him] (Jun 02 2021 at 12:26, on Zulip):

Maybe I should finally look into WASM and whether it can make this easy, then rustup could just include a WASM blob we could use without compiling anything

Florian Diebold (Jun 02 2021 at 12:31, on Zulip):

would it even be possible for us to support different versions of the ABI in the same binary (since the proc-macro bridge is the same rust-analyzer binary as everything else)?

bjorn3 (Jun 02 2021 at 12:34, on Zulip):

I think the bridge doesn't export any #[no_mangle] functions directly to the proc macro, but instead passes a function pointer to the proc macro.

bjorn3 (Jun 02 2021 at 12:34, on Zulip):

This means that it should be possible to support different proc macro bridge versions in the same executable I think.

Last update: Jul 27 2021 at 22:45UTC