Skip to content

Commit 6f65ef5

Browse files
committed
Auto merge of #113562 - saethlin:larger-incr-comp-offset, r=nnethercote
Use u64 for incr comp allocation offsets Fixes #76037 Fixes #95780 Fixes #111613 These issues are all reporting ICEs caused by using `u32` to store offsets to allocations in the incremental compilation cache. This PR aims to lift that limitation by changing the offset type in question to `u64`. There are two perf runs in this PR. The first reports a regression, and the second does not. The changes are the same in both. I rebased the PR then did the second perf run because I noticed that the primary regression in it was very commonly seen in spurious regression reports. I do not know what the perf run will report when this is merged. I would not be surprised to see regression or neutral, but the cachegrind diffs for the regression point at `try_mark_previous_green` which is a common source of inexplicable regressions and I don't think should be perturbed by this PR. I'm not opposed to adding a regression test such as ```rust fn main() { println!("{}", [37; 1 << 30].len()); } ``` But that program takes 1 minute to compile and consumes 4.6 GB of memory then writes that much to disk. Is that a concerning amount of resource use for a test? r? `@nnethercote`
2 parents 299179e + 4e117a9 commit 6f65ef5

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
608608
trace!("encoding {} further alloc ids", new_n - n);
609609
for idx in n..new_n {
610610
let id = self.interpret_allocs[idx];
611-
let pos = self.position() as u32;
611+
let pos = self.position() as u64;
612612
interpret_alloc_index.push(pos);
613613
interpret::specialized_encode_alloc_id(self, tcx, id);
614614
}

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub(crate) struct CrateRoot {
264264
traits: LazyArray<DefIndex>,
265265
impls: LazyArray<TraitImpls>,
266266
incoherent_impls: LazyArray<IncoherentImpls>,
267-
interpret_alloc_index: LazyArray<u32>,
267+
interpret_alloc_index: LazyArray<u64>,
268268
proc_macro_data: Option<ProcMacroData>,
269269

270270
tables: LazyTables,

compiler/rustc_middle/src/mir/interpret/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub struct AllocDecodingState {
274274
// For each `AllocId`, we keep track of which decoding state it's currently in.
275275
decoding_state: Vec<Lock<State>>,
276276
// The offsets of each allocation in the data stream.
277-
data_offsets: Vec<u32>,
277+
data_offsets: Vec<u64>,
278278
}
279279

280280
impl AllocDecodingState {
@@ -289,7 +289,7 @@ impl AllocDecodingState {
289289
AllocDecodingSession { state: self, session_id }
290290
}
291291

292-
pub fn new(data_offsets: Vec<u32>) -> Self {
292+
pub fn new(data_offsets: Vec<u64>) -> Self {
293293
let decoding_state =
294294
std::iter::repeat_with(|| Lock::new(State::Empty)).take(data_offsets.len()).collect();
295295

compiler/rustc_middle/src/query/on_disk_cache.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ struct Footer {
104104
query_result_index: EncodedDepNodeIndex,
105105
side_effects_index: EncodedDepNodeIndex,
106106
// The location of all allocations.
107-
interpret_alloc_index: Vec<u32>,
107+
// Most uses only need values up to u32::MAX, but benchmarking indicates that we can use a u64
108+
// without measurable overhead. This permits larger const allocations without ICEing.
109+
interpret_alloc_index: Vec<u64>,
108110
// See `OnDiskCache.syntax_contexts`
109111
syntax_contexts: FxHashMap<u32, AbsoluteBytePos>,
110112
// See `OnDiskCache.expn_data`
@@ -301,7 +303,7 @@ impl<'sess> OnDiskCache<'sess> {
301303
interpret_alloc_index.reserve(new_n - n);
302304
for idx in n..new_n {
303305
let id = encoder.interpret_allocs[idx];
304-
let pos: u32 = encoder.position().try_into().unwrap();
306+
let pos: u64 = encoder.position().try_into().unwrap();
305307
interpret_alloc_index.push(pos);
306308
interpret::specialized_encode_alloc_id(&mut encoder, tcx, id);
307309
}

compiler/rustc_middle/src/ty/parameterized.rs

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ trivially_parameterized_over_tcx! {
5252
usize,
5353
(),
5454
u32,
55+
u64,
5556
bool,
5657
std::string::String,
5758
crate::metadata::ModChild,

0 commit comments

Comments
 (0)