flang the compiler proves your program cannot hang 0.9.0 GitHub Try in the browserTry it Русский

Standard library

Which module to take for a task and how to import it. The library has 66 modules and 2284 functions. Every module has its own page: functions, their conditions and an example.

Modules by task

Text and parsing

ModuleWhat for
Stringssplit, replace, trim, change case, pad a string
String listslists of strings: first, last, join, common prefix
String setsa set of strings: union, intersection, difference
Automatonregular expressions without backtracking
Parsingparsing the text of your own small language
Samplesfinding a word, a stem or a piece in a string without regex
CLIcommand-line flags and arguments, the --help text
UTF-8text to UTF-8 bytes and back
Text decodingbytes to text: UTF-8, UTF-16, UTF-32, CP1251, KOI8-R
Unicode normalizationUnicode normalization: NFC, NFD, NFKC, NFKD
Unicode graphemesgraphemes: the visible characters of a string and their count
Unicode case foldingcase-insensitive string comparison by Unicode
Unicode tableslooking up a code point in the Unicode tables
Code page datacode page tables for CP1251 and KOI8-R
Unicode case dataUnicode data for case-insensitive comparison
Unicode grapheme dataUnicode data on grapheme boundaries
Unicode normalization dataUnicode data for normalization

Numbers

ModuleWhat for
Numberssign, absolute value, GCD and LCM, power, factorial, digits
Bignumintegers of any size: arithmetic, comparison, decimal text
Rationalsexact fractions over big integers
Number formatprinting a number in bases 2–16 and with a precision
Statisticsmean, median, mode, variance, quantile
Logicand, or, not, implication, "all true" over a list

Collections

ModuleWhat for
Listslength, slice, search, sum, sorting of a list
Higher ordermap, filter, reduce, sort with your own comparison
Optionala value that may be absent (Optional)
Resultsuccess with a value or an error with a reason (Result)
Dictionarya small string → string map as a list of pairs
Hash mapa fast string → value map
Tree mapa string → string map as a search tree
Number treea search tree of numbers, sorting by traversal

Time

ModuleWhat for
Date and timedates and times: ISO-8601, addition, difference, weekdays

Files and network

ModuleWhat for
Requests and responsesHTTP: parsing and printing requests and responses, URLs, headers
WebSocketWebSocket: the upgrade answer and frames
DNSDNS packets: parsing a response, building a query
Wirebytes, network-order integers, cutting a stream into messages
Registrya package registry as data: versions, ranges, dependencies

Databases

ModuleWhat for
Postgresthe PostgreSQL 3.0 protocol: client and server messages
Redisthe Redis protocol (RESP 2): commands and replies
SQLitean SQLite 3 database file: reading tables, building a file, inserting a row

Cryptography

ModuleWhat for
SHA-256the SHA-256 hash
SHA-1SHA-1, HMAC-SHA1 and PBKDF2-HMAC-SHA1 for legacy protocols
HMACHMAC-SHA256
Key derivationa key from a password: PBKDF2-HMAC-SHA256
SCRAMSCRAM-SHA-256 password login, the client side
AESAES-128 and AES-256 encryption: block, CTR, CBC, GCM
X25519X25519 key exchange
ECDSAECDSA signature verification on the P-256 curve
RSA signatureRSA signature verification: PKCS#1 v1.5 and PSS
DERreading DER, the binary ASN.1 encoding
X.509reading an X.509 certificate out of PEM
Revocation listcertificate revocation lists (CRL)
Trust storea store of root certificates
Certificate pathverifying a certificate chain up to a root
TLS recordsTLS 1.3 records: format, keys, decryption
TLS handshakethe TLS 1.3 handshake: messages, Finished, certificates
TLS clienta TLS 1.3 client step by step: from ClientHello to the server response

Formats

ModuleWhat for
JSONJSON: parsing into a value and printing back
TOMLTOML configs: parsing, a value by path, printing
Base64Base64: the standard and the URL-safe alphabet
ProtobufProtocol Buffers: the wire format without a schema
UUIDUUID: parsing, printing, versions 4 and 5

Lemmas for proofs

ModuleWhat for
Math classicsclassical arithmetic lemmas from Coq and Lean
Math classics for listsclassical lemmas about lists from Coq and Lean
List factslemmas about lists for your own proofs
Fmathclaims about the lengths of lists and strings

Importing a module

использует is the import. The module name is written in English, as in the catalogue above. No file path is needed.

File sum.flang:

модуль «Сумма до предела»
  использует «Lists»

тотальная функция «Сумма чисел до предела»
  принимает предел: число
  возвращает число
  пример «До пяти»
    дано предел равно 5
    ожидается 15
  «Сумма» от («Числа до» от предел)
$ flang check sum.flang
модуль «Сумма до предела»: функций 39, из них с доказанным завершением 39; типов 1; файлов вместе с импортами 2
предупреждений 1: встроенная операция в тотальной функции может отказать при работе; код возврата они не меняют, с «--proof --strict» это ошибки
…
sum.flang: проверено — доказано 0, проверено только на тестах 0, не доказано 0 (постусловий и утверждений 0); замечаний нет

The first line counts functions together with the module: all functions of Lists and one of yours. The second is a warning about a function of the Lists module itself; it does not change the exit code. The last line is the result: there are no errors, and your file has no postconditions, so every counter is zero. The postconditions of the module are not counted here.

The tests of the module run with yours, so a program with a large module (AES, TLS client) takes a few minutes to check.

A module has no Russian name

Replace the module name in sum.flang with «Списки» ("lists" in Russian):

$ flang check sum.flang
…
FLANG_IMPORT_NOT_FOUND в файле sum.flang, строка 1, столбец 1: не найден модуль «Списки»: ни рядом с файлом, ни выше по каталогам, ни в библиотеке компилятора
FLANG_UNKNOWN_NAME в файле sum.flang, строка 10, столбец 3: неизвестная функция «Сумма»
…
sum.flang: не проверено — замечаний 5

There is no module «Списки»: lists are «Lists». The compiler says the module was not found next to the file, up the directories, or in its library. The использует line takes the English name.

A part of a module

The word только imports the named functions and the ones they call:

  использует «Lists» только «Двоичный поиск»

With this line the program gets «Двоичный поиск» and the two functions it needs. The tests of the other Lists functions do not run, and the check is faster.

Running a program with a module

flang run evaluates one function. Before that it looks whether every postcondition of the program and of its modules is proved:

$ flang run sum.flang "«Сумма чисел до предела»" 5
не доказано: утверждений 66: доказано 42, сетка 24, на веру 0 — запуск только по явному согласию: --на-веру
…
$ flang run sum.flang "«Сумма чисел до предела»" 5 --trust
на веру: доказанность не считалась — запуск по ключу --trust
15

The first command stopped with exit code 3: of 66 postconditions 42 are proved (доказано) and 24 are checked on tests only (сетка). The --trust flag runs the program without this check; the unproved postconditions are then checked at run time.

How much is proved

A postcondition (обеспечивает) is a statement about the result of a function. The compiler proves it for any arguments. Where it could not, the postcondition is checked on the values from the tests and at run time.

What is countedHow many
modules66
functions2284
postconditions3604
of them proved674
checked on tests only294
not proved49
status not measured for the current version of the module2587

The status of every postcondition is on the module page, next to the function. For your own program flang check sum.flang --proof prints the same report.

Next