Fix collector ICE on closures from non-local crates#345
Open
mbrobbel wants to merge 2 commits into
Open
Conversation
Kernels that reach a closure defined in a non-local crate (here via an
FnOnce trait receiver in helper-lib) ICE the device collector:
internal compiler error: item_name: no name for DefPath { ...
Closure ... } via DeviceCollector::should_collect_from_crate <-
enqueue_callable_trait_receiver_body
Local-crate closures never hit this (early LOCAL_CRATE return), which is
why existing examples pass. This example fails until the collector fix
in the next commit.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Matthijs Brobbel <m1brobbel@gmail.com>
should_collect_from_crate checked the cross-crate kernel-entry-point case with tcx.item_name, which ICEs for unnamed items. Closures in a non-local crate reach it via enqueue_callable_trait_receiver_body (e.g. an FnOnce receiver inside a library function called from a kernel); local-crate closures take the early LOCAL_CRATE return, so this only surfaced with external dependencies. Use opt_item_name and fall through to the crate-based decision for unnamed items, which can never be kernel entry points. Fixes the extern_crate_closure example added in the previous commit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Matthijs Brobbel <m1brobbel@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Kernels that reach a closure defined in a dependency crate ICE the compiler:
should_collect_from_crate(collector.rs) callstcx.item_nameto allow cross-crate kernel entry points, but closures have no item name. Closure DefIds from non-local crates reach it viaenqueue_callable_trait_receiver_body— e.g. anFnOncereceiver inside a library function called from a kernel. Local-crate closures take the earlyLOCAL_CRATEreturn, so existing examples never hit this.The fix uses
opt_item_nameand falls through to the crate-based decision for unnamed items, which can never be kernel entry points.The first commit adds an
extern_crate_closureexample (following thecross_crate_embeddedpattern) that reproduces the ICE without the fix; the closure is routed through an#[inline(never)]applier so MIR inlining doesn't erase it before collection.🤖 Generated with Claude Code