feat(joinir/dev): build Normalized if-only module with structure verification (no behavior change)

Phase 122 P2-P3: Dev-only wiring + structure verification
- Wire Phase 122 emission into existing Phase 121 dev path
- Add verify_normalized_structure() for module validation
- Check: phase, function count, entry point, env args count
- Strict mode: fail-fast on structure mismatch
- No behavior change to existing execution path
This commit is contained in:
nyash-codex
2025-12-18 04:52:09 +09:00
parent 7603ef8a6a
commit cc1a0946b0
2 changed files with 86 additions and 5 deletions

View File

@ -199,18 +199,43 @@ impl MirBuilder {
&tree, &func_name, strict, dev,
)?;
// Phase 121: StepTree→Normalized shadow lowering (dev-only)
// Phase 121/122: StepTree→Normalized shadow lowering (dev-only)
if dev {
use crate::mir::control_tree::normalized_shadow::StepTreeNormalizedShadowLowererBox;
use crate::mir::control_tree::normalized_shadow::parity;
// Try shadow lowering (if-only scope)
let shadow_result = StepTreeNormalizedShadowLowererBox::try_lower_if_only(&tree);
match shadow_result {
Ok(Some((_module, _meta))) => {
// Shadow lowering succeeded
let status = StepTreeNormalizedShadowLowererBox::get_status_string(&tree);
trace.dev("phase121/shadow", &status);
Ok(Some((module, _meta))) => {
// Phase 122: Verify Normalized JoinModule structure
let expected_env_fields = tree.contract.writes.len();
let verify_result = parity::verify_normalized_structure(&module, expected_env_fields);
if !verify_result.ok {
let msg = format!(
"phase122/emit: structure verification failed for {}: {}",
func_name,
verify_result.hint.unwrap_or_else(|| "<no hint>".to_string())
);
if strict {
return Err(format!(
"Phase122 Normalized structure verification failed (strict mode): {}",
msg
));
}
trace.dev("phase122/emit/error", &msg);
} else {
// Shadow lowering succeeded + structure verified
let status = format!(
"module_emitted=true funcs={} env_fields={} step_tree_sig={}",
module.functions.len(),
expected_env_fields,
tree.signature_basis_string()
);
trace.dev("phase122/emit", &status);
}
}
Ok(None) => {
// Out of scope (e.g., contains loops)