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

Macro hygiene change breaks Firefox builds. #76480

Closed
emilio opened this issue Sep 8, 2020 · 17 comments
Closed

Macro hygiene change breaks Firefox builds. #76480

emilio opened this issue Sep 8, 2020 · 17 comments
Labels
regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@emilio
Copy link
Contributor

emilio commented Sep 8, 2020

The following program with paste = "0.1.12" compiles on stable (rustc 1.46.0 (04488afe3 2020-08-24)), but doesn't on Nightly (rustc 1.48.0-nightly (0e2c1281e 2020-09-07)).

This is minimized from Firefox source code, which doesn't build anymore with Rust Nightly.

To be fair, I'm surprised it built in the first place...

#[macro_use] extern crate paste;

#[derive(Clone, Copy)]
struct Bar {
    member: i32,
}

impl Bar {
    fn get_member(&self, _: i32, _: i32) -> i32 {
        self.member
    }
}

macro_rules! foo {
    ($fn_name:ident $(, $arg:ident)*) => {
        paste::expr! {
            Bar::[<get_ $fn_name>](&self.bar $(, $arg)* ,callback)
        }
    };
}

struct Foo {
    bar: Bar,
}

impl Foo {
    fn member(&self, n: i32, callback: i32) -> i32 {
        foo!(member, n)
    }
}

fn main() {}
@jonas-schievink jonas-schievink added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Sep 8, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 8, 2020
@KamilaBorowska
Copy link
Contributor

This also happens on 1.47.0-beta.2 (84b047b 2020-08-28) making it regression-from-stable-to-beta.

@Mark-Simulacrum Mark-Simulacrum added this to the 1.47.0 milestone Sep 8, 2020
@Mark-Simulacrum Mark-Simulacrum added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 8, 2020
@Mark-Simulacrum
Copy link
Member

cc @Aaron1011 @petrochenkov

@emilio
Copy link
Contributor Author

emilio commented Sep 8, 2020

I'm fixing this in Firefox in https://bugzilla.mozilla.org/show_bug.cgi?id=1663677. There's another macro-related regression that I'm trying to reduce and that seems much harder to work around, but I'll file that separately.

@Aaron1011
Copy link
Member

This is intentional - before PR #73084, we were using re-parsed tokens for the call to paste::expr! due to the use of a metavariable. We now use the original tokens, which preserves the hygiene information on self and callback.

@emilio
Copy link
Contributor Author

emilio commented Sep 8, 2020

I'm ok with wontfix, as I noted in my report I was surprised that this compiled at all. But it seems odd to see breaking changes like that...

@emilio
Copy link
Contributor Author

emilio commented Sep 8, 2020

Chances are that #76482 is the same too (just with a bit of indirection because of syn), not sure.

@Aaron1011
Copy link
Member

@emilio: The breaking changes are unfortunate, but are an unavoidable part of making progress towards fixing #43081. As you noted, the broken code should have never compiled in the first place due to the hygiene rules of macro_rules! macros.

Several Crater runs were performed before landing #73084. Unfortunately, Crater cannot test all Rust code - in this case, it looks like firefox-accounts-bridge could have been tested, but Crater did not know about it (it's on neither crates.io nor GitHub).

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Sep 8, 2020
This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Sep 9, 2020
…ger,lina

This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466
@emilio
Copy link
Contributor Author

emilio commented Sep 9, 2020

In the past, breaking changes at least caused warnings for a release or two, which allowed us to notice the brekage and fix in advance without breaking developer builds. Anyhow I'm ok with this being wontfix, it's just odd to have such breakage being introduced without notice.

@estebank
Copy link
Contributor

estebank commented Sep 9, 2020

@Aaron1011 would it be possible to downgrade catch this and emit a warning instead of error (shirt if cherry picking a revert?)? Regardless, this should be in the release notes. Can you make sure this is part of 1.47's public announcement?

@Aaron1011
Copy link
Member

Unfortunately, it's not possible to emit a warning here - see #76482 (comment)

PR #73084 is tagged with relnotes, and is mentioned in #76101

However, I agree that we can do a better job of notifying crates about this kind of breakage. The next PR to cause this kind of breakage will be #75800, which just finished its Crater run. I have a few thoughts on how to make the transition smoother:

  • Make some kind of announcement (blog post, forum post, etc) before landing it
  • Create a 'breaking changes' Zulip stream (or maybe just a 'unwarnable-macro-breaking-chnges' stream) where we post announcements about this kind of change. This should help with crates that are not (or cannot be) tested by Crater, assuming that crate authors subscribe to it.

I'm open to any suggestions as to how we can improve this process. Unfortunately, the black-box nature of proc-macros means that the usual future-compatibility lint approach cannot work here.

@emilio
Copy link
Contributor Author

emilio commented Sep 9, 2020

Unfortunately, it's not possible to emit a warning here - see #76482 (comment)

@Aaron1011 I'm not sure I agree with that argument. While I agree that technically a proc macro can do whatever and have a gazillion side-effects, the vast majority of macros don't.

And if you're at the point where the proc macro has errored, which is the only case in which you'd run it twice, I don't see how running it twice could be worse than failing to build?

@Aaron1011
Copy link
Member

Aaron1011 commented Sep 9, 2020

@emilio: People have made assumptions about the behavior of proc-macros in the past (e.g. trying to store things in thread-locals), so I'm worried that re-running proc-macros without an explicit opt-in could just cause a different kind of breakage.

