1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# 53 typed source and the diagnostics cache
asked: type everything. the compiler, the runtime and the language server had untyped `fn` and `let` in most places, and the stdlib had one untyped method.
built:
- src/rt.zc, src/compiler.zc, lsp/server.zc: every function header and every local and global `let` now has a type. parameters and returns that hold an address are `word`, the rest are `int`, and the `.u` return tag stays as it was (`word .u new(int n)`). `.m` and `.d` parameter tags are kept too.
- lib/std.zc: `fn end()` in struct `capture` is `word end()`.
- the proof that nothing changed: zc0's image of the typed sources is byte-identical to the untyped one (`cat src/rt.zc src/compiler.zc | bin/zc0` against the original). the full genome fixpoint is 232070 words (it was 230551 before the typing: zy generates different code for typed declarations).
- editors/vscode: diagnostics are cached under a sha256 key per document (client/diagcache.js). the key covers the server build, the path and text, and every file the document includes, transitively. a cached key is answered without asking the server, which hears the text only when hover or highlighting needs it. an included file saved or changed on disk checks its dependents again. the cache is saved in the extension's storage. tests/diagcache_test.js checks the rules, tests/ext_cache_test.js runs the client end to end on the built-in server.
- tests/lsp_test.js: tests/undefined_call.zc is an intentional error, like manyerrors.zc, so the clean check skips it.
what went wrong on the way, kept for the next person:
- the first typer dropped `.d` and `.m` parameter tags when it rewrote headers. zc0 writes those tags into the symbol table's signature word, so `free(.d p)` changed from 130 to 2. the typer now keeps the tags, and word-typed parameters and returns turned out to be harmless.
- the typer grouped `let` items by type, which moved some arrays ahead of scalars. zc0 numbers locals by declaration order, so the frame slots of those variables moved (a 5 became a 21 in the image). the typer now keeps source order, and the image matches again.
- a bare `.u name(...)` header is not a type word, so the first typer missed it. `unchecked .u readfile(path)` and the others were typed in a second pass.
- the built-in wasm server cannot read include files (every include is "can't read that include"). the native server reads them. this is an existing limit, and the cache keys do not depend on it.
|