Skip to content

Clarify names of QueryVTable functions for "executing" a query#152434

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Zalathar:call-query
Feb 12, 2026
Merged

Clarify names of QueryVTable functions for "executing" a query#152434
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Zalathar:call-query

Conversation

@Zalathar
Copy link
Member

In the query system, there are several layers of functions involved in “executing” a query, with very different responsibilities at each layer, making it important to be able to tell them apart.

This PR renames two of the function pointers in QueryVTable, along with their associated helper functions, to hopefully do a better job of indicating what their actual responsibilities are.

r? nnethercote

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 10, 2026
Copy link
Contributor

@nnethercote nnethercote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me because it's an improvement over the status quo. But I have some questions, feel free to make changes to address them.

View changes since this review


/// Function pointer that actually calls this query's provider,
/// while also marking a short-backtrace boundary and doing some tracing.
pub invoke_provider_fn: fn(tcx: TyCtxt<'tcx>, key: C::Key) -> C::Value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the distinction between these functions, and the comments help but I'm still left wondering about the relationship between them. Especially given that they have the same signature. Does one call the other, or something?

/// This function would be named `invoke_provider`, but we also want it
/// to mark the boundaries of an omitted region in backtraces.
#[inline(never)]
pub(crate) fn __rust_begin_short_backtrace<'tcx>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Pre-existing) This function has a strange name! Doesn't give any idea what it does, and is the same as the one from std. Is that deliberate? Really confusing. Would invoke_provider_inner or something like that be better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is probably very confusing if you don't already know how short backtraces work.

The backtrace handler looks for pairs of functions named __rust_begin_short_backtrace and __rust_end_short_backtrace in its stack trace, and will replace those stack frames (and everything in between) with [... omitted N frames ...], along with a message telling you to set RUST_BACKTRACE=full to disable short-backtrace mode.

If an ICE occurs in a query provider, we typically want to omit all of the query plumbing between the query caller and the query provider, because it's dozens of lines of irrelevant noise. To make that work, the function that calls the provider has to be named __rust_begin_short_backtrace. (There is also a matching specially named function on the other end of the query plumbing; see .)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To minimize runtime overhead and also make the short-backtraces more reliable, the specially-named functions are used in places where we were going to dynamically call a function pointer from a vtable anyway.

The downside is that those functions have to have unhelpful names, because function names are what the short-backtrace machinery uses to do its work. To compensate for that as much as possible, we define the strangely-named functions in modules that have more helpful names, and use comments to (hopefully) explain what's going on.

@rust-bors

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Feb 11, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Zalathar
Copy link
Member Author

I've done a fairly substantial overhaul of the comments to hopefully make things clearer.

I also changed the signature of call_query_method to omit the return value, because it only has one caller and that caller immediately discards the value anyway.

/// to be used as a function pointer in the query's vtable.
///
/// To mark a short-backtrace boundary, the function's actual name
/// (after demangling) must be `__rust_begin_short_backtrace`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is helpful, thanks.

@nnethercote
Copy link
Contributor

Nice improvements. r=me with the comment nit.

This also changes the signature of `call_query_method` to not return a value,
because its only caller immediately discards the value anyway.
@Zalathar
Copy link
Member Author

@bors r=nnethercote

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 11, 2026

📌 Commit 0de45db has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 11, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 11, 2026
Clarify names of `QueryVTable` functions for "executing" a query

In the query system, there are several layers of functions involved in “executing” a query, with very different responsibilities at each layer, making it important to be able to tell them apart.

This PR renames two of the function pointers in `QueryVTable`, along with their associated helper functions, to hopefully do a better job of indicating what their actual responsibilities are.

r? nnethercote
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 11, 2026
Clarify names of `QueryVTable` functions for "executing" a query

In the query system, there are several layers of functions involved in “executing” a query, with very different responsibilities at each layer, making it important to be able to tell them apart.

This PR renames two of the function pointers in `QueryVTable`, along with their associated helper functions, to hopefully do a better job of indicating what their actual responsibilities are.

r? nnethercote
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 12, 2026
Clarify names of `QueryVTable` functions for "executing" a query

In the query system, there are several layers of functions involved in “executing” a query, with very different responsibilities at each layer, making it important to be able to tell them apart.

This PR renames two of the function pointers in `QueryVTable`, along with their associated helper functions, to hopefully do a better job of indicating what their actual responsibilities are.

r? nnethercote
rust-bors bot pushed a commit that referenced this pull request Feb 12, 2026
Rollup of 17 pull requests

Successful merges:

 - #142415 (Add note when inherent impl for a alias type defined outside of the crate)
 - #142680 (Fix passing/returning structs with the 64-bit SPARC ABI)
 - #150768 (Don't compute FnAbi for LLVM intrinsics in backends)
 - #151152 (Add FCW for derive helper attributes that will conflict with built-in attributes)
 - #151814 (layout: handle rigid aliases without params)
 - #151863 (Borrowck: simplify diagnostics for placeholders)
 - #152159 (Add note for `?Sized` params in int-ptr casts diag)
 - #152434 (Clarify names of `QueryVTable` functions for "executing" a query)
 - #152478 (Remove tm_factory field from CodegenContext)
 - #152498 (Partially revert "resolve: Update `NameBindingData::vis` in place")
 - #152316 (fix: add continue)
 - #152394 (Correctly check if a macro call is actually a macro call in rustdoc highlighter)
 - #152425 (Port #![test_runner] to the attribute parser)
 - #152481 (Use cg_ssa's produce_final_output_artifacts in cg_clif)
 - #152485 (fix issue#152482)
 - #152495 (Clean up some subdiagnostics)
 - #152502 (Implement `BinaryHeap::from_raw_vec`)
@rust-bors rust-bors bot merged commit 0e746d0 into rust-lang:main Feb 12, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 12, 2026
rust-timer added a commit that referenced this pull request Feb 12, 2026
Rollup merge of #152434 - Zalathar:call-query, r=nnethercote

Clarify names of `QueryVTable` functions for "executing" a query

In the query system, there are several layers of functions involved in “executing” a query, with very different responsibilities at each layer, making it important to be able to tell them apart.

This PR renames two of the function pointers in `QueryVTable`, along with their associated helper functions, to hopefully do a better job of indicating what their actual responsibilities are.

r? nnethercote
@Zalathar Zalathar deleted the call-query branch February 12, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants