/**
 * Dead code and islands — one derivation of "nothing in this repository
 * reaches here".
 *
 * The graph can answer that question exactly, and that is the problem: the
 * exact answer is *no incoming edge*, and a symbol with no incoming edge is not
 * the same thing as a symbol nobody uses. Reflection calls it. A framework
 * registers it by name. A test file that was never indexed imports it. The
 * resolver saw the name and could not follow it. So the honest product of this
 * module is two things at once — a list, and everything the list could not see.
 *
 * ## The shape of the claim
 *
 * `unreferenced` is a fact: no edge in the index, other than the `contains`
 * edge from whatever holds it, points at this symbol. `dead` is an inference on
 * top of that fact, and every step of the inference is subtractive — a
 * candidate is dropped from the list the moment there is any reason to believe
 * something outside the graph reaches it:
 *
 * - it is **exported** (something outside this repository may import it);
 * - it lives in a **test** or a **generated** file (not code anyone deletes by
 *   hand);
 * - it is **abstract** or declared on an interface (a declaration is dispatched
 *   to, never called);
 * - it is **decorated** (`@app.route`, `@Component`, `@EventHandler`) — a
 *   decorator is a registration, and the framework that reads it is not in the
 *   graph. Seen as the symbol's own outgoing `decorates` edge, which is where
 *   the engine records it; `node.decorators` is only populated by a couple of
 *   languages and is checked as well rather than instead;
 * - it **overrides** a member an ancestor declares (calls land on the ancestor;
 *   see {@link overrideCandidates} for why an ancestor we cannot read counts
 *   the same way);
 * - it has a name the language calls by itself (`constructor`, `__enter__`,
 *   `main`);
 * - it sits in a **vendored** directory (`vendor/`, `third_party/`,
 *   `node_modules/` — code the repository carries but does not own);
 * - it is in a **test scope** the path does not reveal — a Rust
 *   `#[cfg(test)] mod tests`, a nested `Tests` namespace;
 * - it is in a **component file** whose markup the index reads for calls but
 *   not for references, so a handler passed as `{onkeydown}` is invisible;
 * - it is in a file **nothing in the index reaches**. Then "nothing references
 *   this symbol" is a restatement of "we cannot see how this file is wired",
 *   not a finding about the symbol — and it is the map, not this list, that
 *   says so: a file no one reaches is an island, and islands are drawn there;
 * - the index holds an **unresolved reference** to its name. A `failed` row in
 *   `unresolved_refs` is the resolver's own record of a reference it could not
 *   follow, and a symbol whose name we failed to follow cannot be called
 *   unreferenced.
 * - **another symbol of the same name IS referenced.** This is the one that
 *   matters most and the one nothing else would catch. `CodeGraph.getTopRouteFile`
 *   calls `this.queries.getTopRouteFile()`; the resolver prefers a same-name
 *   definition in the call site's own file, so the edge lands on the caller
 *   itself and the real target is left with nothing. From the edge table,
 *   "nobody calls this" and "the resolver picked the twin" are the same
 *   picture — so the claim is not made about either;
 * - it is declared in a **header** (`.h`, `.hpp`, `.d.ts`, `.pyi`): a header IS
 *   the export surface, and the reference to it is an `#include` the resolver
 *   does not follow to the declaration;
 * - it is in a language this index records **no export marker** for. The
 *   exported filter is the strongest one here, and for Rust (`pub` is not
 *   recorded) or Python and C (no such concept at all) it silently does
 *   nothing — so the index is asked, per language, whether it ran;
 * - **its own file writes the name more than once.** The last rule, and the
 *   only one that is not a graph query. Everything above assumes the edge
 *   table is complete; it is not, and the gaps do not announce themselves —
 *   `this.handleMessage.bind(this)` is a value reference the extractor does not
 *   record, and a call inside an object-literal initialiser is another. Both
 *   leave the name written twice in one file and no edge at all. So before the
 *   claim is made, the identifier is counted in the file itself AND in every
 *   file the index says depends on it — written once, in its own declaration,
 *   nothing that can reach it writes it down; written twice, we simply did not
 *   see the second one.
 *
 * Every subtraction is counted. {@link DeadCodeReport.excluded} is not
 * diagnostics — it is the sentence under the list ("47 exported, 12 overriding
 * an ancestor…"), because a list of eight rows drawn from four thousand
 * candidates means something different from a list of eight drawn from nine.
 *
 * ## Islands
 *
 * The other half of the task, a *module* nothing depends on, is not computed
 * here: it falls straight out of the map's own link set (a module with no
 * incoming link), and the map's layout is already a pure function in the
 * viewer. Computing it a second time on this side would be a second answer to
 * a question the map has already answered. See `ui/src/lib/map-model.ts`.
 *
 * Everything here is query-time and read-only.
 */
