English · Русский · Documentation
flang is a pure functional language with strict static typing. Its keywords are words (function,
accepts, returns). A function has its tests and the conditions on its result written next to its
body. The compiler checks them before anything runs and generates code from the checked program in
C, C++, Go, Rust, Java, JavaScript, TypeScript, Elixir, Python or C#. The compiler is written in
flang. Every keyword has a Russian and an English spelling; the compiler's messages are in Russian.
What "formal proof" means here:
total— the compiler proves that the function terminates on every input; if it cannot, the file fails the check.ensures— a postcondition, a condition on the result. The compiler proves it for all inputs or reports that there is no proof;flang rundoes not run such a program.flang check --proofshows the proof report. A separate C program,checker.c, re-checks the proofs and reports how many of them it could not re-check.
The compiler does not search for a proof. It applies inference rules from a fixed table,
flang/proof/tables/inference-rules.tsv, and the report
names the rule for each postcondition. The limits of the method:
What is proved and what is not.
Prebuilt builds ship with every release: Linux x86_64 and aarch64 (static, any distribution), macOS
arm64 and x86_64. The package is called flang-package; the command it
installs is flang.
Name clash with LLVM Flang. LLVM's Fortran compiler also installs a command named
flang(it is theflangformula in Homebrew and theflangpackage in the AUR). If both are installed, whichever comes first onPATHwins. Check withflang --version: ours printsflang <version>on the first line. Fix it by putting the directory of this install first onPATH, or call it by its full path (for example~/.local/bin/flang).
curl -fsSL https://raw.githubusercontent.com/digitable-lol/flang/main/install.sh | shPicks the build for your system, checks it against the release's SHA256SUMS and installs it into
~/.local without sudo. Pin a version with FLANG_VERSION=<version>, choose a place with
PREFIX=/opt/flang (both are environment variables of sh).
brew install digitable-lol/tap/flang-packagebrew install digitable-lol/tap/flang is an alias of the same formula.
asdf plugin add flang https://github.com/digitable-lol/asdf-flang.git
asdf install flang latest
asdf set -u flang latestThe plugin downloads the prebuilt build and checks its checksum. With ASDF_FLANG_FROM_SOURCE=1 it
builds flang from the C sources instead (needs cc and make).
Download the package for your CPU from the latest release and install it:
sudo apt install ./flang-package_<version>_amd64.deb # or _arm64.deb
sudo dnf install ./flang-package-<version>-1.x86_64.rpm # or .aarch64.rpmThe rpm conflicts with Fedora's flang package (LLVM Flang): both own /usr/bin/flang.
packaging/aur/ holds the PKGBUILD of flang-package-bin. It is not published on the AUR yet;
to build it locally, fill it with the release's SHA256SUMS (sh packaging/prebuilt/manifests.sh) and run
makepkg -si.
git clone https://github.com/digitable-lol/flang && cd flang
make -C bootstrap -j4 # a few minutes
make -C bootstrap install PREFIX=$HOME/.localNeeds only a C99 compiler and make. Along with flang, the standard library and the run-time
libraries of the target languages are installed into share/flang, so the install works outside the
clone too (where flang looks for them). The program that re-checks
proofs independently is not installed this way; the prebuilt builds have it.
Use WSL and the Linux one-liner above. There is no native Windows build yet.
flang --version prints the version. More: Installing.
File hello.flang:
module «Hello»
total function «Twice»
accepts n: nat
returns number
ensures «the doubled value is at least the original» result is at least n
example «twice two»
given n equals 2
expected 4
n plus n
flang check hello.flangмодуль «Hello»: функций 1, из них с доказанным завершением 1; типов 0
hello.flang: проверено — разбор, типы, завершаемость, ядро и примеры; замечаний нет
Exit code 0. The first line reads "module «Hello»: 1 function, 1 of them proved to terminate; 0 types". The second lists the checks that passed — syntax, types, termination, proofs, tests — and ends with "no errors".
flang run hello.flang --function Twice --args '{"n": 21}'доказано: утверждений 1
42
The first line reads "proved: 1 postcondition". The second is the result. The test (example) runs
on every check. The postcondition here follows from the declared type nat and is proved for all
inputs.
Replace the postcondition with one the compiler does not prove by itself. The whole file
hello.flang:
module «Hello»
total function «Twice»
accepts n: nat
returns number
ensures «the result is even» (result modulo 2) equals 0
example «twice two»
given n equals 2
expected 4
n plus n
flang check accepts this file with code 0, and flang run does not run it:
flang run hello.flang --function Twice --args '{"n": 21}'не доказано: утверждений 1: доказано 0, сетка 1, на веру 0 — запуск только по явному согласию: --на-веру
…
Exit code 3. The line reads "not proved: 1 postcondition — 0 proved, 1 tested only; runs only on
explicit consent". The lines after it name the postcondition. The --trust flag runs the program
without the proof. How to write the proof:
Your first proof.
Put the first postcondition back into hello.flang and generate C:
flang emit hello.flang --target c --out out-c
grep -A 6 '^fl_status hello_twice' out-c/hello.cfl_status hello_twice(fl_ctx *ctx, fl_value n, fl_value *result,
fl_error *error) {
if (n.tag != FL_NUMBER || n.tag != FL_NUMBER)
FL_TRY(fl_not_numbers(ctx, "add", n, n, error));
*result = fl_number(n.as.number + n.as.number);
return FL_OK;
}
The function has no check of the postcondition: it is proved. flang emit checks the program the
way flang check does and writes nothing when there is an error. The output directory holds the
module, the run-time library, a command-line program and a Makefile.
flang has fifteen commands, the editor language server among them: check, test, run, emit,
ast, tokens, lint, facts, io, lock, package, new, run-script, repl and lsp. It
generates code for c, cpp, go, rust, java, js, ts, elixir, python and csharp.
- Start: Your first program, Your first proof, Tutorial, Which construct to use when
- Language: Map of the language constructs, Language reference, Standard library reference,
docs/flang/SPEC.md - Tools: Command reference, Error codes, Releases
- Proofs and programs: Proofs: why and how,
docs/examples/
Work happens in a clone; the only thing to build is the compiler.
make -C bootstrap -j8 # builds bootstrap/flang
sh flang/test/обход.sh # the tests written in flang
./bootstrap/flang test flang/stdlib/ # the standard library's tests
git config core.hooksPath .githooks # quick checks before git pushBefore git push the checks that finish in seconds are run; the long ones are run by CI
(.github/workflows/binary.yml). Open tasks are in docs/tasks/, one file
per task. How to build the compiler, run the checks and send a change is in
CONTRIBUTING.md. The rules of the repository that are not visible from the code
are in AGENTS.md. Decisions are recorded in docs/adr/.
The documentation text is checked automatically. Numbers in the text are compared with the
repository (scripts/guards/prose-numbers-guard.fscript). A path in a link must exist
(scripts/guards/link-guard.fscript). The project's internal words are not allowed on pages for
readers (scripts/guards/jargon-guard.fscript).
Four programs outside this repository: flang-tui, digitdisk, flang-ribbon and flang-env.
What stays compatible between releases and what 1.0 freezes is written in
Compatibility. What the compiler proves by itself and where it stops is
described in docs/ROADMAP.md.
BSD 2-Clause — LICENSE. A Russian edition without legal force is LICENSE-RU.md.