Skip to main content

ModuleGraph

Struct ModuleGraph 

Source
pub struct ModuleGraph {
    pub modules: Vec<ModuleNode>,
    pub package_usage: HashMap<String, Vec<FileId>, FxBuildHasher>,
    pub type_only_package_usage: HashMap<String, Vec<FileId>, FxBuildHasher>,
    pub entry_points: HashSet<FileId, FxBuildHasher>,
    pub runtime_entry_points: HashSet<FileId, FxBuildHasher>,
    pub test_entry_points: HashSet<FileId, FxBuildHasher>,
    pub reverse_deps: Vec<Vec<FileId>>,
    pub re_export_cycles: Vec<GraphReExportCycle>,
    /* private fields */
}
Expand description

The core module dependency graph.

Derives serde so the whole graph can be persisted to .fallow/graph-cache.bin (see crate::cache) and skipped on a re-run whose inputs are byte-identical. namespace_imported is a derived FixedBitSet reconstructed from the edge set on cache load (reconstruct_namespace_imported), so it is #[serde(skip, default)] rather than persisted.

Fields§

§modules: Vec<ModuleNode>

All modules indexed by FileId.

Invariant: modules[file_id.0 as usize].file_id == file_id for every FileId in the graph. Holds because discover/walk.rs assigns FileIds sequentially via .enumerate() after path-sorting, and build::populate_edges pushes one ModuleNode per file in iteration order. Detectors rely on this for O(1) FileId-to-module lookup (graph.modules.get(file_id.0 as usize)) instead of building a per-call FxHashMap<FileId, &ModuleNode>.

§package_usage: HashMap<String, Vec<FileId>, FxBuildHasher>

Maps npm package names to the set of FileIds that import them.

§type_only_package_usage: HashMap<String, Vec<FileId>, FxBuildHasher>

Maps npm package names to the set of FileIds that import them with type-only imports. A package appearing here but not in package_usage (or only in both) indicates it’s only used for types and could be a devDependency.

§entry_points: HashSet<FileId, FxBuildHasher>

All entry point FileIds.

§runtime_entry_points: HashSet<FileId, FxBuildHasher>

Runtime/application entry point FileIds.

§test_entry_points: HashSet<FileId, FxBuildHasher>

Test entry point FileIds.

§reverse_deps: Vec<Vec<FileId>>

Reverse index: for each FileId, which files import it.

§re_export_cycles: Vec<GraphReExportCycle>

Re-export cycles and self-loops detected during Phase 4 chain resolution. Each entry names the participating files (sorted lexicographically) and a is_self_loop flag distinguishing single-file self-re-exports from multi-node cycles. Populated by re_exports::find_re_export_cycles and consumed by fallow_core::analyze::re_export_cycles::find_re_export_cycles which wraps each entry in a typed ReExportCycleFinding.

Implementations§

Source§

impl ModuleGraph

Source

pub fn find_cycles(&self) -> Vec<Vec<FileId>>

Find all circular dependency cycles in the module graph.

Uses an iterative implementation of Tarjan’s strongly connected components algorithm (O(V + E)) to find all SCCs with 2 or more nodes. Each such SCC represents a set of files involved in a circular dependency.

Returns cycles sorted by length (shortest first), with files within each cycle sorted by path for deterministic output.

§Panics

Panics if the internal file-to-path lookup is inconsistent with the module list.

Source§

impl ModuleGraph

Source

pub fn focus_file_facts(&self, changed: &[FileId]) -> Vec<FocusFileFacts>

Compute the per-file focus graph facts (fan-in/out + the two confidence-flag signals) for a changed-file seed set.

Out-of-range or duplicate ids in changed are tolerated (dropped / deduped). Each fact is keyed by the changed file’s FileId; the caller relativizes via ModuleGraph::focus_facts_with_paths for serialization.

Source

pub fn focus_facts_with_paths( &self, facts: &[FocusFileFacts], root: &Path, ) -> Vec<FocusFileFactsPaths>

Resolve a FocusFileFacts set’s FileIds to root-relative, forward- slashed paths, sorted for deterministic output. Files whose module is missing are dropped.

Source§

impl ModuleGraph

Source

pub fn impact_closure(&self, changed: &[FileId]) -> ImpactClosure

Compute the impact closure for a changed-file seed set.

BFS over reverse_deps from every changed file yields the transitive affected set; the seed partitions into in_diff, the rest into affected_not_shown. The coordination gap walks each changed file’s exported-symbol references and reports those whose consumer is outside the diff (rule R2: one entry per distinct consumer module).

changed is a slice of FileIds; out-of-range or duplicate ids are tolerated. Type-only re-export edges are skipped for the gap evidence so a import type-only consumer (erased at build, no runtime contract) does not fire.

Source

pub fn closure_with_paths( &self, closure: &ImpactClosure, root: &Path, ) -> ImpactClosurePaths

Resolve a closure’s FileIds to root-relative, forward-slashed paths, sorted for deterministic output. Files whose module is missing are dropped.

Source§

impl ModuleGraph

Source

pub fn partition_order(&self, changed: &[FileId]) -> PartitionOrder

