fasttier_calls.py¶
clew/fasttier_calls.py
The fast tier's outgoing call edges: an edited file's AST call sites, re-resolved in place.
refresh_blocking_calls
int clew.fasttier_calls.refresh_blocking_calls(sqlite3.Connection conn, Path repo_root, IndexCache cache, dict[str, int] files, dict[int, list] file_funcs)
Rewrite the blocking call sites of the edited files.
Called by _apply
Calls _ast_caller_at_line, _harvest_one_file, declared_blocking_harvester
Source · 38 lines
def refresh_blocking_calls(
conn: sqlite3.Connection,
repo_root: Path,
cache: IndexCache,
files: dict[str, int],
file_funcs: dict[int, list],
) -> int:
"""WHOLLY PER FILE, the same way `blocking.extract_blocking_calls` builds it: the file's
payload, each site's holder by the function span that contains its line, one row each.
@brief Replace one or more files' blocking_calls rows.
@return Rows inserted.
@version 1
"""
from .blocking import declared_blocking_harvester
from .call_edges import _ast_caller_at_line, _table_exists
from .harvest import HarvestTally, _harvest_one_file
## NOT `ensure_blocking_table`: its `executescript` COMMITs, which would end the fast tier's
## one transaction half-way. An index without the table never ran the layer; nothing to do.
if not _table_exists(conn, "blocking_calls"):
return 0
inserted = 0
harvester = declared_blocking_harvester(repo_root)
for rel, rowid in files.items():
conn.execute("DELETE FROM blocking_calls WHERE path_rowid = ?", (rowid,))
payload = _harvest_one_file(rel, repo_root / rel, harvester, {}, cache, HarvestTally())
for record in payload or []:
holder = _ast_caller_at_line(file_funcs.get(rowid, []), record[1])
if holder is None:
continue
inserted += conn.execute(
"INSERT OR IGNORE INTO blocking_calls "
"(holder_rowid, path_rowid, line, primitive, wait, wait_operand, guard) "
"VALUES (?, ?, ?, ?, ?, ?, ?)",
(holder, rowid, record[1], record[0], record[2], record[3], record[4]),
).rowcount
return inserted1 more lines, not shown
Activity · 16 steps
Requirements
refresh_outbound_calls
dict[str, Any] clew.fasttier_calls.refresh_outbound_calls(sqlite3.Connection conn, Path repo_root, IndexCache cache, dict[str, int] files)
Replace the AST-fold call edges whose caller lives in one of the edited files.
Called by _apply
Calls _ast_insert_edges, _call_payload, _collapse_duplicate_targets, _delete_fold_edges, _file_of, _fold_call_payload, _rel_paths, _resolution_maps
Source · 45 lines
def refresh_outbound_calls(
conn: sqlite3.Connection, repo_root: Path, cache: IndexCache, files: dict[str, int]
) -> dict[str, Any]:
"""AFTER THE POSITION SHIFT, because the fold assigns each call site to the function whose
span holds its line: the spans must already be the edited file's.
@brief Re-fold and replace one or more files' outgoing AST edges.
@return The resolution maps.
@version 3
"""
from . import call_edges as ce
maps = _resolution_maps(conn)
file_of = ce._file_of(maps["file_funcs"], ce._rel_paths(conn))
resolved: list = []
fuzzy: list = []
for rel, rowid in files.items():
funcs = maps["file_funcs"].get(rowid, [])
_delete_fold_edges(conn, [int(f[0]) for f in funcs])
payload = _call_payload(rel, repo_root / rel, cache)
if not funcs or payload is None:
continue
ce._fold_call_payload(
payload,
funcs,
maps["name_to_rowids"],
resolved,
fuzzy,
maps["definition_of"],
receiver_types=maps["receiver_types"],
scope_of=maps["scope_of"],
argc_of=maps["argc_of"],
unresolved=[],
bases_of=maps["bases_of"],
class_scopes=maps["class_scopes"],
implementors=maps["implementors"],
one_function=maps["one_function"],
caller_file=rel,
file_of=file_of,
)
collapsed, fuzzy = ce._collapse_duplicate_targets(fuzzy, maps["identity_of"], maps["defined"])
ce._ast_insert_edges(conn, resolved + collapsed, fuzzy)
return maps