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.

clew/fasttier_calls.py:191

Show on the map →

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 inserted

1 more lines, not shown

Activity · 16 steps
lines 205–205from .blocking import declared_blocking_harvesterlines 206–206from .call_edges import _ast_caller_at_line, _table_existslines 207–207from .harvest import HarvestTally, _harvest_one_filelines 211–211◇ if not _table_exists(conn, "blocking_calls")lines 212–212return 0lines 213–213inserted = 0lines 214–214harvester = declared_blocking_harvester(repo_root)lines 215–215◇ for rel, rowid in files.items()lines 216–216conn.execute("DELETE FROM blocking_calls WHERE path_rowid = ?", (rowid,))lines 217–217payload = _harvest_one_file(rel, repo_root / rel, harvester, {}, cache, HarvestTally())lines 218–218◇ for record in payload or []lines 219–219holder = _ast_caller_at_line(file_funcs.get(rowid, []), record[1])lines 220–220◇ if holder is Nonelines 221–221continuelines 222–227inserted += 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]), ).rowcountlines 228–228return inserted

Requirements

REQ-DDB-INDEX-006

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.

clew/fasttier_calls.py:48

Show on the map →

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

Activity · 15 steps
lines 58–58from . import call_edges as celines 60–60maps = _resolution_maps(conn)lines 61–61file_of = ce._file_of(maps["file_funcs"], ce._rel_paths(conn))lines 62–62resolved: list = []lines 63–63fuzzy: list = []lines 64–64◇ for rel, rowid in files.items()lines 65–65funcs = maps["file_funcs"].get(rowid, [])lines 66–66_delete_fold_edges(conn, [int(f[0]) for f in funcs])lines 67–67payload = _call_payload(rel, repo_root / rel, cache)lines 68–68◇ if not funcs or payload is Nonelines 69–69continuelines 70–87ce._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, )lines 88–88collapsed, fuzzy = ce._collapse_duplicate_targets(fuzzy, maps["identity_of"], maps["defined"])lines 89–89ce._ast_insert_edges(conn, resolved + collapsed, fuzzy)lines 90–90return maps

Requirements

REQ-DDB-INDEX-006