videoAL Developmentofficial - Microsoftreviewed - checked by Opus

Business Central Under the Hood episode 2: The Inner Workings of The AL Compiler

AL compiler internals and history, from the C/SIDE era to today: Roslyn-based design, partial compilation and LSP for Visual Studio Code, transpiling AL to C#, and the unsupported, undocumented state of the compiler API. Also covers prototype VS Code designers and AL Explorer.

  1. 0:00 History: C-side and the 2T architecture
  2. 2:02 Challenges with C-side and the modernization vision
  3. 3:53 The prototype and symbol reference strategy
  4. 6:03 Early previews and the journey to GA
  5. 7:09 Roslyn architecture and the compiler design
  6. 9:09 AL language concepts and the perfect storm timing
  7. 11:12 Visual Studio Code adoption and language service architecture
  8. 13:17 Partial compilation, LSP protocol, and extensibility
  9. 15:27 Why AL instead of existing languages
  10. 16:48 AL transpiler and code generation to C#
  11. 19:14 Migration from C/SIDE to AL and text-based development
  12. 22:06 Visual Studio Code designers and AL Explorer
  13. 25:53 Compiler API exposure and getting started
video Microsoft Dynamics 365 Business Central (YouTube) · 2024-03-27Watch on YouTube

Overview

Episode 2 of Business Central Under the Hood (published 2024-03-27, 29 minutes) walks through how the AL compiler came about and how it works. It starts with C/SIDE and its two-tier architecture, the prototype that wrapped the old base app in symbol references, and the years of early previews before the first AL compiler shipped without a preview mark in 2019 wave two.

It then covers the design: Roslyn concepts, a compiler-as-a-service that also drives the language server, partial compilation with error recovery, and the Language Service Protocol used with Visual Studio Code. It explains why AL was built instead of reusing an existing language, why AL is transpiled to C#, and what moving to text files meant. It closes with the VS Code designers prototype, AL Explorer, AL Home, and the status of the compiler API.

Key points

  • The AL compiler uses Roslyn architecture concepts. The same base compiler serves command-line compilation and the background compilation that runs in the editor.
  • Partial compilation with error recovery gives intellisense while code is incomplete. Results are reused to keep memory use down and avoid recompiling unchanged code.
  • The editor and the AL language server communicate through the Language Service Protocol.
  • AL is transpiled to C#, and the generated C# is compiled with the regular C# compiler. Metadata is stored in XML and the database.
  • A sandbox language was one stated reason for AL, because third-party code runs on Microsoft’s servers.
  • Moving to text-file source enabled Git, search tools and standard source control. It also fit the cloud, where requiring a direct database connection is a bad idea. The C/SIDE visual designers were lost, and VS Code designers are only a prototype.
  • The compiler API is not officially supported or documented, and may change at any time. Partners already use it in unsupported ways.

Features

Feature Status At
AL compiler status not stated 0:08
Partial compilation and recovery status not stated 13:03
Language Service Protocol support status not stated 12:11
Symbol reference information wrapping status not stated 3:53
AL transpiler to C# status not stated 16:48
Text-based source code storage status not stated 19:14
AL Explorer status not stated 22:06
AL Home status not stated 22:06
Visual Studio Code designers status not stated, demoed 25:16
Compiler API exposure status not stated 25:53
AL extensions in Visual Studio Code marketplace status not stated 27:15

AL objects mentioned

As heard in the captions. A name that matches one object page by exact type and name links to it; the others stay as named.

  • codeunit “safe post code unit” at 4:18
  • other “AL Explorer” at 24:12
  • other “AL Home” at 24:48
  • other “Visual Studio Code Marketplace” at 27:15

Not found in BC28-30: codeunit “safe post code unit”.

Quotes

  • 6:39 “In 2019, in wave two, we shipped the first AL compiler without the preview mark on it, and then at that time we could”
  • 7:46 “they realized that they already have a. They have one compiler for a command line and almost a similar compiler that were used inside”
  • 8:10 “the same compiler, the same base part of the compiler that serves the command line compilation is also the one that constantly runs in”
  • 8:58 “It’s not Roslyn, but we have moved a lot of the concepts out of the Roslyn code base because we are not.”
  • 9:23 “we have way more concepts than C# for instance. So in some some sense we are more complicated because we have I mean 7-8”
  • 11:27 “we also realized that we could easily repurpose A compiler to another environment if we had to. But turned out that best decision ever”
  • 13:24 “it’s textbook to create a compiler that has a perfect source, but but having a source where you are typing something in the middle”
  • 14:28 “They actually invented what is called the Language Service Protocol exactly for this”
  • 15:41 “One of the reasons is that we we we need a sandbox language. Since we are running third party code on our servers, we”
  • 16:48 “This is a language that’s been written for for ERP and for Business Central. Exactly. But the most important part of this was that”
  • 18:08 “We are converting AL to C#. Is that a good idea? Yes, I think for us it is”
  • 19:50 “compiler the code is actually saved in text file like any like many other languages”
  • 25:40 “That’s still a prototype. Right, still a prototype. I would love us to prioritize them, but again, we need to prioritize.”
  • 26:14 “They would like to be able to use it to do all sorts of things and some people actually doing it already in a”
  • 26:28 “It’s envisioned as a service we haven’t officially opened up for. New for for external use means that we haven’t documented it”
  • 26:51 “We’re not preventing it. We’re not just supporting it and we we reserve ourselves the right to change it at any time.”
  • 27:15 “Already incredibly many AL related extensions in the Visual Studio Code Marketplace, which is amazing to see”
  • 27:51 “There’s of course our own documentation on Ms. learning, which is both a combination of reference documentation but also getting started documentation.”

Disclaimers in the video

  • 6:03 preview: early previews of it. And we did that for a couple of years, and the initial one was only we could create simple code units, simple tables, pages.
  • 25:40 preview: That’s still a prototype
  • 25:53 preview: It’s still the prototype label
  • 26:28 preview: It’s envisioned as a service we haven’t officially opened up for. New for for external use means that we haven’t documented it
  • 26:51 subject-to-change: We reserve ourselves the right to change it at any time

Presenters (as heard): Espen.