interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / searchtrace / st_hook.h

99 lines · 4698 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef OMEGA_SEARCHTRACE_HOOK_H
18#define OMEGA_SEARCHTRACE_HOOK_H
19/* M23 search-trace recorder hook (G1 corpus capture).
20 *
21 * One function-pointer type shared by the two search sites:
22 * src/omega_synthesis.c one event per candidate the program search touches
23 * src/omega_realize_synth.c one event per omega_synthesize_realization call
24 *
25 * Pattern of the rx_world recorder (omega#114): at most one recorder per site,
26 * installed explicitly, off by default. The hook is per thread (_Thread_local):
27 * a search on another thread never sees it. With no hook installed each site
28 * does one null test and nothing else, so search behaviour and results are
29 * unchanged. The recorder observes only: it gets const pointers that are valid
30 * for the duration of the call, cannot veto, prune or alter the search, and
31 * must not install or clear hooks from inside the callback. It MAY call
32 * omega_synthesize_realization (the realize hook then fires nested).
33 */
34#include <stdint.h>
35#include <stddef.h>
36
37typedef enum {
38 ST_EV_SYNTH_CANDIDATE = 1, /* omega_synthesis.c */
39 ST_EV_REALIZATION = 2 /* omega_realize_synth.c */
40} StEventKind;
41
42/* Why a candidate left the search (or ST_PRUNE_NONE when it was evaluated). */
43typedef enum {
44 ST_PRUNE_NONE = 0,
45 ST_PRUNE_TYPE = 1, /* composition refused (child absent) */
46 ST_PRUNE_COST = 2, /* insn_count over task budget or config max_cost */
47 ST_PRUNE_EQUIV = 3, /* observationally equivalent to a cheaper/equal seen candidate */
48 ST_PRUNE_BUDGET = 4 /* global max_candidates cutoff reached; search stops */
49} StPruneReason;
50
51/* Verifier result for an evaluated candidate. */
52typedef enum {
53 ST_VERDICT_NONE = 0, /* not evaluated (pruned) */
54 ST_VERDICT_REJECT = 1, /* task evaluation: wrong on an example (or eval error) */
55 ST_VERDICT_SOLVED = 2, /* task solved and omega_program_verify passed */
56 ST_VERDICT_VERIFY_FAIL = 3 /* task solved but omega_program_verify refused */
57} StVerdict;
58
59typedef struct {
60 uint32_t depth; /* 1, 2 or 3 */
61 int32_t parent_index; /* index into the previous depth's kept list; -1 at depth 1 */
62 int32_t prim_index; /* bank primitive applied (depth 1: the primitive itself) */
63 const void *parent; /* const OmegaProgram *; NULL at depth 1 */
64 const void *prim; /* const OmegaProgram * (bank entry) */
65 const void *child; /* const OmegaProgram *; NULL when ST_PRUNE_TYPE or ST_PRUNE_BUDGET */
66 uint32_t prune; /* StPruneReason */
67 uint32_t verdict; /* StVerdict */
68 int32_t eval_rc; /* omega_task_evaluate_candidate rc (0 when not evaluated) */
69 int32_t verify_rc; /* omega_program_verify rc (0 when not run) */
70 uint32_t has_signature; /* 1 when the equivalence signature was computed */
71 uint8_t signature[32]; /* probe-output signature (only when has_signature) */
72} StSynthEvent;
73
74typedef struct {
75 const void *program; /* const OmegaProgram * */
76 const void *machine; /* const OmegaMachineGraph * */
77 const void *result; /* const RealizationSynthesisResult * */
78 int32_t rc; /* return code of omega_synthesize_realization */
79} StRealizeEvent;
80
81typedef struct {
82 uint32_t kind; /* StEventKind */
83 union {
84 StSynthEvent synth;
85 StRealizeEvent realize;
86 } u;
87} StEvent;
88
89typedef void (*StHookFn)(void *ctx, const StEvent *ev);
90
91/* Install the recorder for this thread at one site. Returns 0, or -1 if a hook
92 * is already installed (at most one) or fn is null. */
93int omega_synth_set_trace_hook(StHookFn fn, void *ctx);
94int omega_realize_set_trace_hook(StHookFn fn, void *ctx);
95/* Remove the hook installed with ctx. Returns 0, or -1 if ctx is not the installed one. */
96int omega_synth_clear_trace_hook(void *ctx);
97int omega_realize_clear_trace_hook(void *ctx);
98
99#endif /* OMEGA_SEARCHTRACE_HOOK_H */