refactor: 大規模なモジュールを分割し、コードの構造を改善
runner, mir/builder, backend/llvm の各モジュールが肥大化していたため、責務ごとにファイルを分割し、見通しを改善するリファクタリングを実施。
### `runner`
- `mod.rs` に集中していたロジックを、以下のモジュールに分割:
- `tasks.rs`: `nyash.toml` のタスク実行処理
- `build.rs`: AOTビルドパイプラインの実装
- `pipeline.rs`: `using` の解決など、パイプライン中のユーティリティ
- `demos.rs`: デモの実行処理
### `mir/builder`
- `if/else` 文のPHIノード生成ロジックを `stmts.rs` から `phi.rs` へ切り出し。
- `utils.rs` にあったPHI関連のヘルパーも `phi.rs` に集約。
- ASTから自由変数を収集するロジックを `vars.rs` へ切り出し。
### `backend/llvm/compiler/codegen`
- 巨大だった `lower_one_function` 関数を、`function.rs` モジュールとして分離。
- `sanitize_symbol` などのヘルパー関数を `utils.rs` へ移動。
This commit is contained in:
@ -41,28 +41,7 @@ pub(super) fn builder_debug_log(msg: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
// PHI-based return type inference helper
|
||||
pub(super) fn infer_type_from_phi(
|
||||
function: &super::MirFunction,
|
||||
ret_val: super::ValueId,
|
||||
types: &std::collections::HashMap<super::ValueId, super::MirType>,
|
||||
) -> Option<super::MirType> {
|
||||
for (_bid, bb) in function.blocks.iter() {
|
||||
for inst in bb.instructions.iter() {
|
||||
if let super::MirInstruction::Phi { dst, inputs } = inst {
|
||||
if *dst == ret_val {
|
||||
let mut it = inputs.iter().filter_map(|(_, v)| types.get(v));
|
||||
if let Some(first) = it.next() {
|
||||
if it.all(|mt| mt == first) {
|
||||
return Some(first.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
// Lightweight helpers moved from builder.rs to reduce file size
|
||||
impl super::MirBuilder {
|
||||
|
||||
Reference in New Issue
Block a user