🚨 AI協調開発の危機回避事例を論文化(paper-09)
「ん?大丈夫?」の一言がPython特化ハードコーディングを防いだ事例を記録。
Everything is Box哲学 vs 技術的正しさの綱渡りからの生還を分析。
- docs/research/paper-09-ai-collaboration-pitfall/ を新規作成
- incident-analysis.md: Lowerer特殊化危機の詳細分析
- ai-collaboration-lessons.md: AI協調開発の教訓
- intuition-in-engineering.md: エンジニアの直感の価値
- summary.md: 綱渡りからの生還まとめ
- 研究論文の1論文1フォルダ原則に従い整理
- Python統合関連の実装修正とビルド成功確認
🛡️ Generated with Claude Code
This commit is contained in:
@ -49,6 +49,9 @@ impl MirOptimizer {
|
||||
stats.merge(self.force_plugin_invoke(module));
|
||||
}
|
||||
|
||||
// Normalize Python helper form: py.getattr(obj, name) → obj.getattr(name)
|
||||
stats.merge(self.normalize_python_helper_calls(module));
|
||||
|
||||
// Pass 1: Dead code elimination
|
||||
stats.merge(self.eliminate_dead_code(module));
|
||||
|
||||
@ -326,6 +329,40 @@ impl MirOptimizer {
|
||||
}
|
||||
stats
|
||||
}
|
||||
|
||||
/// Normalize Python helper calls that route via PyRuntimeBox into proper receiver form.
|
||||
///
|
||||
/// Rewrites: PluginInvoke { box_val=py (PyRuntimeBox), method="getattr"|"call", args=[obj, rest...] }
|
||||
/// → PluginInvoke { box_val=obj, method, args=[rest...] }
|
||||
fn normalize_python_helper_calls(&mut self, module: &mut MirModule) -> OptimizationStats {
|
||||
use super::{MirInstruction as I, MirType};
|
||||
let mut stats = OptimizationStats::new();
|
||||
for (_fname, function) in &mut module.functions {
|
||||
for (_bb, block) in &mut function.blocks {
|
||||
for inst in &mut block.instructions {
|
||||
if let I::PluginInvoke { box_val, method, args, .. } = inst {
|
||||
if method == "getattr" && args.len() >= 2 {
|
||||
// Prefer metadata when available
|
||||
// Heuristic: helper形式 (obj, name) のときのみ書換
|
||||
// Rewrite receiver to args[0]
|
||||
let new_recv = args[0];
|
||||
// Remove first arg and keep the rest
|
||||
args.remove(0);
|
||||
*box_val = new_recv;
|
||||
stats.intrinsic_optimizations += 1;
|
||||
} else if method == "call" && !args.is_empty() {
|
||||
// call は helper形式 (func, args...) を receiver=func に正規化
|
||||
let new_recv = args[0];
|
||||
args.remove(0);
|
||||
*box_val = new_recv;
|
||||
stats.intrinsic_optimizations += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stats
|
||||
}
|
||||
/// Normalize legacy instructions into unified MIR26 forms.
|
||||
/// - TypeCheck/Cast → TypeOp(Check/Cast)
|
||||
/// - WeakNew/WeakLoad → WeakRef(New/Load)
|
||||
|
||||
Reference in New Issue
Block a user