How Roc and Win32 fit together§

A Roc app describes a view and how events change its state. The Roc Signals engine owns the reactive state and emits incremental commands. The Rust host applies those commands to a tree of Win32 controls. It translates native notifications into Roc events on the window thread.

Worker jobs have their own Roc instances. The UI thread receives their results from the host event pump. When an app no longer wants a result, the host can discard the reply while a pure computation finishes. A Roc crash in a worker stops the process.

Windows Imaging Component decodes bounded images off the window thread. The image worker resamples large images to their display size and keeps the immutable source available for shader input. A separate Direct3D 11 worker retains textures and coalesces pending changes for each view. It reads back the committed frame for compositing in the native child window. Screenshots and recordings use that same frame.

Incremental sync§

The wire tree records what each batch of commands changed (Tree::changes): the nodes created or changed in value, and the parents whose children changed. Every node also carries the newest revision of any change below it. After a batch, SurfaceRegistry::sync_changed skips every window whose declaration has no newer change, so editing one window leaves the others alone. In a window it changes, Surface::sync_changed does work in proportion to the change:

Raster updates land before the batch’s one sync. An image whose pixels arrive shows them at its laid-out size, and the sync visits nothing else in the window.

The full walk, Surface::sync, is the reference. It visits every node, restyles every control and lays the window out again. A surface’s first sync uses it, and so do the spec verify mode’s fresh twins. ROC_WINDOWS_FULL_SYNC=1 makes every batch use it, to tell an incremental sync bug from an app bug or to measure what incremental sync saves. The differential test in host/src/sync_differential.rs and the spec verify mode check that both give the same native state. See Check the host against oracles.

The event pump§

Effect answers, progress reports, timer ticks and worker results queue for the UI thread, and a pump on a 15 ms timer delivers them. Each one is still its own Roc turn, delivered in order. A turn that only changes text, attributes or effects defers its native sync, so all such turns in one pump tick share one sync at the end of the tick. A turn that adds, removes or moves nodes or listeners, asks for a reference, or attaches a raster syncs at once, as before. The tree and the native windows end in the same state either way. Turns from user input still sync one by one.

The pump stops its timer after a few idle ticks. Any window message, turn, running effect, timer, queued storage write, image or shader job keeps it running or starts it again. Effect threads post a wake-up when they finish.

Effects run on their own threads, at most 32 admitted at once. More wait in a queue, and only a full queue of 1024 refuses one. Specs use the same policy, with the pool size from setup-worker-pool. Cancelling an effect frees its slot at once. A cancelled HTTP request closes its WinHTTP request handle, so its thread stops instead of waiting out the timeout.

A raster update keeps the current picture until the replacement is ready, and a shader keeps its last frame while a new texture renders.

The image queue never refuses work, so no number of images can fail an app. Each image has at most one pending source and one pending resize. A newer input for an image replaces its older one before the worker shows it, so the queue holds only the latest input of each mounted image. The worker takes jobs oldest first. The jobs one native sync queues form a batch, and the pump publishes a batch once the worker has finished all of it. Each image then shows once, and the whole batch lands in one native sync however the worker’s timing falls. A batch still running after 100 ms shows what is ready, so a very large batch still makes progress. The bind turns of newly mounted images share one sync, like queued answers do, so mounting R images costs a fixed number of syncs and O® bridge work.

Local storage and Save As§

Local storage writes and removals run on one background thread. A read sees the latest write at once. The thread writes keys in the order of their last update, and writes only the last value of a key that changed several times while it was busy. Each write is staged, flushed and renamed into place. Normal exit waits for queued writes, so a killed process can lose the last moments' writes. A failed write is reported on stderr instead of stopping the app, and its value stays visible to reads for the rest of the session.

Save As shows its picker on the UI thread and copies the file on a worker. A failed copy shows its error once the copy ends.

Link native features at startup§

An app’s pure native configuration carries the registration functions it selects. The platform calls them on the UI thread before it mounts the first view. Registrations install function pointers or factories. The core calls optional native code through those registrations, so a direct reference from the core cannot keep the optional implementation in every executable. Worker jobs receive the selected function pointers when scheduled. Core control accessibility stays enabled, and an editable grid brings its accessibility provider with it.

Use the feature configuration to select implementations. Registration only supplies code. File choices and the manifest HTTP allowlist still control access to external resources.

Authority at the application boundary§

This section defines the platform’s intended security contract. The app and control chapters describe the APIs available today.

