Skip to content

Commit be1aa7b

Browse files
committed
Add/clarify comments about hooks.
Explaining things that weren't clear to me at first.
1 parent 6ac8878 commit be1aa7b

File tree

1 file changed

+7
-4
lines changed
  • compiler/rustc_middle/src/hooks

1 file changed

+7
-4
lines changed

compiler/rustc_middle/src/hooks/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//! "Hooks" provide a way for `tcx` functionality to be provided by some downstream crate without
2-
//! everything in rustc having to depend on that crate. This is somewhat similar to queries, but
3-
//! queries come with a lot of machinery for caching and incremental compilation, whereas hooks are
4-
//! just plain function pointers without any of the query magic.
1+
//! "Hooks" let you write `tcx` methods in downstream crates and call them in this crate, reducing
2+
//! the amount of code that needs to be in this crate (which is already very big). This is somewhat
3+
//! similar to queries, but queries come with a lot of machinery for caching and incremental
4+
//! compilation, whereas hooks are just plain function pointers without any of the query magic.
55
66
use rustc_hir::def_id::{DefId, DefPathHash};
77
use rustc_session::StableCrateId;
@@ -107,6 +107,9 @@ declare_hooks! {
107107

108108
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
109109
/// can just link to the upstream crate and therefore don't need a mono item.
110+
///
111+
/// Note: this hook isn't called within `rustc_middle` but #127779 suggests it's a hook instead
112+
/// of a normal function because external tools might want to override it.
110113
hook should_codegen_locally(instance: crate::ty::Instance<'tcx>) -> bool;
111114

112115
hook alloc_self_profile_query_strings() -> ();

0 commit comments

Comments
 (0)