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.
Files changed (221) hide show
  1. pycforge/__init__.py +8 -0
  2. pycforge/__main__.py +2 -0
  3. pycforge/_version.py +1 -0
  4. pycforge/converter/__init__.py +0 -0
  5. pycforge/converter/analysis/__init__.py +5 -0
  6. pycforge/converter/analysis/functions.py +723 -0
  7. pycforge/converter/analysis/model.py +158 -0
  8. pycforge/converter/analysis/planning.py +464 -0
  9. pycforge/converter/analysis/stage.py +1976 -0
  10. pycforge/converter/analysis/symbols.py +237 -0
  11. pycforge/converter/analysis/validation.py +2166 -0
  12. pycforge/converter/c_output/__init__.py +2 -0
  13. pycforge/converter/c_output/conformance.py +297 -0
  14. pycforge/converter/c_output/renderer.py +220 -0
  15. pycforge/converter/conditional_regions/__init__.py +71 -0
  16. pycforge/converter/conditional_regions/analysis.py +481 -0
  17. pycforge/converter/conditional_regions/lowering.py +579 -0
  18. pycforge/converter/conditional_regions/model.py +243 -0
  19. pycforge/converter/conditional_regions/validation.py +690 -0
  20. pycforge/converter/containers/__init__.py +19 -0
  21. pycforge/converter/containers/analysis.py +542 -0
  22. pycforge/converter/containers/lowering.py +290 -0
  23. pycforge/converter/containers/model.py +146 -0
  24. pycforge/converter/contracts/__init__.py +0 -0
  25. pycforge/converter/contracts/configuration.py +178 -0
  26. pycforge/converter/contracts/identifiers.py +68 -0
  27. pycforge/converter/contracts/versions.py +71 -0
  28. pycforge/converter/core/__init__.py +0 -0
  29. pycforge/converter/core/artifact_io.py +87 -0
  30. pycforge/converter/core/cancellation.py +7 -0
  31. pycforge/converter/core/canonicalization.py +254 -0
  32. pycforge/converter/core/context.py +13 -0
  33. pycforge/converter/core/diagnostics.py +95 -0
  34. pycforge/converter/core/enums.py +23 -0
  35. pycforge/converter/core/fingerprint.py +22 -0
  36. pycforge/converter/core/pipeline.py +8 -0
  37. pycforge/converter/core/progress.py +25 -0
  38. pycforge/converter/core/request.py +50 -0
  39. pycforge/converter/core/resource_policy.py +31 -0
  40. pycforge/converter/core/result.py +23 -0
  41. pycforge/converter/core/serialization.py +36 -0
  42. pycforge/converter/core/stage.py +10 -0
  43. pycforge/converter/core/stage_artifact.py +80 -0
  44. pycforge/converter/core/stage_outcome.py +15 -0
  45. pycforge/converter/decision_trace/__init__.py +0 -0
  46. pycforge/converter/decision_trace/recorder.py +52 -0
  47. pycforge/converter/facade.py +459 -0
  48. pycforge/converter/frontend/__init__.py +4 -0
  49. pycforge/converter/frontend/normalizer.py +59 -0
  50. pycforge/converter/frontend/parser.py +20 -0
  51. pycforge/converter/frontend/source_document.py +93 -0
  52. pycforge/converter/frontend/stages.py +518 -0
  53. pycforge/converter/frontend/validation.py +76 -0
  54. pycforge/converter/io/__init__.py +0 -0
  55. pycforge/converter/io/atomic_writer.py +33 -0
  56. pycforge/converter/ir/__init__.py +1 -0
  57. pycforge/converter/ir/c_ir/__init__.py +4 -0
  58. pycforge/converter/ir/c_ir/builder.py +26 -0
  59. pycforge/converter/ir/c_ir/model.py +318 -0
  60. pycforge/converter/ir/c_ir/serialization.py +88 -0
  61. pycforge/converter/ir/c_ir/validation.py +834 -0
  62. pycforge/converter/ir/python_ir/__init__.py +17 -0
  63. pycforge/converter/ir/python_ir/nodes.py +86 -0
  64. pycforge/converter/keyword_calls/__init__.py +68 -0
  65. pycforge/converter/keyword_calls/analysis.py +458 -0
  66. pycforge/converter/keyword_calls/lowering.py +271 -0
  67. pycforge/converter/keyword_calls/model.py +304 -0
  68. pycforge/converter/keyword_calls/validation.py +802 -0
  69. pycforge/converter/keyword_only_calls/__init__.py +68 -0
  70. pycforge/converter/keyword_only_calls/analysis.py +640 -0
  71. pycforge/converter/keyword_only_calls/lowering.py +376 -0
  72. pycforge/converter/keyword_only_calls/model.py +328 -0
  73. pycforge/converter/keyword_only_calls/validation.py +1357 -0
  74. pycforge/converter/lowering.py +1000 -0
  75. pycforge/converter/modules/__init__.py +13 -0
  76. pycforge/converter/modules/analysis.py +1250 -0
  77. pycforge/converter/modules/lowering.py +200 -0
  78. pycforge/converter/modules/model.py +73 -0
  79. pycforge/converter/modules/stage.py +192 -0
  80. pycforge/converter/numeric_semantics/__init__.py +23 -0
  81. pycforge/converter/numeric_semantics/analysis.py +420 -0
  82. pycforge/converter/numeric_semantics/lowering.py +153 -0
  83. pycforge/converter/numeric_semantics/model.py +123 -0
  84. pycforge/converter/records/__init__.py +34 -0
  85. pycforge/converter/records/analysis.py +1394 -0
  86. pycforge/converter/records/lowering.py +393 -0
  87. pycforge/converter/records/model.py +319 -0
  88. pycforge/converter/rules/__init__.py +3 -0
  89. pycforge/converter/support_templates/__init__.py +49 -0
  90. pycforge/converter/support_templates/assembly.py +106 -0
  91. pycforge/converter/support_templates/factories.py +348 -0
  92. pycforge/converter/support_templates/model.py +159 -0
  93. pycforge/converter/support_templates/registry.py +388 -0
  94. pycforge/converter/telemetry/__init__.py +0 -0
  95. pycforge/converter/telemetry/sink.py +39 -0
  96. pycforge/ide/__init__.py +19 -0
  97. pycforge/ide/__main__.py +5 -0
  98. pycforge/ide/_worker_event_codec.py +276 -0
  99. pycforge/ide/_worker_protocol_json.py +197 -0
  100. pycforge/ide/_worker_protocol_types.py +90 -0
  101. pycforge/ide/_worker_request_codec.py +200 -0
  102. pycforge/ide/_worker_request_data.py +260 -0
  103. pycforge/ide/_worker_result_data.py +343 -0
  104. pycforge/ide/action_contract.py +469 -0
  105. pycforge/ide/action_validation.py +229 -0
  106. pycforge/ide/command_palette.py +223 -0
  107. pycforge/ide/controller.py +904 -0
  108. pycforge/ide/controller_conversion.py +546 -0
  109. pycforge/ide/controller_io.py +205 -0
  110. pycforge/ide/editor.py +951 -0
  111. pycforge/ide/editor_commands_qt.py +274 -0
  112. pycforge/ide/editor_lexical.py +43 -0
  113. pycforge/ide/editor_sidebars.py +236 -0
  114. pycforge/ide/editor_syntax.py +243 -0
  115. pycforge/ide/find_replace.py +535 -0
  116. pycforge/ide/icons.py +91 -0
  117. pycforge/ide/io_service.py +196 -0
  118. pycforge/ide/model.py +164 -0
  119. pycforge/ide/panels.py +903 -0
  120. pycforge/ide/positions.py +220 -0
  121. pycforge/ide/process_worker.py +130 -0
  122. pycforge/ide/qt.py +230 -0
  123. pycforge/ide/qt_actions.py +418 -0
  124. pycforge/ide/qt_close.py +169 -0
  125. pycforge/ide/qt_command_palette.py +297 -0
  126. pycforge/ide/qt_contract.py +220 -0
  127. pycforge/ide/qt_documents.py +590 -0
  128. pycforge/ide/qt_editor_buffers.py +113 -0
  129. pycforge/ide/qt_editor_surfaces.py +112 -0
  130. pycforge/ide/qt_menus.py +324 -0
  131. pycforge/ide/qt_projection.py +500 -0
  132. pycforge/ide/qt_shell.py +348 -0
  133. pycforge/ide/qt_shell_interactions.py +320 -0
  134. pycforge/ide/qt_state.py +393 -0
  135. pycforge/ide/qt_workspace_features.py +398 -0
  136. pycforge/ide/qt_workspace_navigation.py +208 -0
  137. pycforge/ide/qt_workspace_observers.py +173 -0
  138. pycforge/ide/qt_workspace_panels.py +545 -0
  139. pycforge/ide/qt_workspace_widgets.py +228 -0
  140. pycforge/ide/resources/icons/about.svg +1 -0
  141. pycforge/ide/resources/icons/add-document.svg +1 -0
  142. pycforge/ide/resources/icons/brand-mark.svg +1 -0
  143. pycforge/ide/resources/icons/bundle-search.svg +1 -0
  144. pycforge/ide/resources/icons/cancel.svg +1 -0
  145. pycforge/ide/resources/icons/check.svg +1 -0
  146. pycforge/ide/resources/icons/chevron-right.svg +1 -0
  147. pycforge/ide/resources/icons/close.svg +1 -0
  148. pycforge/ide/resources/icons/collapse-all.svg +1 -0
  149. pycforge/ide/resources/icons/command-palette.svg +1 -0
  150. pycforge/ide/resources/icons/convert.svg +1 -0
  151. pycforge/ide/resources/icons/copy.svg +1 -0
  152. pycforge/ide/resources/icons/cut.svg +1 -0
  153. pycforge/ide/resources/icons/decision-trace.svg +1 -0
  154. pycforge/ide/resources/icons/details.svg +1 -0
  155. pycforge/ide/resources/icons/diagnostics.svg +1 -0
  156. pycforge/ide/resources/icons/duplicate-line.svg +1 -0
  157. pycforge/ide/resources/icons/exit.svg +1 -0
  158. pycforge/ide/resources/icons/expand-all.svg +1 -0
  159. pycforge/ide/resources/icons/export.svg +1 -0
  160. pycforge/ide/resources/icons/find.svg +1 -0
  161. pycforge/ide/resources/icons/go-to-line.svg +1 -0
  162. pycforge/ide/resources/icons/go-to-output.svg +1 -0
  163. pycforge/ide/resources/icons/go-to-source.svg +1 -0
  164. pycforge/ide/resources/icons/history.svg +1 -0
  165. pycforge/ide/resources/icons/indent.svg +1 -0
  166. pycforge/ide/resources/icons/link-c.svg +1 -0
  167. pycforge/ide/resources/icons/mappings.svg +1 -0
  168. pycforge/ide/resources/icons/module.svg +1 -0
  169. pycforge/ide/resources/icons/move-down.svg +1 -0
  170. pycforge/ide/resources/icons/move-line-down.svg +1 -0
  171. pycforge/ide/resources/icons/move-line-up.svg +1 -0
  172. pycforge/ide/resources/icons/move-up.svg +1 -0
  173. pycforge/ide/resources/icons/next.svg +1 -0
  174. pycforge/ide/resources/icons/open.svg +1 -0
  175. pycforge/ide/resources/icons/outdent.svg +1 -0
  176. pycforge/ide/resources/icons/outline.svg +1 -0
  177. pycforge/ide/resources/icons/paste.svg +1 -0
  178. pycforge/ide/resources/icons/previous.svg +1 -0
  179. pycforge/ide/resources/icons/primary-module.svg +1 -0
  180. pycforge/ide/resources/icons/redo.svg +1 -0
  181. pycforge/ide/resources/icons/remove-document.svg +1 -0
  182. pycforge/ide/resources/icons/replace.svg +1 -0
  183. pycforge/ide/resources/icons/save-as.svg +1 -0
  184. pycforge/ide/resources/icons/save.svg +1 -0
  185. pycforge/ide/resources/icons/select-all.svg +1 -0
  186. pycforge/ide/resources/icons/settings.svg +1 -0
  187. pycforge/ide/resources/icons/show-c.svg +1 -0
  188. pycforge/ide/resources/icons/split-view.svg +1 -0
  189. pycforge/ide/resources/icons/summary.svg +1 -0
  190. pycforge/ide/resources/icons/telemetry.svg +1 -0
  191. pycforge/ide/resources/icons/toggle-comment.svg +1 -0
  192. pycforge/ide/resources/icons/toggle-fold.svg +1 -0
  193. pycforge/ide/resources/icons/undo.svg +1 -0
  194. pycforge/ide/resources/icons/whitespace.svg +1 -0
  195. pycforge/ide/revisions.py +400 -0
  196. pycforge/ide/search_service.py +280 -0
  197. pycforge/ide/session_history.py +150 -0
  198. pycforge/ide/source_editing.py +417 -0
  199. pycforge/ide/source_structure.py +558 -0
  200. pycforge/ide/source_structure_async.py +191 -0
  201. pycforge/ide/supervisor.py +503 -0
  202. pycforge/ide/theme.py +119 -0
  203. pycforge/ide/theme_stylesheet.py +598 -0
  204. pycforge/ide/theme_workspace_stylesheet.py +155 -0
  205. pycforge/ide/visual_tokens.py +142 -0
  206. pycforge/ide/worker_protocol.py +80 -0
  207. pycforge/ide/workspace_search.py +462 -0
  208. pycforge/ide/workspace_session.py +256 -0
  209. pycforge/laboratory/__init__.py +6 -0
  210. pycforge/laboratory/audits.py +2244 -0
  211. pycforge/laboratory/checkpoint_e.py +2685 -0
  212. pycforge/laboratory/cli.py +119 -0
  213. pycforge/laboratory/exit_codes.py +11 -0
  214. pycforge/laboratory/keyword_audit.py +661 -0
  215. pycforge/laboratory/keyword_only_audit.py +481 -0
  216. pycforge-0.15.2.dist-info/METADATA +209 -0
  217. pycforge-0.15.2.dist-info/RECORD +221 -0
  218. pycforge-0.15.2.dist-info/WHEEL +5 -0
  219. pycforge-0.15.2.dist-info/entry_points.txt +5 -0
  220. pycforge-0.15.2.dist-info/licenses/LICENSE +674 -0
  221. pycforge-0.15.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,376 @@