Another factor I overlooked is that there are two ways for proc-macros to fail: panicking, and emitting an 'error' TokenStream (e.g. containing a call to compile_error!). While we could attempt to detect calls to compile_error! that occur directly in the output TokenStream, we can't really do anything in the general case. A compilation error can occur at any expansion depth, and result from a combination of tokens for multiple macros expansions - in such a case, we can't determine which macro to retry.

It's possible that addressing the simple case of pancicking/compile_error! would be good enough to cover the majority of breakage. cc @petrochenkov

@spastorino spastorino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 9, 2020
@spastorino
Copy link
Member

This doesn't need prioritization so removing I-prioritize

@petrochenkov
Copy link
Contributor

This is unambiguously a bugfix and producing transition warnings for this would be more on the "heroic efforts" territory, so I wouldn't personally do this from the cost / benefit point of view.

A public announce would be great though.

gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Sep 16, 2020
This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466

UltraBlame original commit: 6d73f925b6cf8b84d8a36895b67504495e06ae57
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Sep 16, 2020
…ger,lina

This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466

UltraBlame original commit: 0bfeb9c69bfa6e7d9b9fb268d199b6c32add061e
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Sep 16, 2020
This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466

UltraBlame original commit: 6d73f925b6cf8b84d8a36895b67504495e06ae57
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Sep 16, 2020
…ger,lina

This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466

UltraBlame original commit: 0bfeb9c69bfa6e7d9b9fb268d199b6c32add061e
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Sep 16, 2020
This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466

UltraBlame original commit: 6d73f925b6cf8b84d8a36895b67504495e06ae57
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Sep 16, 2020
…ger,lina

This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466

UltraBlame original commit: 0bfeb9c69bfa6e7d9b9fb268d199b6c32add061e
@LeSeulArtichaut LeSeulArtichaut added regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Sep 24, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 24, 2020
@LeSeulArtichaut LeSeulArtichaut removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 24, 2020
@spastorino
Copy link
Member

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Oct 2, 2020
…ger,lina, a=jcristau

This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466
ambroff pushed a commit to ambroff/gecko that referenced this issue Nov 4, 2020
This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466
ambroff pushed a commit to ambroff/gecko that referenced this issue Nov 4, 2020
…ger,lina

This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466
@Mark-Simulacrum Mark-Simulacrum added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Nov 6, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 6, 2020
@Mark-Simulacrum
Copy link
Member

This was shipped in 1.47, and included in release notes (IIRC). I don't think there's anything further here so let's go ahead and close.

@LeSeulArtichaut LeSeulArtichaut removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 6, 2020
aosmond pushed a commit to aosmond/gecko that referenced this issue Nov 27, 2021
…ger,lina, a=jcristau

This prevents us from building with rust beta/nightly.

This is technically a Rust regression, see
rust-lang/rust#76480, though I think that this
should've never worked.

Differential Revision: https://phabricator.services.mozilla.com/D89466
shr-project added a commit to shr-project/meta-browser that referenced this issue Aug 16, 2023
* cssparser fails to build with:
  error[E0425]: cannot find value `MAX_LENGTH` in this scope
  error[E0425]: cannot find value `MAP` in this scope
  as shown in:
  http://errors.yoctoproject.org/Errors/Details/731831/

  which leads to
  rust-lang/rust#76480
  https://bugzilla.mozilla.org/show_bug.cgi?id=1663677

* but this still isn't enough to build firefox with current rust 1.71.0 in oe-core
  I've tried to backport multiple changes like:
  https://bugzilla.mozilla.org/show_bug.cgi?id=1663715#c5
  https://hg.mozilla.org/releases/mozilla-esr78/rev/5db8c1e9f643ec26fc93e7a3fc7a90c742b11030
  https://hg.mozilla.org/releases/mozilla-esr78/rev/6445a3a0e81d6aeeaa976be784edf2de9fab84de
  https://hg.mozilla.org/mozilla-central/rev/e2cede25c027
  https://phabricator.services.mozilla.com/D89473
  https://hg.mozilla.org/mozilla-central/rev/da77d5528a08
  https://phabricator.services.mozilla.com/D83816

* but it's neverending story of more and more fixes and esr68 is just
  too old and not worth spending more time on it (just to measure
  build time across different Yocto releases)

* still doesn't build
  http://errors.yoctoproject.org/Errors/Details/731829/

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
shr-project added a commit to shr-project/meta-browser that referenced this issue Nov 15, 2023
* cssparser fails to build with:
  error[E0425]: cannot find value `MAX_LENGTH` in this scope
  error[E0425]: cannot find value `MAP` in this scope
  as shown in:
  http://errors.yoctoproject.org/Errors/Details/731831/

  which leads to
  rust-lang/rust#76480
  https://bugzilla.mozilla.org/show_bug.cgi?id=1663677

* but this still isn't enough to build firefox with current rust 1.71.0 in oe-core
  I've tried to backport multiple changes like:
  https://bugzilla.mozilla.org/show_bug.cgi?id=1663715#c5
  https://hg.mozilla.org/releases/mozilla-esr78/rev/5db8c1e9f643ec26fc93e7a3fc7a90c742b11030
  https://hg.mozilla.org/releases/mozilla-esr78/rev/6445a3a0e81d6aeeaa976be784edf2de9fab84de
  https://hg.mozilla.org/mozilla-central/rev/e2cede25c027
  https://phabricator.services.mozilla.com/D89473
  https://hg.mozilla.org/mozilla-central/rev/da77d5528a08
  https://phabricator.services.mozilla.com/D83816

* but it's neverending story of more and more fixes and esr68 is just
  too old and not worth spending more time on it (just to measure
  build time across different Yocto releases)

* still doesn't build
  http://errors.yoctoproject.org/Errors/Details/731829/

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

10 participants