pycforge 0.15.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycforge/__init__.py +8 -0
- pycforge/__main__.py +2 -0
- pycforge/_version.py +1 -0
- pycforge/converter/__init__.py +0 -0
- pycforge/converter/analysis/__init__.py +5 -0
- pycforge/converter/analysis/functions.py +723 -0
- pycforge/converter/analysis/model.py +158 -0
- pycforge/converter/analysis/planning.py +464 -0
- pycforge/converter/analysis/stage.py +1976 -0
- pycforge/converter/analysis/symbols.py +237 -0
- pycforge/converter/analysis/validation.py +2166 -0
- pycforge/converter/c_output/__init__.py +2 -0
- pycforge/converter/c_output/conformance.py +297 -0
- pycforge/converter/c_output/renderer.py +220 -0
- pycforge/converter/conditional_regions/__init__.py +71 -0
- pycforge/converter/conditional_regions/analysis.py +481 -0
- pycforge/converter/conditional_regions/lowering.py +579 -0
- pycforge/converter/conditional_regions/model.py +243 -0
- pycforge/converter/conditional_regions/validation.py +690 -0
- pycforge/converter/containers/__init__.py +19 -0
- pycforge/converter/containers/analysis.py +542 -0
- pycforge/converter/containers/lowering.py +290 -0
- pycforge/converter/containers/model.py +146 -0
- pycforge/converter/contracts/__init__.py +0 -0
- pycforge/converter/contracts/configuration.py +178 -0
- pycforge/converter/contracts/identifiers.py +68 -0
- pycforge/converter/contracts/versions.py +71 -0
- pycforge/converter/core/__init__.py +0 -0
- pycforge/converter/core/artifact_io.py +87 -0
- pycforge/converter/core/cancellation.py +7 -0
- pycforge/converter/core/canonicalization.py +254 -0
- pycforge/converter/core/context.py +13 -0
- pycforge/converter/core/diagnostics.py +95 -0
- pycforge/converter/core/enums.py +23 -0
- pycforge/converter/core/fingerprint.py +22 -0
- pycforge/converter/core/pipeline.py +8 -0
- pycforge/converter/core/progress.py +25 -0
- pycforge/converter/core/request.py +50 -0
- pycforge/converter/core/resource_policy.py +31 -0
- pycforge/converter/core/result.py +23 -0
- pycforge/converter/core/serialization.py +36 -0
- pycforge/converter/core/stage.py +10 -0
- pycforge/converter/core/stage_artifact.py +80 -0
- pycforge/converter/core/stage_outcome.py +15 -0
- pycforge/converter/decision_trace/__init__.py +0 -0
- pycforge/converter/decision_trace/recorder.py +52 -0
- pycforge/converter/facade.py +459 -0
- pycforge/converter/frontend/__init__.py +4 -0
- pycforge/converter/frontend/normalizer.py +59 -0
- pycforge/converter/frontend/parser.py +20 -0
- pycforge/converter/frontend/source_document.py +93 -0
- pycforge/converter/frontend/stages.py +518 -0
- pycforge/converter/frontend/validation.py +76 -0
- pycforge/converter/io/__init__.py +0 -0
- pycforge/converter/io/atomic_writer.py +33 -0
- pycforge/converter/ir/__init__.py +1 -0
- pycforge/converter/ir/c_ir/__init__.py +4 -0
- pycforge/converter/ir/c_ir/builder.py +26 -0
- pycforge/converter/ir/c_ir/model.py +318 -0
- pycforge/converter/ir/c_ir/serialization.py +88 -0
- pycforge/converter/ir/c_ir/validation.py +834 -0
- pycforge/converter/ir/python_ir/__init__.py +17 -0
- pycforge/converter/ir/python_ir/nodes.py +86 -0
- pycforge/converter/keyword_calls/__init__.py +68 -0
- pycforge/converter/keyword_calls/analysis.py +458 -0
- pycforge/converter/keyword_calls/lowering.py +271 -0
- pycforge/converter/keyword_calls/model.py +304 -0
- pycforge/converter/keyword_calls/validation.py +802 -0
- pycforge/converter/keyword_only_calls/__init__.py +68 -0
- pycforge/converter/keyword_only_calls/analysis.py +640 -0
- pycforge/converter/keyword_only_calls/lowering.py +376 -0
- pycforge/converter/keyword_only_calls/model.py +328 -0
- pycforge/converter/keyword_only_calls/validation.py +1357 -0
- pycforge/converter/lowering.py +1000 -0
- pycforge/converter/modules/__init__.py +13 -0
- pycforge/converter/modules/analysis.py +1250 -0
- pycforge/converter/modules/lowering.py +200 -0
- pycforge/converter/modules/model.py +73 -0
- pycforge/converter/modules/stage.py +192 -0
- pycforge/converter/numeric_semantics/__init__.py +23 -0
- pycforge/converter/numeric_semantics/analysis.py +420 -0
- pycforge/converter/numeric_semantics/lowering.py +153 -0
- pycforge/converter/numeric_semantics/model.py +123 -0
- pycforge/converter/records/__init__.py +34 -0
- pycforge/converter/records/analysis.py +1394 -0
- pycforge/converter/records/lowering.py +393 -0
- pycforge/converter/records/model.py +319 -0
- pycforge/converter/rules/__init__.py +3 -0
- pycforge/converter/support_templates/__init__.py +49 -0
- pycforge/converter/support_templates/assembly.py +106 -0
- pycforge/converter/support_templates/factories.py +348 -0
- pycforge/converter/support_templates/model.py +159 -0
- pycforge/converter/support_templates/registry.py +388 -0
- pycforge/converter/telemetry/__init__.py +0 -0
- pycforge/converter/telemetry/sink.py +39 -0
- pycforge/ide/__init__.py +19 -0
- pycforge/ide/__main__.py +5 -0
- pycforge/ide/_worker_event_codec.py +276 -0
- pycforge/ide/_worker_protocol_json.py +197 -0
- pycforge/ide/_worker_protocol_types.py +90 -0
- pycforge/ide/_worker_request_codec.py +200 -0
- pycforge/ide/_worker_request_data.py +260 -0
- pycforge/ide/_worker_result_data.py +343 -0
- pycforge/ide/action_contract.py +469 -0
- pycforge/ide/action_validation.py +229 -0
- pycforge/ide/command_palette.py +223 -0
- pycforge/ide/controller.py +904 -0
- pycforge/ide/controller_conversion.py +546 -0
- pycforge/ide/controller_io.py +205 -0
- pycforge/ide/editor.py +951 -0
- pycforge/ide/editor_commands_qt.py +274 -0
- pycforge/ide/editor_lexical.py +43 -0
- pycforge/ide/editor_sidebars.py +236 -0
- pycforge/ide/editor_syntax.py +243 -0
- pycforge/ide/find_replace.py +535 -0
- pycforge/ide/icons.py +91 -0
- pycforge/ide/io_service.py +196 -0
- pycforge/ide/model.py +164 -0
- pycforge/ide/panels.py +903 -0
- pycforge/ide/positions.py +220 -0
- pycforge/ide/process_worker.py +130 -0
- pycforge/ide/qt.py +230 -0
- pycforge/ide/qt_actions.py +418 -0
- pycforge/ide/qt_close.py +169 -0
- pycforge/ide/qt_command_palette.py +297 -0
- pycforge/ide/qt_contract.py +220 -0
- pycforge/ide/qt_documents.py +590 -0
- pycforge/ide/qt_editor_buffers.py +113 -0
- pycforge/ide/qt_editor_surfaces.py +112 -0
- pycforge/ide/qt_menus.py +324 -0
- pycforge/ide/qt_projection.py +500 -0
- pycforge/ide/qt_shell.py +348 -0
- pycforge/ide/qt_shell_interactions.py +320 -0
- pycforge/ide/qt_state.py +393 -0
- pycforge/ide/qt_workspace_features.py +398 -0
- pycforge/ide/qt_workspace_navigation.py +208 -0
- pycforge/ide/qt_workspace_observers.py +173 -0
- pycforge/ide/qt_workspace_panels.py +545 -0
- pycforge/ide/qt_workspace_widgets.py +228 -0
- pycforge/ide/resources/icons/about.svg +1 -0
- pycforge/ide/resources/icons/add-document.svg +1 -0
- pycforge/ide/resources/icons/brand-mark.svg +1 -0
- pycforge/ide/resources/icons/bundle-search.svg +1 -0
- pycforge/ide/resources/icons/cancel.svg +1 -0
- pycforge/ide/resources/icons/check.svg +1 -0
- pycforge/ide/resources/icons/chevron-right.svg +1 -0
- pycforge/ide/resources/icons/close.svg +1 -0
- pycforge/ide/resources/icons/collapse-all.svg +1 -0
- pycforge/ide/resources/icons/command-palette.svg +1 -0
- pycforge/ide/resources/icons/convert.svg +1 -0
- pycforge/ide/resources/icons/copy.svg +1 -0
- pycforge/ide/resources/icons/cut.svg +1 -0
- pycforge/ide/resources/icons/decision-trace.svg +1 -0
- pycforge/ide/resources/icons/details.svg +1 -0
- pycforge/ide/resources/icons/diagnostics.svg +1 -0
- pycforge/ide/resources/icons/duplicate-line.svg +1 -0
- pycforge/ide/resources/icons/exit.svg +1 -0
- pycforge/ide/resources/icons/expand-all.svg +1 -0
- pycforge/ide/resources/icons/export.svg +1 -0
- pycforge/ide/resources/icons/find.svg +1 -0
- pycforge/ide/resources/icons/go-to-line.svg +1 -0
- pycforge/ide/resources/icons/go-to-output.svg +1 -0
- pycforge/ide/resources/icons/go-to-source.svg +1 -0
- pycforge/ide/resources/icons/history.svg +1 -0
- pycforge/ide/resources/icons/indent.svg +1 -0
- pycforge/ide/resources/icons/link-c.svg +1 -0
- pycforge/ide/resources/icons/mappings.svg +1 -0
- pycforge/ide/resources/icons/module.svg +1 -0
- pycforge/ide/resources/icons/move-down.svg +1 -0
- pycforge/ide/resources/icons/move-line-down.svg +1 -0
- pycforge/ide/resources/icons/move-line-up.svg +1 -0
- pycforge/ide/resources/icons/move-up.svg +1 -0
- pycforge/ide/resources/icons/next.svg +1 -0
- pycforge/ide/resources/icons/open.svg +1 -0
- pycforge/ide/resources/icons/outdent.svg +1 -0
- pycforge/ide/resources/icons/outline.svg +1 -0
- pycforge/ide/resources/icons/paste.svg +1 -0
- pycforge/ide/resources/icons/previous.svg +1 -0
- pycforge/ide/resources/icons/primary-module.svg +1 -0
- pycforge/ide/resources/icons/redo.svg +1 -0
- pycforge/ide/resources/icons/remove-document.svg +1 -0
- pycforge/ide/resources/icons/replace.svg +1 -0
- pycforge/ide/resources/icons/save-as.svg +1 -0
- pycforge/ide/resources/icons/save.svg +1 -0
- pycforge/ide/resources/icons/select-all.svg +1 -0
- pycforge/ide/resources/icons/settings.svg +1 -0
- pycforge/ide/resources/icons/show-c.svg +1 -0
- pycforge/ide/resources/icons/split-view.svg +1 -0
- pycforge/ide/resources/icons/summary.svg +1 -0
- pycforge/ide/resources/icons/telemetry.svg +1 -0
- pycforge/ide/resources/icons/toggle-comment.svg +1 -0
- pycforge/ide/resources/icons/toggle-fold.svg +1 -0
- pycforge/ide/resources/icons/undo.svg +1 -0
- pycforge/ide/resources/icons/whitespace.svg +1 -0
- pycforge/ide/revisions.py +400 -0
- pycforge/ide/search_service.py +280 -0
- pycforge/ide/session_history.py +150 -0
- pycforge/ide/source_editing.py +417 -0
- pycforge/ide/source_structure.py +558 -0
- pycforge/ide/source_structure_async.py +191 -0
- pycforge/ide/supervisor.py +503 -0
- pycforge/ide/theme.py +119 -0
- pycforge/ide/theme_stylesheet.py +598 -0
- pycforge/ide/theme_workspace_stylesheet.py +155 -0
- pycforge/ide/visual_tokens.py +142 -0
- pycforge/ide/worker_protocol.py +80 -0
- pycforge/ide/workspace_search.py +462 -0
- pycforge/ide/workspace_session.py +256 -0
- pycforge/laboratory/__init__.py +6 -0
- pycforge/laboratory/audits.py +2244 -0
- pycforge/laboratory/checkpoint_e.py +2685 -0
- pycforge/laboratory/cli.py +119 -0
- pycforge/laboratory/exit_codes.py +11 -0
- pycforge/laboratory/keyword_audit.py +661 -0
- pycforge/laboratory/keyword_only_audit.py +481 -0
- pycforge-0.15.2.dist-info/METADATA +209 -0
- pycforge-0.15.2.dist-info/RECORD +221 -0
- pycforge-0.15.2.dist-info/WHEEL +5 -0
- pycforge-0.15.2.dist-info/entry_points.txt +5 -0
- pycforge-0.15.2.dist-info/licenses/LICENSE +674 -0
- pycforge-0.15.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""Module-bundle coordination for the single C translation unit."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def enrich_source_output_mappings(
|
|
10
|
+
payload: dict[str, Any],
|
|
11
|
+
mappings: tuple[Any, ...],
|
|
12
|
+
) -> list[dict[str, Any]]:
|
|
13
|
+
"""Attach closed-bundle source identity without changing the renderer API."""
|
|
14
|
+
|
|
15
|
+
tables = {item.get("table_id"): item for item in payload.get("fact_tables", ())}
|
|
16
|
+
sources = {}
|
|
17
|
+
sources_by_module = {}
|
|
18
|
+
for record in tables.get("module-source-facts", {}).get("records", ()):
|
|
19
|
+
value = record.get("value", {})
|
|
20
|
+
document_id = value.get("source_document_id")
|
|
21
|
+
if document_id:
|
|
22
|
+
sources[document_id] = (
|
|
23
|
+
value.get("module_id"),
|
|
24
|
+
value.get("logical_source_name"),
|
|
25
|
+
)
|
|
26
|
+
sources_by_module[value.get("module_id")] = (
|
|
27
|
+
document_id,
|
|
28
|
+
value.get("logical_source_name"),
|
|
29
|
+
)
|
|
30
|
+
result = []
|
|
31
|
+
for mapping in mappings:
|
|
32
|
+
item = {key: getattr(mapping, key) for key in mapping.__slots__}
|
|
33
|
+
module_id, logical_name = sources.get(item.get("source_document_id"), (None, None))
|
|
34
|
+
item["module_id"] = module_id
|
|
35
|
+
item["logical_source_name"] = logical_name
|
|
36
|
+
result.append(item)
|
|
37
|
+
|
|
38
|
+
# Imports have no rendered token of their own. Publish separate symbol
|
|
39
|
+
# relationships whose source endpoint is the alias span and whose output
|
|
40
|
+
# endpoints are the already-rendered target prototype and definition.
|
|
41
|
+
nodes = {
|
|
42
|
+
node["node_id"]: node for node in payload.get("python_ir", {}).get("nodes", ())
|
|
43
|
+
}
|
|
44
|
+
plans = {
|
|
45
|
+
plan.get("source_node_id"): plan.get("plan_id")
|
|
46
|
+
for plan in payload.get("rule_plans", ())
|
|
47
|
+
}
|
|
48
|
+
bindings = {
|
|
49
|
+
value.get("declaration_node_id"): value.get("binding_id")
|
|
50
|
+
for record in tables.get("binding-facts", {}).get("records", ())
|
|
51
|
+
for value in (record.get("value", {}),)
|
|
52
|
+
}
|
|
53
|
+
module_functions = {
|
|
54
|
+
value.get("function_node_id"): value
|
|
55
|
+
for record in tables.get("module-function-facts", {}).get("records", ())
|
|
56
|
+
for value in (record.get("value", {}),)
|
|
57
|
+
}
|
|
58
|
+
target_outputs: dict[str, list[tuple[str, dict[str, Any]]]] = {}
|
|
59
|
+
for mapping in result:
|
|
60
|
+
c_node_id = mapping.get("c_node_id", "")
|
|
61
|
+
relation = (
|
|
62
|
+
"prototype"
|
|
63
|
+
if isinstance(c_node_id, str) and c_node_id.startswith("c-prototype-")
|
|
64
|
+
else "definition"
|
|
65
|
+
if isinstance(c_node_id, str) and c_node_id.startswith("c-fn-")
|
|
66
|
+
else None
|
|
67
|
+
)
|
|
68
|
+
if relation is None:
|
|
69
|
+
continue
|
|
70
|
+
for source_node_id in mapping.get("source_node_ids", ()):
|
|
71
|
+
if source_node_id in module_functions:
|
|
72
|
+
target_outputs.setdefault(source_node_id, []).append((relation, mapping))
|
|
73
|
+
|
|
74
|
+
import_records = tables.get("module-import-facts", {}).get("records", ())
|
|
75
|
+
for record in import_records:
|
|
76
|
+
value = record.get("value", {})
|
|
77
|
+
alias_node_id = value.get("alias_node_id")
|
|
78
|
+
import_node_id = value.get("import_node_id")
|
|
79
|
+
target_function_node_id = value.get("target_function_node_id")
|
|
80
|
+
importer_module_id = value.get("importer_module_id")
|
|
81
|
+
target_module_id = value.get("target_module_id")
|
|
82
|
+
importer_document_id, importer_logical_name = sources_by_module.get(
|
|
83
|
+
importer_module_id, (None, None)
|
|
84
|
+
)
|
|
85
|
+
target_document_id, target_logical_name = sources_by_module.get(
|
|
86
|
+
target_module_id, (None, None)
|
|
87
|
+
)
|
|
88
|
+
alias_span = nodes.get(alias_node_id, {}).get("provenance", {}).get("source_span")
|
|
89
|
+
outputs = sorted(
|
|
90
|
+
target_outputs.get(target_function_node_id, ()),
|
|
91
|
+
key=lambda item: (0 if item[0] == "prototype" else 1, item[1].get("c_node_id", "")),
|
|
92
|
+
)
|
|
93
|
+
prototype_id = next(
|
|
94
|
+
(item.get("c_node_id") for relation, item in outputs if relation == "prototype"),
|
|
95
|
+
None,
|
|
96
|
+
)
|
|
97
|
+
definition_id = next(
|
|
98
|
+
(item.get("c_node_id") for relation, item in outputs if relation == "definition"),
|
|
99
|
+
None,
|
|
100
|
+
)
|
|
101
|
+
for relation, target_mapping in outputs:
|
|
102
|
+
relationship_seed = "\x1f".join(
|
|
103
|
+
str(item)
|
|
104
|
+
for item in (
|
|
105
|
+
value.get("import_item_id"),
|
|
106
|
+
relation,
|
|
107
|
+
target_mapping.get("c_node_id"),
|
|
108
|
+
)
|
|
109
|
+
).encode("utf-8")
|
|
110
|
+
relationship = {
|
|
111
|
+
**{
|
|
112
|
+
key: target_mapping[key]
|
|
113
|
+
for key in (
|
|
114
|
+
"start_byte",
|
|
115
|
+
"end_byte",
|
|
116
|
+
"start_line",
|
|
117
|
+
"start_column",
|
|
118
|
+
"end_line",
|
|
119
|
+
"end_column",
|
|
120
|
+
)
|
|
121
|
+
},
|
|
122
|
+
"mapping_kind": "imported-function-alias-relationship",
|
|
123
|
+
"relationship_id": "maprel-" + hashlib.sha256(relationship_seed).hexdigest()[:20],
|
|
124
|
+
"c_node_id": target_mapping.get("c_node_id"),
|
|
125
|
+
"origin_kind": "source-symbol-relationship",
|
|
126
|
+
"source_document_id": importer_document_id,
|
|
127
|
+
"source_node_ids": tuple(
|
|
128
|
+
item for item in (import_node_id, alias_node_id) if isinstance(item, str)
|
|
129
|
+
),
|
|
130
|
+
"source_span": alias_span,
|
|
131
|
+
"rule_plan_id": plans.get(alias_node_id),
|
|
132
|
+
"module_id": importer_module_id,
|
|
133
|
+
"logical_source_name": importer_logical_name,
|
|
134
|
+
"import_item_id": value.get("import_item_id"),
|
|
135
|
+
"import_node_id": import_node_id,
|
|
136
|
+
"alias_node_id": alias_node_id,
|
|
137
|
+
"imported_name": value.get("imported_name"),
|
|
138
|
+
"local_name": value.get("local_name"),
|
|
139
|
+
"target_binding_id": bindings.get(target_function_node_id),
|
|
140
|
+
"target_function_node_id": target_function_node_id,
|
|
141
|
+
"target_module_id": target_module_id,
|
|
142
|
+
"target_source_document_id": target_document_id,
|
|
143
|
+
"target_logical_source_name": target_logical_name,
|
|
144
|
+
"target_generated_name": module_functions.get(target_function_node_id, {}).get(
|
|
145
|
+
"flattened_name"
|
|
146
|
+
),
|
|
147
|
+
"target_output_kind": relation,
|
|
148
|
+
"target_c_node_id": target_mapping.get("c_node_id"),
|
|
149
|
+
"target_prototype_c_node_id": prototype_id,
|
|
150
|
+
"target_definition_c_node_id": definition_id,
|
|
151
|
+
}
|
|
152
|
+
result.append(relationship)
|
|
153
|
+
return result
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def ordered_function_ids(
|
|
157
|
+
payload: dict[str, Any],
|
|
158
|
+
root: dict[str, Any],
|
|
159
|
+
nodes: dict[str, dict[str, Any]],
|
|
160
|
+
*,
|
|
161
|
+
imports_allowed: bool,
|
|
162
|
+
records_allowed: bool = False,
|
|
163
|
+
) -> tuple[tuple[str, ...], str | None]:
|
|
164
|
+
"""Keep the validated flattened-bundle order and erase import directives.
|
|
165
|
+
|
|
166
|
+
ImportFrom nodes are analysis inputs only. They never become C declarations;
|
|
167
|
+
the frontend's flattened root already records the deterministic dependency-
|
|
168
|
+
first module and source-function order consumed here.
|
|
169
|
+
"""
|
|
170
|
+
|
|
171
|
+
functions: list[str] = []
|
|
172
|
+
for node_id in root["fields"].get("body", ()):
|
|
173
|
+
kind = nodes[node_id]["kind"]
|
|
174
|
+
if kind == "FunctionDef":
|
|
175
|
+
functions.append(node_id)
|
|
176
|
+
elif not (
|
|
177
|
+
(imports_allowed and kind == "ImportFrom")
|
|
178
|
+
or (records_allowed and kind == "ClassDef")
|
|
179
|
+
):
|
|
180
|
+
return tuple(functions), node_id
|
|
181
|
+
if not imports_allowed:
|
|
182
|
+
return tuple(functions), None
|
|
183
|
+
|
|
184
|
+
tables = {item.get("table_id"): item for item in payload.get("fact_tables", ())}
|
|
185
|
+
function_records = tables.get("module-function-facts", {}).get("records", ())
|
|
186
|
+
root_position = {node_id: ordinal for ordinal, node_id in enumerate(functions)}
|
|
187
|
+
ordered = tuple(
|
|
188
|
+
item["value"]["function_node_id"]
|
|
189
|
+
for item in sorted(
|
|
190
|
+
function_records,
|
|
191
|
+
key=lambda item: (
|
|
192
|
+
item["value"].get(
|
|
193
|
+
"bundle_function_ordinal",
|
|
194
|
+
root_position.get(item["value"].get("function_node_id"), 2**31 - 1),
|
|
195
|
+
),
|
|
196
|
+
item["value"].get("function_node_id", ""),
|
|
197
|
+
),
|
|
198
|
+
)
|
|
199
|
+
)
|
|
200
|
+
return (ordered if ordered and set(ordered) == set(functions) else tuple(functions)), None
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Immutable values published by explicit SourceBundle module resolution."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ModuleResolutionError(Exception):
|
|
10
|
+
"""A deterministic source rejection discovered during module resolution."""
|
|
11
|
+
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
code: str,
|
|
15
|
+
message: str,
|
|
16
|
+
*,
|
|
17
|
+
module_id: str,
|
|
18
|
+
logical_name: str,
|
|
19
|
+
source_span: dict[str, Any],
|
|
20
|
+
related_spans: tuple[dict[str, Any], ...] = (),
|
|
21
|
+
) -> None:
|
|
22
|
+
super().__init__(message)
|
|
23
|
+
self.code = code
|
|
24
|
+
self.message = message
|
|
25
|
+
self.module_id = module_id
|
|
26
|
+
self.logical_name = logical_name
|
|
27
|
+
self.source_span = source_span
|
|
28
|
+
self.related_spans = related_spans
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ModuleAnalysisCanceled(Exception):
|
|
32
|
+
"""Internal control signal used to preserve cancellation semantics."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True, slots=True)
|
|
36
|
+
class ModuleResolutionProduct:
|
|
37
|
+
"""Closed result passed from module analysis to the cumulative analyzer."""
|
|
38
|
+
|
|
39
|
+
python_ir: dict[str, Any]
|
|
40
|
+
module_bundle: dict[str, Any]
|
|
41
|
+
module_resolution: dict[str, Any]
|
|
42
|
+
module_fact_tables: tuple[dict[str, Any], ...]
|
|
43
|
+
module_import_node_ids: tuple[str, ...]
|
|
44
|
+
module_function_by_node: dict[str, dict[str, Any]]
|
|
45
|
+
module_record_by_node: dict[str, dict[str, Any]]
|
|
46
|
+
module_bundle_assembly_node_id: str
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass(frozen=True, slots=True)
|
|
50
|
+
class ResolvedImport:
|
|
51
|
+
import_item_id: str
|
|
52
|
+
import_node_id: str
|
|
53
|
+
alias_node_id: str
|
|
54
|
+
importer_module_id: str
|
|
55
|
+
target_module_id: str
|
|
56
|
+
imported_name: str
|
|
57
|
+
local_name: str
|
|
58
|
+
target_function_node_id: str
|
|
59
|
+
source_ordinal: int
|
|
60
|
+
|
|
61
|
+
def to_fact(self) -> dict[str, Any]:
|
|
62
|
+
return {
|
|
63
|
+
"import_item_id": self.import_item_id,
|
|
64
|
+
"import_node_id": self.import_node_id,
|
|
65
|
+
"alias_node_id": self.alias_node_id,
|
|
66
|
+
"importer_module_id": self.importer_module_id,
|
|
67
|
+
"target_module_id": self.target_module_id,
|
|
68
|
+
"imported_name": self.imported_name,
|
|
69
|
+
"local_name": self.local_name,
|
|
70
|
+
"target_function_node_id": self.target_function_node_id,
|
|
71
|
+
"source_ordinal": self.source_ordinal,
|
|
72
|
+
"supported": True,
|
|
73
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"""Pipeline stage for explicit closed-world module resolution."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from types import MappingProxyType
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from pycforge.converter.contracts.configuration import (
|
|
9
|
+
MAX_IMPORT_ITEMS,
|
|
10
|
+
supports_keyword_only_calls,
|
|
11
|
+
supports_modules,
|
|
12
|
+
supports_records,
|
|
13
|
+
)
|
|
14
|
+
from pycforge.converter.core.diagnostics import Diagnostic
|
|
15
|
+
from pycforge.converter.core.enums import Severity, StageTerminal
|
|
16
|
+
from pycforge.converter.core.fingerprint import fingerprint
|
|
17
|
+
from pycforge.converter.core.stage_artifact import StageArtifact
|
|
18
|
+
from pycforge.converter.core.stage_outcome import StageOutcome
|
|
19
|
+
from pycforge.converter.frontend.validation import validate_python_ir
|
|
20
|
+
from pycforge.converter.ir.python_ir import Provenance, PythonIRModule, PythonIRNode
|
|
21
|
+
|
|
22
|
+
from .analysis import ExplicitModuleAnalyzer
|
|
23
|
+
from .model import ModuleAnalysisCanceled, ModuleResolutionError
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _freeze_field(value: Any) -> Any:
|
|
27
|
+
if isinstance(value, dict):
|
|
28
|
+
return tuple((key, _freeze_field(item)) for key, item in value.items())
|
|
29
|
+
if isinstance(value, (list, tuple)):
|
|
30
|
+
return tuple(_freeze_field(item) for item in value)
|
|
31
|
+
return value
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _python_ir_value(value: dict[str, Any]) -> PythonIRModule:
|
|
35
|
+
nodes = []
|
|
36
|
+
for item in value["nodes"]:
|
|
37
|
+
provenance = item["provenance"]
|
|
38
|
+
nodes.append(
|
|
39
|
+
PythonIRNode(
|
|
40
|
+
item["node_id"],
|
|
41
|
+
item["kind"],
|
|
42
|
+
tuple(
|
|
43
|
+
(key, _freeze_field(field_value))
|
|
44
|
+
for key, field_value in item["fields"].items()
|
|
45
|
+
),
|
|
46
|
+
Provenance(
|
|
47
|
+
provenance["origin_kind"],
|
|
48
|
+
provenance.get("source_span"),
|
|
49
|
+
tuple(provenance.get("origin_node_ids", ())),
|
|
50
|
+
),
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
return PythonIRModule(
|
|
54
|
+
value["schema_version"],
|
|
55
|
+
value["document_id"],
|
|
56
|
+
value["root_node_id"],
|
|
57
|
+
tuple(nodes),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _artifact(prior: StageArtifact, payload: dict[str, object]) -> StageArtifact:
|
|
62
|
+
artifact_fingerprint = fingerprint(
|
|
63
|
+
"stage-artifact",
|
|
64
|
+
{
|
|
65
|
+
"kind": "python_ir",
|
|
66
|
+
"conversion_id": prior.conversion_id,
|
|
67
|
+
"parent": prior.artifact_fingerprint.value,
|
|
68
|
+
"payload": payload,
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
return StageArtifact(
|
|
72
|
+
"python_ir",
|
|
73
|
+
"0.4",
|
|
74
|
+
prior.conversion_id,
|
|
75
|
+
prior.artifact_fingerprint,
|
|
76
|
+
MappingProxyType(payload),
|
|
77
|
+
artifact_fingerprint,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class ModuleResolutionStage:
|
|
82
|
+
stage_id = "modules.resolve"
|
|
83
|
+
input_schema = "python-ir-bundle/0.4"
|
|
84
|
+
input_schemas = ("python-ir/0.3", "python-ir-bundle/0.4")
|
|
85
|
+
output_schema = "python-ir/0.4"
|
|
86
|
+
|
|
87
|
+
def run(self, artifact: StageArtifact, services: Any) -> StageOutcome:
|
|
88
|
+
request = services.context.canonical.request
|
|
89
|
+
if not supports_modules(request.rule_set_version):
|
|
90
|
+
return StageOutcome(StageTerminal.COMPLETED, artifact)
|
|
91
|
+
if services.context.cancellation.is_canceled:
|
|
92
|
+
return self._canceled()
|
|
93
|
+
try:
|
|
94
|
+
product = ExplicitModuleAnalyzer(
|
|
95
|
+
artifact.payload["python_ir_bundle"],
|
|
96
|
+
artifact.payload["source_bundle"],
|
|
97
|
+
max_import_edges=min(request.resource_policy.max_import_edges, MAX_IMPORT_ITEMS),
|
|
98
|
+
cancellation=services.context.cancellation,
|
|
99
|
+
invalidation_dependency=artifact.artifact_fingerprint.value,
|
|
100
|
+
allow_records=supports_records(request.rule_set_version),
|
|
101
|
+
allow_required_keyword_only=supports_keyword_only_calls(
|
|
102
|
+
request.rule_set_version
|
|
103
|
+
),
|
|
104
|
+
).analyze()
|
|
105
|
+
except ModuleAnalysisCanceled:
|
|
106
|
+
return self._canceled()
|
|
107
|
+
except ModuleResolutionError as exc:
|
|
108
|
+
return StageOutcome(
|
|
109
|
+
StageTerminal.REJECTED,
|
|
110
|
+
diagnostics=(
|
|
111
|
+
Diagnostic(
|
|
112
|
+
exc.code,
|
|
113
|
+
Severity.ERROR,
|
|
114
|
+
self.stage_id,
|
|
115
|
+
exc.message,
|
|
116
|
+
source_span=exc.source_span,
|
|
117
|
+
related_spans=exc.related_spans,
|
|
118
|
+
source_module_id=exc.module_id,
|
|
119
|
+
source_logical_name=exc.logical_name,
|
|
120
|
+
),
|
|
121
|
+
),
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
payload: dict[str, object] = {
|
|
125
|
+
"stage_order": tuple(artifact.payload["stage_order"]) + (self.stage_id,),
|
|
126
|
+
"python_ir": product.python_ir,
|
|
127
|
+
"module_bundle": product.module_bundle,
|
|
128
|
+
"module_resolution": product.module_resolution,
|
|
129
|
+
"module_fact_tables": product.module_fact_tables,
|
|
130
|
+
"module_import_node_ids": product.module_import_node_ids,
|
|
131
|
+
"module_function_by_node": product.module_function_by_node,
|
|
132
|
+
"module_bundle_assembly_node_id": product.module_bundle_assembly_node_id,
|
|
133
|
+
}
|
|
134
|
+
if supports_records(request.rule_set_version):
|
|
135
|
+
payload["module_record_by_node"] = product.module_record_by_node
|
|
136
|
+
return StageOutcome(StageTerminal.COMPLETED, _artifact(artifact, payload))
|
|
137
|
+
|
|
138
|
+
def validate(self, artifact: StageArtifact, services: Any) -> tuple[bool, str]:
|
|
139
|
+
request = services.context.canonical.request
|
|
140
|
+
if not supports_modules(request.rule_set_version):
|
|
141
|
+
return (
|
|
142
|
+
artifact.kind == "python_ir" and artifact.schema_version == "0.3",
|
|
143
|
+
"historical Python IR pass-through changed its contract",
|
|
144
|
+
)
|
|
145
|
+
if artifact.kind != "python_ir" or artifact.schema_version != "0.4":
|
|
146
|
+
return False, "module resolver did not publish python-ir/0.4"
|
|
147
|
+
python_ir = artifact.payload.get("python_ir")
|
|
148
|
+
if not isinstance(python_ir, dict):
|
|
149
|
+
return False, "module resolver omitted flattened Python IR"
|
|
150
|
+
source_documents = frozenset(
|
|
151
|
+
item["document_id"]
|
|
152
|
+
for item in artifact.payload.get("module_bundle", {}).get("documents", ())
|
|
153
|
+
)
|
|
154
|
+
valid, message = validate_python_ir(
|
|
155
|
+
_python_ir_value(python_ir),
|
|
156
|
+
allowed_document_ids=source_documents,
|
|
157
|
+
)
|
|
158
|
+
if not valid:
|
|
159
|
+
return False, message
|
|
160
|
+
table_ids = {
|
|
161
|
+
item.get("table_id") for item in artifact.payload.get("module_fact_tables", ())
|
|
162
|
+
}
|
|
163
|
+
required = {
|
|
164
|
+
"module-identity-facts",
|
|
165
|
+
"module-import-facts",
|
|
166
|
+
"module-function-facts",
|
|
167
|
+
"module-initialization-facts",
|
|
168
|
+
"module-namespace-facts",
|
|
169
|
+
"module-source-facts",
|
|
170
|
+
}
|
|
171
|
+
if not required.issubset(table_ids):
|
|
172
|
+
return False, "module resolver omitted required complete fact tables"
|
|
173
|
+
node_ids = {node["node_id"] for node in python_ir["nodes"]}
|
|
174
|
+
for table in artifact.payload.get("module_fact_tables", ()):
|
|
175
|
+
for record in table.get("records", ()):
|
|
176
|
+
source_ids = record.get("provenance", {}).get("source_node_ids", ())
|
|
177
|
+
if not source_ids or any(node_id not in node_ids for node_id in source_ids):
|
|
178
|
+
return False, "module fact provenance is missing or references an absent node"
|
|
179
|
+
return True, ""
|
|
180
|
+
|
|
181
|
+
def _canceled(self) -> StageOutcome:
|
|
182
|
+
return StageOutcome(
|
|
183
|
+
StageTerminal.CANCELED,
|
|
184
|
+
diagnostics=(
|
|
185
|
+
Diagnostic(
|
|
186
|
+
"PYC1901",
|
|
187
|
+
Severity.ERROR,
|
|
188
|
+
self.stage_id,
|
|
189
|
+
"Conversion canceled during module resolution",
|
|
190
|
+
),
|
|
191
|
+
),
|
|
192
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Bounded Phase 14A integer floor-arithmetic feature package."""
|
|
2
|
+
|
|
3
|
+
from .analysis import BoundedNumericAnalyzer
|
|
4
|
+
from .lowering import NumericCIRLowerer, NumericLoweringServices, bind_numeric_lowerer
|
|
5
|
+
from .model import (
|
|
6
|
+
BoundedNumericAnalysis,
|
|
7
|
+
FloorArithmeticKind,
|
|
8
|
+
NumericAnalysisCanceled,
|
|
9
|
+
NumericAnalysisError,
|
|
10
|
+
NumericOperationFact,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"BoundedNumericAnalysis",
|
|
15
|
+
"BoundedNumericAnalyzer",
|
|
16
|
+
"FloorArithmeticKind",
|
|
17
|
+
"NumericAnalysisCanceled",
|
|
18
|
+
"NumericAnalysisError",
|
|
19
|
+
"NumericCIRLowerer",
|
|
20
|
+
"NumericLoweringServices",
|
|
21
|
+
"NumericOperationFact",
|
|
22
|
+
"bind_numeric_lowerer",
|
|
23
|
+
]
|