dispatch_edges.py

clew/dispatch_edges.py

Layer 6: synthetic call edges recovered from the dispatch DECLARATION.

dispatch_harvester

Harvester | None clew.dispatch_edges.dispatch_harvester(DispatchManifest manifest, str extra_key="")

Layer 6's harvester, or None when no dispatch table is declared.

clew/dispatch_edges.py:491

Show on the map →

Called by _harvest_sites, build_harvest_plan

Calls none

Source · 16 lines
def dispatch_harvester(manifest: DispatchManifest, extra_key: str = "") -> Harvester | None:
    """None when the manifest declares no `dispatch_tables`, which is the same
    condition `_harvest_sites` already refuses on — a repo declaring only interfaces
    pays no AST walk, and gh#358's shared parse pass must not warm one for it.

    @brief Build this stage's harvester, or None when it is inert.
    @version 1
    """
    if not manifest.tables:
        return None
    arg_index_by_name = {
        t.register_via.rsplit("::", 1)[-1]: t.handler_arg_index for t in manifest.tables
    }
    return _DispatchHarvester(arg_index_by_name, extra_key)

Activity · 4 steps
lines 499–499◇ if not manifest.tableslines 500–500return Nonelines 501–503arg_index_by_name = { t.register_via.rsplit("::", 1)[-1]: t.handler_arg_index for t in manifest.tables }lines 504–504return _DispatchHarvester(arg_index_by_name, extra_key)

Requirements

REQ-DDB-SCHEMA-004

harvest

Any clew.dispatch_edges._DispatchHarvester.harvest(self, Any tree, bytes src_bytes)

Harvest one file's declared registration sites.

clew/dispatch_edges.py:481

Show on the map →

Called by none

Calls _walk_registration_sites

Source · 4 lines
    def harvest(self, tree: Any, src_bytes: bytes) -> Any:
        return _walk_registration_sites(tree, src_bytes, self.arg_index_by_name)

Activity · 1 steps
lines 482–482return _walk_registration_sites(tree, src_bytes, self.arg_index_by_name)

Requirements

REQ-DDB-SCHEMA-004

import_declared_dispatch_edges

None clew.dispatch_edges.import_declared_dispatch_edges(Path db_path, Path repo_root, DispatchManifest manifest, IndexCache|None cache=None, str extra_key="", Harvester|None harvester=None)

Layer 6: emit the call edges and termini the dispatch declaration implies.

clew/dispatch_edges.py:716

Source · 46 lines
def import_declared_dispatch_edges(
    db_path: Path,
    repo_root: Path,
    manifest: DispatchManifest,
    cache: IndexCache | None = None,
    extra_key: str = "",
    harvester: Harvester | None = None,
) -> None:
    """No declaration means no work and no rows — the state every repo is in
    today, and the one every existing build must keep reproducing exactly.

    @brief Import declared-dispatch call edges and interface termini.
    @version 2
    """
    if manifest.is_empty():
        return
    conn = sqlite3.connect(str(db_path))
    _ensure_external_boundaries_table(conn)
    if not _table_exists(conn, "call_edges"):
        logger.warning("dispatch: call_edges is absent — skipping declared-dispatch stage")
        conn.close()
        return

    resolved: list[tuple[int, int, str]] = []
    fuzzy: list[tuple[int, int, str]] = []
    boundaries: list[tuple[int, str]] = []
    for binding in manifest.interfaces:
        binding_resolved, binding_fuzzy, binding_boundaries = _interface_edges(conn, binding)
        resolved += binding_resolved
        fuzzy += binding_fuzzy
        boundaries += binding_boundaries

    sites = _harvest_sites(conn, repo_root, manifest, cache, extra_key, harvester)
    table_resolved, table_fuzzy = _table_edges(conn, manifest, sites)
    inserted = _insert_edges(conn, resolved + table_resolved, fuzzy + table_fuzzy)
    inserted_boundaries = _insert_boundaries(conn, boundaries)
    conn.commit()
    conn.close()
    logger.info(
        "dispatch: %d registration site(s) -> %d resolved + %d fuzzy declared_dispatch "
        "call_edges, %d interface-boundary terminus row(s)",
        len(sites),
        inserted[0],
        inserted[1],
        inserted_boundaries,
    )

1 more lines, not shown

Activity · 23 steps
lines 730–730◇ if manifest.is_empty()lines 731–731returnlines 732–732conn = sqlite3.connect(str(db_path))lines 733–733_ensure_external_boundaries_table(conn)lines 734–734◇ if not _table_exists(conn, "call_edges")lines 735–735logger.warning("dispatch: call_edges is absent — skipping declared-dispatch stage")lines 736–736conn.close()lines 737–737returnlines 739–739resolved: list[tuple[int, int, str]] = []lines 740–740fuzzy: list[tuple[int, int, str]] = []lines 741–741boundaries: list[tuple[int, str]] = []lines 742–742◇ for binding in manifest.interfaceslines 743–743binding_resolved, binding_fuzzy, binding_boundaries = _interface_edges(conn, binding)lines 744–744resolved += binding_resolvedlines 745–745fuzzy += binding_fuzzylines 746–746boundaries += binding_boundarieslines 748–748sites = _harvest_sites(conn, repo_root, manifest, cache, extra_key, harvester)lines 749–749table_resolved, table_fuzzy = _table_edges(conn, manifest, sites)lines 750–750inserted = _insert_edges(conn, resolved + table_resolved, fuzzy + table_fuzzy)lines 751–751inserted_boundaries = _insert_boundaries(conn, boundaries)lines 752–752conn.commit()lines 753–753conn.close()lines 754–761logger.info( "dispatch: %d registration site(s) -> %d resolved + %d fuzzy declared_dispatch " "call_edges, %d interface-boundary terminus row(s)", len(sites), inserted[0], inserted[1], inserted_boundaries, )

Requirements

REQ-DDB-SCHEMA-004