Skip to content

[ITG] Add modules for ITG graph#78

Open
yushan8 wants to merge 2 commits into
mainfrom
itg-graph
Open

[ITG] Add modules for ITG graph#78
yushan8 wants to merge 2 commits into
mainfrom
itg-graph

Conversation

@yushan8
Copy link
Copy Markdown
Contributor

@yushan8 yushan8 commented Apr 17, 2026

Why?

Implement data structure modules for ITG. The OptimizedGraph structure provides fast look and calculation of reverse dependencies of a target to incrementally calculate the full target graph.

What?

New package: core/itg/graph

Data structures (graph.go)

  • IntSet / StringSet — map-based set types with Insert, Delete, Contains, UnsortedList, Copy
  • OptimizedTarget — compact representation of a Bazel target with integer IDs for deps, rule types, tags, and
    attributes instead of strings (reduces memory)
  • OptimizedGraph — the full dependency graph with bidirectional ID↔name mappings for targets, rule types,
    tags, and attributes
  • OptimizeGraph() — converts a map[string]*targethasher.Target into an OptimizedGraph, wiring reverse deps
    automatically
  • Copy() on both types — deep copies for safe mutation
  • GetReverseDepsAsTargets() — DFS traversal returning a target and all its transitive reverse dependents
  • OptimizedTargetToTarget() — converts a stored target back to targethasher.Target

Graph mutation (invalidate.go)

  • removeTarget — removes a target, cleans up dep/reverse-dep cross-references, promotes deps to root if
    unblocked
  • invalidateHashRecursively — walks reverse deps and sets Hash = nil (marks them as needing recomputation)
  • checkDeletedTargets — removes targets whose packages were deleted or are no longer in a query result
  • upsertTarget — inserts or updates a target, swapping dep references and invalidating affected hashes

Hash recomputation (update.go)

  • UpdateGraph() — top-level entry point: translates a raw Bazel query result into updated targets, upserts
    external rules, computes available hashes, invalidates stale entries, then recomputes hashes in topological
    order
  • computeAvailableHashes() — computes hashes for source files (via SourceHasher), package groups (sha1 of
    name), and rule targets (sha1 of rule attributes, without deps)
  • computeHashes() — recursively computes final hashes: source files and package groups use their pre-computed
    hashes, generated files inherit from their parent rule, and rule targets combine their HashWithoutDeps with
    sorted dep hashes

Test Plan

unit test

Issue

@yushan8 yushan8 requested review from a team as code owners April 17, 2026 18:24
@yushan8 yushan8 changed the title [ITG] Add modules for itg graph [ITG] Add modules for ITG graph Apr 17, 2026
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants