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

ICE when path-exporting and using a macro-generated macro_rules! macro #82504

Closed
danielhenrymantilla opened this issue Feb 25, 2021 · 4 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-decl_macro `#![feature(decl_macro)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@danielhenrymantilla
Copy link
Contributor

The objective was to be able to feature some macro which would yield a $self:ident parameter with the def-site of a there-defined macro macro so as to mock the suggested $self parameter on macros.

Code

#![feature(decl_macro, trace_macros)]

// trace_macros!(true); /* to debug: the expansion works successfully */

module::recurse! { 1 1 1 }

pub mod module {
    pub(super) use private::recurse;

    mod private {
        macro __helper__ ([$dol:tt] $exported_name:ident) {
            macro_rules! $exported_name {(
                $dol(1 $dol($rest:tt)*)?
            ) => (
                $dol(
                //  the idea is for this to have def-site hygiene here
                //  vvvv
                    self::$exported_name! { $dol($rest)* }
                )?
            )} pub(crate) use $exported_name;
        }
        __helper__! { [$] recurse }
    }
}

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (fe1bf8e05 2021-02-23)
binary: rustc
commit-hash: fe1bf8e05c39bdcc73fc09e246b7209444e389bc
commit-date: 2021-02-23
host: x86_64-apple-darwin
release: 1.52.0-nightly
LLVM version: 11.0.1

Error output

error: internal compiler error: expansion entered force mode without producing any errors
  --> src/lib.rs:29:1
   |
29 | outer::recurse! { 1 1 1 }
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at compiler/rustc_expand/src/expand.rs:447:34

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1012:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (fe1bf8e05 2021-02-23) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
Backtrace

stack backtrace:
   …
   5:        0x1020a36a8 - rustc_driver::report_ice::hcdbc085c8141570d
   …
  10:        0x1093532ab - std::panicking::begin_panic_fmt::hba7ec5d426758edb
  11:        0x10600ee16 - rustc_errors::HandlerInner::flush_delayed::h161e3beabf00546a
  12:        0x10600b10b - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::hde0ac14a81f422db
  13:        0x1020ab07d - core::ptr::drop_in_place<rustc_session::parse::ParseSess>::h0cb46aa2558b566b
  14:        0x1020afda8 - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h5a4e1115e34fca86
  15:        0x102110835 - core::ptr::drop_in_place<rustc_interface::interface::Compiler>::hbf9fc4b317f8829b
  16:        0x10210cd08 - rustc_span::with_source_map::hdc8b53d5836d0f69
  17:        0x1020ba394 - rustc_interface::interface::create_compiler_and_run::h2e5f4f156384205a
  18:        0x1020b2db9 - scoped_tls::ScopedKey<T>::set::hb5d8ea6cc29ec656
  19:        0x1020b4101 - std::sys_common::backtrace::__rust_begin_short_backtrace::h316820ab0a243dd5
  20:        0x1020d85e9 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h0dcd073e2532982e
  21:        0x1092d897d - std::sys::unix::thread::Thread::new::thread_start::h4da435b3f287e7dd
  22:     0x7fff20323950 - __pthread_start

cc @Aaron1011

@danielhenrymantilla danielhenrymantilla added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2021
@danielhenrymantilla

This comment has been minimized.

@rustbot rustbot added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) F-decl_macro `#![feature(decl_macro)]` labels Feb 25, 2021
@danielhenrymantilla danielhenrymantilla changed the title ICE when mixing higher order macro_rules! and macro macros ICE when path-exporting and using a macro-generated macro_rules! macro Feb 25, 2021
@danielhenrymantilla
Copy link
Contributor Author

I have found something that may be interesting. The following ICEs:

#![feature(decl_macro)]

pub mod module {
    mod private {
        __helper__! { [$] recurse }
    
        macro __helper__ ([$dol:tt] $exported_name:ident) {
            macro_rules! $exported_name {() => ()}
            pub(crate) use $exported_name;
        }
            // pub(crate) use recurse;
    }
    pub(super) use private::recurse;
}

module::recurse!();

but the following does not:

#![feature(decl_macro)]

pub mod module {
    mod private {
        __helper__! { [$] recurse }
    
        macro __helper__ ([$dol:tt] $exported_name:ident) {
            macro_rules! $exported_name {() => ()}
            // pub(crate) use $exported_name;
        }
            pub(crate) use recurse;
    }
    pub(super) use private::recurse;
}

module::recurse!();

        macro __helper__ ([$dol:tt] $exported_name:ident) {
            macro_rules! $exported_name {() => ()}
+           pub(crate) use $exported_name;
        }
-           pub(crate) use recurse;

fanninpm added a commit to fanninpm/glacier that referenced this issue Feb 26, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 27, 2021
@Alexendoo
Copy link
Member

No longer ICEs since #108729

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 23, 2023
@JohnTitor
Copy link
Member

Triage: Closing as #108729 should have a regression test covering this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-decl_macro `#![feature(decl_macro)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

5 participants