{"record":{"id":"3378c1560700ea47","repo":"rust-lang/rust","slug":"counting-sort-fills-every-slot-of-a-kind-s-range","errorCode":null,"errorMessage":"counting sort fills every slot of a kind's range","messagePattern":"counting sort fills every slot of a kind's range","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_middle/src/dep_graph/serialized.rs","lineNumber":189,"sourceCode":"\nimpl LazyKindIndex {\n    /// Returns this kind's `key_fingerprint -> node index` map.\n    fn fingerprint_map(\n        &self,\n        kind: DepKind,\n        nodes: &IndexSlice<SerializedDepNodeIndex, DepNode>,\n        nodes_by_kind: &[Option<SerializedDepNodeIndex>],\n        profiler: &Option<SelfProfilerRef>,\n    ) -> &UnhashMap<PackedFingerprint, SerializedDepNodeIndex> {\n        self.map.get_or_init(|| {\n            let _prof_timer = profiler\n                .as_ref()\n                .map(|p| p.generic_activity(\"incr_comp_load_dep_graph_reverse_index\"));\n            let range = (self.start as usize)..(self.start as usize + self.len as usize);\n            let mut map =\n                UnhashMap::with_capacity_and_hasher(self.len as usize, Default::default());\n            for &idx in &nodes_by_kind[range] {\n                let idx = idx.expect(\"counting sort fills every slot of a kind's range\");\n                let node = nodes[idx];\n                debug_assert_eq!(node.kind, kind);\n                if map.insert(node.key_fingerprint, idx).is_some()\n                    // Side effect nodes can legitimately share a fingerprint.\n                    && node.kind != DepKind::SideEffect\n                {\n                    panic!(\n                        \"Error: A dep graph node ({kind:?}) does not have an unique index. \\\n                         Running a clean build on a nightly compiler with \\\n                         `-Z incremental-verify-ich` can help narrow down the issue for reporting. \\\n                         A clean build may also work around the issue.\\n\n                         DepNode: {node:?}\"\n                    )\n                }\n            }\n            map\n        })\n    }","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_middle/src/dep_graph/serialized.rs#L171-L207","documentation":"Fires while building the reverse index of the serialized incremental dep-graph (serialized.rs:189). For each `DepKind`, the dep-graph stores a contiguous range of node slots produced by a counting sort; iterating that range, every slot must hold a node index. `idx.expect(\"counting sort fills every slot of a kind's range\")` panics when a slot is `None`, meaning the counting sort left a hole and the serialized dep-graph is internally inconsistent.","triggerScenarios":"Loading an incremental compilation cache (`target/<profile>/incremental/`) whose dep-graph was corrupted or written by an incompatible rustc; a previous build was interrupted while writing the dep-graph; fingerprint collisions producing duplicate node indices (the adjacent panic at line 196 catches the non-SideEffect duplicate case).","commonSituations":"Reusing an incremental cache across rustc versions or across incompatible commits; a killed/crashed previous build leaving a half-written dep-graph; disk corruption in `target/`; clock/FS races on shared build dirs.","solutions":["Run `cargo clean` (or delete `target/<profile>/incremental/`) to discard the corrupt dep-graph and rebuild non-incrementally once.","Disable incremental compilation for the affected profile (`CARGO_INCREMENTAL=0`) if the corruption recurs.","Ensure the same rustc version owns the whole `target/` dir; do not reuse it across toolchain changes.","Reproduces on a clean incremental build -> file an ICE; run with `-Z incremental-verify-ich` to help narrow the fingerprint issue."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# Discard the corrupt dep-graph and rebuild once without incremental\nrm -rf target/debug/incremental target/release/incremental\n# or globally:\nexport CARGO_INCREMENTAL=0\ncargo build","typeGuard":null,"tryCatchPattern":"cargo build || { rm -rf target/*/incremental && cargo build; }","preventionTips":["Do not reuse an incremental cache across rustc versions or large refactors; `cargo clean` after toolchain changes.","Disable incremental compilation (`CARGO_INCREMENTAL=0`) on shared/network filesystems prone to corruption.","Avoid killing builds mid-write; a partial dep-graph triggers this on the next run.","In nightly debugging, run with `-Z incremental-verify-ich` to catch fingerprint issues early."],"tags":["incremental-compilation","dep-graph","ice","corruption"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}