Hand out descriptors a declaration could produce

`Operation::descriptor()` returned `&'static OpDescriptor`, and that lifetime
is the whole reason a build-time node is free and a run-time node is
impossible: only a compile-time literal can satisfy it, so no amount of
reading `ops/*.yaml` at startup could ever produce a descriptor the rest of
the application would accept. FR-PLG-2 says a bundled operation and a
third-party plugin are the same kind of thing, differing only in where the
file was found — and a lifetime outsiders cannot meet is exactly the second,
weaker format that requirement forbids.

So a descriptor is now owned and handed out as `Arc<OpDescriptor>`, with `Vec`
where it held `&'static` slices. `Arc` rather than a `&self`-borrowed
reference because the callers want to *keep* it: the develop panel collects
descriptors and then mutates the graph, and a borrow would tie the
descriptor's lifetime to a borrow of the operation it came from, which is the
one thing `&'static` was doing right.

The identifier newtypes deliberately did not follow. `ParamId` is `Copy`, is
compared in `match` arms against generated constants, is a map key in the
sidecar and history, and reaches Slint model rows; an `Arc<str>` there would
cost a refcount on every one of those and would take `match id { EXPOSURE =>
.. }` away from the generated code. They gain an interner instead, which is
honest about its lifetime rather than pretending to one — the set of ids is
bounded by deduplication and is process-lifetime by construction, because the
sidecar on disk names its parameters and an id has to stay resolvable for as
long as any edit naming it can be opened.

No behaviour changes. Every descriptor that was a `static` is a `LazyLock`
initialiser now, `Operation::helpers` borrows from `self` instead of being
`'static` so a future run-time node can own its list, and `Warp` and `Framing`
follow `Operation` so there is one shape rather than two.

The one place a descriptor is read per frame is `compose_full`, which takes
`descriptor().id` to prefix each active operation's uniforms, and `dr-ui`
composes on every frame it draws. That is a dozen atomic increments beside a
composition that is already building several kilobytes of WGSL on the same
call; it is noted at the trait method rather than left for a profiler to find.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-27 19:02:25 +02:00
co-authored by Claude Opus 5
parent 725f7bf77f
commit 0c3b8cb1c4
23 changed files with 772 additions and 490 deletions
+25 -18
View File
@@ -18,7 +18,7 @@
//!
//! It does not change the runtime model. The generated code implements the
//! same [`Operation`](../src/operation.rs) trait, publishes the same
//! `&'static OpDescriptor`, and composes through the same fused-shader path.
//! `Arc<OpDescriptor>`, and composes through the same fused-shader path.
//! Nothing downstream — not `dr-gpu`, not the develop panel — can tell a
//! declared node from a hand-written one, which is what allows the two to sit
//! side by side in one chain.
@@ -788,7 +788,7 @@ fn param_ctor(
.collect::<Result<Vec<_>, _>>()?;
(
format!(
"ParamDescriptor::choice({:?}, {:?}, &[{}])",
"ParamDescriptor::choice({:?}, {:?}, vec![{}])",
id,
label,
keys.join(", ")
@@ -1495,7 +1495,8 @@ fn emit_node(out: &mut String, node: &Node) -> Result<(), String> {
\x20 Scale, Unit, WidgetDemand, WidgetKind,\n\
\x20 };\n\
\x20 #[allow(unused_imports)]\n\
\x20 use crate::operation::{Helper, Operation, Uniform};\n\n",
\x20 use crate::operation::{Helper, Operation, Uniform};\n\
\x20 use std::sync::{Arc, LazyLock};\n\n",
);
// Ids as consts, so a caller names a parameter through the type system
@@ -1511,20 +1512,26 @@ fn emit_node(out: &mut String, node: &Node) -> Result<(), String> {
}
// Descriptor.
let _ = writeln!(
out,
"\n static DESCRIPTOR: OpDescriptor = OpDescriptor {{\n\
\x20 id: ID,\n\
\x20 label: LocalizedKey({label:?}),\n\
\x20 params: &["
//
// Built once, behind a `LazyLock`, and handed out as an `Arc` clone. It
// was a plain `static` until descriptors became owned (FR-PLG-2): an
// `OpDescriptor` now holds `Vec`s, and an `Arc` is not const-constructible
// in any case. The cost is one lock check the first time an operation is
// asked what it is, and an atomic increment thereafter.
out.push_str(
"\n static DESCRIPTOR: LazyLock<Arc<OpDescriptor>> = LazyLock::new(|| {\n\
\x20 Arc::new(OpDescriptor {\n",
);
let _ = writeln!(out, " id: ID,");
let _ = writeln!(out, " label: LocalizedKey({label:?}),");
out.push_str(" params: vec![\n");
for p in params {
if let Some(doc) = &p.doc {
out.push_str(&comment(doc, "//", 12));
out.push_str(&comment(doc, "//", 16));
}
let _ = writeln!(out, " {},", p.ctor);
let _ = writeln!(out, " {},", p.ctor);
}
out.push_str(" ],\n");
out.push_str(" ],\n");
// What the operation is about. The panel groups by these and names no
// operation, which is what keeps FR-DEV-3a true as the set grows.
@@ -1539,8 +1546,8 @@ fn emit_node(out: &mut String, node: &Node) -> Result<(), String> {
format!("Attribute::{head}{}", c.as_str())
})
.collect();
let _ = writeln!(out, " attributes: &[{}],", attrs.join(", "));
out.push_str(" };\n");
let _ = writeln!(out, " attributes: vec![{}],", attrs.join(", "));
out.push_str(" })\n });\n");
// Helpers: node-local definitions first, then the assembled list.
for h in local_helpers {
@@ -1583,7 +1590,7 @@ fn emit_node(out: &mut String, node: &Node) -> Result<(), String> {
// The trait.
let _ = writeln!(out, "\n impl Operation for {ty} {{");
out.push_str(
" fn descriptor(&self) -> &'static OpDescriptor {\n &DESCRIPTOR\n }\n\n",
" fn descriptor(&self) -> Arc<OpDescriptor> {\n DESCRIPTOR.clone()\n }\n\n",
);
out.push_str(
@@ -1650,7 +1657,7 @@ fn emit_node(out: &mut String, node: &Node) -> Result<(), String> {
if !helper_refs.is_empty() {
out.push_str(
"\n fn helpers(&self) -> &'static [Helper] {\n HELPERS\n }\n",
"\n fn helpers(&self) -> &[Helper] {\n HELPERS\n }\n",
);
}
@@ -1661,12 +1668,12 @@ fn emit_node(out: &mut String, node: &Node) -> Result<(), String> {
out,
"\n fn presentation(&self) -> Option<Presentation> {{\n\
\x20 Some(Presentation {{\n\
\x20 widgets: &[{}],\n\
\x20 widgets: vec![{}],\n\
\x20 demand: WidgetDemand {{\n\
\x20 two_dimensional: {},\n\
\x20 precise_pointing: {},\n\
\x20 }},\n\
\x20 params: &[{}],\n\
\x20 params: vec![{}],\n\
\x20 }})\n\
\x20 }}",
p.widgets.join(", "),