-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
decl_macro incremental compilation bug: missing field #112680
Labels
A-incr-comp
Area: Incremental compilation
A-macros
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
A-macros-2.0
Area: Declarative macros 2.0 (#39412)
C-bug
Category: This is a bug.
F-decl_macro
`#![feature(decl_macro)]`
S-has-mcve
Status: A Minimal Complete and Verifiable Example has been found for this issue
Comments
full code #![feature(decl_macro)]
pub trait Entity {
type Key;
fn index_from_key(key: Self::Key) -> usize;
}
pub macro entity_impl($key_ty:ident, $val_ty:ident) {
struct $key_ty {
inner: usize,
}
impl ::a::Entity for $val_ty {
type Key = $key_ty;
fn index_from_key(key: Self::Key) -> usize {
key.inner
}
}
}
// does not reproduce with this uncommented, and the macro above commented
// #[macro_export]
// macro_rules! entity_impl {
// ($key_ty:ident, $val_ty:ident) => {
// struct $key_ty {
// inner: usize,
// }
// impl ::a::Entity for $val_ty {
// type Key = $key_ty;
// fn index_from_key(key: Self::Key) -> usize {
// key.inner
// }
// }
// }
// }
use a::entity_impl;
entity_impl!(TestId, Test);
struct Test(u32);
// now uncomment the following, and comment the above
// struct Test; |
jieyouxu
added a commit
to jieyouxu/rust
that referenced
this issue
Aug 22, 2024
use old ctx if has same expand environment during decode span Fixes rust-lang#112680 The root reason why rust-lang#112680 failed with incremental compilation on the second attempt is the difference in `opaque` between the span of the field [`ident`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_hir_typeck/src/expr.rs#L2348) and the span in the incremental cache at `tcx.def_ident_span(field.did)`. - Let's call the span of `ident` as `span_a`, which is generated by [`apply_mark_internal`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/hygiene.rs#L553-L554). Its content is similar to: ```rs span_a_ctx -> SyntaxContextData { opaque: span_a_ctx, opaque_and_semitransparent: span_a_ctx, // .... } ``` - And call the span of `tcx.def_ident_span` as `span_b`, which is generated by [`decode_syntax_context`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/hygiene.rs#L1390). Its content is: ```rs span_b_ctx -> SyntaxContextData { opaque: span_b_ctx, // note `span_b_ctx` is not same as `span_a_ctx` opaque_and_semitransparent: span_b_ctx, // .... } ``` Although they have the same `parent` (both refer to the root) and `outer_expn`, I cannot find the specific connection between them. Therefore, I chose a solution that may not be the best: give up the incremental compile cache to ensure we can use `span_a` in this case. r? ``@petrochenkov`` Do you have any advice on this? Or perhaps this solution is acceptable?
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Aug 22, 2024
Rollup merge of rust-lang#127279 - bvanjoi:fix-112680, r=petrochenkov use old ctx if has same expand environment during decode span Fixes rust-lang#112680 The root reason why rust-lang#112680 failed with incremental compilation on the second attempt is the difference in `opaque` between the span of the field [`ident`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_hir_typeck/src/expr.rs#L2348) and the span in the incremental cache at `tcx.def_ident_span(field.did)`. - Let's call the span of `ident` as `span_a`, which is generated by [`apply_mark_internal`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/hygiene.rs#L553-L554). Its content is similar to: ```rs span_a_ctx -> SyntaxContextData { opaque: span_a_ctx, opaque_and_semitransparent: span_a_ctx, // .... } ``` - And call the span of `tcx.def_ident_span` as `span_b`, which is generated by [`decode_syntax_context`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/hygiene.rs#L1390). Its content is: ```rs span_b_ctx -> SyntaxContextData { opaque: span_b_ctx, // note `span_b_ctx` is not same as `span_a_ctx` opaque_and_semitransparent: span_b_ctx, // .... } ``` Although they have the same `parent` (both refer to the root) and `outer_expn`, I cannot find the specific connection between them. Therefore, I chose a solution that may not be the best: give up the incremental compile cache to ensure we can use `span_a` in this case. r? `@petrochenkov` Do you have any advice on this? Or perhaps this solution is acceptable?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-incr-comp
Area: Incremental compilation
A-macros
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
A-macros-2.0
Area: Declarative macros 2.0 (#39412)
C-bug
Category: This is a bug.
F-decl_macro
`#![feature(decl_macro)]`
S-has-mcve
Status: A Minimal Complete and Verifiable Example has been found for this issue
Note: This may be a duplicate, but I couldn't find one, so I'm going ahead and reporting it.
When using
decl_macro
, I'm encountering a strange incremental compilation bug. I have a struct, declared as follows:To reproduce this, do the following:
cargo clean
, thencargo check
.cargo check
again. The error below is emitted.cargo clean && cargo check
is run again with either version, it compiles fine.I don't understand why this would happen, but I do have the code, all of which can be found in this repository.
a/src/lib.rs
has theentity_impl
macros 2.0 macro, whileb/src/lib.rs
has the struct & macro invocation shown above. I've minimized the example as best I can, but a normal (non-decl_macro
) does not work, and I can't seem to reproduce in a single crate. If there's anything else needed, or anything I should try, please let me know.Error message:
Meta
rustc --version --verbose
:@rustbot label +A-incr-comp +A-macros-2.0
(I'm just guessing on these labels.)
The text was updated successfully, but these errors were encountered: