Skip to content

Commit 9f909c7

Browse files
committed
fix(ownir): put the limits in the JSON schema, and stop overclaiming in §4.2
Two review findings on bc8790c, both real, one with a wrong consequence attached. **The schema had to carry the bounds too.** `spec/ownir.schema.json` is what a NON-Python consumer validates against. With the bounds only in `load()`, a producer could be schema-valid and still refused at the door — the same cross-consumer mismatch this change exists to remove, one layer further out. Added `$defs.sourceLine` (signed-64) and a `maximum` on `sourceColumn`, and rebound all 21 inline `"line": {"type": "integer"}` fields to it. The test now asserts the schema's four numbers against the same literals as the code, so the two cannot drift. Mutation-proved both ways: widening `sourceLine.maximum` to `2^64-1` and dropping `sourceColumn.maximum` are each caught. **§4.2 said "every `line`" and two line-bearing fields escaped it.** The finding is right that the sentence overclaimed. Its stated consequence — that this "preserves the Python/port divergence" — is not: measured, both implementations accept those fields, because neither types them. python subscription line 2^80 : ACCEPT rust: ACCEPT python subscription line "x" : ACCEPT rust: ACCEPT python flow op line 2^80 : ACCEPT rust: ACCEPT python flow op line "x" : ACCEPT rust: ACCEPT `components[].subscriptions[].line` and the `line` on a flow op inside `functions[].body` are checked NOWHERE by `load()` — not for range, and not even for type. #325's validator has no check for them either (grep `"line"` in strict.rs: services, effects, bindings, params, sites — not these two). So this is not a parity gap, and closing it is not part of removing one. It is a separate contract question: whether a coordinate no rule reads should nevertheless have to be well-formed. Extending the check would be a new restriction on documents accepted today, arriving inside a PR whose job is to close a measured divergence — so §4.2 now enumerates exactly the fields it enforces, marks the word "validated" as load-bearing, and records the two exceptions with the measurement instead of quietly widening or quietly overclaiming. Corpus scan for the record: 150 JSON files, zero offenders on either path, so extending it later would break nothing in the tree. Refs #250, #259. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CJF7MBi1ijU5m9cJVWgQsM
1 parent bc8790c commit 9f909c7

3 files changed

Lines changed: 66 additions & 25 deletions

File tree

‎spec/OwnIR.md‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,23 @@ of whichever consumer reads it first.
182182

183183
**Source-coordinate integers fit a signed 64-bit integer.**
184184

185-
- every `line` — on services, `ctor_line`, `root_resolve_sites[]`,
186-
`scope_cache_sites[]`, effects, bindings, params, and protocol events — lies
187-
in `[-2^63, 2^63 - 1]`;
185+
- every **validated** `line` — `services[].line`, `services[].ctor_line`,
186+
`services[].root_resolve_sites[].line`, `services[].scope_cache_sites[].line`,
187+
`effects[].line`, `effects[].bindings[].line`, `functions[].params[].line`,
188+
`protocol_functions[].events[].line` — lies in `[-2^63, 2^63 - 1]`;
188189
- every `column` (§4.1) is `1..=2^63 - 1`, or absent, or `null`.
189190

191+
The word *validated* is load-bearing, and the exception is recorded rather than
192+
papered over. Two line-bearing fields are checked **nowhere** by `load()` — not
193+
for range, and not even for type: `components[].subscriptions[].line` and the
194+
`line` on a flow op inside `functions[].body`. Measured, `{"line": "x"}` and
195+
`{"line": true}` are accepted on both. That predates this section, and both
196+
implementations agree about it — neither the reference nor the Rust port types
197+
those fields — so it is **not** a parity gap and closing it is not part of
198+
removing one. It is a separate contract question: whether a coordinate that no
199+
rule reads should nevertheless be well-formed. Until it is answered, the bound
200+
above claims exactly the fields it covers.
201+
190202
Python integers are unbounded, so the reference accepted coordinates no other
191203
consumer could represent. That is not a generosity worth keeping: a coordinate
192204
nothing downstream can hold is not a usable coordinate, and leaving it legal

