Skip to content

Commit 0f923b1

Browse files
committed
fix Monomorphization in genric
1 parent bdd78a6 commit 0f923b1

4 files changed

Lines changed: 862 additions & 23 deletions

File tree

crates/doo_driver/src/compile.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,15 @@ pub fn compile_project(opts: CompileOptions) -> Result<CompileResult, String> {
298298
let t = Instant::now();
299299
let mut type_registry = TypeRegistry::new();
300300
let mut lowerer = Lower::new();
301-
let hir = lowerer.lower_program_typed(&program, &mut type_registry);
301+
let mut hir = lowerer.lower_program_typed(&program, &mut type_registry);
302+
303+
// Phase 4.5: Monomorphization
304+
// Transforms generic function/struct templates into concrete specializations.
305+
// Must run BEFORE analysis (which doesn't understand TypeParam) and MIR building.
306+
{
307+
let mut mono = doo_hir::Monomorphizer::new(&mut type_registry);
308+
mono.monomorphize(&mut hir);
309+
}
302310

303311
// Wrap in Arc for shared access
304312
let type_registry = Arc::new(type_registry);
@@ -2023,6 +2031,7 @@ mod tests {
20232031
span: test_span(),
20242032
decorators: vec![],
20252033
is_async: false,
2034+
type_params: vec![],
20262035
})],
20272036
span: test_span(),
20282037
};
@@ -2093,6 +2102,7 @@ mod tests {
20932102
span: test_span(),
20942103
decorators: vec![],
20952104
is_async: false,
2105+
type_params: vec![],
20962106
})],
20972107
span: test_span(),
20982108
};

crates/doo_hir/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
1818
pub mod types;
1919
pub mod lowering;
20+
pub mod monomorphize;
2021
pub mod visitor;
2122

2223
pub use types::*;
2324
pub use lowering::Lower;
25+
pub use monomorphize::Monomorphizer;
2426
pub use visitor::{HirVisitor, HirVisitorMut};

0 commit comments

Comments
 (0)