Implement nearest-loop transfers and reachable binding analysis
This commit is contained in:
1 parent
095eef1370
commit
69c5dc8d20
40 files changed
+953
-110
No files matched your search
@@ -222,3 +222,7 @@ When that work ships (target `3.1.x`), it must use a new protocol version
|
||||
source digest and the exact Analysis bytes digest; it must not rewrite v2 `units[]`.
|
||||
Consumers that only know v2 must keep passing the existing schema/version contract,
|
||||
and must reject an unknown sidecar/v3 version rather than silently ignoring it.
|
||||
|
||||
Projects containing structured loop transfers use [Analysis v3](analysis-v3.md).
|
||||
A v2 projection never contains those transfer statements. Multiple conditional
|
||||
arms use the existing ordered `branch.arms` array.
|
||||
@@ -0,0 +1,27 @@
|
||||
# Marqdo Analysis v3
|
||||
|
||||
Analysis v3 extends the public [Analysis v2](analysis-v2.md) contract with
|
||||
structured loop control. Its envelope keeps `schema: "marqdo.analysis"` and
|
||||
sets `schema_version: 3`. The writer emits v3 if any emitted function body
|
||||
contains either new statement, including inside a nested body or an imported
|
||||
module. Other projects still emit v2. Multi-arm branches fit both versions.
|
||||
|
||||
## Statement additions
|
||||
|
||||
```json
|
||||
{"kind": "break", "span": {"start": 30, "end": 37}}
|
||||
{"kind": "continue", "span": {"start": 39, "end": 49}}
|
||||
```
|
||||
|
||||
Both spans are half-open UTF-8 byte ranges covering the carrier in the
|
||||
containing module. Walk the enclosing statement bodies to find the nearest
|
||||
loop. `break` transfers to the statement after that loop. `continue`
|
||||
transfers to its condition. There are no operands, labels or call edges.
|
||||
Call and resource projections retain their v2 shapes.
|
||||
|
||||
Consumers check the major version before traversing any function body. A v2
|
||||
reader rejects v3, while a reader that accepts both versions can share its
|
||||
v2 decoding and add two statement kinds. Trace v2 binds to the version
|
||||
automatically emitted for the same input via `source.analysis_digest`.
|
||||
|
||||
JSON Schema: [analysis-v3.schema.json](schemas/analysis-v3.schema.json).
|
||||
@@ -0,0 +1,376 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://marqdo.dev/schemas/analysis-v3.schema.json",
|
||||
"title": "Marqdo Analysis v3",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"schema",
|
||||
"schema_version",
|
||||
"producer",
|
||||
"project",
|
||||
"modules",
|
||||
"diagnostics"
|
||||
],
|
||||
"properties": {
|
||||
"schema": {
|
||||
"const": "marqdo.analysis"
|
||||
},
|
||||
"schema_version": {
|
||||
"const": 3
|
||||
},
|
||||
"producer": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name",
|
||||
"version",
|
||||
"markdown_profile"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"version": {
|
||||
"type": "string"
|
||||
},
|
||||
"markdown_profile": {
|
||||
"const": "marqdo.md.v1"
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
},
|
||||
"project": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"root_id",
|
||||
"identity_kind",
|
||||
"lock_digest"
|
||||
],
|
||||
"properties": {
|
||||
"root_id": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"pattern": "^(root:|sha256:[0-9a-f]{64}$)"
|
||||
},
|
||||
"identity_kind": {
|
||||
"enum": [
|
||||
"manifest",
|
||||
"workspace_snapshot"
|
||||
]
|
||||
},
|
||||
"lock_digest": {
|
||||
"type": "string",
|
||||
"pattern": "^(sha256:[0-9a-f]{64})?$"
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
},
|
||||
"modules": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"package_instance_id",
|
||||
"relative_path",
|
||||
"source_digest",
|
||||
"units",
|
||||
"functions",
|
||||
"imports",
|
||||
"references",
|
||||
"calls",
|
||||
"resources"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"pattern": "::"
|
||||
},
|
||||
"package_instance_id": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"relative_path": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"pattern": "^(?!/)(?!.*\\.\\.)"
|
||||
},
|
||||
"source_digest": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9a-f]{64}$"
|
||||
},
|
||||
"units": {
|
||||
"type": "array"
|
||||
},
|
||||
"functions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"body"
|
||||
],
|
||||
"properties": {
|
||||
"body": {
|
||||
"$ref": "#/$defs/body"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"imports": {
|
||||
"type": "array"
|
||||
},
|
||||
"references": {
|
||||
"type": "array"
|
||||
},
|
||||
"calls": {
|
||||
"type": "array"
|
||||
},
|
||||
"resources": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"module_id",
|
||||
"unit_id",
|
||||
"kind",
|
||||
"span",
|
||||
"content_digest"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"pattern": "#resource:(formula|code)-[0-9]+$"
|
||||
},
|
||||
"module_id": {
|
||||
"type": "string",
|
||||
"pattern": "::"
|
||||
},
|
||||
"unit_id": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"kind": {
|
||||
"enum": [
|
||||
"formula",
|
||||
"code"
|
||||
]
|
||||
},
|
||||
"span": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"start",
|
||||
"end"
|
||||
],
|
||||
"properties": {
|
||||
"start": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"end": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
},
|
||||
"content_digest": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9a-f]{64}$"
|
||||
},
|
||||
"language": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"display": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"diagnostics": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"module",
|
||||
"relative_path",
|
||||
"severity",
|
||||
"code",
|
||||
"message"
|
||||
],
|
||||
"properties": {
|
||||
"module": {
|
||||
"type": "string",
|
||||
"pattern": "::"
|
||||
},
|
||||
"relative_path": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"span": {
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
],
|
||||
"required": [
|
||||
"start",
|
||||
"end"
|
||||
],
|
||||
"properties": {
|
||||
"start": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"end": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"line": {
|
||||
"type": [
|
||||
"integer",
|
||||
"null"
|
||||
],
|
||||
"minimum": 1
|
||||
},
|
||||
"column": {
|
||||
"type": [
|
||||
"integer",
|
||||
"null"
|
||||
],
|
||||
"minimum": 1
|
||||
},
|
||||
"severity": {
|
||||
"enum": [
|
||||
"error",
|
||||
"warning"
|
||||
]
|
||||
},
|
||||
"code": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"hints": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": true,
|
||||
"$defs": {
|
||||
"body": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/$defs/statement"
|
||||
}
|
||||
},
|
||||
"span": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"start",
|
||||
"end"
|
||||
],
|
||||
"properties": {
|
||||
"start": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"end": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"statement": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kind",
|
||||
"span"
|
||||
],
|
||||
"properties": {
|
||||
"kind": {
|
||||
"enum": [
|
||||
"assign",
|
||||
"expression",
|
||||
"branch",
|
||||
"loop",
|
||||
"return",
|
||||
"break",
|
||||
"continue"
|
||||
]
|
||||
},
|
||||
"span": {
|
||||
"$ref": "#/$defs/span"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"kind": {
|
||||
"const": "loop"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"required": [
|
||||
"body"
|
||||
],
|
||||
"properties": {
|
||||
"body": {
|
||||
"$ref": "#/$defs/body"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"kind": {
|
||||
"const": "branch"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"required": [
|
||||
"arms"
|
||||
],
|
||||
"properties": {
|
||||
"arms": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"body"
|
||||
],
|
||||
"properties": {
|
||||
"body": {
|
||||
"$ref": "#/$defs/body"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user