Skip to content

Commit 817f6ae

Browse files
committed
Merge o1w/merge0-ef (22f1681: E re-pin, F scanner form) into the merge-7 line
2 parents 53b8a4b + 22f1681 commit 817f6ae

5 files changed

Lines changed: 74 additions & 2 deletions

File tree

‎docs/pages/native-engine.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4401,7 +4401,7 @@ fails when this table cites a row once too few or too many.
44014401
| `ReplaceOptions` (`retain_trigger_state`, `keep_handle`, `keep_binding`) | Scheduled for 1.1.0. The C replace calls take no options word: a plain replace is available, and carrying the trigger state, the handle or a book binding across it needs C++. | `C_V1_EXCLUSIONS["replace_options"]` |
44024402
| `ExecutionAppliedEvent` beyond the fill | The event carries its definition (origin, label, comment, the request), the closed-row range it booked, the remaining units and allowance before and after, the execution scope and the whole cursor. `pf_native_applied_v1` carries the fill's prices, units, ticket, cycles, terminal reason and incarnations only. Origin and label are scheduled for 1.1.0; the rest has no lane. Inside `on_applied` a C host cannot tell a kernel liquidation from its own fill (`on_margin_call` arrives after it), and it finds the rows the fill booked only by probing `strategy_closed_trade_entry_id` for the new row count. | `C_V1_EXCLUSIONS["applied_event_tail"]` |
44034403
| a closed row's entry comment (`closed_trade(i).entry_comment`) | Scheduled for 1.1.0. No C accessor returns it and `pf_trade_t` carries no strings. `strategy_closed_trade_entry_incarnation` names the request whose fill opened the lot, whose comment the C host wrote itself; while the lot is open, `pf_native_open_lot_v1::entry_comment` reads it. | `C_V1_EXCLUSIONS["closed_entry_comment"]` |
4404-
| closed rows in place (`closed_trade_count()` / `closed_trade(i)`, `report_trade_count()` / `get_report_trade(i)`) | A C++ host reads a closed row whole, at any time, every `Trade` field included. A C host reads the numeric fields from a filled `pf_report_t` (the run's `strategy_native_run_v1` output, or `strategy_stream_fill_report`), and the strings, the close cause and the entry incarnation by report index. | `C_V1_EXCLUSIONS["closed_rows_in_place"]` |
4404+
| closed-row access by copy (`closed_trade_count()` / `closed_trade(i)`, `report_trade_count()` / `get_report_trade(i)`) | Closed rows are paged, and the C++ accessor returns a copy. C v1 still exposes no per-row accessor: a C host reads per-field values by index only, with numeric fields in a filled `pf_report_t` (the run's `strategy_native_run_v1` output, or `strategy_stream_fill_report`) and strings, the close cause and the entry incarnation by report index. | `C_V1_EXCLUSIONS["closed_rows_in_place"]` |
44054405
| the working request's whole definition (`NativeWorkingRequest::definition`) | `pf_native_working_v1` reads back the request's tags, levels, relation tail, origin, label and comment. It leaves out a reduce's size kind, claim and basis, the `Sized` block (side, basis, time, price, grid policy, fee reserve), `Limit::fill_through`, a host-sized request's kind and side, every `BindOpenings` handle past the first, the predecessor, root, priority and kept binding, and the trail's seed. The seed is a submission value (`pf_native_request_v1::trail_best_seed`); the live ride is `strategy_native_trail_state_v1`. | `C_V1_EXCLUSIONS["working_definition"]` |
44064406
| `NativeDecisionContext::closes_session_day_open_ended` | The C decision carries the other three session-day facts (`in_session`, `opens_session_day`, `closes_session_day`). The fourth differs from `closes_session_day` only on a batch's final bar, for a host recomputing a batch whose last input is still forming; a C host's live edge is a `strategy_stream_*` stream, and the decision's session tail gives the calendar facts for a host that applies its own rule. | `C_V1_EXCLUSIONS["open_ended_session_day"]` |
44074407
| the rest of the callback contexts | The decision has no input interval, no source price time, no driver statistics and no quote origin ordinal (`NativeCurrentPointView::quote_origin_ordinal`). `on_input` gets the bar, its index and whether it completes a script interval, without the input or script interval; `on_tick` gets no sequence. | `C_V1_EXCLUSIONS["callback_contexts"]` |

‎scripts/check_native_c_api_surface.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
"closed_entry_comment": ("engine.hpp", "std::string entry_comment;", (
208208
("@declarations", r"\bstrategy_\w*entry_comment\w*"),
209209
("pf_trade_s", r"\b\w*comment\w*"))),
210-
"closed_rows_in_place": ("engine.hpp", "const Trade& closed_trade(std::size_t i) const", (
210+
"closed_rows_in_place": ("engine.hpp", "Trade closed_trade(std::size_t i) const", (
211211
("@declarations", r"\bstrategy_(?:native_)?(?:closed_trade_count|closed_trade_get"
212212
r"|closed_trade_row|report_trade)\w*"),)),
213213
"working_definition": ("native_order.hpp", "std::optional<double> best_seed", (

‎scripts/check_selected_window_ownership.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,13 @@ def scalar_type(node, environment, resolving=frozenset()):
866866
return result
867867
if isinstance(node, ast.Name) and node.id in environment and node.id not in resolving:
868868
return scalar_type(environment[node.id], environment, resolving | {node.id})
869+
# One indexed read from the report arrays reconstructed below, never a slice.
870+
if (isinstance(node, ast.Subscript) and isinstance(node.value, ast.Attribute)
871+
and isinstance(node.value.value, ast.Name) and node.value.value.id == "report"
872+
and node.value.attr in {"trades", "equity_curve"}
873+
and (isinstance(node.slice, ast.Name)
874+
or (isinstance(node.slice, ast.Constant) and type(node.slice.value) is int))):
875+
return {"kind": "number", "null_allowed": False}
869876
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
870877
name = node.func.id
871878
if name in {"int", "len", "sum"}:

‎scripts/test_check_native_c_api_surface.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,28 @@ def test_a_decision_input_interval_closes_the_gap(self) -> None:
149149
"callback_contexts", " uint8_t closes_session_day; /**< It closes its session day. */",
150150
"\n int64_t input_interval_open_ms;")
151151

152+
def test_closed_rows_pin_requires_a_by_value_accessor(self) -> None:
153+
by_value = "Trade closed_trade(std::size_t i) const"
154+
by_reference = "const Trade& closed_trade(std::size_t i) const"
155+
self.assertEqual(guard.C_V1_EXCLUSIONS["closed_rows_in_place"][1], by_value)
156+
saved = guard.INCLUDE
157+
self.addCleanup(setattr, guard, "INCLUDE", saved)
158+
copy = Path(self.c_api.parent, "include")
159+
shutil.copytree(saved, copy)
160+
engine = copy / "engine.hpp"
161+
text = engine.read_text(encoding="utf-8")
162+
self.assertEqual(text.count(by_value), 1)
163+
guard.INCLUDE = copy
164+
code, err = self.run_guard()
165+
self.assertEqual(code, 0, err)
166+
167+
engine.write_text(text.replace(by_value, by_reference, 1), encoding="utf-8")
168+
code, err = self.run_guard()
169+
self.assertEqual(code, 1, err)
170+
self.assertIn(
171+
f'C_V1_EXCLUSIONS["closed_rows_in_place"]: the C++ declaration `{by_value}` '
172+
"is gone from engine.hpp: retire the row, or re-pin it", err)
173+
152174
def test_a_cpp_capability_that_goes_retires_its_row(self) -> None:
153175
saved = guard.INCLUDE
154176
self.addCleanup(setattr, guard, "INCLUDE", saved)

‎tests/ownership/test_manifest_checker.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import ast
1717
import copy
1818
import ctypes
19+
import importlib.util
1920
import json
2021
import math
2122
import re
@@ -30,6 +31,10 @@
3031
ROOT = Path(__file__).resolve().parents[2]
3132
CHECKER = ROOT / "scripts/check_selected_window_ownership.py"
3233
MANIFEST = ROOT / "tests/ownership/manifest.v1.json"
34+
SPEC = importlib.util.spec_from_file_location("selected_window_ownership", CHECKER)
35+
ownership = importlib.util.module_from_spec(SPEC)
36+
sys.modules[SPEC.name] = ownership
37+
SPEC.loader.exec_module(ownership)
3338

3439

3540
def emitted_schema(root: Path) -> dict:
@@ -460,6 +465,44 @@ def test_new_public_field_has_no_implicit_owner(self):
460465
def test_d4_independent_reconstruction_matches_manifest(self):
461466
self.assertEqual(manifest_schema(self.doc), emitted_schema(ROOT))
462467

468+
def scalar_fixture(self, source):
469+
assignment, = ast.parse(source).body
470+
self.assertIsInstance(assignment, ast.Assign)
471+
target, = assignment.targets
472+
self.assertIsInstance(target, ast.Name)
473+
self.assertEqual(target.id, "p")
474+
return ownership.scalar_type(ast.Name(id="p", ctx=ast.Load()), {"p": assignment.value})
475+
476+
def test_d4_report_array_scalar_index_is_accepted(self):
477+
for source in ("p = report.equity_curve[i]", "p = report.equity_curve[0]",
478+
"p = report.trades[i]", "p = report.trades[0]"):
479+
with self.subTest(source=source):
480+
self.assertEqual(self.scalar_fixture(source), {"kind": "number", "null_allowed": False})
481+
482+
def test_d4_unrecognized_report_array_index_is_rejected(self):
483+
self.assertEqual(self.scalar_fixture("p = report.equity_curve[i]"),
484+
{"kind": "number", "null_allowed": False})
485+
for expression in ("report.unknown[i]", "other.equity_curve[i]",
486+
"report.other.equity_curve[i]", "report.equity_curve.values[i]"):
487+
with self.subTest(expression=expression):
488+
with self.assertRaises(ownership.InputError) as raised:
489+
self.scalar_fixture("p = " + expression)
490+
self.assertEqual(str(raised.exception),
491+
"unrecognized scalar producer expression: " + expression)
492+
493+
def test_d4_report_array_slice_is_rejected(self):
494+
self.assertEqual(self.scalar_fixture("p = report.equity_curve[i]"),
495+
{"kind": "number", "null_allowed": False})
496+
for expression in ("report.equity_curve[i:j]", "report.equity_curve[:]",
497+
"report.equity_curve[True]", "report.equity_curve[1.0]",
498+
"report.equity_curve[i + 1]", "report.equity_curve[index()]",
499+
"report.equity_curve[i, j]"):
500+
with self.subTest(expression=expression):
501+
with self.assertRaises(ownership.InputError) as raised:
502+
self.scalar_fixture("p = " + expression)
503+
self.assertEqual(str(raised.exception),
504+
"unrecognized scalar producer expression: " + expression)
505+
463506
def test_d4_manifest_leaf_removed_is_rejected(self):
464507
# Killer for D4-comparison-disabled; checks this specific diagnostic.
465508
rows = self.doc["canonical_schema"]["leaves"]

0 commit comments

Comments
 (0)