Skip to content

Commit 42561e7

Browse files
committed
fix: stage 2 review round — flow-locals CI home, edge canonicalization, extension-method sigs
The wpf-extractor CI job runs WITHOUT --flow-locals, so functions[] is always empty there and the stage-2 assertions could never pass (first CI run caught it). Move OverloadSigSample.cs and its assertions into the dedicated flow-locals step (flow.json), rename its locals (made->opened, s->dropped) clear of the step's existing silent-case guard, and pin the exact leak wording plus the opened/probe silent cases. Codex P2 x2, both verified real: - call_key now canonicalizes the sig-less/unmatched fallback: a forward or return edge to a global::-qualified first-party callee lands on the bare-name merged summary exactly like _mos_lookup resolves a direct call, instead of going extern (unknown) and downgrading a resolvable must/fresh to OWN051/silence. Regression test: qualified forward to agreeing-consume overloads yields OWN002 (271/271). - CanonicalSig canonicalizes through (ReducedFrom ?? m).OriginalDefinition so a reduced extension-method call site (receiver dropped from Parameters) and a constructed generic (type args substituted) produce the same string the declared functions[] record stamps — the precise per-overload contract applies instead of the merged fallback. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsWw4Ay8KLTHFom1HvRu3U
1 parent 540e07d commit 42561e7

5 files changed

Lines changed: 63 additions & 21 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ jobs:
205205
frontend/roslyn/samples/SemaphoreFieldSample.cs \
206206
frontend/roslyn/samples/VoidSubscribeSample.cs \
207207
frontend/roslyn/samples/ReturnedPublisherSample.cs \
208-
frontend/roslyn/samples/OverloadSigSample.cs \
209208
-o "$RUNNER_TEMP/facts.json"
210209
cat "$RUNNER_TEMP/facts.json"
211210
- name: Check facts through the core
@@ -257,18 +256,6 @@ jobs:
257256
echo "$out" | grep -qE "ReturnedPublisherSample\.cs:[0-9]+: warning: \[OWN001\].*'$ev'" \
258257
|| { echo "FAIL: expected the OWN001 warning to survive for '$ev' (provenance must deny)"; exit 1; }
259258
done
260-
# Interprocedural stage 2 (spec/OwnIR.md §5.1): per-overload signature keys.
261-
# SigOverloads.Open is overloaded — the (string) overload is a fresh factory,
262-
# the (FileStream,bool) one returns its parameter — so the name-merged returns
263-
# DISAGREE (no claim). The `sig` stamped on both the functions[] records and
264-
# the call op resolves the fresh overload's own summary, so the dropped
265-
# stream in Drop surfaces as OWN001 (severity-agnostic: a flow leak is an error).
266-
grep -q '"sig":"System.String"\|"sig": "System.String"' "$RUNNER_TEMP/facts.json" \
267-
|| { echo "FAIL: expected the (string) overload sig in the facts"; exit 1; }
268-
grep -q '"sig":"System.IO.FileStream,System.Boolean"\|"sig": "System.IO.FileStream,System.Boolean"' "$RUNNER_TEMP/facts.json" \
269-
|| { echo "FAIL: expected the (FileStream,bool) overload sig in the facts"; exit 1; }
270-
echo "$out" | grep -qE "OverloadSigSample\.cs:[0-9]+:.*\[OWN001\]" \
271-
|| { echo "FAIL: expected the sig-resolved fresh-overload leak (OWN001) in Drop"; exit 1; }
272259
# P-004 provenance: a local that ALIASES an injected source (var src =
273260
# _bus) is NOT method-bounded — it must warn, not be silently dropped. A
274261
# local the scope CONSTRUCTS (var owned = new Calc()) IS bounded -> silent.
@@ -744,7 +731,8 @@ jobs:
744731
dotnet run --project frontend/roslyn/OwnSharp.Extractor -- \
745732
frontend/roslyn/samples/FlowLocalsSample.cs \
746733
frontend/roslyn/samples/MemoryOwnerEscapeSample.cs \
747-
frontend/roslyn/samples/FactoryLeakSample.cs --flow-locals -o "$RUNNER_TEMP/flow.json"
734+
frontend/roslyn/samples/FactoryLeakSample.cs \
735+
frontend/roslyn/samples/OverloadSigSample.cs --flow-locals -o "$RUNNER_TEMP/flow.json"
748736
out=$(python -m ownlang ownir "$RUNNER_TEMP/flow.json" || true)
749737
echo "$out"
750738
echo "$out" | grep -q "OWN002" || { echo "FAIL: expected OWN002 (use-after-dispose)"; exit 1; }
@@ -933,6 +921,23 @@ jobs:
933921
for ok in factoryOk made; do
934922
if echo "$out" | grep -q "'$ok'"; then echo "FAIL: D5.2 silent case '$ok' was reported"; exit 1; fi
935923
done
924+
# Interprocedural stage 2 (spec/OwnIR.md §5.1): per-overload signature keys.
925+
# SigOverloads.Open is overloaded — the (string) overload is a fresh factory,
926+
# the (FileStream,bool) one returns its parameter — so the name-merged returns
927+
# DISAGREE (no fresh claim). The `sig` stamped on both the functions[] records
928+
# and the call op resolves the fresh overload's OWN summary, so the dropped
929+
# stream in Drop surfaces as OWN001 at the call — the recall the merge lost.
930+
grep -q '"sig": "System.String"\|"sig":"System.String"' "$RUNNER_TEMP/flow.json" \
931+
|| { echo "FAIL: expected the (string) overload sig in the facts"; exit 1; }
932+
grep -q '"sig": "System.IO.FileStream,System.Boolean"\|"sig":"System.IO.FileStream,System.Boolean"' "$RUNNER_TEMP/flow.json" \
933+
|| { echo "FAIL: expected the (FileStream,bool) overload sig in the facts"; exit 1; }
934+
echo "$out" | grep -qE "OverloadSigSample\.cs:[0-9]+:.*\[OWN001\].*'dropped' is never disposed" \
935+
|| { echo "FAIL: expected the sig-resolved fresh-overload leak (OWN001 on 'dropped')"; exit 1; }
936+
# the factory itself (transfers out via return), the non-fresh overload's
937+
# balanced probe, and the fresh local it returns all stay silent.
938+
for ok in opened probe; do
939+
if echo "$out" | grep -q "'$ok'"; then echo "FAIL: stage-2 silent case '$ok' was reported"; exit 1; fi
940+
done
936941
echo "OK: flow-sensitive OWN001/002/003 on real C# (path-sensitive, loops via while/foreach/for, try/finally sequential, never-vs-every-path wording, dispose-optional exempt, beyond flat)"
937942
- name: Gallery C#-native bad/ok pairs (examples/gallery/cs/)
938943
run: |