‎spec/ownir.schema.json‎

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@
4949
"sourceColumn": {
5050
"description": "1-based source column of the SAME node `line` anchors on. Optional and additive, so OWNIR_VERSION stays 0 (spec/OwnIR.md §2): a producer that does not report one omits it and no consumer substitutes a value — not 0, not 1, and never recovered by re-reading the source line. Rides to SARIF as region.startColumn, where the OwnAudit occurrence anchor reads it (Own.NET#317).",
5151
"type": "integer",
52-
"minimum": 1
52+
"minimum": 1,
53+
"maximum": 9223372036854775807
54+
},
55+
"sourceLine": {
56+
"description": "A source line. Bounded to a signed 64-bit integer (spec/OwnIR.md \u00a74.2): Python integers are unbounded and the reference used to accept coordinates no other consumer could represent, which made the vocabulary implementable only in a language with bignums. A coordinate nothing downstream can hold is not a usable coordinate. Pinned to ownlang/obligations.py::INT64_MIN/INT64_MAX.",
57+
"type": "integer",
58+
"minimum": -9223372036854775808,
59+
"maximum": 9223372036854775807
5360
},
5461
"resourceKind": {
5562
"description": "The resource-kind discriminator (spec/OwnIR.md §4). It selects the analysis path, so a present-but-unknown value is rejected at load (fail-loud) and a new kind must bump OWNIR_VERSION. Pinned to ownlang/ownir.py::_KNOWN_RESOURCE_KINDS.",
@@ -82,7 +89,7 @@
8289
"properties": {
8390
"type": { "type": "string" },
8491
"file": { "type": "string" },
85-
"line": { "type": "integer" }
92+
"line": { "$ref": "#/$defs/sourceLine" }
8693
}
8794
},
8895
"component": {
@@ -101,7 +108,7 @@
101108
"description": "One owned-resource record (spec/OwnIR.md §4). An unreleased record is OWN001 at `line`; a released one nets balanced and stays silent.",
102109
"type": "object",
103110
"properties": {
104-
"line": { "type": "integer" },
111+
"line": { "$ref": "#/$defs/sourceLine" },
105112
"column": { "$ref": "#/$defs/sourceColumn" },
106113
"event": {
107114
"description": "The event/handle identifier for this owned resource (e.g. `bus.CustomerChanged`, `_timer.Tick`); carried into the finding message and rendered output.",
@@ -168,7 +175,7 @@
168175
"required": ["name"],
169176
"properties": {
170177
"name": { "type": "string" },
171-
"line": { "type": "integer" },
178+
"line": { "$ref": "#/$defs/sourceLine" },
172179
"column": { "$ref": "#/$defs/sourceColumn" },
173180
"effect": { "$ref": "#/$defs/paramEffect" }
174181
}
@@ -183,7 +190,7 @@
183190
"description": "A new owned local (Let+Acquire); kind:\"pool\" tags it a pooled buffer.",
184191
"properties": {
185192
"op": { "const": "acquire" },
186-
"line": { "type": "integer" },
193+
"line": { "$ref": "#/$defs/sourceLine" },
187194
"column": { "$ref": "#/$defs/sourceColumn" },
188195
"var": { "type": "string" },
189196
"kind": { "type": "string", "enum": ["pool"] }
@@ -195,7 +202,7 @@
195202
"description": "Release of the local's handle.",
196203
"properties": {
197204
"op": { "const": "release" },
198-
"line": { "type": "integer" },
205+
"line": { "$ref": "#/$defs/sourceLine" },
199206
"column": { "$ref": "#/$defs/sourceColumn" },
200207
"var": { "type": "string" }
201208
},
@@ -206,7 +213,7 @@
206213
"description": "Use of the handle.",
207214
"properties": {
208215
"op": { "const": "use" },
209-
"line": { "type": "integer" },
216+
"line": { "$ref": "#/$defs/sourceLine" },
210217
"column": { "$ref": "#/$defs/sourceColumn" },
211218
"var": { "type": "string" }
212219
},
@@ -217,7 +224,7 @@
217224
"description": "Overspan (POOL005: a full-length view of a pooled buffer).",
218225
"properties": {
219226
"op": { "const": "overspan" },
220-
"line": { "type": "integer" },
227+
"line": { "$ref": "#/$defs/sourceLine" },
221228
"column": { "$ref": "#/$defs/sourceColumn" },
222229
"var": { "type": "string" }
223230
},
@@ -228,7 +235,7 @@
228235
"description": "Ownership transfer out; `var` optional (a bare return).",
229236
"properties": {
230237
"op": { "const": "return" },
231-
"line": { "type": "integer" },
238+
"line": { "$ref": "#/$defs/sourceLine" },
232239
"column": { "$ref": "#/$defs/sourceColumn" },
233240
"var": { "type": "string" }
234241
},
@@ -239,7 +246,7 @@
239246
"description": "A new owning handle joined to `src`'s alias set (wrap/adopt, D5.4).",
240247
"properties": {
241248
"op": { "const": "alias_join" },
242-
"line": { "type": "integer" },
249+
"line": { "$ref": "#/$defs/sourceLine" },
243250
"column": { "$ref": "#/$defs/sourceColumn" },
244251
"var": { "type": "string" },
245252
"src": { "type": "string" }
@@ -251,7 +258,7 @@
251258
"description": "A Call checked against the callee's contract; a fresh-returning callee mints an acquire for `result` (D5.2). An optional `sig` (the callee's canonical parameter-type list, same format as a function record's `sig`) resolves the call against that overload's own summary; absent or unmatched, the name-merged summary applies (stage 2 fallback — degraded, never a wrong overload).",
252259
"properties": {
253260
"op": { "const": "call" },
254-
"line": { "type": "integer" },
261+
"line": { "$ref": "#/$defs/sourceLine" },
255262
"column": { "$ref": "#/$defs/sourceColumn" },
256263
"callee": { "type": "string" },
257264
"sig": { "type": "string" },
@@ -265,7 +272,7 @@
265272
"description": "An If with both branches lowered.",
266273
"properties": {
267274
"op": { "const": "if" },
268-
"line": { "type": "integer" },
275+
"line": { "$ref": "#/$defs/sourceLine" },
269276
"column": { "$ref": "#/$defs/sourceColumn" },
270277
"then": { "type": "array", "items": { "$ref": "#/$defs/flowOp" } },
271278
"else": { "type": "array", "items": { "$ref": "#/$defs/flowOp" } }
@@ -277,7 +284,7 @@
277284
"description": "A While — a back-edge the core's worklist fixpoint converges over (A1).",
278285
"properties": {
279286
"op": { "const": "while" },
280-
"line": { "type": "integer" },
287+
"line": { "$ref": "#/$defs/sourceLine" },
281288
"column": { "$ref": "#/$defs/sourceColumn" },
282289
"body": { "type": "array", "items": { "$ref": "#/$defs/flowOp" } }
283290
},
@@ -295,7 +302,7 @@
295302
"weak_deps": { "type": "array", "items": { "type": "string" } },
296303
"root_resolves": { "type": "array", "items": { "type": "string" } },
297304
"file": { "type": "string" },
298-
"line": { "type": "integer" },
305+
"line": { "$ref": "#/$defs/sourceLine" },
299306
"ctor_file": { "type": "string" },
300307
"ctor_line": { "type": "integer" },
301308
"ctor_type": { "type": "string" },
@@ -311,7 +318,7 @@
311318
"description": "Whether the effect performs I/O (default false).",
312319
"type": "boolean"
313320
},
314-
"line": { "type": "integer" },
321+
"line": { "$ref": "#/$defs/sourceLine" },
315322
"deps": {
316323
"description": "The effect's dependency-array names.",
317324
"type": "array",
@@ -333,7 +340,7 @@
333340
"type": "string"
334341
},
335342
"refs": { "type": "array", "items": { "type": "string" } },
336-
"line": { "type": "integer" }
343+
"line": { "$ref": "#/$defs/sourceLine" }
337344
}
338345
},
339346
"protocolMatcher": {
@@ -420,7 +427,7 @@
420427
"ev": { "const": "assign" },
421428
"target": { "type": "string", "minLength": 1 },
422429
"value": { "type": ["boolean", "null"] },
423-
"line": { "type": "integer" }
430+
"line": { "$ref": "#/$defs/sourceLine" }
424431
},
425432
"required": ["ev", "target"]
426433
},
@@ -431,7 +438,7 @@
431438
"ev": { "const": "call" },
432439
"callee": { "type": "string", "minLength": 1 },
433440
"arg": { "type": ["string", "null"] },
434-
"line": { "type": "integer" }
441+
"line": { "$ref": "#/$defs/sourceLine" }
435442
},
436443
"required": ["ev", "callee"]
437444
},
@@ -440,7 +447,7 @@
440447
"description": "A normal method exit.",
441448
"properties": {
442449
"ev": { "const": "return" },
443-
"line": { "type": "integer" }
450+
"line": { "$ref": "#/$defs/sourceLine" }
444451
},
445452
"required": ["ev"]
446453
},
@@ -449,7 +456,7 @@
449456
"description": "An exceptional method exit. Frontends thread finally bodies onto exits, like the flow lowering (§5).",
450457
"properties": {
451458
"ev": { "const": "throw" },
452-
"line": { "type": "integer" }
459+
"line": { "$ref": "#/$defs/sourceLine" }
453460
},
454461
"required": ["ev"]
455462
},
@@ -458,7 +465,7 @@
458465
"description": "A branch with both arms lowered.",
459466
"properties": {
460467
"ev": { "const": "if" },
461-
"line": { "type": "integer" },
468+
"line": { "$ref": "#/$defs/sourceLine" },
462469
"then": { "type": "array", "items": { "$ref": "#/$defs/protocolEvent" } },
463470
"else": { "type": "array", "items": { "$ref": "#/$defs/protocolEvent" } }
464471
},
@@ -469,7 +476,7 @@
469476
"description": "A loop; the checker solves the body to a local fixpoint.",
470477
"properties": {
471478
"ev": { "const": "while" },
472-
"line": { "type": "integer" },
479+
"line": { "$ref": "#/$defs/sourceLine" },
473480
"body": { "type": "array", "items": { "$ref": "#/$defs/protocolEvent" } }
474481
},
475482
"required": ["ev"]

