flang the compiler proves your program cannot hang 0.7.29 GitHub Русский

Back to README · Documentation index

The cost of a function before the run

How many steps a function takes, how much memory it uses and how many seconds that is on this machine is printed before the run, as a polynomial in the input sizes. The decision and its limits are in ADR-0083.

The cost of a function

bootstrap/flang run-script cost docs/examples/web/orders-api.flang \
  --function 'Обработать запрос' --sizes '|хвостадреса|=132' \
  --profile scripts/cost/profiles/dev.profile
optionwhat it does
--function «Name»the function to price
--allthe cost of every function in the file, one line each
`--sizes 'н=20,xs=100'`put in sizes and print numbers; without it only the polynomials
--profile <file>turn steps into seconds and bytes with a machine profile
--promise 'polynomial'exit 1 when the promised cost is below the derived one
--no-printeddo not print the program to C (no bound for printed C)

Sizes are named like this: н is the value of the number н; |s| is the bytes of the string s; |xs| is the length of the list xs; |xs[]| is the size of its element.

The output says where each number comes from: "derived from the function" means no assumptions; "ОЦЕНЕНО" (estimated) means there is an assumption and it is printed; "оценки нет" (no estimate) comes with the reason. The bound is an upper bound: a real run never costs more, but may cost much less.

The cost of one run

flang run --cost prints what the run cost to standard error:

цена прогона: шагов 595213, пик памяти 179953664 байт, секунд 2.947812

Steps are the same counter that --max-steps limits. Seconds and memory include the start of the interpreter (parsing and checking the program).

The printed runner (flang emit --target c --cli) answers a request carrying "cost":"1" with the fields "steps", "handed", "reserved", "depth" and "seconds".

The machine profile

bootstrap/flang run-script cost:calibrate

prints the profile of this machine: seconds per step of the interpreter and of printed C (low and high), seconds per unit of length, bytes per estimated byte, the machine name, its cores and the load. Save the output in scripts/cost/profiles/<machine>.profile. Take the profile on the machine the program will run on.

Validation and forgery