Skip to main content

Module declaration

Module declaration 

Source
Expand description

Type surface of submilli:llm.

call and batch are declared generic, and that generic is only sound because the typechecker intercepts it. The typed forms are not a second signature: they are a rewrite. A generic call<T> reaching the ordinary generic-call lowering would set return_cast, which codegen emits as a Wasm representation cast rather than a structural check, so a response that ignored the schema would arrive statically typed and never validated. So the typechecker matches the symbol by mangled name and rewrites the call into a checked Cast instead — the contract submilli:session’s get carries. The declaration and that interception are a matched pair, and a generic declaration without the interception is the unsound half on its own, which is why the generics landed together with checked_llm_call rather than ahead of it. is_checked_call is the hook that interception matches on.

T defaults to Completion (or Completion[] for batch) rather than to unknown: the untyped call keeps its envelope, carrying ok/text/ reason, while the typed form trades that envelope for the checked value — the same trade session.get<T> makes. That is why T appears only in the return type here and is never inferable from an argument.

The trailing schema parameter is likewise not surface a program writes. It defaults to undefined, and the typed lowering fills it with the JSON Schema emitted from T at compile time — the way McpCall passes its server and tool as constants. Passing it by hand changes only what the provider is asked for; the structural check lives in the synthetic Cast, not in the host fn, so a hand-passed schema buys no verification.

Functions§

is_checked_batch
Whether mangled is the single-prompt checked read, as opposed to the batch. The two lower the same way but differ in what a bare call returns — Completion against Completion[] — so the interception needs to tell them apart to pick the untyped default.
is_checked_call
Whether mangled is one of this package’s checked reads. Matching the package-export mangled name rather than a receiver name is what makes the typechecker’s rewrite independent of how the symbol was imported — llm.call, models.call under an aliased namespace import, and a named-import call all carry this name, while a user’s own llm binding never can.
package_declaration
untyped_result_type
What T binds to when the program wrote no type argument, which keeps the untyped call’s pre-generic meaning: the Completion envelope for call, and one per prompt for batch. Unlike session.get, the default is not unknown — an untyped llm.call is not an unchecked read, it is a different and fully-typed result.