|
153 | 153 | ReturnSkeleton, |
154 | 154 | Transfer, |
155 | 155 | solve, |
| 156 | + solve_with_log, |
156 | 157 | ) |
157 | 158 |
|
158 | 159 | # The OwnIR schema version this core understands. Bump it whenever the fact |
@@ -1473,7 +1474,11 @@ def _merge_skeletons(group: list[MethodSkeleton]) -> MethodSkeleton: |
1473 | 1474 | params = tuple( |
1474 | 1475 | ParamSkeleton(i, names[i], True, tuple(by_index[i])) for i in sorted(by_index) |
1475 | 1476 | ) |
1476 | | - return MethodSkeleton(group[0].key, params, _merge_returns([sk.ret for sk in group])) |
| 1477 | + # the merged location must not depend on `functions[]` input order (the summary |
| 1478 | + # dump is a deterministic parity surface): take the smallest (file, line) pair. |
| 1479 | + floc = min((sk.file, sk.line) for sk in group) |
| 1480 | + return MethodSkeleton(group[0].key, params, |
| 1481 | + _merge_returns([sk.ret for sk in group]), floc[0], floc[1]) |
1477 | 1482 |
|
1478 | 1483 |
|
1479 | 1484 | def _build_skeletons(raw_fns: list[Any]) -> list[MethodSkeleton]: |
@@ -1569,7 +1574,10 @@ def _build_skeletons(raw_fns: list[Any]) -> list[MethodSkeleton]: |
1569 | 1574 | params.append(ParamSkeleton(i, cname, True, paths)) |
1570 | 1575 | pnames = {str(p.get("name", "")) for p in raw_params if isinstance(p, dict)} |
1571 | 1576 | ret = _infer_return_skeleton(body, pnames, first_party) |
1572 | | - by_key.setdefault(key, []).append(MethodSkeleton(key, tuple(params), ret)) |
| 1577 | + # carry the declaration file so the summary dump is navigable (functions[] |
| 1578 | + # entries carry no line of their own — params do; line stays 0). |
| 1579 | + by_key.setdefault(key, []).append( |
| 1580 | + MethodSkeleton(key, tuple(params), ret, str(fn.get("file", "?")))) |
1573 | 1581 | # one skeleton per name: solve() keys by name (a forward names its callee with no |
1574 | 1582 | # signature), so same-name overloads are joined into a single conservative summary. |
1575 | 1583 | return [_merge_skeletons(group) for group in by_key.values()] |
@@ -2027,6 +2035,44 @@ def _flow_local_steps(sub: dict[str, Any], code: str, dline: int, |
2027 | 2035 | return ((f, acq, origin), (f, dline, viol)) |
2028 | 2036 |
|
2029 | 2037 |
|
| 2038 | +def dump_summaries(facts: dict[str, Any]) -> dict[str, Any]: |
| 2039 | + """The MOS observability / parity surface (roadmap stage 1, TZ §5.4): derive |
| 2040 | + the skeletons, run the solver, and return the solved summaries plus the |
| 2041 | + extern-boundary log as ONE deterministic document. |
| 2042 | +
|
| 2043 | + Two consumers, one contract: |
| 2044 | + - a human asking "why did this call stay plain?" reads the method's summary |
| 2045 | + (transfer per param, return kind) and the `unresolved` extern boundaries |
| 2046 | + without reading bridge code; |
| 2047 | + - the Rust port of the inference layer is diffed against this document |
| 2048 | + (`oracle_exact`-style), which checks the port at the summary level — finer |
| 2049 | + than diffing final diagnostics, where an inference bug can hide behind an |
| 2050 | + unrelated silence. |
| 2051 | +
|
| 2052 | + Determinism is the contract: summaries are sorted by method key, the |
| 2053 | + unresolved log arrives sorted from `solve_with_log`, and `to_dict` field |
| 2054 | + order is fixed — the same facts yield byte-identical JSON regardless of |
| 2055 | + `functions[]` input order. A failed solve degrades exactly like |
| 2056 | + `check_facts` (empty summaries), with the reason in `degraded` — the same |
| 2057 | + honesty OWN052 gives the checking path.""" |
| 2058 | + raw_fns = facts.get("functions", []) |
| 2059 | + raw_fns = raw_fns if isinstance(raw_fns, list) else [] |
| 2060 | + degraded: str | None = None |
| 2061 | + summaries: dict[str, Any] = {} |
| 2062 | + unresolved: list[str] = [] |
| 2063 | + try: |
| 2064 | + summaries, unresolved = solve_with_log(_build_skeletons(raw_fns)) |
| 2065 | + except Exception as exc: |
| 2066 | + degraded = f"{type(exc).__name__}: {exc}" |
| 2067 | + return { |
| 2068 | + "module": str(facts.get("module", "?")), |
| 2069 | + "ownir_version": OWNIR_VERSION, |
| 2070 | + "summaries": [summaries[k].to_dict() for k in sorted(summaries)], |
| 2071 | + "unresolved": unresolved, |
| 2072 | + "degraded": degraded, |
| 2073 | + } |
| 2074 | + |
| 2075 | + |
2030 | 2076 | def check_facts(facts: dict[str, Any]) -> list[Finding]: |
2031 | 2077 | """Run the core checker over the lowered facts and return findings mapped |
2032 | 2078 | back to their original C# locations (v0: the `event += without -=` leak). |
|
0 commit comments