diff --git a/gemini-extension.json b/gemini-extension.json index 61a14197f..9cfece080 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -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": { diff --git a/graph/bundle/SCHEMA.md b/graph/bundle/SCHEMA.md index 3b54dcc71..3c7bddeb7 100644 --- a/graph/bundle/SCHEMA.md +++ b/graph/bundle/SCHEMA.md @@ -347,7 +347,7 @@ Every callable the graph refers to: all client methods/functions from the IR, pl | `client` | all | Declared in the analysed project. | | `lib` | all | Declared in a staged library IR; listed because an edge reaches it. | | `generated` | java | Declared by a compile-time annotation processor: present in the compiled artefact and in every caller's source, and in no IR, so the bundle synthesises it to give the edge a target. id `generated:#/`, no file and no line numbers. | -| `generated` | csharp | The Invoke of the delegate held in one field or property: id `generated:#.Invoke`, no file and no line numbers. Every call through that member is an edge to it (tier boundary_lib, which is also where the compiler binds the call), and what the member holds is in dispatch_candidates with basis `value`. | +| `generated` | csharp | The Invoke of the delegate held in one field or property: id `generated:#.Invoke`, no file and no line numbers. Every call through that member is an edge to it (tier boundary_lib, which is also where the compiler binds the call), and what the member holds is in dispatch_candidates with basis `value`. And the parameterless constructor of a staged library type whose IR carries no constructor: id `generated:#/0`. `new T()` compiles only if T has one, so the target exists, but a library IR is a signature subset and cannot say whether T declares it or the compiler supplies it. The `new` site is an edge to it with callee_provenance `lib` and tier boundary_lib, not an `external:` label, because the library WAS staged. | **Notes** @@ -578,7 +578,7 @@ THE GRAPH. One row per (site, resolved target). A site with N possible targets h |---|---|---| | `external` | all | The target is outside every staged IR. callee_method_id is NULL and callee_label names it, as `external:.`. A client-only run of a C# project reaches the BCL this way for most of its calls. | | `client` | all | Target is a client method (callee_method_id set). | -| `lib` | all | Target is a method of a staged library IR (callee_method_id set, methods.provenance = lib). | +| `lib` | all | Target is a method of a staged library IR (callee_method_id set, methods.provenance = lib). C# only: or the parameterless constructor of a staged type its IR does not carry, a methods row with provenance `generated`. | | `generated` | csharp | The target is a member the compiler generated and no source declares (a `boundary_generated` row); callee_label names it. | | `builtin` | python | Target is a CPython builtin with no Python source (callee_label = `builtin:NAME`). | | `external` | python, java | Target is outside every staged IR and has no methods row. Python: an import path (callee_label = the written path). Java: a method of an unstaged ancestor type (callee_label = `external:.`), reached through a receiver declared as that type or inherited by a client subclass; see types.provenance external. | diff --git a/graph/bundle/schema.ts b/graph/bundle/schema.ts index 906ca4eda..94fe91ad6 100644 --- a/graph/bundle/schema.ts +++ b/graph/bundle/schema.ts @@ -415,7 +415,7 @@ export const VOCAB: readonly VocabSpec[] = [ { table: 'methods', column: 'provenance', value: 'client', languages: 'all', meaning: 'Declared in the analysed project.' }, { table: 'methods', column: 'provenance', value: 'lib', languages: 'all', meaning: 'Declared in a staged library IR; listed because an edge reaches it.' }, { table: 'methods', column: 'provenance', value: 'generated', languages: J, meaning: 'Declared by a compile-time annotation processor: present in the compiled artefact and in every caller\'s source, and in no IR, so the bundle synthesises it to give the edge a target. id `generated:#/`, no file and no line numbers.' }, - { table: 'methods', column: 'provenance', value: 'generated', languages: C, meaning: 'The Invoke of the delegate held in one field or property: id `generated:#.Invoke`, no file and no line numbers. Every call through that member is an edge to it (tier boundary_lib, which is also where the compiler binds the call), and what the member holds is in dispatch_candidates with basis `value`.' }, + { table: 'methods', column: 'provenance', value: 'generated', languages: C, meaning: 'The Invoke of the delegate held in one field or property: id `generated:#.Invoke`, no file and no line numbers. Every call through that member is an edge to it (tier boundary_lib, which is also where the compiler binds the call), and what the member holds is in dispatch_candidates with basis `value`. And the parameterless constructor of a staged library type whose IR carries no constructor: id `generated:#/0`. `new T()` compiles only if T has one, so the target exists, but a library IR is a signature subset and cannot say whether T declares it or the compiler supplies it. The `new` site is an edge to it with callee_provenance `lib` and tier boundary_lib, not an `external:` label, because the library WAS staged.' }, { table: 'types', column: 'provenance', value: 'client', languages: 'all', meaning: 'Declared in the analysed project.' }, { table: 'types', column: 'provenance', value: 'lib', languages: 'all', meaning: 'Declared in a staged library IR.' }, { table: 'types', column: 'provenance', value: 'external', languages: J, meaning: 'Named by the client as an ancestor (`extends`/`implements`) but declared in no staged IR: id `external:`, category EXTERNAL_TYPE, no file, no members. Kept so the subtype edge survives; stage the library to replace it with the real declaration.' }, @@ -617,7 +617,7 @@ export const VOCAB: readonly VocabSpec[] = [ // call_edges.callee_provenance { table: 'call_edges', column: 'callee_provenance', value: 'client', languages: 'all', meaning: 'Target is a client method (callee_method_id set).' }, - { table: 'call_edges', column: 'callee_provenance', value: 'lib', languages: 'all', meaning: 'Target is a method of a staged library IR (callee_method_id set, methods.provenance = lib).' }, + { table: 'call_edges', column: 'callee_provenance', value: 'lib', languages: 'all', meaning: 'Target is a method of a staged library IR (callee_method_id set, methods.provenance = lib). C# only: or the parameterless constructor of a staged type its IR does not carry, a methods row with provenance `generated`.' }, { table: 'call_edges', column: 'callee_provenance', value: 'generated', languages: C, meaning: 'The target is a member the compiler generated and no source declares (a `boundary_generated` row); callee_label names it.' }, { table: 'call_edges', column: 'callee_provenance', value: 'builtin', languages: P, meaning: 'Target is a CPython builtin with no Python source (callee_label = `builtin:NAME`).' }, { table: 'call_edges', column: 'callee_provenance', value: 'external', languages: ['python', 'java'], meaning: 'Target is outside every staged IR and has no methods row. Python: an import path (callee_label = the written path). Java: a method of an unstaged ancestor type (callee_label = `external:.`), reached through a receiver declared as that type or inherited by a client subclass; see types.provenance external.' }, diff --git a/graph/csharp/engine/call-edge-generation/call_chain.dl b/graph/csharp/engine/call-edge-generation/call_chain.dl index 61db248e2..64e94f417 100644 --- a/graph/csharp/engine/call-edge-generation/call_chain.dl +++ b/graph/csharp/engine/call-edge-generation/call_chain.dl @@ -111,6 +111,8 @@ site_leaves_client(prov, e) :- client_calls_lib(prov, e, _, _). // a real project that is most of the unresolved sites -- which makes the number that // matters unreadable. site_leaves_client(prov, e) :- external_target(prov, e, _). +// And one into a staged type whose parameterless constructor its IR does not carry. +site_leaves_client(prov, e) :- staged_parameterless_ctor(prov, e, _). // A call through a field or property holding a delegate lands on the delegate's // Invoke, which the runtime supplies (resolution/delegates.dl). The site gets an edge // to that member's Invoke node and the stored functions are in the envelope. @@ -235,6 +237,14 @@ call_chain_edge(e, caller, "-", label, "external", "boundary_lib", kind) :- call_from("client", e, caller), invocation_site("client", e, kind). +// client -> A STAGED TYPE'S PARAMETERLESS CONSTRUCTOR, NOT CARRIED BY ITS IR. The +// target belongs to a staged type, so the provenance is `lib`; it is the `generated:` +// node resolution/external-types.dl names, which the bundle gives a methods row. +call_chain_edge(e, caller, "-", node, "lib", "boundary_lib", kind) :- + staged_parameterless_ctor("client", e, node), + call_from("client", e, caller), + invocation_site("client", e, kind). + // client -> A DELEGATE MEMBER'S INVOKE (#1206). `getPath(url)` on a field holding a // delegate calls Invoke -- Roslyn's answer too -- and which stored function then runs // is value flow, recorded in method_dispatch_candidate with basis `value` rather than @@ -400,6 +410,7 @@ call_has_edge(prov, e) :- client_calls_lib(prov, e, _, _). call_has_edge("client", e) :- client_calls_external(e, _). call_has_edge("client", e) :- delegate_member_call("client", e, _). call_has_edge("client", e) :- delegate_param_call(e, _). +call_has_edge("client", e) :- staged_parameterless_ctor("client", e, _). call_chain_edge(e, caller, "-", "-", "-", cls, kind) :- invocation_site("client", e, kind), diff --git a/graph/csharp/engine/resolution/external-types.dl b/graph/csharp/engine/resolution/external-types.dl index 966db7a15..6ff6722e0 100644 --- a/graph/csharp/engine/resolution/external-types.dl +++ b/graph/csharp/engine/resolution/external-types.dl @@ -435,20 +435,52 @@ external_target(prov, e, label) :- // constructor clause above needs the type to be UNSTAGED, so once a library // declares the type the site had neither a constructor to resolve nor a name to // carry. Refusing the implicit-constructor claim alone leaves it a blind spot. +// +// NOT FOR `new T()` ON A STAGED TYPE THAT CARRIES NO CONSTRUCTOR AT ALL. That site +// runs T's parameterless constructor, which exists whether the library declares it +// or the compiler supplies it, and T is staged: `external` would say the +// dependency was not supplied, and it was (#1339). staged_parameterless_ctor names +// it inside the library instead. What is left here is a site whose argument count +// no carried constructor accepts although the IR carries some: a member the subset +// IR was not told about, named like an uncarried method. external_target(prov, e, label) :- call_needs_ctor_lookup(prov, e), expr_new_type(prov, e, gk), type_group("lib", _, gk), call_argc(prov, e, ac), !call_ctor_target_accepts(prov, e, ac), + !staged_parameterless_ctor(prov, e, _), type_decl("lib", n, _, _, _, t), type_group("lib", t, gk), label = cat("external:", cat(n, ".")). // Whether any constructor of the created type accepts this site's argument // count. Named rather than inlined because the rule above needs its NEGATION, // and a negated conjunction over three relations is where a cross-product hides. +// +// call_ctor_target already admits a constructor only where it accepts the site's +// argument count, under the provenance the constructor is DECLARED in. Re-checking +// it here under the SITE's provenance missed every staged constructor -- a client +// `new` reaching a library constructor -- so a resolved site was also labelled an +// unstaged one and had two rows (#1339). call_ctor_target_accepts(prov, e, ac) :- - call_ctor_target(prov, e, ctor), ctor_accepts_argc(prov, ctor, ac). + call_ctor_target(prov, e, _), call_argc(prov, e, ac). + +// staged_parameterless_ctor(Prov, Site, Node) -- `new T()` with no argument, on a +// staged type whose IR carries no constructor. Not known_implicit_ctor: a library IR +// is a signature subset, so it cannot show that T declares none. But `new T()` +// compiles only if T has a parameterless constructor, declared or supplied, so the +// target is known to exist and to be T's. The node is the `generated:` member id the +// bundle gives a methods row (provenance generated, owner T), so the edge points at +// T inside the library rather than at a label for an unsupplied dependency. +staged_parameterless_ctor(prov, e, node) :- + call_needs_ctor_lookup(prov, e), + expr_new_type(prov, e, gk), + type_group("lib", _, gk), + !type_ctor("lib", gk, _), + !type_ctor(prov, gk, _), + call_argc(prov, e, "0"), + type_decl("lib", _, qn, _, _, t), type_group("lib", t, gk), + node = cat("generated:", cat(qn, "#/0")). // ── A PROPERTY READ ON AN EXTERNAL RECEIVER ───────────────────────────────── // `someString.Length`, `dict.Count`, `ex.Message`. Reading a property IS a call, and diff --git a/graph/csharp/souffle/decls_all.dl b/graph/csharp/souffle/decls_all.dl index 182506dd0..d5c4ceda7 100644 --- a/graph/csharp/souffle/decls_all.dl +++ b/graph/csharp/souffle/decls_all.dl @@ -916,6 +916,7 @@ .decl site_unresolved_named(c0:symbol,c1:symbol,c2:symbol) .decl site_unresolved_real(c0:symbol) .decl sseg(c0:symbol,c1:number,c2:symbol) +.decl staged_parameterless_ctor(c0:symbol,c1:symbol,c2:symbol) .decl starts_slash(c0:symbol) .decl static_edge_exists(c0:symbol,c1:symbol) .decl static_fan_member(c0:symbol,c1:symbol,c2:symbol) diff --git a/graph/test/csharp/staging-test.sh b/graph/test/csharp/staging-test.sh index 7274c0edd..8dc3467f2 100755 --- a/graph/test/csharp/staging-test.sh +++ b/graph/test/csharp/staging-test.sh @@ -288,6 +288,51 @@ aln=$(awk -F' ' '$6=="boundary_lib"' "$AL" 2>/dev/null | wc -l | tr -d ' ') [ "${aln:-0}" -eq 2 ] || fail "a keyword-typed receiver did not reach the staged framework type: got ${aln:-0} of 2" grep -q "external:" "$AL" 2>/dev/null && fail "a keyword-typed receiver was still labelled external although its type is staged" +# ── `new T()` ON A STAGED TYPE IS NOT AN UNSTAGED DEPENDENCY (#1339) ─────── +# Two shapes of one site, each in its own run because the library is the variable: +# ctor/ Store declares a constructor. The site has exactly ONE row, the +# resolved one. It used to have a second, `external:Store.`, +# because the "no carried constructor accepts this arity" check joined +# the library's constructor under the client's provenance and found +# nothing, so a resolved site was also labelled unstaged. +# noctor/ Store declares none. The parameterless constructor the site runs is +# not carried, but the TYPE is staged, so the row must not say +# `external` -- that provenance means "this dependency was not +# supplied", and it was. Nor is it known_implicit_ctor: a library IR is +# a signature subset, so it cannot prove the type declares none. +for shape in ctor noctor; do + mkdir -p "$WORK/new-$shape-lib" "$WORK/new-$shape-cli" + if [ "$shape" = ctor ]; then decl='public Store() { }'; else decl=''; fi + cat > "$WORK/new-$shape-lib/Store.cs" < "$WORK/new-$shape-cli/Program.cs" <<'EOF2' +using Acme; +namespace App; +public static class Program { public static int Main() { var s = new Store(); return s.Open("x").Size(); } } +EOF2 + node "$REPO/parser/dist/index.js" "$WORK/new-$shape-lib" "new-$shape-lib" false "$WORK/new-$shape-libir" --per-language > "$WORK/new-$shape-parse.log" 2>&1 + bash "$REPO/bin/axiomcode" all --language csharp --src "$WORK/new-$shape-cli" --out "$WORK/new-$shape-out" \ + --library "$WORK/new-$shape-libir" --version pinned --debug > "$WORK/new-$shape.log" 2>&1 + NEW="$WORK/new-$shape-out/csharp/raw/call-chain-edges.csv" + rows=$(awk -F'\t' '$7=="new"' "$NEW" 2>/dev/null | wc -l | tr -d ' ') + ext=$(awk -F'\t' '$7=="new" && $5=="external"' "$NEW" 2>/dev/null | wc -l | tr -d ' ') + libm=$(awk -F'\t' '$7=="new" && $5=="lib" && $4 ~ /^CS_METHOD_/' "$NEW" 2>/dev/null | wc -l | tr -d ' ') + implicit=$(awk -F'\t' '$7=="new" && $6=="known_implicit_ctor"' "$NEW" 2>/dev/null | wc -l | tr -d ' ') + if [ "$shape" = ctor ]; then + [ "${rows:-0}" -eq 1 ] && [ "${libm:-0}" -eq 1 ] || \ + fail "\`new Store()\` on a staged type that DECLARES its constructor has ${rows:-0} row(s), ${libm:-0} to the library constructor and ${ext:-0} external; expected exactly the one resolved row" + else + [ "${rows:-0}" -eq 1 ] || fail "\`new Store()\` on a staged type with no carried constructor has ${rows:-0} row(s), expected 1" + [ "${ext:-0}" -eq 0 ] || fail "\`new Store()\` on a STAGED type with no carried constructor is labelled external, as if the library had not been supplied" + [ "${implicit:-0}" -eq 0 ] || fail "\`new Store()\` on a staged type claimed known_implicit_ctor, which a signature-subset IR cannot prove" + fi + [ "${rows:-0}" -ge 1 ] || awk -F'\t' '{print " got: "$4" "$5" "$6" "$7}' "$NEW" 2>/dev/null | head -5 + [ "${rows:-0}" -le 1 ] || awk -F'\t' '$7=="new"{print " got: "$4" "$5" "$6" "$7}' "$NEW" 2>/dev/null | head -5 +done + # ── STAGING NOTHING CHANGES NOTHING ───────────────────────────────────────── # The cross-provenance clauses must be inert on a client-only run. Compared # relation by relation, and then the SAME comparison is run against the staged diff --git a/package.json b/package.json index c1fd43e95..144dabe85 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/plugins/axiomcode/.claude-plugin/plugin.json b/plugins/axiomcode/.claude-plugin/plugin.json index a45810eee..55c135b5e 100644 --- a/plugins/axiomcode/.claude-plugin/plugin.json +++ b/plugins/axiomcode/.claude-plugin/plugin.json @@ -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" } diff --git a/plugins/axiomcode/.codex-plugin/plugin.json b/plugins/axiomcode/.codex-plugin/plugin.json index 29c2ba521..c5a0c074c 100644 --- a/plugins/axiomcode/.codex-plugin/plugin.json +++ b/plugins/axiomcode/.codex-plugin/plugin.json @@ -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", diff --git a/plugins/axiomcode/.cursor-plugin/plugin.json b/plugins/axiomcode/.cursor-plugin/plugin.json index fadd636d0..a797bda89 100644 --- a/plugins/axiomcode/.cursor-plugin/plugin.json +++ b/plugins/axiomcode/.cursor-plugin/plugin.json @@ -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",