Skip to content

refactor(aegis-core): public_symbols → Layer 1 cache (PR #16)#16

Merged
wei9072 merged 1 commit into
mainfrom
feat/layer1-public-symbols
May 7, 2026
Merged

refactor(aegis-core): public_symbols → Layer 1 cache (PR #16)#16
wei9072 merged 1 commit into
mainfrom
feat/layer1-public-symbols

Conversation

@wei9072
Copy link
Copy Markdown
Owner

@wei9072 wei9072 commented May 7, 2026

Summary

Continues PR #10's pattern. Any per-file fact whose extraction was
duplicated across consumers belongs in `ast::*` with a
`OnceCell` cache on `ParsedFile`.

`extract_public_symbols` / `extract_imported_symbols` /
`walk_export` / `is_public_name` / `is_likely_public` all
moved from `workspace.rs` to a new `ast::symbols` module.
`ParsedFile` gains `.public_symbols()` and `.imported_symbols()`
lazy accessors that mirror the existing `.imports()` API.

Changes

File Diff
`ast/symbols.rs` new — 228 lines (100 moved logic + 50 tests + 78 docs)
`ast/mod.rs` +2 / -0 (re-export)
`ast/parsed_file.rs` +21 / -0 (two more lazy caches)
`workspace.rs` -158 (deleted moved helpers)

Test plan

  • `cargo test --workspace` 167 / 167 pass (was 164; +3 new
    symbols tests)
  • All 11 existing workspace tests still pass — behavior of
    `summarize_file` preserved
  • No FP / FN in the SEC tests (rule library unchanged)
  • CI green on push

🤖 Generated with Claude Code

Continues PR #10's pattern: any per-file fact whose extraction was
duplicated across consumers belongs in `ast::*` with a `OnceCell`
cache on `ParsedFile`.

Both extractors used to live as private helpers inside
`workspace.rs::summarize_file`. They moved to a new
`ast::symbols` module:

- `extract_public_symbols(parsed) -> HashSet<String>` — top-level
  function / class / type / trait / variable names this file
  exposes. Skips function bodies (nested local helpers are not the
  file's public API). Rust requires `pub` modifier.
- `extract_imported_symbols(parsed) -> HashSet<String>` — names
  pulled in via `from X import Y` (Python) or
  `import { a, b } from 'x'` (TS / JS).
- `walk_export()` — preserved verbatim for `export default` /
  `export { a, b as c }` shapes.
- `is_public_name()` / `is_likely_public()` — moved alongside.

`ParsedFile` grows two more lazy caches:

- `public_symbols() -> &HashSet<String>`
- `imported_symbols() -> &HashSet<String>`

`workspace.rs::summarize_file` now reads both caches instead of
walking the tree itself. Net: -158 / +257 (the +257 includes 100
lines of moved code + 50 lines of new tests inside ast::symbols +
21 lines of new ParsedFile API).

3 new unit tests in `ast::symbols`: Python public-fn / Python
private-skip, Rust pub-only filter, Python `from … import …`
including `aliased_import`.

`workspace.rs` unchanged behaviour-wise; same 11 existing
workspace tests still pass.

Total: 164 → 167 tests pass.

Architectural rationale: this is the third per-file fact that
moved into Layer 1 (after `Import` in PR #10 and Layer 1 was
already provider for `ParsedFile`). The pattern is now stable
enough that any future "per-file derived fact" (call_sites,
function definitions, etc.) just adds another `OnceCell` field +
`extract_X` function.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@wei9072 wei9072 merged commit 0a27e03 into main May 7, 2026
1 check passed
@wei9072 wei9072 deleted the feat/layer1-public-symbols branch May 7, 2026 08:31
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.

1 participant