Skip to main content

keep_reachable_functions

Function keep_reachable_functions 

Source
pub fn keep_reachable_functions(user_source: &str, spliced: &str) -> String
Expand description

Drop top-level ## To … function definitions that are UNREACHABLE from the program’s entry, keeping every non-function section (## A structs, ## Main, prose) and every function whose name is transitively called. This is the C backends’ tree-shake: a flat C namespace can’t tolerate emitting an unused stdlib function that either collides with a libc name or exercises a C-codegen gap the function is never actually reached through (the Rust backend tolerates both, so this is C-only).

Reachability is seeded from the entry sections of spliced (the prelude-spliced source) and from every function a post-parse lowering calls — a ## Route dispatcher’s pathOf, a derived codec’s jsonQuote — which synthesized_prelude_roots reads off user_source, the author’s own text. Those calls are written by the compiler, so no scan of the source can see them; a pruner that dropped them would leave the lowering calling a function that is gone, which the bytecode compiler turns into an Unknown function failure at run time.