ERR/E3.0 (slice 3a): embedded Frame trace resolution

Return-trace frames now resolve to real `func at file:line:col`
in-process — no DWARF, no symbolizer.

- New niladic, span-stamped `.trace_frame` IR op (mirrors is_comptime):
  carries no operands; each backend derives the frame from context.
  lower.zig's placeholderTraceFrame emits it; the existing
  sx_trace_push call consumes it.
- emit_llvm: resolve the op's span + current function to
  {file(basename), line, col, func}, build an interned Frame global
  ({string,i32,i32,string}, strings cached by content), push its
  address (ptrtoint).
- interp: pack (func_id << 32 | span.start) for the comptime resolver
  (slice 3b); never a pointer.
- sx_trace.c report_unhandled derefs SxFrame; trace.sx gains the Frame
  struct, frame_at -> *Frame, and field-reading to_string. Layout
  mirrored in 3 places with cross-ref comments.

Verified JIT + AOT. Snapshots 243/244/247 regenerated (placeholder ->
func at file:line:col). Gates: zig build, zig build test,
run_examples.sh -> 290 passed.
This commit is contained in:
agra
2026-06-01 15:10:46 +03:00
parent 8b8ba3a1bf
commit 1b6cbc17e7
10 changed files with 150 additions and 32 deletions

View File

@@ -69,14 +69,20 @@ uint64_t sx_trace_frame_at(uint32_t i) {
return sx_trace_frames[(base + i) % SX_TRACE_CAP];
}
// A compiled trace frame (ERR E3.0 slice 3a) is a pointer to an interned
// `Frame { string file; i32 line; i32 col; string func; }`, where an sx
// `string` is `{ const char* ptr; int64_t len; }`. This mirror MUST stay in
// lockstep with `getFrameStructType` in emit_llvm.zig and `Frame` in trace.sx.
typedef struct { const char *ptr; int64_t len; } SxStr;
typedef struct { SxStr file; int32_t line; int32_t col; SxStr func; } SxFrame;
// The failable-`main` entry-point reporter (ERR step E4.2). Called by the
// emitted main wrapper when an error reaches the function boundary: prints the
// unhandled-error header (with the tag name passed in — the compiler resolves
// it from the always-linked tag-name table) followed by the surviving trace
// frames, all to stderr. `name` is borrowed (a `string` slice, not NUL-
// terminated), so `name_len` bounds the print. The frame format mirrors
// trace.sx's `to_string`; both stay placeholder ("<location pending DWARF>")
// until DWARF line-info (E3.0) lands, after which both gain real file:line:col.
// trace.sx's `to_string` — `func at file:line:col`.
void sx_trace_report_unhandled(uint32_t tag, const char *name, size_t name_len) {
(void)tag;
dprintf(2, "error: unhandled error reached main: error.%.*s\n",
@@ -88,8 +94,10 @@ void sx_trace_report_unhandled(uint32_t tag, const char *name, size_t name_len)
dprintf(2, " ... older frames omitted (buffer full)\n");
}
for (uint32_t i = 0u; i < n; i++) {
uint64_t frame = sx_trace_frame_at(i);
dprintf(2, " frame %u: <location pending DWARF> (raw %llu)\n",
i, (unsigned long long)frame);
const SxFrame *f = (const SxFrame *)(uintptr_t)sx_trace_frame_at(i);
dprintf(2, " %.*s at %.*s:%d:%d\n",
(int)f->func.len, f->func.ptr,
(int)f->file.len, f->file.ptr,
f->line, f->col);
}
}