import type CodeGraph from '../index';
import type { Node, NodeKind } from '../types';
/**
 * Kinds asked about by default.
 *
 * Callables and types, and nothing else. `variable`/`constant`/`field` are out
 * deliberately: a value's uses are recorded as `references` edges, and that
 * coverage is the most language-dependent thing in the resolver — a default
 * that included them would produce a list whose truthfulness varied by which
 * language the reader happened to be looking at.
 */
export declare const DEAD_CODE_KINDS: readonly NodeKind[];
/** Kinds a `kinds=` request may ask for. Anything else is a caller bug. */
export declare const DEAD_CODE_ALLOWED_KINDS: ReadonlySet<NodeKind>;
/**
 * Candidates pulled out of SQL before any exclusion runs.
 *
 * High enough that no real repository reaches it with the default kinds (this
 * index produces ~1 400), and bounded so that a half-indexed monorepo cannot
 * turn one screen into a scan of a million rows. When it bites,
 * {@link DeadCodeReport.bounded} says so.
 */
export declare const MAX_DEAD_CODE_CANDIDATES = 20000;
/** Levels walked up looking for an ancestor that declares the same member. */
export declare const MAX_OVERRIDE_ANCESTOR_DEPTH = 8;
/**
 * Files read for the corroboration pass, and the biggest one read.
 *
 * The pass runs over the survivors only — everything cheap has already fired —
 * so on this index it reads a few dozen files. The caps are a backstop against
 * a repository whose survivors span a thousand files or include a generated
 * megabyte. A file skipped for either reason counts as NOT corroborated, which
 * drops the row: the safe direction is always the one that says less.
 */
