Charms (charms v0.1.4)

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 defm can 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 in defm/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 or defm/2s), while in Beaver.>>>/2, the extension happens at the op level (define your op expression).
  • In Beaver.>>>/2 the management of MLIR context and other resources are done by the user, while in defm/2, the management of resources are done by the Charms compiler.
  • In defm/2, there is expected to be extra verifications built-in to the Charms compiler (both syntax and types), while in Beaver.>>>/2, there is none.

Caveats and limitations

  • We need a explicit call in function call because the :: special form has a parser priority that is too low so a call macro is introduced to ensure proper scope.

Glossary of modules

Summary

Functions

define a function that can be JIT compiled

Functions

defm(call, body \\ [])

(macro)

define a function that can be JIT compiled