✓
Passing This code compiles and runs correctly.
Code
// Test 430_010: AST Dump at Multiple Pipeline Stages
//
// Override frontend and analysis to dump AST at each stage.
// Demonstrates introspection into the compiler pipeline.
//
// Expected output (to stdout during compilation):
// === AST DUMP: post-elaborate ===
// { ... JSON AST ... }
// === AST DUMP: post-analysis ===
// { ... JSON AST ... }
import std/compiler
import std/io
// ============================================================================
// DUMP AST AFTER FRONTEND
// ============================================================================
std/compiler:elaborate = std/compiler:elaborate.default(ctx): c |> std/compiler:ast-dump(ctx: c, flag: "post-elaborate") -> c
// ============================================================================
// DUMP AST AFTER ANALYSIS
// ============================================================================
std/compiler:analysis = std/compiler:analysis.default(ctx)
| ctx c |> std/compiler:ast-dump(ctx: c, flag: "post-analysis") => ctx c
| failed f => failed { f.ctx, f.message }
// ============================================================================
// THE PROGRAM
// ============================================================================
std/io:print.ln("AST was dumped at 2 stages!")
Actual
AST was dumped at 2 stages!
Expected output
AST was dumped at 2 stages!
Flows
subflow ~elaborate click a branch to expand · @labels scroll to their anchor
elaborate.default (ctx)
subflow ~analysis click a branch to expand · @labels scroll to their anchor
analysis.default (ctx)
flow ~print.ln click a branch to expand · @labels scroll to their anchor
print.ln (expr: "AST was dumped at 2 stages!")
Test Configuration
MUST_RUN
Post-validation Script:
#!/bin/bash
# Post-validation: Verify AST dumps at both stages
# The ast_dump event runs during backend execution, output goes to backend.err
set -e
if [ ! -f "backend.err" ]; then
echo "❌ FAIL: No backend.err file found"
exit 1
fi
# Check for post-elaborate dump
if ! grep -q "=== AST DUMP: post-elaborate ===" backend.err; then
echo "❌ Missing post-elaborate AST dump"
exit 1
fi
echo "✅ Post-elaborate AST dump found"
# Check for post-analysis dump
if ! grep -q "=== AST DUMP: post-analysis ===" backend.err; then
echo "❌ Missing post-analysis AST dump"
exit 1
fi
echo "✅ Post-analysis AST dump found"
# Verify dumps contain JSON (have opening brace after header)
if ! grep -A1 "post-elaborate" backend.err | grep -q "{"; then
echo "❌ Post-elaborate dump doesn't look like JSON"
exit 1
fi
if ! grep -A1 "post-analysis" backend.err | grep -q "{"; then
echo "❌ Post-analysis dump doesn't look like JSON"
exit 1
fi
echo ""
echo "🎉 AST dumps at multiple pipeline stages working!"
echo " You can now introspect the compiler at any point."
exit 0