Skip to content

Commit a82e9a3

Browse files
committed
Reproduce issue
1 parent a41284b commit a82e9a3

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

compiler/rustc_hir_analysis/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
201201
}
202202
});
203203

204+
// Make sure we actually have a value for static items, as they aren't cached in incremental.
205+
// While we could just wait for codegen to invoke this, the definitions freeze below will cause
206+
// that to ICE, because evaluating statics can create more items.
207+
tcx.hir().par_body_owners(|item_def_id| {
208+
if let DefKind::Static { .. } = tcx.def_kind(item_def_id) {
209+
let _ = tcx.eval_static_initializer(item_def_id);
210+
}
211+
});
212+
204213
// Freeze definitions as we don't add new ones at this point. This improves performance by
205214
// allowing lock-free access to them.
206215
tcx.untracked().definitions.freeze();

compiler/rustc_middle/src/query/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,6 @@ rustc_queries! {
10651065
"evaluating initializer of static `{}`",
10661066
tcx.def_path_str(key)
10671067
}
1068-
cache_on_disk_if { key.is_local() }
10691068
separate_provide_extern
10701069
feedable
10711070
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ revisions:rpass1 rpass2
2+
3+
//! Test that the following order of instructions will not create duplicate
4+
//! `DefId`s for the nested static items.
5+
// ensure(eval_static_initializer(FOO))
6+
// -> try_mark_green(eval_static_initializer(FOO))
7+
// -> green
8+
// -> replay side effects
9+
// -> create some definitions.
10+
//
11+
// get(eval_static_initializer(FOO))
12+
// -> graph in place
13+
// -> replay
14+
// -> eval_static_initializer.compute
15+
// -> how do we skip re-creating the same definitions ?
16+
17+
#![feature(const_mut_refs)]
18+
#![cfg_attr(rpass2, warn(dead_code))]
19+
20+
pub static mut FOO: &mut i32 = &mut 42;
21+
22+
pub static mut BAR: &mut i32 = unsafe { FOO };
23+
24+
fn main() {
25+
unsafe {
26+
assert_eq!(BAR as *mut i32, FOO as *mut i32);
27+
}
28+
}

0 commit comments

Comments
 (0)