‎tests/test_ownir_defensive_limits.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,28 @@ def run() -> int:
159159
f"Changing a defensive limit is a contract change: update the "
160160
f"spec, this literal, and the Rust side together")
161161

162+
# ---- the JSON schema carries the same numbers -------------------------
163+
# `spec/ownir.schema.json` is the contract a NON-Python consumer validates
164+
# against. If the bounds live only in `load()`, a producer can be schema-
165+
# valid and still refused at the door — which is the same cross-consumer
166+
# mismatch this change exists to remove, one layer out.
167+
schema_path = os.path.join(
168+
os.path.dirname(__file__), "..", "spec", "ownir.schema.json")
169+
with open(schema_path, encoding="utf-8") as f:
170+
defs = json.load(f)["$defs"]
171+
for name, key, expected in (
172+
("sourceLine", "minimum", SPEC_INT64_MIN),
173+
("sourceLine", "maximum", SPEC_INT64_MAX),
174+
("sourceColumn", "minimum", 1),
175+
("sourceColumn", "maximum", SPEC_INT64_MAX),
176+
):
177+
actual = defs.get(name, {}).get(key)
178+
if actual != expected:
179+
failures += _fail(
180+
f"spec/ownir.schema.json $defs.{name}.{key} is {actual!r}, "
181+
f"expected {expected} — the schema and `load()` must state the "
182+
f"same bound or a producer can satisfy one and fail the other")
183+
162184
# ---- line: the full signed-64 range, and one step outside each end -----
163185
for label, build in LINE_PATHS:
164186
for value, expect_reject in ((INT64_MIN, False), (0, False),

0 commit comments

Comments
 (0)