mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 14:58:05 +08:00
Support bare reference parameters and lending outputs in the node macro and make the clone node the clone-out adapter
This commit is contained in:
@@ -12,6 +12,7 @@ pub fn validate_node_fn(parsed: &ParsedNodeFn) -> syn::Result<()> {
|
||||
validate_min_max,
|
||||
validate_range_slider_bounds,
|
||||
validate_async_source,
|
||||
validate_lend_fields,
|
||||
];
|
||||
|
||||
for validator in validators {
|
||||
@@ -63,6 +64,30 @@ fn validate_async_source(parsed: &ParsedNodeFn) {
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_lend_fields(parsed: &ParsedNodeFn) {
|
||||
let future_kernel = crate::codegen::is_source_kernel(&parsed.output_type);
|
||||
for field in &parsed.fields {
|
||||
let ParsedFieldType::Regular(RegularParsedField { lend: Some(reference), .. }) = &field.ty else {
|
||||
continue;
|
||||
};
|
||||
if let Some(mutability) = &reference.mutability {
|
||||
emit_error!(mutability.span(), "reference parameters are read-only lends; `&mut` is not supported");
|
||||
}
|
||||
if let Some(lifetime) = &reference.lifetime {
|
||||
emit_error!(lifetime.span(), "reference parameters use the eval lifetime implicitly; write a bare `&T`");
|
||||
}
|
||||
if field.is_data_field {
|
||||
emit_error!(field.pat_ident.span(), "`#[data]` fields are node-resident state and cannot be references");
|
||||
}
|
||||
if parsed.is_async || future_kernel {
|
||||
emit_error!(
|
||||
field.pat_ident.span(),
|
||||
"source kernels move their inputs into the spawned task, so they cannot take reference parameters"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_min_max(parsed: &ParsedNodeFn) {
|
||||
for field in &parsed.fields {
|
||||
if let ParsedField {
|
||||
|
||||
Reference in New Issue
Block a user