Start with the user’s choice§

An ordinary desktop app should work without a capability declaration. The platform provides its controls, read-only packaged assets, and app-scoped storage. For external resources, prefer a Windows interaction that expresses the user’s choice of target and operation. Opening or dropping an item grants read access to that item. A folder choice grants the documented operations beneath that folder. Save As authorizes one export to the confirmed destination. It gives no standing write access to the input or destination directory.

Bind a user gesture to the specific operation the host exposes for that control. An ordinary Roc event, a path string, a clipboard value, or a launch argument carries data. Treat a native file activation as authority only when the host can establish the provenance and scope of the designation. A later effect does not gain authority merely because the app posts it after a click. Keep native edit and clipboard gestures scoped to the focused operation. Any API that retains a user’s choice across launches must define how the user can revoke it and what happens when the resource moves, is replaced, or becomes inaccessible.

Carry authority in bounded handles§

Use typed, opaque, host-issued handles for live resources. Put the resource identity, allowed operations, and lifetime in the host contract. A helper or worker receives the authority in the handles passed to it. Read-only types have no write operations. The host keeps native handles and transport IDs private and releases resources when their owners are gone. Bound admission and retained work before opening or retaining resources.

Bind rights to the opened object or a confined directory and leaf. A path can be reused for a different object. Preserve identity across asynchronous work, check each descendant under its authorized root, and handle replacement and links without extending the grant. Keep saved paths as display or discovery data unless a supported, host-managed mechanism can re-establish the grant.

Declare unattended access only when needed§

Start with the workflow and show why platform-provided authority or a user grant cannot cover it. Then allow an optional, narrowly scoped declaration for access that must occur without a fresh user choice. The declaration sets an auditable ceiling for the application. Any code able to construct a public app-wide request can use that grant. Omitting the declaration grants no unattended external authority. Malformed or unsupported declarations fail closed. Launch flags, environment variables, and mutable files beside the executable do not extend policy in a distributed app.

Enforce the boundary in the host§

The app decides what should happen, the platform API expresses the request, and the host mediates access to Windows. This split lets the host enforce the app author’s declared limits and the scope of the user’s choice, even if a dependency submits a request directly or untrusted data supplies its target. The Roc API helps callers express valid requests. The host is responsible for checking the actual operation and the authority behind it.

Authorize each operation in the host before native work, queue admission, or test simulation. Apply the same rule to raw requests, native ports, and changes of target, such as a network redirect. A test runner may substitute outcomes for admitted requests. It cannot extend the application’s authority.

The trust boundary is Roc application code running through a trusted native host. A dependency can use authority the app has made available to it. The host enforces the scope of that authority and cannot infer the user’s intent from an otherwise valid request. Ordinary desktop Windows still applies its own process rights, ACLs, and privacy rules. OS-enforced isolation is a separate deployment property and requires verification of the running process. The Roc capability contract applies there as well.

Make the secure path the ordinary API§

Design the simplest call to do the safe thing for the usual workflow. Prefer a read handle for opening an item, an exact target for external access, and finite bounds for data and work. Let callers request broader authority explicitly when a workflow warrants it. Handle an unavailable grant as a normal outcome. Preserve the requested scope when permissions or external conditions change. A failed check never authorizes a broader grant or a fallback target.

Use types to express valid inputs and separate rights where practical. Report expected failures as named result tags. Distinguish policy denial, cancellation, invalid runtime input, OS access failure, resource limits, and temporary unavailability where they lead to different app behavior. Give a tag a structured payload when the app needs a fact to decide what to do, such as the byte limit behind TooLarge. Keep messages and native diagnostics for people. Application code should be able to handle a denial, ask for a fresh selection, or report a limit by matching on the result, without parsing a string. Limit result payloads and diagnostics to details the caller is authorized to see.

What the bundle contains§

platform/main.roc declares the host calls and linker inputs. host/src/roc_platform_abi.rs records the generated ABI. The Windows platform bundle links the same generated resource into both target architectures. It embeds the Common Controls v6, DPI-awareness, and long-path manifest from host/windows/windows.manifest.

The Rust host uses bindings from windows-rs. Zig supplies open-source startup and runtime inputs and generates import libraries from its bundled definitions. Windows supplies the DLL implementations when the app runs. The bundle carries compiled host and linker inputs. See the third-party notices for their origins.

The platform runner uses the same host to mount an app, send control events, and handle effects. See Runner boundary for how the CLI hands a scenario to the host.