Implement comprehensive dead code detection for hako_check with JoinIR integration, following Phase 133/134/152 box-based modularity pattern. ## Key Achievements 1. **Comprehensive Inventory** (`phase153_hako_check_inventory.md`): - Documented current hako_check architecture (872 lines) - Analyzed existing HC011/HC012 rules - Confirmed JoinIR-only pipeline (Phase 124) - Identified Phase 153 opportunities 2. **DeadCodeAnalyzerBox** (`rule_dead_code.hako`): - Unified HC019 rule (570+ lines) - Method-level + box-level dead code detection - DFS reachability from entrypoints - Text-based analysis (no MIR JSON dependency for MVP) - Heuristic-based false positive reduction 3. **CLI Integration** (`cli.hako`): - Added `--dead-code` flag for comprehensive mode - Added `--rules dead_code` for selective execution - Compatible with --format (text/json-lsp/dot) 4. **Test Infrastructure**: - HC019_dead_code test directory (ng/ok/expected.json) - `hako_check_deadcode_smoke.sh` with 4 test cases ## Technical Details - **Input**: Analysis IR (MapBox with methods/calls/boxes/entrypoints) - **Output**: HC019 diagnostics - **Algorithm**: Graph-based DFS reachability - **Pattern**: Box-based modular architecture - **No ENV vars**: CLI flags only ## Files Modified - NEW: docs/development/current/main/phase153_hako_check_inventory.md - NEW: tools/hako_check/rules/rule_dead_code.hako - MOD: tools/hako_check/cli.hako - NEW: tools/hako_check/tests/HC019_dead_code/ - NEW: tools/hako_check_deadcode_smoke.sh - MOD: CURRENT_TASK.md ## Next Steps - Phase 154+: MIR CFG integration for block-level detection - Phase 160+: Integration with .hako JoinIR/MIR migration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
3.5 KiB
3.5 KiB
Plugin Loader Migration Plan
Status: Migration plan memo(継続検討用の設計メモ)
Note: 実際の進捗と優先度はCURRENT_TASK.mdと roadmap 側を正として管理し、このファイルはプラグインローダ統合の設計メモ・タスクリストとして扱います。
Overview
Consolidate three plugin loader implementations into a single unified system.
Current State
- plugin_loader_v2.rs (906 lines) - Main BID-FFI plugin system
- plugin_loader.rs (1217 lines) - Builtin box dynamic loading
- plugin_loader_legacy.rs (299 lines) - Legacy host vtable system
Total: ~2400 lines of code with significant duplication
Target State
- plugin_loader_unified.rs - Single unified loader (~800 lines)
- plugin_ffi_common.rs - Shared FFI utilities (~300 lines)
- Total: ~1100 lines (55% reduction)
Migration Steps
Phase 1: Infrastructure (DONE)
- Create plugin_loader_unified.rs skeleton
- Create plugin_ffi_common.rs for shared types
- Update runtime/mod.rs
- Basic compilation check
Phase 2: Common Pattern Extraction
- Extract TLV encoding/decoding to plugin_ffi_common
- Extract handle management patterns
- Extract memory management utilities
- Extract error handling patterns
Phase 3: BID Plugin Migration
- Port PluginBoxV2 implementation
- Port BID FFI invoke mechanism
- Port plugin loading logic
- Port configuration parsing
- Migrate tests
Phase 4: Builtin Plugin Migration
- Port FileBoxProxy and related proxies
- Port dynamic library loading for builtins
- Port builtin-specific FFI patterns
- Migrate feature flags handling
Phase 5: Legacy Plugin Migration
- Port host vtable implementation
- Port legacy box creation
- Decide on deprecation timeline
Phase 6: Integration
- Update all references to old loaders
- Ensure backward compatibility
- Performance benchmarking
- Documentation update
Phase 7: Cleanup
- Remove old plugin loaders
- Remove redundant tests
- Update CLAUDE.md
- Final code review
Technical Decisions
Unified Plugin Type Detection
fn detect_plugin_type(path: &str) -> PluginType {
// 1. Check file extension (.bid, .legacy, .builtin)
// 2. Check nyash-box.toml for type field
// 3. Probe for known symbols
// 4. Default to BID
}
Handle Management Strategy
- Use generic
PluginHandle<T>for all plugin types - Centralized handle registry in plugin_ffi_common
- Reference counting with Arc<Mutex>
Error Handling
- Convert all errors to Result<T, String> at boundaries
- Plugin-specific errors wrapped with context
- Consistent error messages across all plugin types
Risk Mitigation
Backward Compatibility
- Keep old loaders under feature flags during migration
- Provide compatibility shims if needed
- Extensive testing with existing plugins
Performance
- Benchmark before and after migration
- Profile hot paths (box creation, method dispatch)
- Optimize only after correctness verified
Testing Strategy
- Unit tests for each component
- Integration tests with real plugins
- E2E tests with full applications
- Regression tests for edge cases
Success Metrics
- Code reduction: 50%+ fewer lines
- All existing tests pass
- No performance regression
- Cleaner API surface
- Better error messages
- Easier to add new plugin types
Timeline
- Phase 1-2: Day 1 (Today)
- Phase 3-4: Day 2-3
- Phase 5-6: Day 4
- Phase 7: Day 5
Total: 5 days for complete migration