Skip to content

spec(t27f): add the spec -> graph IR exporter in t27 (Closes #10162) - #10173

Merged
gHashTag merged 1 commit into
masterfrom
t27f/spec-graph-export
Oct 18, 2026
Merged

gHashTag merged 1 commit into
masterfrom
t27f/spec-graph-export

Conversation

@gHashTag

Copy link
Copy Markdown
Owner

Closes #10162

Epic gHashTag/trinity#1648, RFC gHashTag/trinity#1649.

What this adds

specs/t27f/spec_graph_export.t27 (module t27f_spec_graph_export): the T27F exporter, written in t27. export_graph(path, src) is a deterministic byte scanner from spec source to a SpecGraph; export_verdict is validate_graph of the result. It reuses spec_graph's builders, codes and validate_graph through use and restates none of them.

  • Nodes: one per top-level declaration line (optional pub ). module/use/const/fn/test/invariant/bench map to their NODE_* kind. struct/enum/var/spec/endmodule are OPAQUE + EXACT. Anything else, or a keyword with no readable name, is OPAQUE + UNKNOWN.
  • Spans: declaration line to the line of the matching closing brace; braces in strings, character literals, // comments and ; comment lines are skipped. A brace-less declaration ends at its ; line or its last indented continuation line.
  • Labels: everything read is EXACT; the scanner never emits DERIVED or SUGGESTED.
  • Edges (all EXACT, edge_line = first use, deduplicated, EDGE_FROM/TO_KINDS respected): module USES import, fn/test/invariant/bench CALLS a declared fn (name followed by (), USES a declared const or imported name, invariant CONSTRAINS a const.
  • Overflow: past MAX_NODES (20) or MAX_EDGES (24) the counts keep growing, so validate_graph answers ERR_TOO_MANY_NODES / ERR_TOO_MANY_EDGES; nothing is truncated.

Docs: .claude/skills/t27f/SKILL.md (exporter row with its limits, graph view row now "drawn by the MCP tool t27f_graph (gHashTag/t27-mcp#9)", the "Show a spec" and "does not claim" sections), specs/OWNERS.md (t27f/ row).

Verified (Railway lab only, nothing built or run on the Mac)

  • t27c test-report specs/t27f/spec_graph_export.t27: 20 tests, 20 pass, 0 fail, 0 vacuous of 20.
  • t27b test specs/t27f/spec_graph_export.t27 --check (qemu-aarch64): 20 passed, 0 failed, 259 runtime asserts.
  • Every test has a negative control (a source that must not produce the node, edge or verdict). Tests cover one source with all 8 node kinds, opaque EXACT vs UNKNOWN, nameless declarations, nested braces, braces in string/comment/char/; lines and an escaped quote, brace-less continuation, block-form module, edge direction rules, dedupe, both overflow boundaries (20 vs 21 nodes, 24 vs 27 edges), empty source and empty path.
  • The tutorial snapshot embedded in the spec is byte-identical to specs/tutorial/08_modules_and_arrays.t27 (sha256 c291e925d9dabef8b72b5a64aef153a2126c0b0b43d67bc08b1b2d7eaa98039a, checked locally; the file's last change is 2f39502).

Tutorial 08: exporter vs the hand-read tutorial_08_graph()

Not an exact match. Compared field by field, the differences are:

  1. Nodes: the exporter returns 14, the fixture 15. Nodes 0..13 are identical on kind, label, name and span. The fixture's node 14 (std.testing, OPAQUE + UNKNOWN, lines 79..89) is a region inferred from call targets, not a declaration, so the scanner does not produce it.
  2. Edges: the exporter returns 9, the fixture 16. The 9 are the fixture's 9 EXACT edges, identical on kind, endpoints, label and line, with 0 extras. The other 7 fixture edges are DERIVED (4 DATA_FLOW, 3 TESTED_BY); a scanner never derives, so it does not emit them.
  3. Edge order differs (the exporter groups by source node), so the test compares sets, not positions.

The test tutorial_08_exports_the_fixture_exactly_except_what_is_derived asserts exactly this boundary, with negative controls (a moved span, a moved edge line).

Not claimed

  • Names are matched as text with no scope or type resolution; a local named like a const or import counts as a use.
  • Only the top level is read: no struct/enum bodies, no statements, no cross-spec use resolution, no block comments.
  • Capacity is IR version 1's 20 nodes and 24 edges, so most real specs are refused; this is the IR's limit, not a scanner defect.
  • The source is a []const u8 slice, not the [65536]u8 plus a length sketched in the task: t27 slices carry their length, and the probe on both compilers accepted it.
  • The test compares an embedded snapshot of tutorial 08, not the live file.
  • No host calls the exporter yet (the MCP tool is not claimed to use it), and spec_graph_view.t27 has no view_fx case for an exported graph.
  • Lab deviation: /data on the lab was 100% full, so the lab run used /root/w-sgx instead of /data/w-sgx.

0 lines of non-t27 code; ASCII only under specs/.

🤖 Generated with Claude Code

export_graph(path, src) scans spec source bytes into a SpecGraph: one node per
top-level declaration, brace-matched spans, EXACT CALLS/USES/CONSTRAINS edges,
refusal past MAX_NODES/MAX_EDGES. Tutorial 08 matches the hand-read fixture on
all 14 declaration nodes and all 9 EXACT edges; the fixture-only std.testing
node and 7 DERIVED edges are not emitted. Refs gHashTag/trinity#1648, #1649.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-10-18 02:56:56 UTC

Summary

Status Count
Total Open PRs 50
PRs with Failing Checks 45
PRs with All Checks Green 5
READY 0
FAILING 45
PENDING 0
NO CHECKS YET 0

These columns do not partition: 0 + 45 + 0 + 0 = 45, and there are 50 open PRs. A PR is being counted twice or not at all.

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=3b53d48ddb52 != manifest seal=87e5cbd3ad94.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spec(t27f): spec -> graph IR exporter in t27, read out of real spec source

1 participant