mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-12-01 07:24:56 -10:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1df2abeda | ||
|
|
309c376ff0 | ||
|
|
40db86f650 | ||
|
|
db205b5153 | ||
|
|
5b61db5d5c | ||
|
|
407492b698 |
No files matched your search
@@ -1038,7 +1038,6 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
},
|
||||
DocumentNode {
|
||||
inputs: vec![
|
||||
NodeInput::value(TaggedValue::None, false),
|
||||
NodeInput::import(generic!(T), 0),
|
||||
NodeInput::import(concrete!(Footprint), 1),
|
||||
NodeInput::node(NodeId(1), 0),
|
||||
|
||||
@@ -985,20 +985,6 @@ mod test {
|
||||
element
|
||||
}
|
||||
|
||||
/// Grab all of the values of the input every time it occurs in the graph.
|
||||
pub fn grab_all_input<'a, Input: NodeInputDecleration + 'a>(&'a self, runtime: &'a NodeRuntime) -> impl Iterator<Item = Input::Result> + 'a
|
||||
where
|
||||
Input::Result: Send + Sync + Clone + 'static,
|
||||
{
|
||||
self.protonodes_by_name
|
||||
.get(&Input::identifier())
|
||||
.map_or([].as_slice(), |x| x.as_slice())
|
||||
.iter()
|
||||
.filter_map(|inputs| inputs.get(Input::INDEX))
|
||||
.filter_map(|input_monitor_node| runtime.executor.introspect(input_monitor_node).ok())
|
||||
.filter_map(Instrumented::downcast::<Input>) // Some might not resolve (e.g. generics that don't work properly)
|
||||
}
|
||||
|
||||
/// Grab all of the values of a LEVELED input, which introspects as its
|
||||
/// whole legacy list rather than as one element. `T` is the introspected
|
||||
/// element type, which differs from the declared one where a conversion
|
||||
|
||||
@@ -79,45 +79,6 @@ impl<'e, A: Attribute> std::fmt::Debug for Attr<'e, A> {
|
||||
}
|
||||
}
|
||||
|
||||
/// An attribute write that outlives the evaluation producing it: an async
|
||||
/// source's slot persists across generations, so a reference value cannot
|
||||
/// cross as itself. The value crosses deep-copied through the field glue and
|
||||
/// parks into the serving arena at every lift, which is why the copy is paid
|
||||
/// once per invocation rather than once per evaluation.
|
||||
pub struct OwnedAttr<A: Attribute>(Box<dyn AnyAttributeValue>, PhantomData<fn() -> A>);
|
||||
|
||||
impl<A: Attribute> OwnedAttr<A> {
|
||||
/// Deep-copies `value` out of the evaluation that produced it.
|
||||
pub fn new(value: A::Value<'_>) -> Self {
|
||||
// SAFETY: the read addresses a live local of the marker's value type.
|
||||
let erased = unsafe { A::read_erased((&raw const value).cast()) };
|
||||
OwnedAttr(crate::record::deepen_field_value(erased), PhantomData)
|
||||
}
|
||||
|
||||
/// Parks the copy into `arena` for one evaluation; `None` reports arena
|
||||
/// exhaustion.
|
||||
pub fn park<'e>(&self, arena: &'e crate::arena::Arena) -> Option<A::Value<'e>> {
|
||||
let resident = crate::record::replay_field_value(&*self.0, arena)?;
|
||||
let mut value = A::default();
|
||||
// SAFETY: the slot is a live field of the marker's value type, and the
|
||||
// stored value is the copy `new` took at that same type.
|
||||
unsafe { write_stored::<A>(resident.as_deref().unwrap_or(&*self.0), (&raw mut value).cast(), arena) }?;
|
||||
Some(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Attribute> Clone for OwnedAttr<A> {
|
||||
fn clone(&self) -> Self {
|
||||
OwnedAttr(self.0.clone(), PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Attribute> std::fmt::Debug for OwnedAttr<A> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple(A::NAME).field(&self.0.display_string()).finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// A deletion of `A` in a node's return tuple: the name leaves the output
|
||||
/// layout, so downstream reads yield the declared default again. Functionally
|
||||
/// a write of the default; the value carries nothing.
|
||||
@@ -449,27 +410,6 @@ mod tests {
|
||||
assert_eq!(row.size, size_of::<&str>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_owned_reference_crossing_parks_into_the_serving_arena() {
|
||||
let owned = OwnedAttr::<Name>::new("crossing");
|
||||
let arena = crate::arena::Arena::new(1024).unwrap();
|
||||
assert_eq!(owned.park(&arena).unwrap(), "crossing");
|
||||
assert_eq!(owned.clone().park(&arena).unwrap(), "crossing", "the crossing parks again on every evaluation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_owned_plain_crossing_rides_its_bytes() {
|
||||
let arena = crate::arena::Arena::new(64).unwrap();
|
||||
assert_eq!(OwnedAttr::<Opacity>::new(0.25).park(&arena).unwrap(), 0.25);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_exhausted_arena_refuses_an_owned_reference_crossing() {
|
||||
let owned = OwnedAttr::<Name>::new("too long for this arena");
|
||||
let arena = crate::arena::Arena::new(8).unwrap();
|
||||
assert!(owned.park(&arena).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reregistration_at_the_same_type_is_idempotent() {
|
||||
register::<Opacity>();
|
||||
|
||||
@@ -337,20 +337,6 @@ impl AttributeDyn {
|
||||
self.0.len() == 0
|
||||
}
|
||||
|
||||
/// Builds a new attribute matching `target_len` items, taking values from this attribute (wrapping if shorter, truncating if longer).
|
||||
pub fn cloned_to_length(&self, key: &str, target_len: usize) -> Box<dyn AnyAttribute> {
|
||||
let mut result = self.0.new_with_defaults(0);
|
||||
let source_len = self.0.len();
|
||||
if source_len == 0 {
|
||||
pad_with_implicit_default(key, &mut result, target_len);
|
||||
return result;
|
||||
}
|
||||
for i in 0..target_len {
|
||||
let value = self.0.clone_value(i % source_len).expect("source_len > 0");
|
||||
result.push(value);
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for AttributeDyn {
|
||||
@@ -784,13 +770,6 @@ impl Attributes {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets a mutable reference to the value at the given index, creating the attribute if it doesn't exist or has the wrong type.
|
||||
fn get_or_insert_default_value<T: Clone + Send + Sync + Default + Debug + PartialEq + CacheHash + 'static>(&mut self, key: &str, index: usize) -> &mut T {
|
||||
let attribute_position = self.find_or_create_attribute::<T>(key);
|
||||
let attribute = (*self.attributes[attribute_position].1).as_any_mut().downcast_mut::<Attribute<T>>().unwrap();
|
||||
&mut attribute.0[index]
|
||||
}
|
||||
|
||||
/// Sets the value at the given index in the attribute for the given key.
|
||||
/// Creates the attribute with defaults if it doesn't exist.
|
||||
fn set_value<T: Clone + Send + Sync + Default + Debug + PartialEq + CacheHash + 'static>(&mut self, key: impl Into<String>, index: usize, value: T) {
|
||||
@@ -1031,14 +1010,6 @@ impl<T> List<T> {
|
||||
self.attributes.set_value(key, index, value);
|
||||
}
|
||||
|
||||
/// Replaces (or adds) an attribute from a type-erased source. The source is wrapped or truncated to match this list's item count.
|
||||
pub fn set_attribute_dyn(&mut self, key: impl Into<String>, source: AttributeDyn) {
|
||||
let key = key.into();
|
||||
self.attributes.attributes.retain(|(k, _)| k != &key);
|
||||
let new_attribute = source.cloned_to_length(&key, self.element.len());
|
||||
self.attributes.attributes.push((key, new_attribute));
|
||||
}
|
||||
|
||||
/// Sets a single type-erased attribute value at the given index, creating the attribute from the value's underlying type if it doesn't exist (padded with defaults to match the list's length).
|
||||
/// Falls back to default if the value's type doesn't match an existing attribute.
|
||||
pub fn set_attribute_value_dyn(&mut self, key: impl Into<String>, index: usize, value: AttributeValueDyn) {
|
||||
@@ -1058,12 +1029,6 @@ impl<T> List<T> {
|
||||
self.attributes.remove_attribute(key);
|
||||
}
|
||||
|
||||
/// Runs the given closure on a mutable reference to the attribute value at the given item index,
|
||||
/// creating the attribute with defaults if it doesn't exist, and returns the closure's result.
|
||||
pub fn with_attribute_mut_or_default<U: Clone + Send + Sync + Default + Debug + PartialEq + CacheHash + 'static, R, F: FnOnce(&mut U) -> R>(&mut self, key: &str, index: usize, f: F) -> R {
|
||||
f(self.attributes.get_or_insert_default_value::<U>(key, index))
|
||||
}
|
||||
|
||||
/// Returns a debug-formatted display string for the attribute at the given item index and key.
|
||||
pub fn attribute_display_value(&self, key: &str, index: usize, overrides: fn(&dyn std::any::Any) -> Option<String>) -> Option<String> {
|
||||
self.attributes.display_value(key, index, overrides)
|
||||
|
||||
@@ -136,18 +136,6 @@ impl<'a> RecordBatchMut<'a> {
|
||||
unsafe { RecordBatch::new(self.scratch.as_ptr().cast(), self.len, self.layout) }
|
||||
}
|
||||
|
||||
/// Lane `lane`'s frame for in-place writes through the layout's offsets.
|
||||
pub fn lane_ptr(&mut self, lane: usize) -> *mut u8 {
|
||||
assert!(lane < self.len, "lane {lane} out of bounds for a batch of {}", self.len);
|
||||
// SAFETY: in-bounds by the assert against the constructor's contract.
|
||||
unsafe { self.scratch.as_mut_ptr().cast::<u8>().add(lane * self.layout.lane_stride()) }
|
||||
}
|
||||
|
||||
/// Reclaims the raw buffer, e.g. to rebind it under a same-stride output
|
||||
/// layout for an in-place map.
|
||||
pub fn into_scratch(self) -> &'a mut [MaybeUninit<u64>] {
|
||||
self.scratch
|
||||
}
|
||||
}
|
||||
|
||||
/// One lane's record: its pointer paired with the batch's layout.
|
||||
|
||||
@@ -1426,25 +1426,13 @@ fn deep_field_glue(type_id: std::any::TypeId) -> Option<DeepFieldGlue> {
|
||||
DEEP_FIELD_VALUES.lock().unwrap().get(&type_id).copied()
|
||||
}
|
||||
|
||||
/// The copy-out half over an erased field value: the owned form a value takes
|
||||
/// when it crosses out of the evaluation whose arena its content borrows. A
|
||||
/// value with no registered glue already owns everything and passes through.
|
||||
pub fn deepen_field_value(value: Box<dyn crate::list::AnyAttributeValue>) -> Box<dyn crate::list::AnyAttributeValue> {
|
||||
fn deepen_field_value(value: Box<dyn crate::list::AnyAttributeValue>) -> Box<dyn crate::list::AnyAttributeValue> {
|
||||
match deep_field_glue(value.as_any().type_id()) {
|
||||
Some(glue) => (glue.copy_out)(&*value).unwrap_or(value),
|
||||
None => value,
|
||||
}
|
||||
}
|
||||
|
||||
/// The replay half over an erased field value: `Some(None)` where the value
|
||||
/// already owns its content, `None` on arena exhaustion.
|
||||
pub fn replay_field_value(value: &dyn crate::list::AnyAttributeValue, arena: &crate::arena::Arena) -> Option<Option<Box<dyn crate::list::AnyAttributeValue>>> {
|
||||
match deep_field_glue(value.as_any().type_id()) {
|
||||
Some(glue) => (glue.replay)(value, arena),
|
||||
None => Some(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// The element slot a record wire of `T` carries, its erased glue bound at
|
||||
/// the statically-known type.
|
||||
pub fn element_write<T: Clone + Send + Sync + dyn_any::StaticTypeSized>() -> ElementWrite
|
||||
@@ -1930,9 +1918,14 @@ unsafe fn promote_record(layout: &Layout, dst: *mut u8, promotion: &Promotion<'_
|
||||
}
|
||||
// SAFETY: the slot images a parked field of this descriptor.
|
||||
let value = deepen_field_value(unsafe { (field.read_erased)(slot.cast_const()) });
|
||||
let resident = replay_field_value(&*value, promotion.persistent)?;
|
||||
// SAFETY: the replay produced this field's own value type.
|
||||
unsafe { repark(resident.as_deref().unwrap_or(&*value), slot, promotion.persistent) }?;
|
||||
match deep_field_glue(value.as_any().type_id()) {
|
||||
Some(glue) => match (glue.replay)(&*value, promotion.persistent)? {
|
||||
// SAFETY: the replay produced this field's own value type.
|
||||
Some(resident) => unsafe { repark(&*resident, slot, promotion.persistent) }?,
|
||||
None => unsafe { repark(&*value, slot, promotion.persistent) }?,
|
||||
},
|
||||
None => unsafe { repark(&*value, slot, promotion.persistent) }?,
|
||||
}
|
||||
}
|
||||
Some(())
|
||||
}
|
||||
@@ -2210,8 +2203,13 @@ impl OwnedRecord {
|
||||
for (index, value) in &self.fields {
|
||||
let field = &layout.fields[*index];
|
||||
let repark = field.repark.expect("copied fields carry re-park glue");
|
||||
let resident = replay_field_value(&**value, arena)?;
|
||||
unsafe { repark(resident.as_deref().unwrap_or(&**value), dst.add(field.offset), arena) }?;
|
||||
match deep_field_glue(value.as_any().type_id()) {
|
||||
Some(glue) => match (glue.replay)(&**value, arena)? {
|
||||
Some(resident) => unsafe { repark(&*resident, dst.add(field.offset), arena) }?,
|
||||
None => unsafe { repark(&**value, dst.add(field.offset), arena) }?,
|
||||
},
|
||||
None => unsafe { repark(&**value, dst.add(field.offset), arena) }?,
|
||||
}
|
||||
}
|
||||
Some(())
|
||||
}
|
||||
|
||||
@@ -69,18 +69,6 @@ macro_rules! future {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! fn_type {
|
||||
($type:ty) => {
|
||||
$crate::Type::Fn(Box::new(concrete!(())), Box::new(concrete!($type)))
|
||||
};
|
||||
($in_type:ty, $type:ty, alias: $outname:ty) => {
|
||||
$crate::Type::Fn(Box::new(concrete!($in_type)), Box::new(concrete!($type, $outname)))
|
||||
};
|
||||
($in_type:ty, $type:ty) => {
|
||||
$crate::Type::Fn(Box::new(concrete!($in_type)), Box::new(concrete!($type)))
|
||||
};
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! fn_type_fut {
|
||||
($type:ty) => {
|
||||
|
||||
@@ -584,13 +584,6 @@ impl<'e> Graphic<'e> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_vector_mut(&mut self) -> Option<&mut Vector> {
|
||||
match self {
|
||||
Graphic::Vector(vector) => Some(vector),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_raster(&self) -> Option<&Raster<CPU>> {
|
||||
match self {
|
||||
Graphic::RasterCPU(raster) => Some(raster),
|
||||
|
||||
@@ -2094,12 +2094,7 @@ fn collect_raster_metadata<S: LaneSource>(source: &S, metadata: &mut RenderMetad
|
||||
let transform: DAffine2 = source.attr::<Transform>(0);
|
||||
metadata.local_transforms.insert(element_id, transform);
|
||||
|
||||
// If this raster carries a snapshot of upstream graphic content (e.g. it was produced by Rasterize,
|
||||
// which destructively merges its inputs into pixels), recurse into that snapshot so the editor can
|
||||
// surface the original child layers' click targets (the same mechanism Boolean Operation uses).
|
||||
// The snapshot was captured before Rasterize shifted its input transforms to align with the rasterization
|
||||
// area, so the children are already in the coordinate space matching `footprint` here — we must NOT
|
||||
// multiply in `transform` (which is the rasterization area, not a layer-stack transform).
|
||||
// The snapshot's children already match `footprint`, so `transform` (the rasterization area) must not be applied.
|
||||
if let Some(upstream_nested_layers) = source.attr::<EditorMergedLayers>(0).filter(|layers| !layers.is_empty()) {
|
||||
upstream_nested_layers.collect_metadata(metadata, footprint, None);
|
||||
}
|
||||
|
||||
@@ -129,23 +129,18 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Flipped nodes carry their kernel generics as struct parameters: record
|
||||
// edges no longer bind them through `Output`, so the struct must. A
|
||||
// ranked input's element generic is carried on any node kind for the
|
||||
// same reason: the materialized view monomorphizes the kernel per row. A
|
||||
// record-io node's secondary inputs read erased off their wire, so a
|
||||
// generic one of them names is carried too.
|
||||
// Flipped kernels and ranked-input element generics must be carried as struct parameters.
|
||||
let ctx_ident_for_flip = context_param(parsed).map(|ctx| ctx.ident.clone());
|
||||
let carries_generic = |ident: &Ident| {
|
||||
regular_fields.iter().enumerate().any(|(index, field)| match &field.ty {
|
||||
ParsedFieldType::Regular(RegularParsedField { ty, list_levels, .. }) => (*list_levels > 0 || (record_io && index > 0)) && type_contains_ident(ty, ident),
|
||||
let ranked_carries = |ident: &Ident| {
|
||||
regular_fields.iter().any(|field| match &field.ty {
|
||||
ParsedFieldType::Regular(RegularParsedField { ty, list_levels, .. }) => *list_levels > 0 && type_contains_ident(ty, ident),
|
||||
_ => false,
|
||||
})
|
||||
};
|
||||
let carried_generics: Vec<&syn::GenericParam> = fn_generics
|
||||
.iter()
|
||||
.filter(|param| match param {
|
||||
syn::GenericParam::Type(tp) => Some(&tp.ident) != ctx_ident_for_flip.as_ref() && !data_field_generic_idents.contains(&tp.ident) && (flip || carries_generic(&tp.ident)),
|
||||
syn::GenericParam::Type(tp) => Some(&tp.ident) != ctx_ident_for_flip.as_ref() && !data_field_generic_idents.contains(&tp.ident) && (flip || ranked_carries(&tp.ident)),
|
||||
_ => false,
|
||||
})
|
||||
.collect();
|
||||
@@ -1861,28 +1856,14 @@ pub(crate) fn generate_node_impl(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
||||
// carried frame when the node has a carrier.
|
||||
// A writing source stores the kernel's whole tuple as that plain value:
|
||||
// the lift writes the attributes through the claim, then lifts the
|
||||
// element, the shape the sync record tail closes with. An owned crossing
|
||||
// parks into the serving arena first, so its exhaustion is a poll.
|
||||
// element, the shape the sync record tail closes with.
|
||||
let source_writes = (record_io && async_source && !write_markers.is_empty()).then(|| {
|
||||
let binders: Vec<Ident> = (0..write_markers.len()).map(|index| format_ident!("__attr_{index}")).collect();
|
||||
let stores = node.output.shape.attrs.iter().enumerate().map(|(index, attr)| {
|
||||
let binder = &binders[index];
|
||||
let slot = format_ident!("__write_{index}");
|
||||
match attr.owned {
|
||||
false => quote!(unsafe { __frame.attr_at(self.#slot, #binder.0) };),
|
||||
true => quote! {
|
||||
let #binder = match #binder.park(#core_types::context::ExtractArena::arena(__input)) {
|
||||
::core::option::Option::Some(value) => value,
|
||||
::core::option::Option::None => return #core_types::gpoll::GPoll::arena_exhausted(),
|
||||
};
|
||||
unsafe { __frame.attr_at(self.#slot, #binder) };
|
||||
},
|
||||
}
|
||||
});
|
||||
let slots: Vec<Ident> = (0..write_markers.len()).map(|index| format_ident!("__write_{index}")).collect();
|
||||
quote! {
|
||||
.and_then(|(__element #(, #binders)*)| {
|
||||
#(#stores)*
|
||||
#core_types::gpoll::GPoll::Final(__element)
|
||||
.map(|(__element #(, #core_types::attribute::Attr(#binders))*)| {
|
||||
#(unsafe { __frame.attr_at(self.#slots, #binders) };)*
|
||||
__element
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! The intent IR: a node built from its signature, from which lowering derives.
|
||||
// Fields below the `Node` root are read by the IR's own tests only.
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::codegen::classify::{Dialect, RoutingIo, bare_ident, context_param, dialect, flip_carrier, generic_assignment, generic_extractable, is_served, record_shape, routing_io, slot_value_type};
|
||||
@@ -13,7 +14,6 @@ pub(crate) fn build(parsed: &ParsedNodeFn) -> Node {
|
||||
let generic_idents: Vec<Ident> = generics.iter().map(|generic| generic.ident.clone()).collect();
|
||||
let fields: Vec<&ParsedField> = parsed.fields.iter().filter(|field| !field.is_data_field).collect();
|
||||
Node {
|
||||
kernel: Kernel { fn_name: parsed.fn_name.clone() },
|
||||
monomorphizations: monomorphizations(parsed, &fields, &generic_idents),
|
||||
inputs: inputs(parsed, &fields, &generic_idents),
|
||||
output: output(parsed, &generic_idents),
|
||||
@@ -96,16 +96,9 @@ fn output(parsed: &ParsedNodeFn, generics: &[Ident]) -> Output {
|
||||
shape: ItemShape {
|
||||
element: element_of(&element, generics),
|
||||
depth,
|
||||
attrs: writes
|
||||
.into_iter()
|
||||
.map(|write| LevelAttr {
|
||||
marker: write.marker,
|
||||
level: 0,
|
||||
owned: write.owned,
|
||||
})
|
||||
.collect(),
|
||||
attrs: writes.into_iter().map(|marker| LevelAttr { marker, level: 0 }).collect(),
|
||||
},
|
||||
removes: removes.into_iter().map(|marker| LevelAttr { marker, level: 0, owned: false }).collect(),
|
||||
removes: removes.into_iter().map(|marker| LevelAttr { marker, level: 0 }).collect(),
|
||||
gathers,
|
||||
}
|
||||
}
|
||||
@@ -165,7 +158,6 @@ fn item_shape(element: &Type, depth: u8, reads: &[AttributeRead], generics: &[Id
|
||||
.map(|read| LevelAttr {
|
||||
marker: read.marker.clone(),
|
||||
level: 0,
|
||||
owned: false,
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
@@ -496,7 +488,6 @@ pub(crate) fn lazy_binding(node: &Node, index: usize) -> LazyBinding {
|
||||
}
|
||||
|
||||
pub(crate) struct Node {
|
||||
pub(crate) kernel: Kernel,
|
||||
pub(crate) generics: Vec<Generic>,
|
||||
/// Correlated rows (zipped `#[implementations]`, not crossed); empty = erased.
|
||||
pub(crate) monomorphizations: Vec<ImplRow>,
|
||||
@@ -507,11 +498,6 @@ pub(crate) struct Node {
|
||||
pub(crate) derives: bool,
|
||||
}
|
||||
|
||||
/// The kernel fn the node wraps.
|
||||
pub(crate) struct Kernel {
|
||||
pub(crate) fn_name: Ident,
|
||||
}
|
||||
|
||||
pub(crate) struct Generic {
|
||||
pub(crate) ident: Ident,
|
||||
pub(crate) bounds: Vec<TypeParamBound>,
|
||||
@@ -565,8 +551,6 @@ pub(crate) enum Element {
|
||||
pub(crate) struct LevelAttr {
|
||||
pub(crate) marker: Type,
|
||||
pub(crate) level: u8,
|
||||
/// Writes only: the value crosses as an owned copy that parks at the lift.
|
||||
pub(crate) owned: bool,
|
||||
}
|
||||
|
||||
pub(crate) enum Effect {
|
||||
@@ -690,7 +674,7 @@ mod tests {
|
||||
Facts {
|
||||
sources: if skips_carrier(parsed) { vec![] } else { vec![0] },
|
||||
carried: token_carrier(parsed),
|
||||
writes: markers(write_markers.iter().map(|write| &write.marker)),
|
||||
writes: markers(write_markers.iter()),
|
||||
removes: markers(removes.iter()),
|
||||
delta: 0,
|
||||
}
|
||||
@@ -790,19 +774,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bridge_record_owned_write_async_source() {
|
||||
let node = assert_bridge(
|
||||
quote!(category("")),
|
||||
quote!(
|
||||
async fn tag_async(_: impl Ctx, _: (), val: f64) -> (f64, OwnedAttr<Label>) {
|
||||
(val, OwnedAttr::new(""))
|
||||
}
|
||||
),
|
||||
);
|
||||
assert!(node.output.shape.attrs.iter().all(|attr| attr.owned), "an `OwnedAttr` slot crosses the boundary owned");
|
||||
}
|
||||
|
||||
/// An async source's element is the value its slot stores, so a byte-carried
|
||||
/// generic token has no form here.
|
||||
#[test]
|
||||
|
||||
@@ -51,20 +51,13 @@ pub(crate) struct AttributeRead {
|
||||
pub(crate) marker: Type,
|
||||
}
|
||||
|
||||
/// One attribute write slot: the marker, and whether it crosses as an owned
|
||||
/// copy (`OwnedAttr<M>`) instead of an evaluation-lifetime value (`Attr<M>`).
|
||||
pub(crate) struct AttrWrite {
|
||||
pub(crate) marker: Type,
|
||||
pub(crate) owned: bool,
|
||||
}
|
||||
|
||||
/// The write half of a record kernel's return: the element type in the first
|
||||
/// tuple slot, then the attribute markers written and the ones removed. `None`
|
||||
/// unless the value is a well-formed write tuple (a non-marker element first,
|
||||
/// then only `Attr`, `OwnedAttr` and `RemoveAttr` slots, at least one).
|
||||
/// then only `Attr` and `RemoveAttr` slots, at least one).
|
||||
pub(crate) struct RecordWrites {
|
||||
pub(crate) element: Type,
|
||||
pub(crate) markers: Vec<AttrWrite>,
|
||||
pub(crate) markers: Vec<Type>,
|
||||
pub(crate) removes: Vec<Type>,
|
||||
}
|
||||
|
||||
@@ -72,16 +65,14 @@ pub(crate) fn record_writes(value: &Type) -> Option<RecordWrites> {
|
||||
let Type::Tuple(tuple) = value else { return None };
|
||||
let mut slots = tuple.elems.iter();
|
||||
let element = slots.next()?;
|
||||
if attr_marker(element).is_some() || owned_attr_marker(element).is_some() || remove_attr_marker(element).is_some() {
|
||||
if attr_marker(element).is_some() || remove_attr_marker(element).is_some() {
|
||||
return None;
|
||||
}
|
||||
let mut markers = Vec::new();
|
||||
let mut removes = Vec::new();
|
||||
for slot in slots {
|
||||
if let Some(marker) = attr_marker(slot) {
|
||||
markers.push(AttrWrite { marker, owned: false });
|
||||
} else if let Some(marker) = owned_attr_marker(slot) {
|
||||
markers.push(AttrWrite { marker, owned: true });
|
||||
markers.push(marker);
|
||||
} else if let Some(marker) = remove_attr_marker(slot) {
|
||||
removes.push(marker);
|
||||
} else {
|
||||
@@ -100,11 +91,6 @@ pub(crate) fn attr_marker(ty: &Type) -> Option<Type> {
|
||||
marker_of(ty, "Attr")
|
||||
}
|
||||
|
||||
/// Returns the marker type of an `OwnedAttr<Marker>` type, if `ty` is one.
|
||||
pub(crate) fn owned_attr_marker(ty: &Type) -> Option<Type> {
|
||||
marker_of(ty, "OwnedAttr")
|
||||
}
|
||||
|
||||
/// Returns the marker type of a `RemoveAttr<Marker>` type, if `ty` is one.
|
||||
pub(crate) fn remove_attr_marker(ty: &Type) -> Option<Type> {
|
||||
marker_of(ty, "RemoveAttr")
|
||||
|
||||
@@ -162,11 +162,8 @@ fn validate_record_io(parsed: &ParsedNodeFn) {
|
||||
}
|
||||
if let Some(writes) = &writes {
|
||||
let mut seen_writes: Vec<String> = Vec::new();
|
||||
for write in &writes.markers {
|
||||
if write.owned && !async_source {
|
||||
emit_error!(parsed.output_type.span(), "an owned attribute crossing belongs to an async source; a synchronous write parks its value in the kernel");
|
||||
}
|
||||
let written = write.marker.to_token_stream().to_string();
|
||||
for marker in &writes.markers {
|
||||
let written = marker.to_token_stream().to_string();
|
||||
if seen_writes.contains(&written) {
|
||||
emit_error!(parsed.output_type.span(), "attribute `{}` is written twice", written);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//! wiring is by hand until the compiler pass constructs layouts.
|
||||
|
||||
use core_types::Ctx;
|
||||
use core_types::attribute::{Attr, EditorLayerPath, Opacity, OwnedAttr, RemoveAttr, Transform};
|
||||
use core_types::attribute::{Attr, EditorLayerPath, Opacity, RemoveAttr, Transform};
|
||||
use core_types::context::{DeriveCtx, ExtractIndex, IndexLink, InjectIndex, ModifyIndex};
|
||||
use core_types::extent::{ExtentIn, LevelIn, ListIn, ValueIn};
|
||||
use core_types::gpoll::{ErrorKind, Extent, GPoll, GraphError, Interrupt, Level};
|
||||
@@ -379,13 +379,6 @@ async fn measure_async(_: impl Ctx, _: (), element: f64) -> (f64, Attr<Length>)
|
||||
(element, Attr(element.abs()))
|
||||
}
|
||||
|
||||
/// Test-only async source whose reference value crosses the future boundary
|
||||
/// owned: the slot holds the deep copy and every lift parks it afresh.
|
||||
#[node_macro::node(category("Test"))]
|
||||
async fn tag_async(_: impl Ctx, _: (), element: f64, label: String) -> (f64, OwnedAttr<Label>) {
|
||||
(element, OwnedAttr::new(label.as_str()))
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Test"))]
|
||||
fn fallback(ctx: impl Ctx, _: (), #[expose] content: impl Node<Context<'_>, Output = (f64, Attr<Opacity>)>, #[expose] alternate: impl Node<Context<'_>, Output = f64>) -> Result<f64, Interrupt> {
|
||||
let (element, opacity) = content.eval(ctx)?;
|
||||
@@ -2459,37 +2452,6 @@ mod tests {
|
||||
assert_eq!(served.attr::<Length>(), 4.);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_owned_crossing_parks_its_reference_on_every_lift() {
|
||||
let arena = Arena::new(1024).unwrap();
|
||||
let generations = [];
|
||||
let scope = scope_fixture(&generations, &arena);
|
||||
let ctx = ContextImpl::root(&scope);
|
||||
|
||||
let (runtime, _) = lifted_value(core_types::runtime::RuntimeHandle(std::sync::Arc::new(InlineRuntime)));
|
||||
let (source_id, _) = lifted_value(7 as SourceId);
|
||||
let layout = tag_async_layout();
|
||||
let frames = frames_for(&[&layout]);
|
||||
|
||||
let node = install(
|
||||
TagAsyncNode::new(ValueSource::new(()), ValueSource::new(3.), ValueSource::new("tagged".to_string()), runtime, source_id),
|
||||
tag_async_layout_meta(),
|
||||
&[],
|
||||
);
|
||||
assert_eq!(Node::<ContextImpl>::layout(&node), &layout);
|
||||
let offset = layout.offset_of("label", 0).expect("the source writes the label");
|
||||
|
||||
for pass in ["the spawning eval", "the slot hit"] {
|
||||
let scoped = frames.scope();
|
||||
let GPoll::Final(value) = core_types::record::serve_edge(&node, &ctx, &scoped) else {
|
||||
panic!("an inline completion is final on {pass}");
|
||||
};
|
||||
let rec = layout.rec(&value);
|
||||
assert_eq!(unsafe { rec.element::<f64>() }, 3., "{pass}");
|
||||
assert_eq!(unsafe { rec.read::<&str>(offset) }, "tagged", "{pass}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lazy_reads_bind_to_their_edge_and_leave_the_untaken_branch_unevaluated() {
|
||||
let arena = Arena::new(1024).unwrap();
|
||||
|
||||
@@ -349,12 +349,8 @@ fn mirror_vector_extent(
|
||||
|
||||
pub use _mirror_vector_mod::mirror_vector_entries;
|
||||
|
||||
/// Returns the path identifying the subgraph (network) that contains this proto node — i.e. the input `node_path`
|
||||
/// with its own trailing entry dropped. The terminating element of the returned path is the document node whose
|
||||
/// encapsulated network we live in, so the path doubles as a unique reference to that node at any nesting depth.
|
||||
/// Used as the value source for stamping the `editor:layer_path` attribute on each item of a layer's output, which lets
|
||||
/// editor tools (e.g. selection, click target routing) trace data back to its owning layer regardless of whether
|
||||
/// the layer is at the root document network or nested inside a custom subgraph.
|
||||
/// `node_path` with its trailing entry dropped: the containing network's path, which is also a unique
|
||||
/// reference to the owning document node at any nesting depth. Stamped onto `editor:layer_path`.
|
||||
#[node_macro::node(name("Path of Subgraph"), category(""))]
|
||||
pub fn path_of_subgraph(_: impl Ctx, node_path: Vec<NodeId>) -> Vec<NodeId> {
|
||||
let len = node_path.len();
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
use base64::Engine;
|
||||
#[cfg(target_family = "wasm")]
|
||||
use canvas_utils::{Canvas, CanvasHandle};
|
||||
#[cfg(target_family = "wasm")]
|
||||
use core_types::attribute::{Attr, OwnedAttr, Transform};
|
||||
use core_types::color::SRGBA8;
|
||||
use core_types::gpoll::GPoll;
|
||||
#[cfg(target_family = "wasm")]
|
||||
use core_types::list::List;
|
||||
use core_types::list::{Item, List};
|
||||
|
||||
#[cfg(target_family = "wasm")]
|
||||
use core_types::math::bbox::Bbox;
|
||||
@@ -23,13 +21,13 @@ pub use graph_craft::document::value::RenderOutputType;
|
||||
#[cfg(target_family = "wasm")]
|
||||
pub use graphene_canvas_utils as canvas_utils;
|
||||
#[cfg(target_family = "wasm")]
|
||||
use graphic_types::ATTR_EDITOR_MERGED_LAYERS;
|
||||
#[cfg(target_family = "wasm")]
|
||||
use graphic_types::Graphic;
|
||||
#[cfg(target_family = "wasm")]
|
||||
use graphic_types::IntoGraphicList;
|
||||
#[cfg(target_family = "wasm")]
|
||||
use graphic_types::Vector;
|
||||
#[cfg(target_family = "wasm")]
|
||||
use graphic_types::markers::EditorMergedLayers;
|
||||
use graphic_types::raster_types::Image;
|
||||
use graphic_types::raster_types::{CPU, Raster};
|
||||
#[cfg(target_family = "wasm")]
|
||||
@@ -206,7 +204,6 @@ fn create_canvas(_: impl Ctx) -> CanvasHandle {
|
||||
#[node_macro::node(category(""))]
|
||||
async fn rasterize<T: WasmNotSend + Clone>(
|
||||
_: impl Ctx,
|
||||
_: (),
|
||||
#[implementations(
|
||||
List<Vector>,
|
||||
List<Raster<CPU>>,
|
||||
@@ -217,7 +214,7 @@ async fn rasterize<T: WasmNotSend + Clone>(
|
||||
mut data: List<T>,
|
||||
footprint: Footprint,
|
||||
mut canvas: CanvasHandle,
|
||||
) -> (Raster<CPU>, Attr<Transform>, OwnedAttr<EditorMergedLayers>)
|
||||
) -> List<Raster<CPU>>
|
||||
where
|
||||
List<T>: Render + Clone + graphic_types::IntoGraphicList,
|
||||
{
|
||||
@@ -225,15 +222,12 @@ where
|
||||
|
||||
if footprint.transform.matrix2.determinant() == 0. {
|
||||
log::trace!("Invalid footprint received for rasterization");
|
||||
// A zero-size raster renders as nothing, matching the legacy empty list
|
||||
return (Raster::new_cpu(Image::default()), Attr(DAffine2::IDENTITY), OwnedAttr::new(None));
|
||||
return List::new();
|
||||
}
|
||||
|
||||
// Snapshot the input as a List<Graphic> so the renderer can recurse into the original child layers
|
||||
// when collecting metadata, exposing their click targets to editor tools (same mechanism as Boolean Operation).
|
||||
// The copy is owned before the first await: the input's arena content dies with the spawning evaluation.
|
||||
let upstream_graphic_list = data.clone().into_graphic_list();
|
||||
let merged_layers = OwnedAttr::new(Some(&upstream_graphic_list));
|
||||
|
||||
let mut render = SvgRender::new();
|
||||
let aabb = Bbox::from_transform(footprint.transform).to_axis_aligned_bbox();
|
||||
@@ -270,7 +264,11 @@ where
|
||||
let rasterized = context.get_image_data(0, 0, resolution.x as i32, resolution.y as i32).unwrap();
|
||||
|
||||
let image = Image::from_image_data(&rasterized.data().0, resolution.x as u32, resolution.y as u32);
|
||||
(Raster::new_cpu(image), Attr(footprint.transform), merged_layers)
|
||||
List::new_from_item(
|
||||
Item::new_from_element(Raster::new_cpu(image))
|
||||
.with_attribute(ATTR_TRANSFORM, footprint.transform)
|
||||
.with_attribute(ATTR_EDITOR_MERGED_LAYERS, Some(upstream_graphic_list)),
|
||||
)
|
||||
}
|
||||
|
||||
#[node_macro::node(category(""), inject_scope)]
|
||||
|
||||
@@ -17,7 +17,7 @@ use core_types::transform::Transform;
|
||||
use core_types::uuid::NodeId;
|
||||
use core_types::{ATTR_BLEND_MODE, ATTR_CLIPPING_MASK, ATTR_EDITOR_LAYER_PATH, ATTR_OPACITY, ATTR_OPACITY_FILL, ATTR_TRANSFORM, CacheHash, Color, Ctx, DeriveCtx, ExtractIndex, InjectIndex};
|
||||
use glam::{DAffine2, DMat2, DVec2};
|
||||
use graphic_types::graphic::{bake_paint_transforms, has_paint, is_paint_present, paint_graphics, set_paint_attribute_at};
|
||||
use graphic_types::graphic::{bake_paint_transforms, has_paint, is_paint_present, set_paint_attribute_at};
|
||||
use graphic_types::markers::{EditorMergedLayers, Fill, Stroke as StrokeAttr};
|
||||
use graphic_types::raster_types::{CPU, GPU, Raster};
|
||||
use graphic_types::{ATTR_EDITOR_MERGED_LAYERS, ATTR_FILL, ATTR_STROKE, Graphic, IntoGraphicList};
|
||||
@@ -3776,6 +3776,7 @@ fn centroid(_: impl Ctx, vector: IList<Vector>, centroid_type: CentroidType) ->
|
||||
mod test {
|
||||
use super::*;
|
||||
use core_types::transform::Footprint;
|
||||
use graphic_types::graphic::paint_graphics;
|
||||
use kurbo::{CubicBez, Ellipse, Point, Rect};
|
||||
use vector_types::vector::algorithms::bezpath_algorithms::{TValue, trim_pathseg};
|
||||
use vector_types::vector::misc::pathseg_abs_diff_eq;
|
||||
|
||||
Reference in new issue
Block a user