mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 20:28:02 +00:00
parent
ec16ba9837
commit
892143f113
2 changed files with 20 additions and 8 deletions
|
@ -36,6 +36,26 @@ terminal, e.g. `roc build main.roc`.
|
|||
|
||||
(mono, specialization)
|
||||
|
||||
Monomorphization, also known as type specialization, is the process of creating a distinct copy
|
||||
of each instance of a generic function or value based on all specific usages in a program.
|
||||
For example; a function with the type `Num a -> Num a` may only be called in the program with a
|
||||
`U64` and a `I64`. Specialization will then create two functions with the types `U64 -> U64` and
|
||||
`I64 -> I64`.
|
||||
This trades off some compile time for a much better runtime performance, since we don't need to
|
||||
look up which implementation to call at runtime (AKA dynamic dispatch).
|
||||
|
||||
Related Files:
|
||||
- new compiler:
|
||||
- [specialize_functions.zig](src/build/specialize_functions.zig)
|
||||
- [specialize_functions folder](src/build/specialize_functions)
|
||||
- [specialize_types.zig](src/build/specialize_types.zig)
|
||||
- [specialize types folder](src/build/specialize_types)
|
||||
|
||||
- old compiler:
|
||||
- [mono folder](crates/compiler/mono)
|
||||
- [mono tests](crates/compiler/test_mono)
|
||||
- [mono macro tests](crates/compiler/test_mono_macros)
|
||||
|
||||
## Type Checking
|
||||
|
||||
## Reference Count
|
|
@ -1,13 +1,5 @@
|
|||
//! The intermediate representation (IR) for a Roc module that has been monomorphized.
|
||||
//!
|
||||
//! Monomorphization, also known as type specialization, is the process of creating a distinct copy
|
||||
//! of each instance of a generic function or value based on all specific usages in a program.
|
||||
//! For example; a function with the type `Num a -> Num a` may only be called in the program with a
|
||||
//! `U64` and a `I64`. Specialization will then create two functions with the types `U64 -> U64` and
|
||||
//! `I64 -> I64`.
|
||||
//! This trades off some compile time for a much better runtime performance, since we don't need to
|
||||
//! look up which implementation to call at runtime (AKA dynamic dispatch).
|
||||
//!
|
||||
//! Doing type specialization as the first build stage helps simplify compilation of lambda sets, or
|
||||
//! values captured by closures.
|
||||
//!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue