Gleam doesn't compile to Erlang source anymore
Source Entity
Hacker News

Gleam v1.19.0 marks a significant architectural shift by moving from Erlang source code generation to Erlang abstract forms. This transition optimizes the compilation process by leveraging internal compiler representations for improved performance and integration.
The Evolution of Gleam: A Shift in Compilation Strategy
The release of Gleam v1.19.0 represents a pivotal moment in the development of the Gleam programming language, a tool celebrated for bringing type-safety and scalability to the Erlang virtual machine (BEAM) and JavaScript runtimes. By entirely rewriting the Erlang code generator, lead developer Giacomo Cavalieri has fundamentally altered how Gleam interacts with the underlying Erlang ecosystem. This update moves the language away from its previous method of generating human-readable Erlang source code, opting instead for a more sophisticated, low-level approach.
Understanding Erlang Abstract Forms
At the heart of this update is the shift to "Erlang abstract forms." In the traditional compilation lifecycle of the BEAM, code is typically tokenized and parsed into these abstract forms—a metadata-annotated tree structure that acts as an intermediate representation. By generating these forms directly, the Gleam compiler bypasses the need to translate its logic into standard Erlang syntax before the final compilation stage. This method utilizes Erlang's external term format, a binary encoding that allows the compiler to interface more efficiently with the Erlang ecosystem.
Performance and Integration Implications
This architectural change offers several advantages for developers working within the BEAM environment. By outputting abstract forms, Gleam achieves a tighter integration with the Erlang compiler's internal processes. This binary-level interaction reduces the overhead previously associated with string-based source code generation, potentially leading to faster compilation times and more robust error reporting. It signifies a maturation of the language, moving beyond a high-level transpiler toward a more native-feeling citizen of the Erlang virtual machine.
Historical Context and Technical Maturity
Since its inception, Gleam has sought to bridge the gap between static type safety and the dynamic, fault-tolerant nature of Erlang. Historically, transpilation into Erlang source code was a necessary compromise to ensure compatibility and ease of debugging. However, as the language has grown, the limitations of that approach—such as potential discrepancies between source generation and the final bytecode—have become more apparent. This rewrite is a proactive measure to ensure that Gleam remains performant as it scales alongside the complex systems it is designed to support.
Future Trends for the Gleam Ecosystem
Looking forward, this shift suggests a long-term strategy of deeper alignment with the Erlang compiler's internal pipeline. By adopting binary representations, the Gleam team is positioning the language to take advantage of future optimizations within the Erlang compiler itself without needing to rewrite high-level source code generators. This update not only stabilizes the current build process but also provides a more flexible foundation for implementing advanced language features that require direct access to low-level compiler metadata.
Conclusion
The transition in Gleam v1.19.0 is a testament to the project's commitment to technical excellence and performance. By moving to Erlang abstract forms, the developers have successfully streamlined the compilation pipeline, ensuring that Gleam remains a competitive and reliable choice for modern, scalable backend development. As the language continues to evolve, this fundamental change in its compilation target will likely serve as a benchmark for how high-level languages can effectively integrate with established, runtime-heavy environments like the BEAM.