‎frontend/roslyn/OwnSharp.Extractor/Program.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,15 @@ static string FlowFunctionName(BaseMethodDeclarationSyntax method, string fallba
12031203
// the `call` op) derive it from the SAME resolved IMethodSymbol, so they agree by
12041204
// construction; the bridge falls back to the name-merged summary whenever either side
12051205
// lacks or mismatches it.
1206+
// Canonicalize through the DECLARED definition (Codex P2 on #217): a call site
1207+
// resolves the REDUCED form of an extension method (no `this` receiver in
1208+
// Parameters) and/or a CONSTRUCTED generic (type args substituted), while the
1209+
// `functions[]` record is stamped from the declaration — `ReducedFrom` restores
1210+
// the receiver parameter, `OriginalDefinition` restores the open type params, so
1211+
// both sides of the edge always produce the same string.
12061212
static string CanonicalSig(IMethodSymbol m) =>
1207-
string.Join(",", m.Parameters.Select(p => CanonicalTypeName(p.Type)));
1213+
string.Join(",", (m.ReducedFrom ?? m).OriginalDefinition
1214+
.Parameters.Select(p => CanonicalTypeName(p.Type)));
12081215

12091216
static string CanonicalTypeName(ITypeSymbol t) => t switch
12101217
{

‎frontend/roslyn/samples/OverloadSigSample.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public static class SigOverloads
1414
{
1515
public static FileStream Open(string path)
1616
{
17-
var made = new FileStream(path, FileMode.Open); // fresh factory
18-
return made;
17+
var opened = new FileStream(path, FileMode.Open); // fresh factory
18+
return opened;
1919
}
2020

2121
public static FileStream Open(FileStream existing, bool flush)
@@ -29,7 +29,7 @@ public static FileStream Open(FileStream existing, bool flush)
2929

3030
public static void Drop(string path)
3131
{
32-
var s = Open(path); // sig'd call -> the fresh overload's contract -> dropped result
33-
s.Flush(); // used but never disposed: OWN001 (the leak stage 2 restores)
32+
var dropped = Open(path); // sig'd call -> the fresh overload's contract
33+
dropped.Flush(); // used but never disposed: OWN001 (the leak stage 2 restores)
3434
}
3535
}

‎ownlang/ownir.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,13 +1900,21 @@ def _build_skeletons(raw_fns: list[Any]) -> list[MethodSkeleton]:
19001900

19011901
def call_key(callee: str, sig: str | None) -> str:
19021902
"""The summary key a call-op edge resolves against: the per-overload key
1903-
when the edge's `sig` names an emitted group (raw or `global::`-stripped,
1904-
mirroring `_mos_lookup`), else the bare callee (merged fallback)."""
1903+
when the edge's `sig` names an emitted group (raw or `global::`-stripped),
1904+
else the bare callee — canonicalized to its `global::`-stripped form when
1905+
THAT names a first-party record, so a forward to a qualified callee lands
1906+
on the merged summary exactly like `_mos_lookup` resolves a direct call
1907+
(Codex P2 on #217: the raw-keyed edge went extern → `unknown`, downgrading
1908+
a resolvable `must`/`fresh` to OWN051/silence)."""
19051909
if sig is not None:
19061910
for cand in (_sig_key(callee, sig),
19071911
_sig_key(_canonical_callee_name(callee), sig)):
19081912
if cand in sig_keys:
19091913
return cand
1914+
if callee not in counts:
1915+
identity = _canonical_callee_name(callee)
1916+
if identity in counts:
1917+
return identity
19101918
return callee
19111919

19121920
by_key: dict[str, list[MethodSkeleton]] = {}

‎tests/test_ownir.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,28 @@ def _boom2(_sk): # type: ignore[no-untyped-def]
22002200
if got2dup != [("dd", "OWN002")]:
22012201
fails.append("stage 2: duplicate name+sig records must merge within their "
22022202
f"group, not degrade the solve (dd OWN002), got {got2dup}")
2203+
# (Codex P2 on #217) a FORWARD to a `global::`-qualified first-party callee
2204+
# resolves through the bare-name merged key, exactly like `_mos_lookup` does
2205+
# for a direct call: both overloads consume, so the wrapper's param solves
2206+
# `must` and the caller's later use is OWN002 — the raw-keyed edge used to go
2207+
# extern (`unknown`), downgrading the verdict to an OWN051 advisory.
2208+
checks += 1
2209+
s2gf = check_facts({"module": "M", "functions": [
2210+
{"name": "C.M", "file": "F.cs", "params": [{"name": "a", "line": 1}],
2211+
"body": [{"op": "release", "var": "a", "line": 2}]},
2212+
{"name": "C.M", "file": "F.cs", "params": [{"name": "b", "line": 5}],
2213+
"body": [{"op": "release", "var": "b", "line": 6}]},
2214+
{"name": "gfw", "file": "F.cs", "params": [{"name": "p", "line": 8}],
2215+
"body": [{"op": "call", "callee": "global::C.M", "args": ["p"],
2216+
"line": 9}]},
2217+
{"name": "d10", "file": "F.cs",
2218+
"body": [{"op": "acquire", "var": "s", "line": 10},
2219+
{"op": "call", "callee": "gfw", "args": ["s"], "line": 11},
2220+
{"op": "use", "var": "s", "line": 12}]}]})
2221+
got2gf = sorted((x.component, x.code) for x in s2gf)
2222+
if got2gf != [("d10", "OWN002")]:
2223+
fails.append("stage 2: forward to a global::-qualified first-party callee "
2224+
f"must resolve the merged consume (d10 OWN002), got {got2gf}")
22032225
# the parity dump (roadmap stage 1) carries the extended key vocabulary: the
22042226
# bare-name merged fallback AND one `name(sig)` entry per overload, each with
22052227
# its own (unmerged) verdicts — byte-deterministic under input permutation.

0 commit comments

Comments
 (0)