Configuration: redsat.toml
Like tsconfig.json for TypeScript, an optional redsat.toml file configures the compiler for
every program in its directory and below. RedSAT looks for it in the program’s directory, then
in each parent directory, and uses the first one it finds. --config <file> names one
explicitly instead.
[compiler]
strict = true # turn on every strict check below
explicit-types = "unknowns" # "off" | "unknowns" | "all" (default "off"; strict: "unknowns")
unbounded-ints = "error" # "deepen" | "error" (default "deepen"; strict: "error")
fallback-int-bits = 32 # first magnitude tried for unbounded integers
max-int-bits = 256 # stop deepening beyond this
Every key is optional, and an empty file is fine. Unknown keys are errors, so a typo cannot go unnoticed.
Options
| Key | Values | Default | Command line |
|---|---|---|---|
strict | true, false | false | --strict |
explicit-types | "off", "unknowns", "all" | "off" | --explicit-types |
unbounded-ints | "deepen", "error" | "deepen" | --unbounded-ints |
fallback-int-bits | 1 to max-int-bits | 32 | --fallback-int-bits |
max-int-bits | up to 65536 | 256 | --max-int-bits |
explicit-types
Which variable declarations need a type annotation.
"off": types may always be inferred."unknowns": every unknown (avarwithout an initial value) needs a type, like TypeScript’snoImplicitAny."all": everyvarneeds a type, evenvar n: int = 42.
These checks apply to your code (and the files it imports), not to the standard library’s own functions.
var x, y
var n = 42
require x + y == n
error: `x` needs a type annotation
--> main.rsat:1:5
|
1 | var x, y
| ^ no type given
= note: required by the compiler option explicit-types = "unknowns"
= help: annotate it, e.g. `var x: int`
error: `y` needs a type annotation
--> main.rsat:1:8
|
1 | var x, y
| ^ no type given
= note: required by the compiler option explicit-types = "unknowns"
= help: annotate it, e.g. `var x: int`
unbounded-ints
What to do with an integer unknown whose range cannot be inferred.
"deepen": warn, and search with growing bounds:|x| < 2^fallback-int-bitsfirst, doubling the number of bits after each “no solution”, up to2^max-int-bits. Solutions found are genuine; “no solution” only covers the bounds searched. See Unbounded integers."error": reject the program, asking for bounds.
fallback-int-bits and max-int-bits
The first and the largest magnitude, in bits, tried for unbounded integers with
unbounded-ints = "deepen".
Strict mode
strict = true (or --strict) turns on the whole family of strict checks at once:
explicit-types = "unknowns" and unbounded-ints = "error". A strictly checked program declares
the type of every unknown and gives every integer a finite range, inferred or declared:
var x: int[0..=100]
var y: int[0..=100]
require x + y == 42 and x == 2 * y
solve x, y
x = 28, y = 14
var x: int
require x > 5
solve x
error: cannot infer a finite domain for `x`
--> main.rsat:1:5
|
1 | var x: int
| ^ unbounded
= note: required by the compiler option unbounded-ints = "error"
= help: give it bounds, e.g. `var x: int[0..=1000]`, or a constraint that limits it
Precedence
Settings are combined from four layers, each overriding the ones before:
- the built-in defaults;
- what
strictimplies; - keys set explicitly in
redsat.toml; - command-line flags.
So a strict project can still opt out of a single check, by setting its key explicitly:
[compiler]
strict = true
unbounded-ints = "deepen" # strict, except for this one check