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.
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
Requirements
harvest
Any clew.dispatch_edges._DispatchHarvester.harvest(self, Any tree, bytes src_bytes)
Harvest one file's declared 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
Requirements
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.
Called by _build_stages
Tested by 12 tests
test_a_declared_boundary_is_recorded_even_from_a_fuzzy_call_site, test_ambiguous_handler_name_records_NOTHING_rather_than_guessing, test_ambiguous_or_absent_class_is_skipped_not_guessed, test_boundary_flag_records_the_second_terminus_kind, test_declared_dispatch_table_connects_the_dispatcher_to_its_handlers, test_declared_interface_binding_continues_the_chain_to_the_implementor, test_inherited_members_do_not_pair_the_interface_with_itself, test_method_filter_narrows_the_binding, test_no_declaration_writes_nothing_at_all, test_registration_site_is_harvested_but_is_not_itself_a_call_edge, test_synthetic_edge_inherits_the_weakest_link_from_a_fuzzy_premise, test_unresolvable_dispatch_via_leaves_the_handlers_unconnected
Calls _ensure_external_boundaries_table, _harvest_sites, _insert_boundaries, _insert_edges, _interface_edges, _table_edges, _table_exists
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