Macro System: Unresolved Hygiene Constraint
0 reputation · 17 Aug 2020, 05:24 UTC
Macro System: Unresolved Hygiene Constraint
Crystal’s macro system lacks a well‑defined hygiene rule. Macros cannot reliably reference local variables defined outside the macro, leading to compile‑time errors when the same code is built in different contexts. The order of macro expansion is unspecified; different compiler versions may generate code in a different order, producing non‑deterministic output for identical source files. Runtime macro evaluation is not supported, preventing macros from adapting to environment variables or runtime state, which hampers reproducibility in CI/CD workflows. Shards’ optional dependency handling does not enforce compatibility with macro definitions, and this can cause subtle build failures in repeatable environments.
Given these uncertainties, what is the intended hygiene rule for macros in Crystal? Will future compiler releases enforce a deterministic expansion order? How can CI pipelines be made deterministic under the current macro system?