Skip to main content
Added
IO.Reader<E> and IO.Writer<E>, the stream protocols, generic in the error each implementor fails with. A type that implements read(count, options) -> Binary ! E gets read_string(count, options) and read_line(options) from the protocol, each failing with E | String.ConversionError. read_line returns Option<String>, with Option.None at end of input. IO.Writer<E> requires write(data, options) -> Int ! E. IO.Descriptor implements both as IO.Reader<IO.Error> and IO.Writer<IO.Error>. TCPSocket implements both as IO.Reader<IO.Error | TLSError> and IO.Writer<IO.Error | TLSError>, so a TLS failure on an open connection keeps its name instead of folding into a stream error. A call site never writes E. A bound does, as in fn drain<S: IO.Reader<IO.Error>>(source: S).
IO.Error, the error for an open stream, with BrokenPipe, Closed, ConnectionReset, Interrupted, TimedOut, and Unknown(Int). File.Error, the error for a path, with AlreadyExists, DirectoryNotEmpty, InvalidPath, IsDirectory, NotDirectory, NotFound, PermissionDenied, and Unknown(Int). Each has from_code(code) -> Option<Self>, last(), and message().
IO.Reader.Options and IO.Writer.Options, each with timeout: Option<Duration> = Option.None. Every stream read and write takes one as a trailing parameter with an all-default value, so socket.read(16, IO.Reader.Options{timeout: Option.Some(limit)}) bounds one call and socket.read(16) waits without limit. A call that passes its timeout fails with IO.Error.TimedOut. A timed out write can follow a partial write, so the count returned by an earlier write is the only record of what was sent. On both backends a timeout is a bounded reactor wait, the mechanism receive ... after uses, so no socket option is set.
TCPSocket.connect(host, port, timeout), connect_addr(addr, timeout), connect_tls(host, port, timeout), and connect_tls_with(host, port, config, timeout) take a trailing Option<Duration> that bounds the TCP handshake. It defaults to Option.None. DNS resolution is not bounded. The two TLS forms apply the same bound again, measured anew, to the TLS handshake.
TCPListener.accept(timeout), TCPSocket.upgrade_tls(host, config, timeout), accept_tls(config, timeout), TLSSession.connect(descriptor, host, config, timeout), and TLSSession.accept(descriptor, config, timeout) take a trailing Option<Duration>, Option.None by default, that bounds the wait for a connection or the handshake.
IO.Descriptor.block takes a trailing timeout: Option<Duration> = Option.None and returns Bool, true when the wait ended on the timeout. Socket.accept and Socket.connect take the same parameter. A Duration.ZERO bound is a poll on every one of them, so listener.accept(Option.Some(Duration.ZERO)) returns a pending connection at once and fails with Socket.Error.TimedOut when the backlog is empty.
IO.Descriptor.Interest, with Readable and Writable, names the readiness a process waits for. IO.Descriptor.block and IO.Descriptor.watch take one.
- A
const can hold a list, map, or set literal, such as const PRIMES = [2, 3, 5, 7] or const PORTS = ["http": 80], and a struct or enum variant whose fields hold one. A constant value takes the same grammar as a field default, so it can also read another constant declared anywhere in the program. A collection constant is built once at program start and every read borrows the shared value. A constant that depends on itself through other constants is a compile error.
- A union widens into a wider union that holds all of its members, the same way one member does. A
Cat | Dog value flows into a Cat | Dog | Fish slot, and a function that fails with ParseError | NetError can be called with try, or rescued with rescue e -> fail e, from one that fails with ParseError | NetError | AuthError. Before, both were type errors.
@experimental marks a declaration as unstable. Every use warns with `Name` is experimental and may change in a later release., the tag’s optional message, and a hint that names the opt-in. It goes where @deprecated goes, with the same carve-outs inside the tagged declaration and in impl/extend blocks on a tagged target, and does not combine with @doc false. koja doc marks a tagged item experimental and renders an Experimental callout.
experimental = true under [project] in koja.toml accepts @experimental declarations in that package’s own files without a warning. The flag is per package, so a dependency’s flag does not cover the project and the project’s flag does not cover a dependency.
- Experimental.
Process.context() returns the calling process’s Process.Context, a 32-byte request context the runtime carries with the work. spawn copies the parent’s context into the child, every cast, call, and send_after message carries the sender’s context, and the receiver takes it on when the message is dequeued. A reply leaves the caller’s context alone. The value answers sampled?(), trace_id() (16 bytes), and span_id() (8 bytes). A process nobody traced carries Process.Context.ZERO. Trace fills it in, and user code reads it but never builds one.
- Experimental.
Trace, closure-scoped spans in the standard library. Trace.root(name, work) or Trace.root(name, options, work) starts a trace at a boundary, and Trace.span(name, work) or Trace.span(name, kind, work) opens a child of the calling process’s context. Both install the span’s context for the closure, so every message sent inside it carries the span, and both restore the context they found. The closure gets a Trace.Span handle with attribute(key, value), status(status), and recording?(). Trace.Attribute, Trace.SpanKind, and Trace.Status are the value types.
- Experimental.
Trace.Parent carries a parent decoded off the wire. Trace.Parent.new(trace_id, span_id, sampled) builds one and fails with Trace.Error on a wrong length, and trace_id() and span_id() give the ids back as bytes. Trace.RootOptions{kind, parent} is how a root opens, with Internal and no parent as the defaults. Trace.root ignores the context the process carries. Without a parent it starts a new sampled trace, and with one it keeps the parent’s trace id and sampled flag and names the parent’s span as its parent. Trace.current() is the context a codec encodes into an outgoing header.
- Experimental.
Trace.Export, the queue an exporter package drains. A finished Trace.SpanRecord joins a queue of at most 4096 records. Trace.Export.pop() takes the oldest and Trace.Export.dropped() counts what a full queue refused.
- Experimental.
Log, structured logging in the standard library. Log.trace, Log.debug, Log.info, Log.warn, and Log.error take a message and a Map<String, Log.Attribute> and write a Log.Record that carries the calling process’s Process.Context and a timestamp. Trace is the floor below Debug, for the records that show every step. Log.with(attributes) returns a Log.Logger whose records merge the bound attributes, with the call’s own attributes winning. A handler is a fn (Log.Record) -> Result<(), Log.Error>, or a type that implements Log.Handler and reaches that shape through to_fn(). A handler that fails is dropped for the rest of that emit, and one Warn record named log handler failed goes through the handlers that remain. A handler that logs does not recurse. Log.Level, Log.Attribute, Log.Record, Log.Config, Log.Error, Log.Handler, and Log.Formatter<T> are the types, and Log.Text and Log.Stdout are the stdlib formatter and handler.
- Experimental.
Log.configure(config) installs a Log.Config in the calling process. The runtime holds the configuration and the level floor on the process slot beside the context, so a record below the floor is dropped before it is built. spawn copies the parent’s configuration into the child, and a process spawned before the call keeps what it had. A process nobody configured writes Info and above to stdout through Log.Text.
- Experimental.
Log.Capture, a collector process for tests. Log.Capture.start() spawns it, handler() is the fn for a Log.Config, and take() returns every record so far and clears the collector.
koja test --only <file>:<line> runs one test. Repeat the flag to run several.
- Quick fixes in the language server. The
unless removal and a valued return in a Unit function carry the first ones.
- A
Run test code lens on each test block.
- The language server rechecks open documents when a
.koja file or koja.toml changes on disk.
koja shell now accepts :q as an alias for :quit.
Changed
- Breaking change.
File is the path module and IO.Descriptor is the handle. File.open(path, mode) returns the IO.Descriptor for the file and fails with File.Error, and reads, writes, and close are then IO.Descriptor methods that fail with IO.Error. There is no File value. File.read, File.read_binary, File.write, File.delete, File.rename, File.mkdir, File.mkdir_p, and File.rmdir fail with File.Error instead of String, the one-shot read and write add IO.Error for the stream half, and the functions that returned a sentinel String return Unit. A rescue message -> ... on one of these becomes rescue e -> ... with e.message() or #{e} for the text, and a file: File binding becomes descriptor: IO.Descriptor.
- Breaking change.
Fd becomes IO.Descriptor and Fd.Interest becomes IO.Descriptor.Interest. The struct field is raw: Int32, so Fd{descriptor: n} becomes IO.Descriptor{raw: n} and fd.descriptor becomes descriptor.raw. The socket types follow. Socket.fd becomes Socket.descriptor, TCPListener.fd() becomes TCPListener.descriptor(), and the fd parameter on TLSSession.accept, connect, read, and write becomes descriptor. IO.Ready carries an IO.Descriptor in each variant. The runtime externs keep their koja_fd_* names.
- Breaking change. Stream errors are
IO.Error and connection errors are Socket.Error. TCPSocket.read, read_binary, write, and close, TCPListener.close, and UDPSocket.close fail with IO.Error. Socket.create, bind, listen, accept, resolve, set_reuse_addr, recv_from, and send_to fail with Socket.Error instead of String. The close functions on Socket, TCPSocket, TCPListener, and UDPSocket return Unit, so _ = socket.close() becomes try socket.close() or a bare call under rescue.
- Breaking change.
IO.Descriptor.read(count) returns Binary. IO.Descriptor.read_string(count) is the decoding read, so the old read becomes read_string and the old read_binary becomes read. IO.Descriptor.close fails with IO.Error instead of String.
- Breaking change.
TCPSocket.read(count) returns Binary and TCPSocket.read_string(count) decodes, the same split as IO.Descriptor, so the old read becomes read_string and the old read_binary becomes read. Both come from the IO.Reader conformance, and read_line arrives with them. read fails with IO.Error | TLSError and no longer lists String.ConversionError, so a match on it drops that arm. TLSSession.read_binary(descriptor, count, timeout) becomes TLSSession.read(descriptor, count, timeout).
- Breaking change.
IO.gets(prompt) returns Option<String> ! IO.Error | String.ConversionError, with Option.None at end of input. It reads through STDIN.read_line. Before, it returned String and could not report an error. name = IO.gets("> ") becomes a match on try IO.gets("> "), or try IO.gets("> ") rescue ... followed by an Option unwrap.
- Breaking change.
Socket.Error keeps the connection setup causes and gains Interrupted. BrokenPipe and ConnectionReset moved to IO.Error, so a Socket.Error.BrokenPipe pattern becomes IO.Error.BrokenPipe. NotConnected and WouldBlock are gone, since no function produced them.
- Breaking change.
IO.Descriptor.block and IO.Descriptor.watch take an IO.Descriptor.Interest instead of a bare flag. fd.block(true) becomes descriptor.block(IO.Descriptor.Interest.Readable) and fd.block(false) becomes descriptor.block(IO.Descriptor.Interest.Writable). fd.watch(0) becomes descriptor.watch(IO.Descriptor.Interest.Readable) and fd.watch(1) becomes descriptor.watch(IO.Descriptor.Interest.Writable).
TCPServer reports an accept failure to its owner as TCPServer.Event.Error and keeps listening. Before, it dropped the failure and waited for the next connection.
Removed
- Breaking change. The
@test annotation is removed after its 0.19 deprecation. The compiler reports an old annotation with a hint that names the replacement, so @test "description" on a function becomes a test "description" block, and a body that returned Result<T, String> returns nothing and uses assert or fail instead.
- Breaking change. The
File value type and File.close are removed. File.open returns an IO.Descriptor, so file.close() becomes descriptor.close() on the descriptor it returned.
- Breaking change.
IO.Descriptor.read_binary and TCPSocket.read_binary are removed. read returns Binary on both now, so socket.read_binary(n) becomes socket.read(n).
- Breaking change.
TCPListener.try_accept and Socket.try_accept_raw are removed. A zero bound on accept is the same poll, so match listener.try_accept() with Option.Some(socket) and Option.None arms becomes match listener.accept(Option.Some(Duration.ZERO)) with Result.Ok(socket) and Result.Err(Socket.Error.TimedOut) arms, and the other Result.Err arm now sees the failures try_accept hid.
- Breaking change.
TCPServer.Event.Closed is removed. No version of TCPServer ever produced it, since the server hands each TCPSocket to its owner at Connected and does not watch it after that, so a closed connection is seen by the holder as an empty read or an IO.Error. A TCPEvent.Closed(_) -> arm in an owner’s handle is deleted.
Fixed
- Two nested types with the same last name, such as
File.Error and IO.Error, stay distinct in a union. Before, File.Error | IO.Error collapsed to one member and a value of the other was rejected.
- Diagnostics spell a nested type by its full path, so a mismatch reads
expects IO.Error, got File.Error where both printed as Error before. Types from Global drop the Global. prefix they carried in some messages, and types from every other package keep theirs, so a type reads the same way in every message.
- A field default can be a struct literal named through a dotted path, such as
options: IO.Reader.Options = IO.Reader.Options{}, or through a file alias. Enum variants with a payload, such as Option.Some(3), are accepted as defaults too. Before, the dotted literal was rejected and the aliased one could panic the compiler.
- The language server syncs documents incrementally and checks 150 ms after the last edit. A check that an edit overtook publishes nothing, so a multi-step edit no longer leaves errors from a half-applied state on screen.
- Language server positions are right on a line with a multi-byte character. Before, every hover, highlight, and edit after it on that line was off by the extra bytes.
koja format no longer panics on a comment inside an empty list, map, or struct literal. The literal stays broken open with the comment inside, the layout an empty call argument list already used.
- A read, write, or wait that a signal interrupts fails with
Interrupted. Before, the interpreter recorded no cause for it, so the caller saw a stale one.
- A
const or type declared inside a @deprecated or @experimental type counts as inside it, so its body no longer warns about its own owner. Before, the compiler hoisted it out without the tag and warned.
- Reading a constant owned by a
@deprecated or @experimental type, such as Old.ZERO, warns for the owner, the same as a static call does. Before, the read was silent.
- A literal that converts through a literal protocol, such as
1 into a type that conforms to IntLiteral, no longer counts as a use of the carrier type. Before, the symbol index listed the carrier’s declaration line as a reference, and a @deprecated carrier warned there from every converting literal.