Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gemini-extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "axiomcode",
"version": "0.2.3",
"version": "0.2.4",
"description": "Ask your repository how its code connects: who calls this, what breaks if I change it, which tests an edit reaches, how A reaches B. Answers come from a resolved call graph and are verified against it; nothing is guessed.",
"contextFileName": "plugins/axiomcode/AGENTS.md",
"mcpServers": {
Expand Down
17 changes: 14 additions & 3 deletions graph/python/engine/projections/bindings.dl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,20 @@ binding_is_namespace("lib", h) :- lib_py_binding(_, _, _, _, _, _, _, _, _, _, _
// bindingCount is the number of DISTINCT binding sites for this name in this scope.
// == 1 is the precondition for treating a name as single-valued (the alias case
// `_Aliased = Base`); > 1 means the name is rebound and a single-value inference is
// unsound. Consumed by resolution/name-resolution.dl.
binding_rebinding("client", n, first, last, h) :- py_binding(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, n, first, last, _, _, _, _, _, _, _, _, _, _, h).
binding_rebinding("lib", n, first, last, h) :- lib_py_binding(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, n, first, last, _, _, _, _, _, _, _, _, _, _, h).
// unsound.
// This is the RAW per-row count. It cannot see a write made from a NESTED scope through
// `nonlocal`: that write is a separate NONLOCAL row with its own count, so the enclosing
// cell's row still says 1. resolution/name-resolution.dl derives binding_rebinding from
// this and adds those writes; every single-write guard reads binding_rebinding. Only the
// LEGB walk reads the raw count, because it is what binding_rebinding is derived from.
binding_rebinding_raw("client", n, first, last, h) :- py_binding(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, n, first, last, _, _, _, _, _, _, _, _, _, _, h).
binding_rebinding_raw("lib", n, first, last, h) :- lib_py_binding(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, n, first, last, _, _, _, _, _, _, _, _, _, _, h).

// ── binding_is_assigned(Prov, BindingHash) ───────────────────────────────────
// Symbol.is_assigned(): the name is a store target in this scope. Separates a
// `nonlocal fn` that rebinds the enclosing cell from one that only reads it.
binding_is_assigned("client", h) :- py_binding(_, _, _, _, _, _, _, _, _, _, "true", _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, h).
binding_is_assigned("lib", h) :- lib_py_binding(_, _, _, _, _, _, _, _, _, _, "true", _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, h).

// ── binding_annotation(Prov, DeclaredTypeName, DeclaredBaseType, PotentialQName, BindingHash) ──
// "" on 68.2% of parameters, which is exactly why declared-type receiver typing —
Expand Down
27 changes: 25 additions & 2 deletions graph/python/engine/resolution/name-resolution.dl
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,15 @@ binding_lookup(p, b, b2) :-
binding_owner(p, mod, _, b),
module_init(p, _, modScope, mod),
binding_decl(p, n, modScope, _, _, b2), b2 != b,
binding_rebinding(p, cnt, _, _, b2), cnt != "0".
binding_rebinding_raw(p, cnt, _, _, b2), cnt != "0".
// (c) FREE / NONLOCAL — nearest enclosing scope that binds the name. Candidate set
// first, then the max-depth filter in the next stratum.
binding_free_candidate(p, b, b2, d) :-
binding_is_free_kind(p, b),
binding_decl(p, n, s, _, _, b),
scope_ancestor(p, s, anc),
binding_decl(p, n, anc, _, _, b2),
binding_rebinding(p, cnt, _, _, b2), cnt != "0",
binding_rebinding_raw(p, cnt, _, _, b2), cnt != "0",
scope_depth(p, dstr, _, anc),
d = to_number(dstr).
binding_free_nearest_depth(p, b, dmax) :-
Expand All @@ -456,6 +456,29 @@ binding_lookup(p, b, b2) :-
binding_free_nearest_depth(p, b, dmax),
binding_free_candidate(p, b, b2, dmax).

// ── binding_nonlocal_write / binding_rebinding: writes from a nested scope ──
// symtable counts a name's binding sites per scope, so a cell rebound from a nested
// function through `nonlocal` has two rows, each with its own count: the cell's own
// (1, `fn = first`) and the nested NONLOCAL row (`fn = second`). Read alone, the cell's
// row says the name is written once, and every single-write guard then commits to the
// first write. #381: `fn = first; def swap(): nonlocal fn; fn = second; swap(); fn()`
// came out known_edge -> first, a function that cannot run there, and `second` was the
// target of no edge.
// A NONLOCAL row that is ASSIGNED is a write to the cell its LEGB walk lands on. One that
// only reads (`nonlocal fn` and no store) is not, and leaves the count alone.
binding_nonlocal_write(p, cell, nb) :-
binding_decl(p, _, _, "NONLOCAL", _, nb),
binding_is_assigned(p, nb),
binding_lookup(p, nb, cell), cell != nb.
binding_rebinding(p, n, first, last, b) :-
binding_rebinding_raw(p, n, first, last, b),
!binding_nonlocal_write(p, b, _).
binding_rebinding(p, total, first, last, b) :-
binding_rebinding_raw(p, n, first, last, b),
binding_nonlocal_write(p, b, _),
k = count : { binding_nonlocal_write(p, b, _) },
total = to_string(to_number(n) + k).

// ── binding_lookup_unresolved(Prov, ReferenceBinding, Name, BindingKind) ─────
// A reference-side binding whose LEGB walk found no declaration. THE HONEST FRONTIER:
// a builtin (`super`, `len`, `object`), a name from `from x import *`, or a genuine
Expand Down
3 changes: 3 additions & 0 deletions graph/python/souffle/decls_all.dl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
.decl binding_decl(c0:symbol,c1:symbol,c2:symbol,c3:symbol,c4:symbol,c5:symbol)
.decl binding_predicates(c0:symbol,c1:symbol,c2:symbol,c3:symbol,c4:symbol,c5:symbol,c6:symbol)
.decl binding_is_namespace(c0:symbol,c1:symbol)
.decl binding_rebinding_raw(c0:symbol,c1:symbol,c2:symbol,c3:symbol,c4:symbol)
.decl binding_rebinding(c0:symbol,c1:symbol,c2:symbol,c3:symbol,c4:symbol)
.decl binding_is_assigned(c0:symbol,c1:symbol)
.decl binding_nonlocal_write(c0:symbol,c1:symbol,c2:symbol)
.decl binding_annotation(c0:symbol,c1:symbol,c2:symbol,c3:symbol,c4:symbol)
.decl binding_declared_ref(c0:symbol,c1:symbol,c2:symbol)
.decl binding_declared_nominal(c0:symbol,c1:symbol,c2:symbol)
Expand Down
56 changes: 56 additions & 0 deletions graph/test/python/cases/44-nonlocal-rebind/src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# A closure cell rebound from a nested scope through `nonlocal` is written twice, so the
# call through it must not commit to the first write alone (#381).


def first() -> str:
return "first"


def second() -> str:
return "second"


def nonlocal_rebind() -> str:
fn = first

def swap() -> None:
nonlocal fn
fn = second

swap()
return fn()


def nonlocal_read_only() -> str:
# A nested scope that only READS the cell through `nonlocal` is not a write; the call
# still has exactly one value and stays a committed edge.
fn = first

def peek() -> str:
nonlocal fn
return fn.__name__

peek()
return fn()


def unrelated_nested_name() -> str:
# A nested scope that assigns its OWN local of the same name does not touch the cell.
fn = first

def shadow() -> None:
fn = second
fn()

shadow()
return fn()


def main() -> None:
nonlocal_rebind()
nonlocal_read_only()
unrelated_nested_name()


if __name__ == "__main__":
main()
16 changes: 16 additions & 0 deletions graph/test/python/expected/44-nonlocal-rebind.edges
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ambiguous_unknown SIMPLE_CALL main.nonlocal_rebind -> -
callback_registered METHOD_REFERENCE main.nonlocal_read_only -> main.first
callback_registered METHOD_REFERENCE main.nonlocal_rebind -> main.first
callback_registered METHOD_REFERENCE main.nonlocal_rebind.<locals>.swap -> main.second
callback_registered METHOD_REFERENCE main.unrelated_nested_name -> main.first
callback_registered METHOD_REFERENCE main.unrelated_nested_name.<locals>.shadow -> main.second
known_edge SIMPLE_CALL main.<module> -> main.main
known_edge SIMPLE_CALL main.main -> main.nonlocal_read_only
known_edge SIMPLE_CALL main.main -> main.nonlocal_rebind
known_edge SIMPLE_CALL main.main -> main.unrelated_nested_name
known_edge SIMPLE_CALL main.nonlocal_read_only -> main.first
known_edge SIMPLE_CALL main.nonlocal_read_only -> main.nonlocal_read_only.<locals>.peek
known_edge SIMPLE_CALL main.nonlocal_rebind -> main.nonlocal_rebind.<locals>.swap
known_edge SIMPLE_CALL main.unrelated_nested_name -> main.first
known_edge SIMPLE_CALL main.unrelated_nested_name -> main.unrelated_nested_name.<locals>.shadow
known_edge SIMPLE_CALL main.unrelated_nested_name.<locals>.shadow -> main.second
1 change: 1 addition & 0 deletions graph/test/python/expected/44-nonlocal-rebind.entries
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
── entry_point (0) ──
5 changes: 5 additions & 0 deletions graph/test/python/expected/44-nonlocal-rebind.framework
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
── framework_edge (0) ──
── framework_unjoined (0) ──
── remote_edge (0) ──
── remote_unserved (0) ──
── remote_unsent (0) ──
24 changes: 24 additions & 0 deletions graph/test/python/expected/44-nonlocal-rebind.tiers
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
distinct call sites emitted: 16

--- by tier: edge ROWS, and the distinct SITES they cover ---
1 rows 1 sites ambiguous_unknown
5 rows 5 sites callback_registered
10 rows 10 sites known_edge

--- edge rows by call kind ---
5 METHOD_REFERENCE
11 SIMPLE_CALL

--- unresolved reasons ---
1 no_rule

--- the engine's own conservation ledger ---
11 _total_sites
1 ambiguous_unknown
10 known_edge

--- reconciling rows against the conserved site count ---
edge rows 16
minus extra rows from multi-target sites 0
= tier/site pairs 16
engine's conserved site total 11
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axiomcode/code-graph",
"version": "0.2.3",
"version": "0.2.4",
"description": "AxiomCode Graph: a resolved call graph of your codebase grounded in formal methods, so you and your coding agents can see who calls what, what a change breaks, and which tests it reaches.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -31,11 +31,11 @@
],
"license": "FSL-1.1-Apache-2.0",
"optionalDependencies": {
"@axiomcode/engine-darwin-arm64": "0.2.3",
"@axiomcode/engine-darwin-x64": "0.2.3",
"@axiomcode/engine-linux-x64": "0.2.3",
"@axiomcode/engine-linux-arm64": "0.2.3",
"@axiomcode/engine-win32-x64": "0.2.3"
"@axiomcode/engine-darwin-arm64": "0.2.4",
"@axiomcode/engine-darwin-x64": "0.2.4",
"@axiomcode/engine-linux-x64": "0.2.4",
"@axiomcode/engine-linux-arm64": "0.2.4",
"@axiomcode/engine-win32-x64": "0.2.4"
},
"bin": {
"axiomcode": "bin/axiomcode.js"
Expand Down
2 changes: 1 addition & 1 deletion plugins/axiomcode/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "axiomcode",
"description": "Ask your repository how its code connects: who calls this, what breaks if I change it, which tests an edit reaches, how A reaches B. Answers come from a resolved call graph and are verified against it; nothing is guessed.",
"version": "0.2.3",
"version": "0.2.4",
"author": {
"name": "AxiomCode"
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/axiomcode/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "axiomcode",
"version": "0.2.3",
"version": "0.2.4",
"description": "Ask your repository how its code connects: who calls this, what breaks if I change it, which tests an edit reaches, how A reaches B. Answers come from a resolved call graph and are verified against it; nothing is guessed.",
"author": { "name": "AxiomCode", "url": "https://github.com/AxiomCodeAI/axiomcodegraph" },
"homepage": "https://github.com/AxiomCodeAI/axiomcodegraph",
Expand Down
2 changes: 1 addition & 1 deletion plugins/axiomcode/.cursor-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "axiomcode",
"version": "0.2.3",
"version": "0.2.4",
"description": "Ask your repository how its code connects: who calls this, what breaks if I change it, which tests an edit reaches, how A reaches B. Answers come from a resolved call graph and are verified against it; nothing is guessed. Java, TypeScript, Python, JavaScript.",
"author": { "name": "AxiomCode" },
"homepage": "https://github.com/AxiomCodeAI/axiomcodegraph",
Expand Down
Loading