Compute the by-module partition and dependency-sensible order for a changed-file seed set.

Out-of-range or duplicate ids in changed are tolerated (dropped / deduped). The partition groups each changed file by its parent directory; the order is a deterministic topological sort over the inter-unit DAG (definitions before consumers, ties broken by the module_dir sort).

Source

pub fn partition_order_with_paths( &self, partition: &PartitionOrder, root: &Path, ) -> PartitionOrderPaths

Resolve a partition + order’s FileIds to root-relative, forward-slashed paths, sorted for deterministic output. Files whose module is missing are dropped; a unit left empty after that drop is omitted. The module_dir keys (and the order entries, which are module_dir strings) are root-relativized too so the whole shape is root-relative.

Source§

impl ModuleGraph

Source

pub fn public_export_keys( &self, public_api_entry_points: &HashSet<FileId, FxBuildHasher>, root: &Path, ) -> HashSet<String, FxBuildHasher>

Compute the set of public-export keys reachable through the given public_api_entry_points (an exports-aware set; see module docs).

Keys are "<root-relative forward-slashed path>::<export name>". Type-only exports are skipped: a type erased at build carries no runtime contract, so it never widens the public value surface that 6.A tracks.

Source§

impl ModuleGraph

Source

pub fn build( resolved_modules: &[ResolvedModule], entry_points: &[EntryPoint], files: &[DiscoveredFile], ) -> ModuleGraph

Build the module graph from resolved modules and entry points.

Source

pub fn build_with_reachability_roots( resolved_modules: &[ResolvedModule], entry_points: &[EntryPoint], runtime_entry_points: &[EntryPoint], test_entry_points: &[EntryPoint], files: &[DiscoveredFile], ) -> ModuleGraph

Build the module graph with explicit runtime and test reachability roots.

Source

pub const fn module_count(&self) -> usize

Total number of modules.

Source

pub const fn edge_count(&self) -> usize

Total number of edges.

Source

pub fn has_namespace_import(&self, file_id: FileId) -> bool

Check if any importer uses import * as ns for this module. Uses precomputed bitset, O(1) lookup.

Source

pub fn edges_for(&self, file_id: FileId) -> Vec<FileId>

Get the target FileIds of all outgoing edges for a module.

Source

pub fn outgoing_symbol_edges( &self, file_id: FileId, ) -> impl Iterator<Item = (FileId, &[ImportedSymbol])>

Iterate the outgoing edges of file_id with full per-symbol data.

fallow trace needs the raw ImportedSymbol set on each edge in both directions, which the flattened summary structs cannot express. Returns an empty iterator for out-of-range file ids.

Source

pub fn importers_of(&self, target: FileId) -> &[FileId]

The importer FileIds that directly import target (reverse-dep view).

Returns an empty slice when target is out of range.

Source

pub fn direct_importer_summaries( &self, target: FileId, ) -> Vec<DirectImporterSummary>

Summarize files that directly import target.

Uses existing reverse dependency and edge indexes. Returns an empty list when the target is out of range or has no importers.

Source

pub fn find_import_span_start( &self, source: FileId, target: FileId, ) -> Option<u32>

Find the byte offset of the import statement from source to target.

Mixed type/value imports to the same target are stored as one edge. Prefer the first value-carrying import so runtime-cycle diagnostics and line suppressions anchor on the import that actually participates in the cycle. Returns None if no edge exists or the edge has no symbols.

Source

pub fn outgoing_edge_summaries( &self, file_id: FileId, ) -> impl Iterator<Item = (FileId, bool, Option<u32>)>

Iterate outgoing edges with the data the boundary detector needs in a single pass: target file id, whether every symbol on the edge is type-only (matches the predicate used by cycle detection), and the span start of the first value-carrying symbol (or the first symbol when every symbol is type-only).

When featureB has both import type { Foo } from './x' and import { bar } from './x', fallow groups them into ONE edge with the type-only symbol first and the value symbol second. Consumers need the value span so findings anchor on the runtime import line; otherwise a // fallow-ignore-next-line above the type-only line would silently suppress the real violation.

Returns an empty iterator for out-of-range file ids.

Source

pub fn outgoing_edge_summaries_with_exclusions<'a>( &'a self, file_id: FileId, excluded_span_starts: &'a HashSet<u32, FxBuildHasher>, ) -> impl Iterator<Item = (FileId, bool, Option<u32>, bool)> + 'a

Like Self::outgoing_edge_summaries but additionally reports, as a fourth boolean, whether EVERY non-type-only symbol on the edge has an import_span start in excluded_span_starts (all_client_only). The security client-server-leak BFS passes the next/dynamic ssr:false dynamic-import span starts so it can skip an edge reached ONLY through the client-only escape hatch. An edge with no non-type-only symbols, or with at least one non-type-only symbol whose span is not excluded, reports false (so a target also reached via a real static import stays in the cone).

Returns an empty iterator for out-of-range file ids.

Trait Implementations§

Source§

impl Debug for ModuleGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ModuleGraph

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ModuleGraph, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ModuleGraph

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromIn<'a, T> for T

Source§

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Source§

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more