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,271 @@
|
|
|
1
|
+
"""Structured C IR staging for independently proved keyword-call bindings."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any, Callable, Mapping, Sequence
|
|
7
|
+
|
|
8
|
+
from pycforge.converter.ir.c_ir import CIdentifierRef, CType
|
|
9
|
+
|
|
10
|
+
from .model import KEYWORD_CALL_LOWERING_SHAPE, KEYWORD_CALL_TABLE_ID
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _value(item: Any, name: str, default: Any = None) -> Any:
|
|
14
|
+
if isinstance(item, Mapping):
|
|
15
|
+
return item.get(name, default)
|
|
16
|
+
return getattr(item, name, default)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _category_value(value: Any) -> str:
|
|
20
|
+
return value.value if hasattr(value, "value") else str(value or "unknown")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _sequence(value: Any) -> bool:
|
|
24
|
+
return isinstance(value, (list, tuple))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _exact_permutation(
|
|
28
|
+
value: Any,
|
|
29
|
+
size: int,
|
|
30
|
+
check_cancellation: Callable[[], None],
|
|
31
|
+
) -> bool:
|
|
32
|
+
"""Validate a bounded permutation in linear time without comparison sorting."""
|
|
33
|
+
|
|
34
|
+
if not _sequence(value) or len(value) != size:
|
|
35
|
+
return False
|
|
36
|
+
seen = [False] * size
|
|
37
|
+
for item in value:
|
|
38
|
+
check_cancellation()
|
|
39
|
+
if (
|
|
40
|
+
not isinstance(item, int)
|
|
41
|
+
or isinstance(item, bool)
|
|
42
|
+
or item < 0
|
|
43
|
+
or item >= size
|
|
44
|
+
or seen[item]
|
|
45
|
+
):
|
|
46
|
+
return False
|
|
47
|
+
seen[item] = True
|
|
48
|
+
return True
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(slots=True)
|
|
52
|
+
class KeywordCallLoweringServices:
|
|
53
|
+
nodes: dict[str, dict[str, Any]]
|
|
54
|
+
facts: dict[str, dict[str, Any]]
|
|
55
|
+
expression: Callable[[dict[str, Any]], tuple[tuple[Any, ...], Any]]
|
|
56
|
+
temporary: Callable[..., tuple[Any, CIdentifierRef]]
|
|
57
|
+
type_from_name: Callable[[str | None], CType]
|
|
58
|
+
reject: Callable[..., Any]
|
|
59
|
+
check_cancellation: Callable[[], None]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class KeywordCallCIRLowerer:
|
|
63
|
+
"""Stage values in source order and return references in formal order."""
|
|
64
|
+
|
|
65
|
+
def __init__(self, services: KeywordCallLoweringServices) -> None:
|
|
66
|
+
self.services = services
|
|
67
|
+
|
|
68
|
+
def has_fact(self, call_node_id: str) -> bool:
|
|
69
|
+
return call_node_id in self.services.facts
|
|
70
|
+
|
|
71
|
+
def arguments(
|
|
72
|
+
self,
|
|
73
|
+
node: dict[str, Any],
|
|
74
|
+
signature: Any,
|
|
75
|
+
) -> tuple[tuple[Any, ...], tuple[CIdentifierRef, ...]]:
|
|
76
|
+
s = self.services
|
|
77
|
+
s.check_cancellation()
|
|
78
|
+
if not isinstance(node, Mapping) or not isinstance(node.get("node_id"), str):
|
|
79
|
+
s.reject("PYC2912", "Keyword-call node evidence is malformed", node)
|
|
80
|
+
call_node_id = node.get("node_id")
|
|
81
|
+
if call_node_id not in s.facts:
|
|
82
|
+
s.reject(
|
|
83
|
+
"PYC2910",
|
|
84
|
+
"Keyword call lacks an exact binding fact",
|
|
85
|
+
node,
|
|
86
|
+
)
|
|
87
|
+
fact = s.facts[call_node_id]
|
|
88
|
+
if not isinstance(fact, Mapping):
|
|
89
|
+
s.reject("PYC2912", "Keyword-call binding fact is malformed", node)
|
|
90
|
+
rejection_node = s.nodes.get(fact.get("rejection_node_id"), node)
|
|
91
|
+
if fact.get("supported") is False:
|
|
92
|
+
if (
|
|
93
|
+
not isinstance(fact.get("diagnostic_code"), str)
|
|
94
|
+
or not isinstance(fact.get("reason"), str)
|
|
95
|
+
or not isinstance(fact.get("rejection_node_id"), str)
|
|
96
|
+
or not isinstance(rejection_node, Mapping)
|
|
97
|
+
):
|
|
98
|
+
s.reject("PYC2912", "Keyword-call rejection fact is malformed", node)
|
|
99
|
+
s.reject(
|
|
100
|
+
fact.get("diagnostic_code") or "PYC2910",
|
|
101
|
+
fact.get("reason") or "Unsupported keyword-call binding",
|
|
102
|
+
rejection_node,
|
|
103
|
+
)
|
|
104
|
+
if fact.get("supported") is not True:
|
|
105
|
+
s.reject("PYC2912", "Keyword-call support state is malformed", node)
|
|
106
|
+
parameters_value = _value(signature, "parameters")
|
|
107
|
+
if not _sequence(parameters_value):
|
|
108
|
+
s.reject("PYC2912", "Keyword-call signature parameters are malformed", node)
|
|
109
|
+
parameters: Sequence[Any] = tuple(parameters_value)
|
|
110
|
+
sequence_fields = (
|
|
111
|
+
"argument_bindings",
|
|
112
|
+
"source_argument_node_ids",
|
|
113
|
+
"evaluation_order",
|
|
114
|
+
"source_to_parameter_ordinals",
|
|
115
|
+
"parameter_argument_node_ids",
|
|
116
|
+
"parameter_to_source_ordinals",
|
|
117
|
+
"positional_argument_node_ids",
|
|
118
|
+
"keyword_node_ids",
|
|
119
|
+
"keyword_value_node_ids",
|
|
120
|
+
)
|
|
121
|
+
if any(not _sequence(fact.get(name)) for name in sequence_fields):
|
|
122
|
+
s.reject("PYC2912", "Keyword-call binding sequences are malformed", node)
|
|
123
|
+
bindings = tuple(fact["argument_bindings"])
|
|
124
|
+
source_ids = tuple(fact["source_argument_node_ids"])
|
|
125
|
+
evaluation_order = tuple(fact["evaluation_order"])
|
|
126
|
+
source_to_parameter = tuple(fact["source_to_parameter_ordinals"])
|
|
127
|
+
parameter_argument_ids = tuple(fact["parameter_argument_node_ids"])
|
|
128
|
+
parameter_to_source = tuple(fact["parameter_to_source_ordinals"])
|
|
129
|
+
expected_call_fields = node.get("fields")
|
|
130
|
+
if (
|
|
131
|
+
not isinstance(expected_call_fields, Mapping)
|
|
132
|
+
or not _sequence(expected_call_fields.get("args"))
|
|
133
|
+
or not _sequence(expected_call_fields.get("keywords"))
|
|
134
|
+
):
|
|
135
|
+
s.reject("PYC2912", "Keyword-call node fields are malformed", node)
|
|
136
|
+
expected_keyword_ids = tuple(expected_call_fields["keywords"])
|
|
137
|
+
expected_keyword_values: list[str] = []
|
|
138
|
+
for keyword_id in expected_keyword_ids:
|
|
139
|
+
keyword = s.nodes.get(keyword_id)
|
|
140
|
+
keyword_fields = keyword.get("fields") if isinstance(keyword, Mapping) else None
|
|
141
|
+
if (
|
|
142
|
+
not isinstance(keyword_id, str)
|
|
143
|
+
or not isinstance(keyword, Mapping)
|
|
144
|
+
or keyword.get("kind") != "keyword"
|
|
145
|
+
or not isinstance(keyword_fields, Mapping)
|
|
146
|
+
or not isinstance(keyword_fields.get("value"), str)
|
|
147
|
+
):
|
|
148
|
+
s.reject("PYC2912", "Keyword-call keyword evidence is malformed", node)
|
|
149
|
+
expected_keyword_values.append(keyword_fields["value"])
|
|
150
|
+
if (
|
|
151
|
+
fact.get("call_node_id") != node.get("node_id")
|
|
152
|
+
or fact.get("callee_node_id") != expected_call_fields.get("func")
|
|
153
|
+
or fact.get("lowering_shape") != KEYWORD_CALL_LOWERING_SHAPE
|
|
154
|
+
or fact.get("arguments_evaluated_once") is not True
|
|
155
|
+
or fact.get("parameter_coverage_exact") is not True
|
|
156
|
+
or fact.get("allocation_model") != "none"
|
|
157
|
+
or fact.get("cleanup_model") != "none"
|
|
158
|
+
or fact.get("runtime_binding_failure") != "proved-absent"
|
|
159
|
+
or tuple(fact.get("positional_argument_node_ids", ()))
|
|
160
|
+
!= tuple(expected_call_fields.get("args", ()))
|
|
161
|
+
or tuple(fact.get("keyword_node_ids", ())) != expected_keyword_ids
|
|
162
|
+
or tuple(fact.get("keyword_value_node_ids", ())) != tuple(expected_keyword_values)
|
|
163
|
+
or source_ids != evaluation_order
|
|
164
|
+
or len(bindings) != len(source_ids)
|
|
165
|
+
or len(parameters) != len(parameter_argument_ids)
|
|
166
|
+
or len(parameters) != len(parameter_to_source)
|
|
167
|
+
or len(parameters) != len(source_ids)
|
|
168
|
+
or not _exact_permutation(
|
|
169
|
+
source_to_parameter,
|
|
170
|
+
len(parameters),
|
|
171
|
+
s.check_cancellation,
|
|
172
|
+
)
|
|
173
|
+
or not _exact_permutation(
|
|
174
|
+
parameter_to_source,
|
|
175
|
+
len(parameters),
|
|
176
|
+
s.check_cancellation,
|
|
177
|
+
)
|
|
178
|
+
):
|
|
179
|
+
s.reject("PYC2912", "Keyword-call binding fact is incomplete or inconsistent", node)
|
|
180
|
+
|
|
181
|
+
# Validate the whole permutation before lowering any value so tampered
|
|
182
|
+
# evidence cannot publish a partial C IR prelude.
|
|
183
|
+
for source_ordinal, binding in enumerate(bindings):
|
|
184
|
+
s.check_cancellation()
|
|
185
|
+
if not isinstance(binding, Mapping):
|
|
186
|
+
s.reject("PYC2912", "Keyword-call argument binding is malformed", node)
|
|
187
|
+
parameter_ordinal = binding.get("parameter_ordinal")
|
|
188
|
+
argument_id = binding.get("source_argument_node_id")
|
|
189
|
+
keyword_id = binding.get("keyword_node_id")
|
|
190
|
+
if (
|
|
191
|
+
binding.get("source_ordinal") != source_ordinal
|
|
192
|
+
or argument_id != source_ids[source_ordinal]
|
|
193
|
+
or parameter_ordinal != source_to_parameter[source_ordinal]
|
|
194
|
+
or not isinstance(parameter_ordinal, int)
|
|
195
|
+
or not 0 <= parameter_ordinal < len(parameters)
|
|
196
|
+
or parameter_argument_ids[parameter_ordinal] != argument_id
|
|
197
|
+
or parameter_to_source[parameter_ordinal] != source_ordinal
|
|
198
|
+
or argument_id not in s.nodes
|
|
199
|
+
or s.nodes[argument_id].get("kind") == "Starred"
|
|
200
|
+
or (
|
|
201
|
+
keyword_id is not None
|
|
202
|
+
and (
|
|
203
|
+
keyword_id not in s.nodes
|
|
204
|
+
or s.nodes[keyword_id].get("kind") != "keyword"
|
|
205
|
+
or s.nodes[keyword_id].get("fields", {}).get("value") != argument_id
|
|
206
|
+
or s.nodes[keyword_id].get("fields", {}).get("arg")
|
|
207
|
+
!= binding.get("keyword_name")
|
|
208
|
+
)
|
|
209
|
+
)
|
|
210
|
+
or binding.get("parameter_node_id")
|
|
211
|
+
!= _value(parameters[parameter_ordinal], "parameter_node_id")
|
|
212
|
+
or binding.get("parameter_name")
|
|
213
|
+
!= _value(parameters[parameter_ordinal], "source_name")
|
|
214
|
+
or binding.get("expected_category")
|
|
215
|
+
!= _category_value(_value(parameters[parameter_ordinal], "category"))
|
|
216
|
+
):
|
|
217
|
+
s.reject("PYC2912", "Keyword-call argument permutation is inconsistent", node)
|
|
218
|
+
|
|
219
|
+
prelude: list[Any] = []
|
|
220
|
+
references: list[CIdentifierRef | None] = [None] * len(parameters)
|
|
221
|
+
for source_ordinal, binding in enumerate(bindings):
|
|
222
|
+
s.check_cancellation()
|
|
223
|
+
argument_id = binding["source_argument_node_id"]
|
|
224
|
+
parameter_ordinal = binding["parameter_ordinal"]
|
|
225
|
+
expression_prelude, expression = s.expression(s.nodes[argument_id])
|
|
226
|
+
prelude.extend(expression_prelude)
|
|
227
|
+
keyword_id = binding.get("keyword_node_id")
|
|
228
|
+
origins = tuple(
|
|
229
|
+
item
|
|
230
|
+
for item in (argument_id, keyword_id, node["node_id"])
|
|
231
|
+
if isinstance(item, str)
|
|
232
|
+
)
|
|
233
|
+
declaration, reference = s.temporary(
|
|
234
|
+
"arg",
|
|
235
|
+
node,
|
|
236
|
+
source_ordinal,
|
|
237
|
+
s.type_from_name(_value(parameters[parameter_ordinal], "c_type")),
|
|
238
|
+
expression,
|
|
239
|
+
origins,
|
|
240
|
+
)
|
|
241
|
+
if not isinstance(reference, CIdentifierRef):
|
|
242
|
+
s.reject("PYC2912", "Keyword-call staging did not produce a pure reference", node)
|
|
243
|
+
prelude.append(declaration)
|
|
244
|
+
references[parameter_ordinal] = reference
|
|
245
|
+
s.check_cancellation()
|
|
246
|
+
if any(item is None for item in references):
|
|
247
|
+
s.reject("PYC2912", "Keyword-call staging omitted a formal parameter", node)
|
|
248
|
+
return tuple(prelude), tuple(references) # type: ignore[arg-type]
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def bind_keyword_call_lowerer(owner: Any) -> KeywordCallCIRLowerer:
|
|
252
|
+
"""Bind the feature lowerer without adding keyword mechanics centrally."""
|
|
253
|
+
|
|
254
|
+
return KeywordCallCIRLowerer(
|
|
255
|
+
KeywordCallLoweringServices(
|
|
256
|
+
nodes=owner.nodes,
|
|
257
|
+
facts=owner._optional_values(KEYWORD_CALL_TABLE_ID, "call_node_id"),
|
|
258
|
+
expression=owner._expression,
|
|
259
|
+
temporary=owner._temporary,
|
|
260
|
+
type_from_name=owner._type_from_name,
|
|
261
|
+
reject=owner._reject,
|
|
262
|
+
check_cancellation=owner._check_cancel,
|
|
263
|
+
)
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
__all__ = [
|
|
268
|
+
"KeywordCallCIRLowerer",
|
|
269
|
+
"KeywordCallLoweringServices",
|
|
270
|
+
"bind_keyword_call_lowerer",
|
|
271
|
+
]
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"""Immutable evidence for exact direct keyword-call binding.
|
|
2
|
+
|
|
3
|
+
Phase 14C does not add a Python runtime binder. These records prove at
|
|
4
|
+
conversion time that an already-resolved source function receives every
|
|
5
|
+
argument exactly once. Argument *evaluation* order and formal-parameter
|
|
6
|
+
order are represented separately because conflating them would change Python
|
|
7
|
+
semantics when keyword values contain nested calls.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import hashlib
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
KEYWORD_CALL_FACT_SCHEMA = "fact-table/0.14.2"
|
|
18
|
+
KEYWORD_CALL_TABLE_ID = "keyword-call-binding-facts"
|
|
19
|
+
KEYWORD_CALL_KEY_DOMAIN = "keyword-call-node-id"
|
|
20
|
+
KEYWORD_CALL_LOWERING_SHAPE = (
|
|
21
|
+
"source-order-temporaries-formal-order-references-v1"
|
|
22
|
+
)
|
|
23
|
+
KEYWORD_CALL_RULE_ID = "phase14.keyword_call.exact_binding"
|
|
24
|
+
KEYWORD_CALL_RULE_VERSION = "0.14.2"
|
|
25
|
+
KEYWORD_CALL_TABLE_DEPENDENCIES = (
|
|
26
|
+
"binding-facts",
|
|
27
|
+
"function-signature-facts",
|
|
28
|
+
"value-category-facts",
|
|
29
|
+
"call-target-facts",
|
|
30
|
+
"evaluation-order-facts",
|
|
31
|
+
)
|
|
32
|
+
KEYWORD_CALL_PROVENANCE_EVIDENCE = (
|
|
33
|
+
"direct-source-target",
|
|
34
|
+
"exact-explicit-keyword-names",
|
|
35
|
+
"complete-parameter-coverage",
|
|
36
|
+
"source-order-evaluation",
|
|
37
|
+
"formal-order-reference-permutation",
|
|
38
|
+
"single-evaluation",
|
|
39
|
+
)
|
|
40
|
+
CUMULATIVE_KEYWORD_TARGET_DIAGNOSTIC_CODE = "PYC2911"
|
|
41
|
+
CUMULATIVE_KEYWORD_TARGET_REASON = (
|
|
42
|
+
"Keyword-call target is outside the eligible direct source-function profile"
|
|
43
|
+
)
|
|
44
|
+
KEYWORD_CALL_OBLIGATIONS = (
|
|
45
|
+
"direct-source-target-resolved-once",
|
|
46
|
+
"explicit-keywords-only-no-unpacking",
|
|
47
|
+
"positional-prefix-bound-in-order",
|
|
48
|
+
"keyword-names-bound-to-positional-or-keyword-parameters",
|
|
49
|
+
"parameter-coverage-exact",
|
|
50
|
+
"argument-representations-compatible-after-binding",
|
|
51
|
+
"source-arguments-evaluated-left-to-right-once",
|
|
52
|
+
"argument-temporaries-reordered-only-after-evaluation",
|
|
53
|
+
"c-call-arguments-in-formal-order",
|
|
54
|
+
"parameter-ownership-boundary-explicit",
|
|
55
|
+
"runtime-binding-failure-absent",
|
|
56
|
+
"allocation-and-cleanup-absent",
|
|
57
|
+
"structured-c-ir-only",
|
|
58
|
+
"source-provenance-anchored",
|
|
59
|
+
"cancellation-safe-points-honored",
|
|
60
|
+
"target-contract-exact",
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class KeywordCallAnalysisCanceled(Exception):
|
|
65
|
+
"""Raised when cooperative cancellation retires keyword-call analysis."""
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class KeywordCallValidationCanceled(Exception):
|
|
69
|
+
"""Raised when independent keyword-call reconstruction is canceled."""
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class KeywordCallAnalysisError(Exception):
|
|
73
|
+
"""A bounded source-facing failure that cannot be serialized as a fact."""
|
|
74
|
+
|
|
75
|
+
def __init__(
|
|
76
|
+
self,
|
|
77
|
+
code: str,
|
|
78
|
+
message: str,
|
|
79
|
+
node_id: str,
|
|
80
|
+
source_span: dict[str, object] | None,
|
|
81
|
+
) -> None:
|
|
82
|
+
super().__init__(message)
|
|
83
|
+
self.code = code
|
|
84
|
+
self.message = message
|
|
85
|
+
self.node_id = node_id
|
|
86
|
+
self.source_span = source_span
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@dataclass(frozen=True, slots=True)
|
|
90
|
+
class KeywordArgumentBindingFact:
|
|
91
|
+
"""Binding of one source-order argument value to at most one parameter."""
|
|
92
|
+
|
|
93
|
+
source_argument_node_id: str
|
|
94
|
+
keyword_node_id: str | None
|
|
95
|
+
keyword_name: str | None
|
|
96
|
+
source_ordinal: int
|
|
97
|
+
parameter_node_id: str | None
|
|
98
|
+
parameter_name: str | None
|
|
99
|
+
parameter_ordinal: int | None
|
|
100
|
+
category: str
|
|
101
|
+
expected_category: str | None
|
|
102
|
+
|
|
103
|
+
def to_dict(self) -> dict[str, Any]:
|
|
104
|
+
return {
|
|
105
|
+
"source_argument_node_id": self.source_argument_node_id,
|
|
106
|
+
"keyword_node_id": self.keyword_node_id,
|
|
107
|
+
"keyword_name": self.keyword_name,
|
|
108
|
+
"source_ordinal": self.source_ordinal,
|
|
109
|
+
"parameter_node_id": self.parameter_node_id,
|
|
110
|
+
"parameter_name": self.parameter_name,
|
|
111
|
+
"parameter_ordinal": self.parameter_ordinal,
|
|
112
|
+
"category": self.category,
|
|
113
|
+
"expected_category": self.expected_category,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@dataclass(frozen=True, slots=True)
|
|
118
|
+
class KeywordCallRejection:
|
|
119
|
+
call_node_id: str
|
|
120
|
+
diagnostic_code: str
|
|
121
|
+
reason: str
|
|
122
|
+
rejection_node_id: str
|
|
123
|
+
source_span: dict[str, object] | None
|
|
124
|
+
|
|
125
|
+
def to_dict(self) -> dict[str, Any]:
|
|
126
|
+
return {
|
|
127
|
+
"call_node_id": self.call_node_id,
|
|
128
|
+
"diagnostic_code": self.diagnostic_code,
|
|
129
|
+
"reason": self.reason,
|
|
130
|
+
"rejection_node_id": self.rejection_node_id,
|
|
131
|
+
"source_span": self.source_span,
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@dataclass(frozen=True, slots=True)
|
|
136
|
+
class KeywordCallBindingFact:
|
|
137
|
+
binding_id: str
|
|
138
|
+
call_node_id: str
|
|
139
|
+
callee_node_id: str
|
|
140
|
+
target_function_node_id: str
|
|
141
|
+
target_binding_id: str
|
|
142
|
+
target_name: str
|
|
143
|
+
positional_only_parameter_count: int
|
|
144
|
+
parameter_node_ids: tuple[str, ...]
|
|
145
|
+
parameter_names: tuple[str, ...]
|
|
146
|
+
parameter_categories: tuple[str, ...]
|
|
147
|
+
positional_argument_node_ids: tuple[str, ...]
|
|
148
|
+
keyword_node_ids: tuple[str, ...]
|
|
149
|
+
keyword_names: tuple[str | None, ...]
|
|
150
|
+
keyword_value_node_ids: tuple[str, ...]
|
|
151
|
+
argument_bindings: tuple[KeywordArgumentBindingFact, ...]
|
|
152
|
+
source_argument_node_ids: tuple[str, ...]
|
|
153
|
+
source_argument_categories: tuple[str, ...]
|
|
154
|
+
source_to_parameter_ordinals: tuple[int | None, ...]
|
|
155
|
+
parameter_argument_node_ids: tuple[str | None, ...]
|
|
156
|
+
parameter_to_source_ordinals: tuple[int | None, ...]
|
|
157
|
+
evaluation_order: tuple[str, ...]
|
|
158
|
+
arguments_evaluated_once: bool
|
|
159
|
+
parameter_coverage_exact: bool
|
|
160
|
+
lowering_shape: str
|
|
161
|
+
allocation_model: str
|
|
162
|
+
cleanup_model: str
|
|
163
|
+
runtime_binding_failure: str
|
|
164
|
+
supported: bool
|
|
165
|
+
diagnostic_code: str | None
|
|
166
|
+
reason: str | None
|
|
167
|
+
rejection_node_id: str | None
|
|
168
|
+
|
|
169
|
+
@property
|
|
170
|
+
def rule_facts(self) -> tuple[str, ...]:
|
|
171
|
+
return (
|
|
172
|
+
f"keyword-call-binding:{self.binding_id}",
|
|
173
|
+
f"keyword-call:{self.call_node_id}",
|
|
174
|
+
f"keyword-call-target:{self.target_binding_id}",
|
|
175
|
+
f"keyword-source-argument-count:{len(self.source_argument_node_ids)}",
|
|
176
|
+
f"keyword-parameter-count:{len(self.parameter_node_ids)}",
|
|
177
|
+
f"keyword-call-lowering-shape:{self.lowering_shape}",
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
@property
|
|
181
|
+
def explanation_tokens(self) -> tuple[str, ...]:
|
|
182
|
+
return (
|
|
183
|
+
"keyword-call-binding",
|
|
184
|
+
self.target_name,
|
|
185
|
+
"source-order-arguments",
|
|
186
|
+
str(len(self.source_argument_node_ids)),
|
|
187
|
+
"formal-order-parameters",
|
|
188
|
+
str(len(self.parameter_node_ids)),
|
|
189
|
+
"lowered-as",
|
|
190
|
+
self.lowering_shape,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
@property
|
|
194
|
+
def provenance_node_ids(self) -> tuple[str, ...]:
|
|
195
|
+
values = (
|
|
196
|
+
self.call_node_id,
|
|
197
|
+
self.callee_node_id,
|
|
198
|
+
self.target_function_node_id,
|
|
199
|
+
*self.parameter_node_ids,
|
|
200
|
+
*self.positional_argument_node_ids,
|
|
201
|
+
*self.keyword_node_ids,
|
|
202
|
+
*self.keyword_value_node_ids,
|
|
203
|
+
)
|
|
204
|
+
return tuple(dict.fromkeys(values))
|
|
205
|
+
|
|
206
|
+
@property
|
|
207
|
+
def call_target_overrides(self) -> dict[str, Any]:
|
|
208
|
+
"""Fields used to replace the predecessor's keyword rejection fact."""
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
"argument_node_ids": self.source_argument_node_ids,
|
|
212
|
+
"argument_categories": self.source_argument_categories,
|
|
213
|
+
"evaluation_order": self.evaluation_order,
|
|
214
|
+
"arguments_evaluated_once": self.arguments_evaluated_once,
|
|
215
|
+
"resolution": (
|
|
216
|
+
"understood-source-function"
|
|
217
|
+
if self.supported
|
|
218
|
+
else "ineligible-source-function"
|
|
219
|
+
),
|
|
220
|
+
"supported": self.supported,
|
|
221
|
+
"diagnostic_code": self.diagnostic_code,
|
|
222
|
+
"reason": self.reason,
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
def to_dict(self) -> dict[str, Any]:
|
|
226
|
+
return {
|
|
227
|
+
"binding_id": self.binding_id,
|
|
228
|
+
"call_node_id": self.call_node_id,
|
|
229
|
+
"callee_node_id": self.callee_node_id,
|
|
230
|
+
"target_function_node_id": self.target_function_node_id,
|
|
231
|
+
"target_binding_id": self.target_binding_id,
|
|
232
|
+
"target_name": self.target_name,
|
|
233
|
+
"positional_only_parameter_count": self.positional_only_parameter_count,
|
|
234
|
+
"parameter_node_ids": list(self.parameter_node_ids),
|
|
235
|
+
"parameter_names": list(self.parameter_names),
|
|
236
|
+
"parameter_categories": list(self.parameter_categories),
|
|
237
|
+
"positional_argument_node_ids": list(self.positional_argument_node_ids),
|
|
238
|
+
"keyword_node_ids": list(self.keyword_node_ids),
|
|
239
|
+
"keyword_names": list(self.keyword_names),
|
|
240
|
+
"keyword_value_node_ids": list(self.keyword_value_node_ids),
|
|
241
|
+
"argument_bindings": [item.to_dict() for item in self.argument_bindings],
|
|
242
|
+
"source_argument_node_ids": list(self.source_argument_node_ids),
|
|
243
|
+
"source_argument_categories": list(self.source_argument_categories),
|
|
244
|
+
"source_to_parameter_ordinals": list(self.source_to_parameter_ordinals),
|
|
245
|
+
"parameter_argument_node_ids": list(self.parameter_argument_node_ids),
|
|
246
|
+
"parameter_to_source_ordinals": list(self.parameter_to_source_ordinals),
|
|
247
|
+
"evaluation_order": list(self.evaluation_order),
|
|
248
|
+
"arguments_evaluated_once": self.arguments_evaluated_once,
|
|
249
|
+
"parameter_coverage_exact": self.parameter_coverage_exact,
|
|
250
|
+
"lowering_shape": self.lowering_shape,
|
|
251
|
+
"allocation_model": self.allocation_model,
|
|
252
|
+
"cleanup_model": self.cleanup_model,
|
|
253
|
+
"runtime_binding_failure": self.runtime_binding_failure,
|
|
254
|
+
"supported": self.supported,
|
|
255
|
+
"diagnostic_code": self.diagnostic_code,
|
|
256
|
+
"reason": self.reason,
|
|
257
|
+
"rejection_node_id": self.rejection_node_id,
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
@dataclass(frozen=True, slots=True)
|
|
262
|
+
class KeywordCallAnalysis:
|
|
263
|
+
facts: tuple[KeywordCallBindingFact, ...]
|
|
264
|
+
rejections: tuple[KeywordCallRejection, ...]
|
|
265
|
+
|
|
266
|
+
@property
|
|
267
|
+
def supported_call_node_ids(self) -> frozenset[str]:
|
|
268
|
+
return frozenset(item.call_node_id for item in self.facts if item.supported)
|
|
269
|
+
|
|
270
|
+
@property
|
|
271
|
+
def fact_by_call_node_id(self) -> dict[str, KeywordCallBindingFact]:
|
|
272
|
+
return {item.call_node_id: item for item in self.facts}
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def keyword_call_binding_id(call_node_id: str, target_binding_id: str) -> str:
|
|
276
|
+
digest = hashlib.sha256(
|
|
277
|
+
f"{call_node_id}\x1f{target_binding_id}\x1fexact-keyword-binding-v1".encode(
|
|
278
|
+
"utf-8"
|
|
279
|
+
)
|
|
280
|
+
).hexdigest()
|
|
281
|
+
return "keyword-call-binding-" + digest[:20]
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
__all__ = [
|
|
285
|
+
"CUMULATIVE_KEYWORD_TARGET_DIAGNOSTIC_CODE",
|
|
286
|
+
"CUMULATIVE_KEYWORD_TARGET_REASON",
|
|
287
|
+
"KEYWORD_CALL_FACT_SCHEMA",
|
|
288
|
+
"KEYWORD_CALL_KEY_DOMAIN",
|
|
289
|
+
"KEYWORD_CALL_LOWERING_SHAPE",
|
|
290
|
+
"KEYWORD_CALL_OBLIGATIONS",
|
|
291
|
+
"KEYWORD_CALL_PROVENANCE_EVIDENCE",
|
|
292
|
+
"KEYWORD_CALL_RULE_ID",
|
|
293
|
+
"KEYWORD_CALL_RULE_VERSION",
|
|
294
|
+
"KEYWORD_CALL_TABLE_DEPENDENCIES",
|
|
295
|
+
"KEYWORD_CALL_TABLE_ID",
|
|
296
|
+
"KeywordArgumentBindingFact",
|
|
297
|
+
"KeywordCallAnalysis",
|
|
298
|
+
"KeywordCallAnalysisCanceled",
|
|
299
|
+
"KeywordCallAnalysisError",
|
|
300
|
+
"KeywordCallBindingFact",
|
|
301
|
+
"KeywordCallRejection",
|
|
302
|
+
"KeywordCallValidationCanceled",
|
|
303
|
+
"keyword_call_binding_id",
|
|
304
|
+
]
|