export declare const MAX_CORROBORATION_FILES = 600;
export declare const MAX_CORROBORATION_BYTES = 2000000;
/** One symbol nothing reaches, and what it takes with it. */
export interface DeadCodeEntry {
    node: Node;
    /**
     * Members that are themselves unreferenced and live inside {@link node}.
     *
     * A class nobody instantiates takes its methods with it, and listing all
     * eleven of them as siblings would turn one finding into eleven. They are
     * folded in here instead and reported as a count.
     */
    members: Node[];
    /** Source lines the entry spans, members included (they are inside it). */
    lines: number;
    /**
     * The symbol is exported. Only ever true when the caller asked for exported
     * symbols — and then it is the row's own caveat, because an exported symbol
     * is reachable from outside the index by definition.
     */
    exported: boolean;
}
/** How many candidates each rule removed, in the order the rules ran. */
export interface DeadCodeExclusions {
    /** In a file that looks like test or fixture code. */
    tests: number;
    /** In a tool-generated file. */
    generated: number;
    /** Exported, or declared in a header — reachable from outside this index. */
    exported: number;
    /**
     * In a language this index records no export marker for, so nothing here can
     * be told apart from that language's public surface.
     */
    exportsUnknown: number;
    /** Abstract, or a member of an interface / trait / protocol. */
    declarations: number;
    /** Carries a decorator, so a framework registers it. */
    decorated: number;
    /** Overrides a member an ancestor declares, or an ancestor we cannot read. */
    overriding: number;
    /** Named something the language calls by itself. */
    implicit: number;
    /** In a vendored directory — carried code, reached by something outside the index. */
    vendored: number;
    /** In a test scope the file path does not reveal (a Rust `mod tests`). */
    testScope: number;
    /** In a component file whose markup can reference a symbol invisibly. */
    markup: number;
    /** In a file nothing in the index reaches — an island, drawn on the map. */
    unreachableFile: number;
    /** The index holds an unresolved reference to this name. */
    unresolvedName: number;
    /** Another symbol of the same name IS referenced, so the resolver may have picked it. */
    ambiguousName: number;
    /** Its own file writes the name more than once, so something uses it there. */
    mentioned: number;
    /** Its file could not be read, so the mention count could not be checked. */
    unreadable: number;
    /** Folded into a container that is itself on the list. */
    nested: number;
}
export interface DeadCodeReport {
    /** Ranked, capped. */
    entries: DeadCodeEntry[];
    /** Entries before {@link DeadCodeQuery.limit} — always the real number. */
    total: number;
    /** Symbols with no incoming reference at all, before any exclusion ran. */
    candidates: number;
    excluded: DeadCodeExclusions;
    /** The kinds actually asked about. */
    kinds: NodeKind[];
    /** Exported symbols were included, so every row carries the outside-reach caveat. */
    includeExported: boolean;
    /** The candidate scan stopped at {@link MAX_DEAD_CODE_CANDIDATES}. */
    bounded: boolean;
    /**
     * Every surviving row was checked against its own file's text — the rule that
     * covers the edges the extractor never recorded. False when no reader was
     * available, and then the list is weaker than it looks.
     */
    corroborated: boolean;
}
export interface DeadCodeQuery {
    kinds?: readonly NodeKind[];
    /** Include symbols something outside the index could import. Default false. */
    includeExported?: boolean;
    /** Include symbols in test files. Default false. */
    includeTests?: boolean;
    /** Include symbols in tool-generated files. Default false. */
    includeGenerated?: boolean;
    /** Entries returned. `total` stays the real count. */
    limit?: number;
    /**
     * How to read a project-relative source file, for the corroboration pass.
     *
     * Injected rather than assumed so that a caller with a read chokepoint — the
     * viewer's API refuses any path outside the project before opening it — keeps
     * its own rule. Return `null` for anything unreadable. Omitted entirely means
     * the default reader, which resolves against the project root; passing `null`
     * turns the pass off, and {@link DeadCodeReport.corroborated} then says so.
     */
    readSource?: ((filePath: string) => string | null) | null;
}
/**
 * The dead code report: unreferenced symbols, minus every reason to doubt it,
 * plus a count of every doubt.
 */
export declare function buildDeadCodeReport(cg: CodeGraph, query?: DeadCodeQuery): DeadCodeReport;
/**
 * How many times `name` is written in `source` as a whole identifier, counting
 * no further than `stopAt`.
 *
 * Deliberately dumb: no parsing, no comment or string stripping. A mention in a
 * comment or in a string is exactly the kind of thing that turns out to be a
 * reflective call or a registration key, and the rule this serves only ever
 * uses the count to say LESS. `\b` is not used because it is ASCII-only in
 * JavaScript and an identifier may not be.
 */
export declare function mentionCount(source: string, name: string, stopAt?: number): number;
/** A file whose contents are declarations for somebody else — see {@link HEADER_EXTENSIONS}. */
export declare function isHeaderFile(filePath: string): boolean;
/** A qualified name that runs through a test scope — see {@link TEST_SCOPE_SEGMENTS}. */
export declare function isTestScope(qualifiedName: string): boolean;
/** Code the repository carries rather than owns — see {@link VENDOR_SEGMENTS}. */
export declare function isVendoredPath(filePath: string): boolean;
/** A name the language calls by itself, so no source file could name it. */
export declare function isImplicitEntryName(name: string): boolean;
//# sourceMappingURL=dead-code.d.ts.map