tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

54 lignes · 2762 octetsBrut · Historique

ADR 0049: std/file — whole-file reads and writes

Status: Proposed (2026-10-18); needs engineering review (#44).

Context

The HTTP demo could not serve a file: std had no file IO at all (std/io is the console, std/os the environment). Meanwhile the runtime grew a blocking pool (ADR 0005): externs can be declared blocking, running on a few worker threads while the actor waits, so a slow call never stalls a scheduler thread — its module doc already named file IO as a motivation, and argon2 uses it for hashing.

Decision

A new module, std/file, with whole-file operations only:

pub fn read :: path: String -> Result<String, String> / <io> // UTF-8 checked
pub fn read_bytes :: path: String -> Result<Bytes, String> / <io>
pub fn write :: path: String content: String -> Result<(), String> / <io>
pub fn write_bytes :: path: String content: Bytes -> Result<(), String> / <io>
pub fn exists :: path: String -> Bool / <io> // a file, not a directory
pub fn size :: path: String -> Result<Int, String> / <io>
  • Every operation is / <io> and reports Error with the OS's message — the conventions of std/net and std/tls (OS services); ffi stays for foreign libraries. Nothing panics; a missing file is Error("No such file or directory (os error 2)").
  • All four externs are blocking (runtime/louise_rt/src/fs.rs): they run on the blocking pool while the actor is parked. They never panic, perform or drop, as the pool requires; the interpreter implements them inline (std::fs), so louise run and interpreted tests see files too.
  • No sandbox. Which paths a request may reach is the program's decision; the demo's static_file rejects .. and answers 404 for anything missing, mapping the extension to a content type (GET /static/robots.txt serves ./static/robots.txt).

Not in v0

Directory listing, removal, rename, permissions, append, and handles with streaming reads/writes. Streaming wants a Resource<File> design (close semantics under the Perceus discipline and actor stops) and its own ADR section when a use case asks for it.

Consequences

  • Five touch points per extern, as docs/runtime-abi.md lists: the std @externs, louise_rt's fs.rs, louise_rt.h, the interpreter, and the table in louise_core::externs (marked blocking, which implies may_unwind) — cross-checked by louise_codegen_c/tests/externs.rs.
  • write never creates directories; Result keeps that explicit.
  • The demo serves its pages as pug templates (ADR 0048) and its assets — the stylesheet included — from disk under /static/ (GET /static/style.css → ./static/style.css): a request path with .. is a 404.