Charms (charms v0.1.2)
Documentation for Charms.
defm and intrinsic
There are two ways to define a function with defm/2 or implement callbacks of Charms.Intrinsic behavior. The defm/2 is a macro that generates a function definition in Charm. The intrinsic is a behavior that generates a function definition in MLIR.
The intrinsic is more flexible than defm because:
- Intrinsic is suitable for the cases where directly writing or generating MLIR is more ideal
- An intrinsic should be responsible for its type check while the Charm’s type system is responsible for function call’s type check
- It is possible for an intrinsic to return a MLIR type, while
defmcan only return value. - Intrinsic function is always inline.
The defm is more suitable for simple functions because it is designed to be as close to vanilla Elixir as possible. As a rule of thumb, use defm for simple functions and intrinsic for complex functions or function with type as argument.
defm's differences from Beaver.>>>/2 op expressions
- In
Beaver.>>>/2, MLIR code are expected to mixed with regular Elixir code. While indefm/2, there is only Elixir code (a subset of Elixir, to be more precise). - In
defm/2, the extension of the compiler happens at the function level (define your intrinsics ordefm/2s), while inBeaver.>>>/2, the extension happens at the op level (define your op expression). - In
Beaver.>>>/2the management of MLIR context and other resources are done by the user, while indefm/2, the management of resources are done by theCharmscompiler. - In
defm/2, there is expected to be extra verifications built-in to theCharmscompiler (both syntax and types), while inBeaver.>>>/2, there is none.
Caveats and limitations
- We need a explicit
callin function call because the::special form has a parser priority that is too low so acallmacro is introduced to ensure proper scope.
Glossary of modules
Charms: the top level macrosdefmanduse CharmsCharms.Defm: thedefmDSL syntax and special formsCharms.Defm.Definition: functions to define and compiledefmfunctions to MLIRCharms.Intrinsic: the behavior used to define and compile intrinsic functions
Summary
Functions
define a function that can be JIT compiled