Draft
Conversation
This filters out all `lang_start` items (functions, closures, drop glue etc.). It only removes the items if they are `std::rt::lang_start` or are exclusively reachable by those functions. That means `black_box` is removed if it is not called otherwise in the program, but if it is then it is not removed. There is a couple of stages to get the data together in the right form so that only the items desired to be removed are.
Introduces an extensible ItemFilter enum so future exclusion predicates can be added by just adding a variant, wiring its env var in enabled(), and implementing compute_exclusions. The key behavioral change: apply_all() now prunes ctx.functions in addition to items, so ctx.resolve_call_target() returns None for excluded callees. This eliminates the need to thread an `excluded` set through every render function; both dot and d2 renderers are simplified.
Adds a `make test-skip-lang-start` target that runs every test program through the D2 renderer with SKIP_LANG_START=1 and verifies the output contains no lang_start references. Catches regressions in the ItemFilter pipeline without needing separate golden files.
…ring Replace if-let + early-return with match expression in filter_map, use matches! macro for single-arm boolean match, and switch enabled() from imperative push to declarative array-of-options pattern.
The integration test now validates at the data-structure level instead of grepping rendered output. When ASSERT_FILTER=1 is set alongside SKIP_LANG_START=1, apply_all() asserts two things: 1. The filter's exclusion set is non-empty (precondition: lang_start items were present to begin with). 2. No matching items survive in the filtered output (postcondition: the filter actually worked). The precondition check is pedantically complete: std::rt::lang_start is the runtime wrapper rustc generates for every crate with a fn main, so it will always appear in monomorphized output. Every one of the 29 test programs has a main function and every expected output contains exactly 11 lang_start references. It would take a fundamental change to rustc's runtime initialization for this to stop being true; but if it does, the assertion will tell us the test data is stale rather than silently passing. The more realistic failure mode: someone adds a library crate (no main) to the test suite. The assert message spells this out and gives two actionable options (skip lib crates in the test target, or gate the filter on the presence of main).
echo's treatment of \n is shell-dependent (bash interprets it by default, zsh and POSIX sh do not without -e). Switch report() and the failure summary to printf in both integration-test and test-skip-lang-start targets.
Add GRAPH_UNMANGLE support to demangle symbol names in dot/d2 output, separate display names from node identity so demangled names render correctly, sort external function nodes for deterministic output, fix double-escaping of newlines in D2 container labels, and wire UNMANGLE and SKIPLANGSTART env vars through Make graph targets.
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.
Dirty Deeds Demangled Dirt Cheap
So, this PR does one main thing: it makes the external function nodes in dot/d2 graphs actually readable. Those red boxes have always shown raw mangled symbols (
_ZN4core3fmt3num3imp52_$LT$impl...), which is not exactly pleasant reading. Turns outrustc_demangleis already sitting right there in the sysroot; we just weren't using it.The new flag is
UNMANGLE=1, surfaced through Make:It composes with the
SKIPLANGSTART=1flag (also wired through Make in this PR):A natural question: does demangling affect graph structure? Turns out, no. Display names are strictly separated from node identity.
ctx.functionsstays mangled (preserving hash-based node IDs), so mangled and unmangled graphs are structurally identical; only labels differ. TheGraphContextgains adisplay_namesmap that holds demangled names when the flag is set, and renderers calldisplay_name()to get the label for a given node.A few other things came along for the ride:
rustc_demangleadded to the compat layer (it's already available in the sysroot, so this is not a new dependency; just a newextern crate)HashMapiteration order was causing non-deterministic layouts across runs)GRAPH_ENVvariable in the Makefile\nline separators in D2 container labels (escape_d2was turning\ninto\\n; swapped call order so escaping happens before line-breaking)Depends on #119 (
dc/remove-lang-start): theItemFilterenum andSKIP_LANG_STARTsupport that this branch stacks on.Before
assert_eq
After
assert_eq
Test plan
make integration-testpasses (no change to JSON output)make test-skip-lang-startpassesmake dotandmake dot UNMANGLE=1produce structurally identical dot files (same node IDs, same edges; different labels only)make svg UNMANGLE=1 SKIPLANGSTART=1produces readable,lang_start-free SVGscore::panicking::panic::h...instead of_ZN4core9panicking5panic17h...