Upgrading from 0.1.x

midad is pre-1.0, and breaking changes are made deliberately and written down. This page is the migration path: what changed, what your code looked like before, what it looks like now, and which check finds it.

Start with the checker on the whole project. It reports every one of these before the program runs:

$ midad check .

0.1.1: / is real division, and idiv is integer division

7 / 2 printed 3. It prints 3.5 now, on every path, and integer division is idiv(a, b), which floors rather than truncating.

div.md
---
midad: "0.1"
module: div
---

```exec
print(str(7 / 2));
print(str(idiv(7, 2)));
```
output
3.5
3

midad check warns W008 at every / with two number operands, because that is exactly where the old meaning was. x /= 2 means x = x / 2, so on a number variable it is now a type error rather than a silent integer divide.

What to do: a / that meant an integer quotient becomes idiv(a, b). A / that wanted a real quotient keeps /, and its result is a float.

0.1.0: get(map, key) on a missing key returns None

get returned a null value for a key that was not there. It returns an empty option now, which is what the C backend already did.

get.md
---
midad: "0.1"
module: get
---

```exec
const m = {"a": 1};
print(str(unwrap_or(get(m, "b"), "anonymous")));
print(str(type_of(get(m, "b"))));
```
output
anonymous
option

What to do: reading a key you know is there needs no change. Reading one that may be absent wants unwrap_or(get(m, "k"), default), is_none(get(m, "k")), or if let Some(v) = .... is_null(get(m, "k")) no longer holds.

0.2.0: the mutation rule

push, set_at, sort and remove_at always change their first argument and no longer answer a new container. Using the answer is now an error rather than a silent no-op, which is what the old form hid:

check-3.md
---
midad: "0.1"
module: mut
---

```exec
let xs = [1];
xs = push(xs, 2);
print(str(xs));
```
midad check
× E0260: `push(...)` changes its first argument in place and answers

What to do: drop the assignment and keep the statement. push(xs, 1); grows xs. remove_at(xs, 0) answers the element it removed and shortens the list; put(m, k, v) and del(m, k) still answer the map.

0.2.0: null is a value of its own again

null and None used to be the same value, so type_of said option and is_null answered the opposite of its name on a JSON null. Now type_of(null) is null, print(null) is null, is_null(null) is true, is_none(null) is a runtime refusal, and JSON null parses to it and round-trips as null. The empty option is None and only None.

What to do: if you relied on is_null to test for a missing map key, that test moves to is_none, as above.

0.2.0: a run stops on a budget

A program that does not serve stops after 120 seconds or 10 billion steps, whichever comes first, and the refusal names the limit and the way past it. A program that serves is exempt, because it is meant to keep running.

What to do: nothing for a normal program. A batch program that legitimately runs longer takes --no-limit.

0.2.1: static: is a filesystem read

static: serves a directory, so it needs an fs_read grant that covers that directory, or *. Without it, a program that declared no filesystem access could publish the whole machine with one line of frontmatter:

check-4.md
---
midad: "0.1"
module: pub
permissions:
  listen: ["127.0.0.1:8799"]
static: "./pub"
---

```exec
print("x");
```
midad check
× E0305: `static: "./pub"` serves a directory, so it needs an `fs_read`

What to do: add fs_read: ["./pub"].

0.2.1: a db grant is a file grant

A db grant is decided on real paths the way fs_read is, so a symlinked database outside the granted path is refused, and ATTACH and DETACH are refused at run time.

What to do: name the database file you mean, and open only that one connection per file.

0.2.1: a runaway recursion stops

Recursion stops at a depth the stack can hold instead of taking the process down. A program that recursed past the new limit gets a named runtime error rather than a crash.

What to do: nothing, unless a program legitimately recursed that deep; then it needs a loop or an explicit stack.

Not in a release yet

One change is on main and in the changelog as 0.2.2, unreleased, so it is not in the binary you install today. A relative grant and a relative path resolve against the directory of the .md file rather than the process's working directory, so fs_read: ["data/"] and read_file("data/ok.txt") name the data/ beside the program wherever a launcher starts it. Absolute paths are used as written, and a native build refuses a relative grant by name. A program that already used absolute paths needs no change. The rule is written out with examples on Permissions and the frontmatter.

What did not break

mdx: is still accepted as the pre-rename spelling of the midad: key, and a file carrying both keys is E0006. imports: paths are still relative to the importing file. A permissions: block that named absolute paths still means the same thing.

On this page