Repository: rust-lang/rust
File: compiler/rustc_query_impl/src/plumbing.rs (Rust)

Code before:
        }
    } else {
        let fingerprint_style = <C::Key as DepNodeKey<TyCtxt<'tcx>>>::fingerprint_style();
        if !fingerprint_style.reconstructible() {
            DepKindVTable {
                is_anon: false,
                is_eval_always,
                fingerprint_style,
                force_from_dep_node: None,
                try_load_from_on_disk_cache: None,
                name: Q::NAME,
            }
        } else {
            DepKindVTable {
                is_anon: false,
                is_eval_always,
                fingerprint_style,
                force_from_dep_node: Some(|tcx, dep_node, _| {
                    force_from_dep_node(Q::query_dispatcher(tcx), tcx, dep_node)
                }),
                try_load_from_on_disk_cache: Some(|tcx, dep_node| {
                    try_load_from_on_disk_cache(Q::query_dispatcher(tcx), tcx, dep_node)
                }),
                name: Q::NAME,
            }
        }
    }
}

macro_rules! item_if_cached {
    ([] $tokens:tt) => {};
    ([(cache) $($rest:tt)*] { $($tokens:tt)* }) => {
        $($tokens)*
    };
    ([$other:tt $($modifiers:tt)*] $tokens:tt) => {
        item_if_cached! { [$($modifiers)*] $tokens }
    };
}

macro_rules! expand_if_cached {
    ([], $tokens:expr) => {{
        None
    }};
    ([(cache) $($rest:tt)*], $tokens:expr) => {{
        Some($tokens)
    }};
    ([$other:tt $($modifiers:tt)*], $tokens:expr) => {
        expand_if_cached!([$($modifiers)*], $tokens)
    };
}


Review comment (refactor):
I think I would prefer not to do this overhaul of `make_dep_kind_vtable_for_query`, because I'm planning to give the function some more attention in other ways, and the less-DRY style might actually make that harder (e.g. dismantling `QueryDispatcherUnerased`, or trying to make dep-graph vtable creation more const).

I respect the less-DRY-more-explicit style, but I don't think it's the right move here and now.

Code after:

    if is_anon || !fingerprint_style.reconstructible() {
        return DepKindVTable {
            is_anon,
            is_eval_always,
            fingerprint_style,
            force_from_dep_node: None,
            try_load_from_on_disk_cache: None,
            name: Q::NAME,
        };
    }

    DepKindVTable {
        is_anon,
        is_eval_always,
        fingerprint_style,
        force_from_dep_node: Some(|tcx, dep_node, _| {
            force_from_dep_node(Q::query_dispatcher(tcx), tcx, dep_node)
        }),
        try_load_from_on_disk_cache: Some(|tcx, dep_node| {
            try_load_from_on_disk_cache(Q::query_dispatcher(tcx), tcx, dep_node)
        }),
        name: Q::NAME,
    }
}

macro_rules! item_if_cached {
    ([] $tokens:tt) => {};
    ([(cache) $($rest:tt)*] { $($tokens:tt)* }) => {
        $($tokens)*
    };
    ([$other:tt $($modifiers:tt)*] $tokens:tt) => {
        item_if_cached! { [$($modifiers)*] $tokens }
    };
}

macro_rules! expand_if_cached {
    ([], $tokens:expr) => {{
        None
    }};
    ([(cache) $($rest:tt)*], $tokens:expr) => {{
        Some($tokens)
    }};
    ([$other:tt $($modifiers:tt)*], $tokens:expr) => {
        expand_if_cached!([$($modifiers)*], $tokens)
    };
}

// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
// invoked by `rustc_with_all_queries`.
macro_rules! define_queries {