Skip to content

Commit c6c92c3

Browse files
committed
Reproduce issue DO NOT MERGE
1 parent b670776 commit c6c92c3

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

compiler/rustc_hir_analysis/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
225225
}
226226
});
227227

228+
// Make sure we actually have a value for static items, as they aren't cached in incremental.
229+
// While we could just wait for codegen to invoke this, the definitions freeze below will cause
230+
// that to ICE, because evaluating statics can create more items.
231+
tcx.par_hir_body_owners(|item_def_id| {
232+
if let DefKind::Static { .. } = tcx.def_kind(item_def_id) {
233+
let _ = tcx.eval_static_initializer(item_def_id);
234+
}
235+
});
236+
228237
tcx.par_hir_body_owners(|item_def_id| {
229238
let def_kind = tcx.def_kind(item_def_id);
230239
// Skip `AnonConst`s because we feed their `type_of`.

compiler/rustc_middle/src/query/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,6 @@ rustc_queries! {
12761276
"evaluating initializer of static `{}`",
12771277
tcx.def_path_str(key)
12781278
}
1279-
cache_on_disk_if { key.is_local() }
12801279
separate_provide_extern
12811280
feedable
12821281
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#![cfg_attr(rpass2, warn(dead_code))]
18+
19+
pub static mut FOO: &mut i32 = &mut 42;
20+
21+
pub static mut BAR: &mut i32 = unsafe { FOO };
22+
23+
fn main() {
24+
unsafe {
25+
assert_eq!(BAR as *mut i32, FOO as *mut i32);
26+
}
27+
}

0 commit comments

Comments
 (0)