fix: 修复 Map/Set GC 追踪与 CodeForge 缓存键

This commit is contained in:
爱特每羊队
2026-06-17 09:38:48 +08:00
parent 1b77028340
commit 9db28b22d6
10 changed files with 482 additions and 126 deletions
@@ -16,6 +16,12 @@ fn parse_to_hash(source: &str) -> u64 {
oxide_compiler::compiler::structural_hash(&program)
}
fn parse_to_compiled_hash(source: &str) -> u64 {
let allocator = Allocator::default();
let program = oxide_parser::parse(&allocator, source).expect("parse failed");
oxide_compiler::compiler::compiled_module_hash(&program)
}
#[test]
fn structural_hash_hit() {
let forge = CodeForge::new();
@@ -43,6 +49,20 @@ fn structural_hash_identifier_renaming_remains_normalized() {
assert_eq!(hash_a, hash_b);
}
#[test]
fn compiled_module_hash_distinguishes_same_shape_different_identifier_loads() {
let hash_a = parse_to_compiled_hash("var x = 1; var y = 2; x");
let hash_b = parse_to_compiled_hash("var x = 1; var y = 2; y");
assert_ne!(hash_a, hash_b);
}
#[test]
fn compiled_module_hash_distinguishes_assignment_targets() {
let hash_a = parse_to_compiled_hash("var x = 1; x = 2; x");
let hash_b = parse_to_compiled_hash("var x = 1; y = 2; x");
assert_ne!(hash_a, hash_b);
}
#[test]
fn structural_hash_different_init_values() {
let hash_a = parse_to_hash("var x = 1 + 2;");