## 修正内容
### Core MIR/PHI (5ファイル)
- builder.rs: variable_map, value_types, value_origin_newbox
- context.rs: 3つのマップ
- loop_builder.rs: 3箇所
- loop_snapshot_manager.rs: snapshot マップ
- loop_snapshot_merge.rs: 2箇所
### MIR関連 (4ファイル)
- function.rs: FunctionMetadata.value_types
- resolver.rs: CalleeResolverBox
- guard.rs: CalleeGuardBox
- loop_common.rs: apply_increment_before_continue
### JSON Bridge (5ファイル)
- json_v0_bridge/lowering.rs
- json_v0_bridge/lowering/expr.rs
- json_v0_bridge/lowering/if_else.rs
- json_v0_bridge/lowering/merge.rs
- json_v0_bridge/lowering/try_catch.rs
- json_v0_bridge/mod.rs
### Printer & Providers (4ファイル)
- printer.rs, printer_helpers.rs
- host_providers/mir_builder.rs
- backend/mir_interpreter/handlers/extern_provider.rs
### Tests (3ファイル)
- phi_core/conservative.rs
- tests/json_program_loop.rs
- tests/mir_stage1_using_resolver_verify.rs (2テスト有効化)
## テスト結果
- mir_stage1_using_resolver_resolve_with_modules_map_verifies: 80%成功率
- 完全な決定性は未達成 (HashMap 86箇所、HashSet 63箇所が残存)
🐱 Generated with Claude Code
99 lines
3.0 KiB
Rust
99 lines
3.0 KiB
Rust
use serde_json::json;
|
|
use std::collections::BTreeMap;
|
|
|
|
fn verify_program(label: &str, program: serde_json::Value) {
|
|
let src = serde_json::to_string(&program).expect("serialize program");
|
|
let module = nyash_rust::runner::json_v0_bridge::parse_json_v0_to_module_with_imports(
|
|
&src,
|
|
BTreeMap::new(),
|
|
)
|
|
.unwrap_or_else(|e| panic!("{}: failed to parse Program(JSON): {}", label, e));
|
|
|
|
let mut verifier = nyash_rust::mir::verification::MirVerifier::new();
|
|
if let Err(errors) = verifier.verify_module(&module) {
|
|
panic!(
|
|
"{}: MIR verification failed with errors: {:?}",
|
|
label, errors
|
|
);
|
|
}
|
|
}
|
|
|
|
fn program_simple_loop() -> serde_json::Value {
|
|
json!({
|
|
"version": 0,
|
|
"kind": "Program",
|
|
"body": [
|
|
{ "type": "Local", "name": "loopCount", "expr": { "type": "Int", "value": 0 } },
|
|
{
|
|
"type": "Loop",
|
|
"cond": { "type": "Bool", "value": true },
|
|
"body": [
|
|
{ "type": "Break" }
|
|
]
|
|
},
|
|
{ "type": "Return", "expr": { "type": "Var", "name": "loopCount" } }
|
|
]
|
|
})
|
|
}
|
|
|
|
fn program_loop_with_continue() -> serde_json::Value {
|
|
json!({
|
|
"version": 0,
|
|
"kind": "Program",
|
|
"body": [
|
|
{ "type": "Local", "name": "cycles", "expr": { "type": "Int", "value": 0 } },
|
|
{
|
|
"type": "Loop",
|
|
"cond": { "type": "Bool", "value": true },
|
|
"body": [
|
|
{ "type": "Local", "name": "loopTick", "expr": { "type": "Int", "value": 1 } },
|
|
{
|
|
"type": "If",
|
|
"cond": { "type": "Bool", "value": true },
|
|
"then": [
|
|
{ "type": "Continue" }
|
|
],
|
|
"else": [
|
|
{ "type": "Break" }
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{ "type": "Return", "expr": { "type": "Var", "name": "cycles" } }
|
|
]
|
|
})
|
|
}
|
|
|
|
fn program_loop_body_local_exit() -> serde_json::Value {
|
|
json!({
|
|
"version": 0,
|
|
"kind": "Program",
|
|
"body": [
|
|
{
|
|
"type": "Loop",
|
|
"cond": { "type": "Bool", "value": true },
|
|
"body": [
|
|
{ "type": "Local", "name": "bodyTemp", "expr": { "type": "Int", "value": 42 } },
|
|
{ "type": "Break" }
|
|
]
|
|
},
|
|
{ "type": "Return", "expr": { "type": "Var", "name": "bodyTemp" } }
|
|
]
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn json_loop_simple_verifies() {
|
|
verify_program("json_loop_simple", program_simple_loop());
|
|
}
|
|
|
|
#[test]
|
|
fn json_loop_with_continue_verifies() {
|
|
verify_program("json_loop_with_continue", program_loop_with_continue());
|
|
}
|
|
|
|
#[test]
|
|
fn json_loop_body_local_exit_verifies() {
|
|
verify_program("json_loop_body_local_exit", program_loop_body_local_exit());
|
|
}
|