Repository: rust-lang/rust
File: compiler/rustc_query_system/src/dep_graph/graph.rs (Rust)

Code before:
            };

            let fingerprint = fingerprint.unwrap_or(Fingerprint::ZERO);

            let dep_node_index = self.current.encoder.send_and_color(
                prev_index,
                &self.colors,
                key,
                fingerprint,
                edges,
                is_green,
            );

            self.current.record_node(dep_node_index, key, fingerprint);

            dep_node_index
        } else {
            self.current.alloc_new_node(key, edges, fingerprint.unwrap_or(Fingerprint::ZERO))
        }
    }

    fn promote_node_and_deps_to_current(&self, prev_index: SerializedDepNodeIndex) -> DepNodeIndex {
        self.current.debug_assert_not_in_new_nodes(&self.previous, prev_index);

        let dep_node_index = self.current.encoder.send_promoted(prev_index, &self.colors);

        #[cfg(debug_assertions)]
        self.current.record_edge(
            dep_node_index,
            *self.previous.index_to_node(prev_index),
            self.previous.fingerprint_by_index(prev_index),
        );

        dep_node_index
    }
}

impl<D: Deps> DepGraph<D> {
    /// Checks whether a previous work product exists for `v` and, if
    /// so, return the path that leads to it. Used to skip doing work.
    pub fn previous_work_product(&self, v: &WorkProductId) -> Option<WorkProduct> {
        self.data.as_ref().and_then(|data| data.previous_work_products.get(v).cloned())
    }

    /// Access the map of work-products created during the cached run. Only
    /// used during saving of the dep-graph.
    pub fn previous_work_products(&self) -> &WorkProductMap {
        &self.data.as_ref().unwrap().previous_work_products
    }

    pub fn debug_was_loaded_from_disk(&self, dep_node: DepNode) -> bool {

Review comment (bug):
This check obviously fails with `debug_assertions` enabled.

Code after:
            };

            let fingerprint = fingerprint.unwrap_or(Fingerprint::ZERO);

            let dep_node_index = self.current.encoder.send_and_color(
                prev_index,
                &self.colors,
                key,
                fingerprint,
                edges,
                is_green,
            );

            self.current.record_node(dep_node_index, key, fingerprint);

            dep_node_index
        } else {
            self.current.alloc_new_node(key, edges, fingerprint.unwrap_or(Fingerprint::ZERO))
        }
    }

    fn promote_node_and_deps_to_current(
        &self,
        prev_index: SerializedDepNodeIndex,
    ) -> Option<DepNodeIndex> {
        self.current.debug_assert_not_in_new_nodes(&self.previous, prev_index);

        let dep_node_index = self.current.encoder.send_promoted(prev_index, &self.colors);

        #[cfg(debug_assertions)]
        if let Some(dep_node_index) = dep_node_index {
            self.current.record_edge(
                dep_node_index,
                *self.previous.index_to_node(prev_index),
                self.previous.fingerprint_by_index(prev_index),
            );
        }

        dep_node_index
    }
}

impl<D: Deps> DepGraph<D> {
    /// Checks whether a previous work product exists for `v` and, if
    /// so, return the path that leads to it. Used to skip doing work.
    pub fn previous_work_product(&self, v: &WorkProductId) -> Option<WorkProduct> {
        self.data.as_ref().and_then(|data| data.previous_work_products.get(v).cloned())
    }

    /// Access the map of work-products created during the cached run. Only
    /// used during saving of the dep-graph.