📦 Hotfix 4: Static Method Receiver ValueId Reservation
**根本原因**: Static method (e.g., `collect_entries/1`) は暗黙の 'me' receiver を持つが、signature.params に含まれていない
**問題の構造**:
```
static box Stage1UsingResolverFull {
collect_entries(src_unused) { // signature: /1 (1 param)
me._find_from(...) // 'me' を使用!
}
}
```
- Signature: params.len() = 1 (src_unused のみ)
- 実際の ValueIds: 2つ必要 (%0 = receiver/me, %1 = src_unused)
**修正内容**:
src/mir/function.rs - MirFunction::new() で static method 判定追加:
1. **判定ロジック**:
- Function name に "." が含まれる → box method or static method
- params[0] が Box type でない → static method (implicit receiver)
- → +1 ValueId for receiver
2. **予約計算**:
```rust
let receiver_count = if has_implicit_receiver { 1 } else { 0 };
let total_value_ids = param_count + receiver_count;
let initial_counter = total_value_ids.max(1);
```
**Test Result**:
```
[MirFunction::new] fn='Stage1UsingResolverFull.collect_entries/1'
params=1, receiver=1, total=2, initial_counter=2 ✅
[MirFunction::new] fn='Stage1UsingResolverFull._find_from/3'
params=3, receiver=1, total=4, initial_counter=4 ✅
```
**進捗**:
- ✅ Hotfix 1: Parameter ValueId reservation
- ✅ Hotfix 2: Exit PHI validation
- ✅ Hotfix 3: NewBox ValueId fix
- ✅ Hotfix 4: Static method receiver reservation
- ⏸️ Remaining: bb57 %0 undefined error (別の問題、次セッションで調査)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -77,15 +77,36 @@ impl MirFunction {
|
|||||||
let mut blocks = HashMap::new();
|
let mut blocks = HashMap::new();
|
||||||
blocks.insert(entry_block, BasicBlock::new(entry_block));
|
blocks.insert(entry_block, BasicBlock::new(entry_block));
|
||||||
|
|
||||||
// 📦 Hotfix 1: Reserve ValueIds for function parameters at creation time
|
// 📦 Hotfix 1 + 4: Reserve ValueIds for function parameters at creation time
|
||||||
// Parameter ValueIds are %0, %1, ..., %N-1 where N = signature.params.len()
|
// Parameter ValueIds are %0, %1, ..., %N-1 where N = signature.params.len()
|
||||||
// next_value_id must start at N to avoid overwriting parameters
|
//
|
||||||
|
// 📦 Hotfix 4: Static method receiver reservation
|
||||||
|
// Static methods (e.g., Stage1UsingResolverFull.collect_entries/1) have implicit 'me' receiver
|
||||||
|
// that's not included in signature.params but needs ValueId reservation.
|
||||||
|
//
|
||||||
|
// Detection: If function name contains "." (box method or static method) AND
|
||||||
|
// params[0] is NOT a Box type → static method → needs +1 for receiver
|
||||||
let param_count = signature.params.len() as u32;
|
let param_count = signature.params.len() as u32;
|
||||||
let initial_counter = param_count.max(1); // At least 1 to reserve ValueId(0) as sentinel
|
let has_implicit_receiver = if signature.name.contains('.') {
|
||||||
|
// Box method or static method
|
||||||
|
if signature.params.is_empty() {
|
||||||
|
// No params → static method with only receiver
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
// Check if first param is Box type (instance method) or not (static method)
|
||||||
|
!matches!(signature.params[0], MirType::Box(_))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
let receiver_count = if has_implicit_receiver { 1 } else { 0 };
|
||||||
|
let total_value_ids = param_count + receiver_count;
|
||||||
|
let initial_counter = total_value_ids.max(1); // At least 1 to reserve ValueId(0) as sentinel
|
||||||
|
|
||||||
if std::env::var("NYASH_LOOPFORM_DEBUG").is_ok() {
|
if std::env::var("NYASH_LOOPFORM_DEBUG").is_ok() {
|
||||||
eprintln!("[MirFunction::new] fn='{}' params={}, initial_counter={}",
|
eprintln!("[MirFunction::new] fn='{}' params={}, receiver={}, total={}, initial_counter={}",
|
||||||
signature.name, param_count, initial_counter);
|
signature.name, param_count, receiver_count, total_value_ids, initial_counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
Reference in New Issue
Block a user