Skip to main content

Module cshake

Module cshake 

Source
Expand description

Structural reachability over an emitted C translation unit — split the runtime into top-level definition UNITS, then keep only those reachable (transitively) from a set of root symbols.

This is the shared tree-shaking pass for the C-derived tiers. The CUDA device-lift uses it so nvcc only compiles the slice a program actually references (a float one-liner pulls in ~3 functions, not the whole ~1900-line runtime); the same pass can later shrink the C / Tenstorrent output. It is an OVER-APPROXIMATION (a body’s every identifier is treated as a dependency), so it never drops a needed unit; and it is verified downstream — a genuinely missed edge surfaces as a compiler “undefined symbol”, never a silent miscompile.

The parser is a small byte scanner that understands C string/char/line/block-comment lexemes (so a brace inside "{" does not throw off nesting) and the three top-level shapes the runtime uses: typedef … ;, static … (…) { … } / … (…) ; functions, and file-scope globals.

Structs§

CUnit
One top-level C construct: a typedef, a static function definition or forward declaration, or a file-scope global. defined is the symbol(s) it introduces; references is every identifier it mentions (an over-approximation of its dependencies); text is the exact source span (with any leading comment/blank lines attached, so units travel with their doc comment).

Enums§

UnitKind

Functions§

c_identifiers
Collect every C identifier in s, skipping string/char literals and comments.
macro_references
A #define’s macro name and the names its replacement mentions, its own parameters left out: a macro is expanded where it is named, so what it names is reached through it. None for any other directive. A preprocessor unit is its one directive behind whatever comments parse_c_units attached to it.
parse_c_units
Split an emitted C translation unit into top-level CUnits. Leading comments/blank lines attach to the unit that follows. #… preprocessor directives, backslash-continued lines included, are their own UnitKind::Preproc units.
reachable_units
Indices (in original order) of the units transitively reachable from roots. A unit is reached when any symbol it defines is in the frontier; reaching it adds every identifier it references.