|
| 1 | +{ |
| 2 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 3 | + "$id": "https://physshell.dev/spec/ownir.schema.json", |
| 4 | + "title": "OwnIR", |
| 5 | + "description": "The OwnIR fact contract: the JSON seam between a language frontend (Roslyn C# extractor, OwnTS, hand-written fixtures) and the OwnLang core. Normative prose lives in spec/OwnIR.md; the Python validator is ownlang/ownir.py::load(). This schema is the single source both the Python core and the Rust `own-ir` crate are checked against — the enums here are pinned to the code's authoritative sets by tests/test_ownir.py (no jsonschema dependency), so schema and code cannot drift.", |
| 6 | + "type": "object", |
| 7 | + "required": ["ownir_version", "module"], |
| 8 | + "properties": { |
| 9 | + "ownir_version": { |
| 10 | + "description": "OwnIR fact-vocabulary version. Every producer stamps the same integer (OWNIR_VERSION in ownlang/ownir.py); a document whose version differs from the core's is rejected at load (spec/OwnIR.md IR1/IR2). An absent field is read as the current version by the core, but this schema requires it.", |
| 11 | + "const": 0 |
| 12 | + }, |
| 13 | + "module": { |
| 14 | + "description": "The extracted module/assembly name.", |
| 15 | + "type": "string" |
| 16 | + }, |
| 17 | + "components": { |
| 18 | + "description": "Owned-resource records grouped by the component (class) that owns them (spec/OwnIR.md §4).", |
| 19 | + "type": "array", |
| 20 | + "items": { "$ref": "#/$defs/component" } |
| 21 | + }, |
| 22 | + "functions": { |
| 23 | + "description": "Per-method intra-procedural flow bodies — the CFG facts the core lowers to acquire/use/release (spec/OwnIR.md §5).", |
| 24 | + "type": "array", |
| 25 | + "items": { "$ref": "#/$defs/function" } |
| 26 | + }, |
| 27 | + "services": { |
| 28 | + "description": "The DI registration graph feeding the DI001 captive-dependency check (spec/OwnIR.md §6).", |
| 29 | + "type": "array", |
| 30 | + "items": { "$ref": "#/$defs/service" } |
| 31 | + }, |
| 32 | + "effects": { |
| 33 | + "description": "The reactive-effect graph feeding the EFF001 effect-storm check (spec/OwnIR.md §7).", |
| 34 | + "type": "array", |
| 35 | + "items": { "$ref": "#/$defs/effect" } |
| 36 | + } |
| 37 | + }, |
| 38 | + "$defs": { |
| 39 | + "resourceKind": { |
| 40 | + "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.", |
| 41 | + "type": "string", |
| 42 | + "enum": [ |
| 43 | + "subscription", |
| 44 | + "subscribe", |
| 45 | + "timer", |
| 46 | + "disposable", |
| 47 | + "local-disposable", |
| 48 | + "pool", |
| 49 | + "capture", |
| 50 | + "unresolved-subscription" |
| 51 | + ] |
| 52 | + }, |
| 53 | + "diLifetime": { |
| 54 | + "description": "A DI registration lifetime (spec/OwnIR.md §6). Pinned to ownlang/di.py::LIFETIMES.", |
| 55 | + "type": "string", |
| 56 | + "enum": ["singleton", "scoped", "transient"] |
| 57 | + }, |
| 58 | + "paramEffect": { |
| 59 | + "description": "A parameter's ownership effect in a method contract (P-006/2b). Pinned to the enum in ownlang/ownir.py::load().", |
| 60 | + "type": "string", |
| 61 | + "enum": ["consume", "borrow", "borrow_mut", "plain"] |
| 62 | + }, |
| 63 | + "site": { |
| 64 | + "description": "A {type, file, line} call-site record (DI004/DI005 metadata).", |
| 65 | + "type": "object", |
| 66 | + "required": ["type", "file", "line"], |
| 67 | + "properties": { |
| 68 | + "type": { "type": "string" }, |
| 69 | + "file": { "type": "string" }, |
| 70 | + "line": { "type": "integer" } |
| 71 | + } |
| 72 | + }, |
| 73 | + "component": { |
| 74 | + "type": "object", |
| 75 | + "properties": { |
| 76 | + "name": { "type": "string" }, |
| 77 | + "file": { "type": "string" }, |
| 78 | + "subscriptions": { |
| 79 | + "description": "The component's owned-resource records (historically keyed `subscriptions`).", |
| 80 | + "type": "array", |
| 81 | + "items": { "$ref": "#/$defs/resourceRecord" } |
| 82 | + } |
| 83 | + } |
| 84 | + }, |
| 85 | + "resourceRecord": { |
| 86 | + "description": "One owned-resource record (spec/OwnIR.md §4). An unreleased record is OWN001 at `line`; a released one nets balanced and stays silent.", |
| 87 | + "type": "object", |
| 88 | + "properties": { |
| 89 | + "line": { "type": "integer" }, |
| 90 | + "event": { |
| 91 | + "description": "The event/handle identifier for this owned resource (e.g. `bus.CustomerChanged`, `_timer.Tick`); carried into the finding message and rendered output.", |
| 92 | + "type": "string" |
| 93 | + }, |
| 94 | + "handler": { |
| 95 | + "description": "The subscribing handler's name (e.g. `OnCustomerChanged`); may be empty for a tokenless subscribe/capture.", |
| 96 | + "type": "string" |
| 97 | + }, |
| 98 | + "lambda": { |
| 99 | + "description": "Whether the handler is an inline lambda — no `-=` handle exists to detach it, so the subscription can never be released.", |
| 100 | + "type": "boolean" |
| 101 | + }, |
| 102 | + "released": { |
| 103 | + "description": "Whether a matching release (`-=`, Dispose, Stop, Return) was found.", |
| 104 | + "type": "boolean" |
| 105 | + }, |
| 106 | + "resource": { "$ref": "#/$defs/resourceKind" }, |
| 107 | + "type": { |
| 108 | + "description": "The concrete resource type (optional, additive — an older core reads the record without it). Explicit null is accepted and preserved (ownlang/ownir.py::load only rejects a non-null non-string), so it maps to Option<String> in the Rust `own-ir` types.", |
| 109 | + "type": ["string", "null"] |
| 110 | + }, |
| 111 | + "source": { |
| 112 | + "description": "Lifetime tier of a subscription/subscribe/capture source: self (silent cycle), injected (OWN001 warning, may escalate via §6), or static/external/unknown (leak).", |
| 113 | + "type": ["string", "null"] |
| 114 | + }, |
| 115 | + "source_type": { |
| 116 | + "description": "The declared type of an injected event source, cross-referenced against `services` to derive its DI lifetime/region (P-006 + P-004). Additive/optional. Explicit null is accepted and preserved (Option<String>).", |
| 117 | + "type": ["string", "null"] |
| 118 | + } |
| 119 | + } |
| 120 | + }, |
| 121 | + "function": { |
| 122 | + "type": "object", |
| 123 | + "properties": { |
| 124 | + "name": { "type": "string" }, |
| 125 | + "file": { "type": "string" }, |
| 126 | + "params": { |
| 127 | + "description": "The method's ownership contract: its parameters and their effects (P-006/2b). Optional — an omitted contract is inferred from the body.", |
| 128 | + "type": "array", |
| 129 | + "items": { "$ref": "#/$defs/param" } |
| 130 | + }, |
| 131 | + "body": { |
| 132 | + "description": "An ordered list of flow ops modelling the method's intra-procedural CFG.", |
| 133 | + "type": "array", |
| 134 | + "items": { "$ref": "#/$defs/flowOp" } |
| 135 | + } |
| 136 | + } |
| 137 | + }, |
| 138 | + "param": { |
| 139 | + "type": "object", |
| 140 | + "required": ["name"], |
| 141 | + "properties": { |
| 142 | + "name": { "type": "string" }, |
| 143 | + "line": { "type": "integer" }, |
| 144 | + "effect": { "$ref": "#/$defs/paramEffect" } |
| 145 | + } |
| 146 | + }, |
| 147 | + "flowOp": { |
| 148 | + "description": "One flow op (spec/OwnIR.md §5). The `op` discriminator is the complete vocabulary the lowerer (_lower_flow) handles; any other value is rejected at load (fail-loud). Pinned to the branch set in ownlang/ownir.py::_lower_flow.", |
| 149 | + "type": "object", |
| 150 | + "required": ["op"], |
| 151 | + "oneOf": [ |
| 152 | + { |
| 153 | + "title": "acquire", |
| 154 | + "description": "A new owned local (Let+Acquire); kind:\"pool\" tags it a pooled buffer.", |
| 155 | + "properties": { |
| 156 | + "op": { "const": "acquire" }, |
| 157 | + "line": { "type": "integer" }, |
| 158 | + "var": { "type": "string" }, |
| 159 | + "kind": { "type": "string", "enum": ["pool"] } |
| 160 | + }, |
| 161 | + "required": ["op", "var"] |
| 162 | + }, |
| 163 | + { |
| 164 | + "title": "release", |
| 165 | + "description": "Release of the local's handle.", |
| 166 | + "properties": { |
| 167 | + "op": { "const": "release" }, |
| 168 | + "line": { "type": "integer" }, |
| 169 | + "var": { "type": "string" } |
| 170 | + }, |
| 171 | + "required": ["op", "var"] |
| 172 | + }, |
| 173 | + { |
| 174 | + "title": "use", |
| 175 | + "description": "Use of the handle.", |
| 176 | + "properties": { |
| 177 | + "op": { "const": "use" }, |
| 178 | + "line": { "type": "integer" }, |
| 179 | + "var": { "type": "string" } |
| 180 | + }, |
| 181 | + "required": ["op", "var"] |
| 182 | + }, |
| 183 | + { |
| 184 | + "title": "overspan", |
| 185 | + "description": "Overspan (POOL005: a full-length view of a pooled buffer).", |
| 186 | + "properties": { |
| 187 | + "op": { "const": "overspan" }, |
| 188 | + "line": { "type": "integer" }, |
| 189 | + "var": { "type": "string" } |
| 190 | + }, |
| 191 | + "required": ["op", "var"] |
| 192 | + }, |
| 193 | + { |
| 194 | + "title": "return", |
| 195 | + "description": "Ownership transfer out; `var` optional (a bare return).", |
| 196 | + "properties": { |
| 197 | + "op": { "const": "return" }, |
| 198 | + "line": { "type": "integer" }, |
| 199 | + "var": { "type": "string" } |
| 200 | + }, |
| 201 | + "required": ["op"] |
| 202 | + }, |
| 203 | + { |
| 204 | + "title": "alias_join", |
| 205 | + "description": "A new owning handle joined to `src`'s alias set (wrap/adopt, D5.4).", |
| 206 | + "properties": { |
| 207 | + "op": { "const": "alias_join" }, |
| 208 | + "line": { "type": "integer" }, |
| 209 | + "var": { "type": "string" }, |
| 210 | + "src": { "type": "string" } |
| 211 | + }, |
| 212 | + "required": ["op", "var", "src"] |
| 213 | + }, |
| 214 | + { |
| 215 | + "title": "call", |
| 216 | + "description": "A Call checked against the callee's contract; a fresh-returning callee mints an acquire for `result` (D5.2).", |
| 217 | + "properties": { |
| 218 | + "op": { "const": "call" }, |
| 219 | + "line": { "type": "integer" }, |
| 220 | + "callee": { "type": "string" }, |
| 221 | + "args": { "type": "array", "items": { "type": "string" } }, |
| 222 | + "result": { "type": "string" } |
| 223 | + }, |
| 224 | + "required": ["op", "callee"] |
| 225 | + }, |
| 226 | + { |
| 227 | + "title": "if", |
| 228 | + "description": "An If with both branches lowered.", |
| 229 | + "properties": { |
| 230 | + "op": { "const": "if" }, |
| 231 | + "line": { "type": "integer" }, |
| 232 | + "then": { "type": "array", "items": { "$ref": "#/$defs/flowOp" } }, |
| 233 | + "else": { "type": "array", "items": { "$ref": "#/$defs/flowOp" } } |
| 234 | + }, |
| 235 | + "required": ["op"] |
| 236 | + }, |
| 237 | + { |
| 238 | + "title": "while", |
| 239 | + "description": "A While — a back-edge the core's worklist fixpoint converges over (A1).", |
| 240 | + "properties": { |
| 241 | + "op": { "const": "while" }, |
| 242 | + "line": { "type": "integer" }, |
| 243 | + "body": { "type": "array", "items": { "$ref": "#/$defs/flowOp" } } |
| 244 | + }, |
| 245 | + "required": ["op"] |
| 246 | + } |
| 247 | + ] |
| 248 | + }, |
| 249 | + "service": { |
| 250 | + "type": "object", |
| 251 | + "required": ["name", "lifetime"], |
| 252 | + "properties": { |
| 253 | + "name": { "type": "string", "minLength": 1 }, |
| 254 | + "lifetime": { "$ref": "#/$defs/diLifetime" }, |
| 255 | + "deps": { "type": "array", "items": { "type": "string" } }, |
| 256 | + "weak_deps": { "type": "array", "items": { "type": "string" } }, |
| 257 | + "root_resolves": { "type": "array", "items": { "type": "string" } }, |
| 258 | + "file": { "type": "string" }, |
| 259 | + "line": { "type": "integer" }, |
| 260 | + "ctor_file": { "type": "string" }, |
| 261 | + "ctor_line": { "type": "integer" }, |
| 262 | + "ctor_type": { "type": "string" }, |
| 263 | + "root_resolve_sites": { "type": "array", "items": { "$ref": "#/$defs/site" } }, |
| 264 | + "scope_cached": { "type": "array", "items": { "type": "string" } }, |
| 265 | + "scope_cache_sites": { "type": "array", "items": { "$ref": "#/$defs/site" } } |
| 266 | + } |
| 267 | + }, |
| 268 | + "effect": { |
| 269 | + "type": "object", |
| 270 | + "properties": { |
| 271 | + "io": { |
| 272 | + "description": "Whether the effect performs I/O (default false).", |
| 273 | + "type": "boolean" |
| 274 | + }, |
| 275 | + "line": { "type": "integer" }, |
| 276 | + "deps": { |
| 277 | + "description": "The effect's dependency-array names.", |
| 278 | + "type": "array", |
| 279 | + "items": { "type": "string" } |
| 280 | + }, |
| 281 | + "bindings": { |
| 282 | + "description": "The render-scope binding table; the core decides identity stability, not the frontend.", |
| 283 | + "type": "array", |
| 284 | + "items": { "$ref": "#/$defs/binding" } |
| 285 | + } |
| 286 | + } |
| 287 | + }, |
| 288 | + "binding": { |
| 289 | + "type": "object", |
| 290 | + "properties": { |
| 291 | + "name": { "type": "string" }, |
| 292 | + "init": { |
| 293 | + "description": "How the binding is initialised (e.g. useState, useMemo); default \"unknown\".", |
| 294 | + "type": "string" |
| 295 | + }, |
| 296 | + "refs": { "type": "array", "items": { "type": "string" } }, |
| 297 | + "line": { "type": "integer" } |
| 298 | + } |
| 299 | + } |
| 300 | + } |
| 301 | +} |
0 commit comments