1
+ """Structured C IR staging for proved required keyword-only calls."""
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 (
11
+ KEYWORD_ONLY_CALL_LOWERING_SHAPE,
12
+ KEYWORD_ONLY_CALL_TABLE_ID,
13
+ )
14
+
15
+
16
+ def _value(item: Any, name: str, default: Any = None) -> Any:
17
+ if isinstance(item, Mapping):
18
+ return item.get(name, default)
19
+ return getattr(item, name, default)
20
+
21
+
22
+ def _category(value: Any) -> str:
23
+ return value.value if hasattr(value, "value") else str(value or "unknown")
24
+
25
+
26
+ def _sequence(value: Any) -> bool:
27
+ return isinstance(value, (list, tuple))
28
+
29
+
30
+ def lowering_supports_parameter_shape(
31
+ fields: Any,
32
+ *,
33
+ allow_required_keyword_only: bool,
34
+ ) -> bool:
35
+ """Recognize the exact declaration shape accepted by the C lowering boundary."""
36
+
37
+ if not isinstance(fields, Mapping):
38
+ return False
39
+ keyword_only = fields.get("kwonlyargs")
40
+ keyword_defaults = fields.get("kw_defaults")
41
+ if (
42
+ not _sequence(fields.get("posonlyargs"))
43
+ or not _sequence(fields.get("args"))
44
+ or not _sequence(keyword_only)
45
+ or not _sequence(keyword_defaults)
46
+ or fields.get("vararg")
47
+ or fields.get("kwarg")
48
+ or fields.get("defaults")
49
+ ):
50
+ return False
51
+ if not keyword_only:
52
+ return not keyword_defaults
53
+ return (
54
+ allow_required_keyword_only
55
+ and len(keyword_defaults) == len(keyword_only)
56
+ and all(item is None for item in keyword_defaults)
57
+ )
58
+
59
+
60
+ def lowered_parameter_node_ids(
61
+ fields: Mapping[str, Any],
62
+ *,
63
+ include_required_keyword_only: bool,
64
+ ) -> tuple[str, ...]:
65
+ result = tuple(fields.get("posonlyargs", ())) + tuple(fields.get("args", ()))
66
+ if include_required_keyword_only:
67
+ result += tuple(fields.get("kwonlyargs", ()))
68
+ return result
69
+
70
+
71
+ def _exact_permutation(
72
+ value: Any,
73
+ size: int,
74
+ check_cancellation: Callable[[], None],
75
+ ) -> bool:
76
+ if not _sequence(value) or len(value) != size:
77
+ return False
78
+ seen = [False] * size
79
+ for item in value:
80
+ check_cancellation()
81
+ if (
82
+ not isinstance(item, int)
83
+ or isinstance(item, bool)
84
+ or item < 0
85
+ or item >= size
86
+ or seen[item]
87
+ ):
88
+ return False
89
+ seen[item] = True
90
+ return True
91
+
92
+
93
+ @dataclass(slots=True)
94
+ class KeywordOnlyCallLoweringServices:
95
+ nodes: dict[str, dict[str, Any]]
96
+ facts: dict[str, dict[str, Any]]
97
+ expression: Callable[[dict[str, Any]], tuple[tuple[Any, ...], Any]]
98
+ temporary: Callable[..., tuple[Any, CIdentifierRef]]
99
+ type_from_name: Callable[[str | None], CType]
100
+ reject: Callable[..., Any]
101
+ check_cancellation: Callable[[], None]
102
+
103
+
104
+ class KeywordOnlyCallCIRLowerer:
105
+ """Stage actuals in source order and return references in formal order."""
106
+
107
+ def __init__(self, services: KeywordOnlyCallLoweringServices) -> None:
108
+ self.services = services
109
+
110
+ def has_fact(self, call_node_id: str) -> bool:
111
+ return call_node_id in self.services.facts
112
+
113
+ def arguments(
114
+ self,
115
+ node: dict[str, Any],
116
+ signature: Any,
117
+ ) -> tuple[tuple[Any, ...], tuple[CIdentifierRef, ...]]:
118
+ s = self.services
119
+ s.check_cancellation()
120
+ if not isinstance(node, Mapping) or not isinstance(node.get("node_id"), str):
121
+ s.reject("PYC2912", "Keyword-only call node is malformed", node)
122
+ call_id = node["node_id"]
123
+ fact = s.facts.get(call_id)
124
+ if not isinstance(fact, Mapping):
125
+ s.reject(
126
+ "PYC2910",
127
+ "Required keyword-only call lacks an exact binding fact",
128
+ node,
129
+ )
130
+ rejection = s.nodes.get(fact.get("rejection_node_id"), node)
131
+ if fact.get("supported") is False:
132
+ if (
133
+ not isinstance(fact.get("diagnostic_code"), str)
134
+ or not isinstance(fact.get("reason"), str)
135
+ or not isinstance(fact.get("rejection_node_id"), str)
136
+ or not isinstance(rejection, Mapping)
137
+ ):
138
+ s.reject("PYC2912", "Keyword-only rejection fact is malformed", node)
139
+ s.reject(
140
+ fact["diagnostic_code"],
141
+ fact["reason"],
142
+ rejection,
143
+ )
144
+ if fact.get("supported") is not True:
145
+ s.reject("PYC2912", "Keyword-only support state is malformed", node)
146
+ parameters_value = _value(signature, "parameters")
147
+ if not _sequence(parameters_value):
148
+ s.reject("PYC2912", "Keyword-only signature is malformed", node)
149
+ parameters: Sequence[Any] = tuple(parameters_value)
150
+ sequence_fields = (
151
+ "parameter_node_ids",
152
+ "parameter_names",
153
+ "parameter_kinds",
154
+ "parameter_categories",
155
+ "required_keyword_only_parameter_node_ids",
156
+ "required_keyword_only_parameter_names",
157
+ "required_keyword_only_parameter_categories",
158
+ "argument_bindings",
159
+ "source_argument_node_ids",
160
+ "source_argument_categories",
161
+ "evaluation_order",
162
+ "source_to_parameter_ordinals",
163
+ "parameter_argument_node_ids",
164
+ "parameter_to_source_ordinals",
165
+ "positional_argument_node_ids",
166
+ "keyword_node_ids",
167
+ "keyword_names",
168
+ "keyword_value_node_ids",
169
+ )
170
+ if any(not _sequence(fact.get(name)) for name in sequence_fields):
171
+ s.reject("PYC2912", "Keyword-only binding sequences are malformed", node)
172
+ bindings = tuple(fact["argument_bindings"])
173
+ source_ids = tuple(fact["source_argument_node_ids"])
174
+ source_categories = tuple(fact["source_argument_categories"])
175
+ source_to_parameter = tuple(fact["source_to_parameter_ordinals"])
176
+ parameter_arguments = tuple(fact["parameter_argument_node_ids"])
177
+ parameter_to_source = tuple(fact["parameter_to_source_ordinals"])
178
+ parameter_kinds = tuple(fact["parameter_kinds"])
179
+ call_fields = node.get("fields")
180
+ if (
181
+ not isinstance(call_fields, Mapping)
182
+ or not _sequence(call_fields.get("args"))
183
+ or not _sequence(call_fields.get("keywords"))
184
+ ):
185
+ s.reject("PYC2912", "Keyword-only call fields are malformed", node)
186
+ keyword_ids = tuple(call_fields["keywords"])
187
+ keyword_names: list[str | None] = []
188
+ keyword_values: list[str] = []
189
+ for keyword_id in keyword_ids:
190
+ keyword = s.nodes.get(keyword_id)
191
+ fields = keyword.get("fields") if isinstance(keyword, Mapping) else None
192
+ if (
193
+ not isinstance(keyword_id, str)
194
+ or not isinstance(keyword, Mapping)
195
+ or keyword.get("kind") != "keyword"
196
+ or not isinstance(fields, Mapping)
197
+ or not isinstance(fields.get("value"), str)
198
+ ):
199
+ s.reject("PYC2912", "Keyword-only keyword evidence is malformed", node)
200
+ keyword_names.append(fields.get("arg"))
201
+ keyword_values.append(fields["value"])
202
+ positional_only_count = fact.get("positional_only_parameter_count")
203
+ positional_or_keyword_count = fact.get(
204
+ "positional_or_keyword_parameter_count"
205
+ )
206
+ keyword_only_count = fact.get("keyword_only_parameter_count")
207
+ if (
208
+ not isinstance(positional_only_count, int)
209
+ or not isinstance(positional_or_keyword_count, int)
210
+ or not isinstance(keyword_only_count, int)
211
+ or positional_only_count < 0
212
+ or positional_or_keyword_count < 0
213
+ or keyword_only_count <= 0
214
+ or positional_only_count
215
+ + positional_or_keyword_count
216
+ + keyword_only_count
217
+ != len(parameters)
218
+ or fact.get("call_node_id") != call_id
219
+ or fact.get("callee_node_id") != call_fields.get("func")
220
+ or fact.get("lowering_shape") != KEYWORD_ONLY_CALL_LOWERING_SHAPE
221
+ or fact.get("arguments_evaluated_once") is not True
222
+ or fact.get("parameter_coverage_exact") is not True
223
+ or fact.get("keyword_only_coverage_exact") is not True
224
+ or fact.get("allocation_model") != "none"
225
+ or fact.get("cleanup_model") != "none"
226
+ or fact.get("runtime_binding_failure") != "proved-absent"
227
+ or tuple(fact["positional_argument_node_ids"])
228
+ != tuple(call_fields["args"])
229
+ or tuple(fact["keyword_node_ids"]) != keyword_ids
230
+ or tuple(fact["keyword_names"]) != tuple(keyword_names)
231
+ or tuple(fact["keyword_value_node_ids"]) != tuple(keyword_values)
232
+ or source_ids != tuple(fact["evaluation_order"])
233
+ or len(bindings) != len(parameters)
234
+ or len(source_ids) != len(parameters)
235
+ or len(source_categories) != len(parameters)
236
+ or len(parameter_arguments) != len(parameters)
237
+ or len(parameter_to_source) != len(parameters)
238
+ or tuple(
239
+ parameter_kinds[
240
+ positional_only_count + positional_or_keyword_count :
241
+ ]
242
+ )
243
+ != ("keyword-only",) * keyword_only_count
244
+ or not _exact_permutation(
245
+ source_to_parameter,
246
+ len(parameters),
247
+ s.check_cancellation,
248
+ )
249
+ or not _exact_permutation(
250
+ parameter_to_source,
251
+ len(parameters),
252
+ s.check_cancellation,
253
+ )
254
+ ):
255
+ s.reject(
256
+ "PYC2912",
257
+ "Keyword-only binding fact is incomplete or inconsistent",
258
+ node,
259
+ )
260
+
261
+ for source_ordinal, binding in enumerate(bindings):
262
+ s.check_cancellation()
263
+ if not isinstance(binding, Mapping):
264
+ s.reject("PYC2912", "Keyword-only argument binding is malformed", node)
265
+ parameter_ordinal = binding.get("parameter_ordinal")
266
+ argument_id = binding.get("source_argument_node_id")
267
+ keyword_id = binding.get("keyword_node_id")
268
+ if (
269
+ binding.get("source_ordinal") != source_ordinal
270
+ or argument_id != source_ids[source_ordinal]
271
+ or binding.get("category") != source_categories[source_ordinal]
272
+ or parameter_ordinal != source_to_parameter[source_ordinal]
273
+ or not isinstance(parameter_ordinal, int)
274
+ or not 0 <= parameter_ordinal < len(parameters)
275
+ or parameter_arguments[parameter_ordinal] != argument_id
276
+ or parameter_to_source[parameter_ordinal] != source_ordinal
277
+ or argument_id not in s.nodes
278
+ or s.nodes[argument_id].get("kind") == "Starred"
279
+ or binding.get("parameter_node_id")
280
+ != _value(parameters[parameter_ordinal], "parameter_node_id")
281
+ or binding.get("parameter_name")
282
+ != _value(parameters[parameter_ordinal], "source_name")
283
+ or binding.get("parameter_kind")
284
+ != parameter_kinds[parameter_ordinal]
285
+ or binding.get("expected_category")
286
+ != _category(_value(parameters[parameter_ordinal], "category"))
287
+ ):
288
+ s.reject(
289
+ "PYC2912",
290
+ "Keyword-only argument permutation is inconsistent",
291
+ node,
292
+ )
293
+ if keyword_id is not None:
294
+ keyword = s.nodes.get(keyword_id)
295
+ if (
296
+ not isinstance(keyword, Mapping)
297
+ or keyword.get("kind") != "keyword"
298
+ or keyword.get("fields", {}).get("value") != argument_id
299
+ or keyword.get("fields", {}).get("arg")
300
+ != binding.get("keyword_name")
301
+ ):
302
+ s.reject(
303
+ "PYC2912",
304
+ "Keyword-only named binding is inconsistent",
305
+ node,
306
+ )
307
+ if parameter_kinds[parameter_ordinal] == "keyword-only" and keyword_id is None:
308
+ s.reject(
309
+ "PYC2912",
310
+ "Keyword-only formal was not supplied by explicit keyword",
311
+ node,
312
+ )
313
+
314
+ prelude: list[Any] = []
315
+ references: list[CIdentifierRef | None] = [None] * len(parameters)
316
+ for source_ordinal, binding in enumerate(bindings):
317
+ s.check_cancellation()
318
+ argument_id = binding["source_argument_node_id"]
319
+ parameter_ordinal = binding["parameter_ordinal"]
320
+ expression_prelude, expression = s.expression(s.nodes[argument_id])
321
+ prelude.extend(expression_prelude)
322
+ origins = tuple(
323
+ item
324
+ for item in (
325
+ argument_id,
326
+ binding.get("keyword_node_id"),
327
+ call_id,
328
+ )
329
+ if isinstance(item, str)
330
+ )
331
+ declaration, reference = s.temporary(
332
+ "arg",
333
+ node,
334
+ source_ordinal,
335
+ s.type_from_name(_value(parameters[parameter_ordinal], "c_type")),
336
+ expression,
337
+ origins,
338
+ )
339
+ if not isinstance(reference, CIdentifierRef):
340
+ s.reject(
341
+ "PYC2912",
342
+ "Keyword-only staging did not produce a pure reference",
343
+ node,
344
+ )
345
+ prelude.append(declaration)
346
+ references[parameter_ordinal] = reference
347
+ s.check_cancellation()
348
+ if any(item is None for item in references):
349
+ s.reject("PYC2912", "Keyword-only staging omitted a formal", node)
350
+ return tuple(prelude), tuple(references) # type: ignore[arg-type]
351
+
352
+
353
+ def bind_keyword_only_call_lowerer(owner: Any) -> KeywordOnlyCallCIRLowerer:
354
+ return KeywordOnlyCallCIRLowerer(
355
+ KeywordOnlyCallLoweringServices(
356
+ nodes=owner.nodes,
357
+ facts=owner._optional_values(
358
+ KEYWORD_ONLY_CALL_TABLE_ID,
359
+ "call_node_id",
360
+ ),
361
+ expression=owner._expression,
362
+ temporary=owner._temporary,
363
+ type_from_name=owner._type_from_name,
364
+ reject=owner._reject,
365
+ check_cancellation=owner._check_cancel,
366
+ )
367
+ )
368
+
369
+
370
+ __all__ = [
371
+ "KeywordOnlyCallCIRLowerer",
372
+ "KeywordOnlyCallLoweringServices",
373
+ "bind_keyword_only_call_lowerer",
374
+ "lowered_parameter_node_ids",
375
+ "lowering_supports_parameter_shape",
376
+ ]