diff --git a/api/sixtyfps-cpp/include/sixtyfps_pathdata.h b/api/sixtyfps-cpp/include/sixtyfps_pathdata.h index 58eff2fa1..9c83f0fdb 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_pathdata.h +++ b/api/sixtyfps-cpp/include/sixtyfps_pathdata.h @@ -8,6 +8,9 @@ // The C++ code generator assumes that enums are in the cbindgen_private namespace namespace sixtyfps::cbindgen_private { +using cbindgen_private::types::PathEvent; +} +namespace sixtyfps::private_api { using cbindgen_private::types::PathArcTo; using cbindgen_private::types::PathCubicTo; using cbindgen_private::types::PathElement; @@ -16,11 +19,6 @@ using cbindgen_private::types::PathLineTo; using cbindgen_private::types::PathMoveTo; using cbindgen_private::types::PathQuadraticTo; using cbindgen_private::types::Point; -} -namespace sixtyfps::private_api { -using cbindgen_private::types::PathElement; -using cbindgen_private::types::PathEvent; -using cbindgen_private::types::Point; struct PathData { diff --git a/sixtyfps_compiler/builtins.60 b/sixtyfps_compiler/builtins.60 index c22a6989d..58a91ff44 100644 --- a/sixtyfps_compiler/builtins.60 +++ b/sixtyfps_compiler/builtins.60 @@ -270,7 +270,7 @@ MoveTo := _ { property y; //-rust_type_constructor:sixtyfps::re_exports::PathElement::MoveTo(PathMoveTo{{}}) - //-cpp_type:sixtyfps::cbindgen_private::PathMoveTo + //-cpp_type:sixtyfps::private_api::PathMoveTo //-is_non_item_type } @@ -279,7 +279,7 @@ LineTo := _ { property y; //-rust_type_constructor:sixtyfps::re_exports::PathElement::LineTo(PathLineTo{{}}) - //-cpp_type:sixtyfps::cbindgen_private::PathLineTo + //-cpp_type:sixtyfps::private_api::PathLineTo //-is_non_item_type } @@ -293,7 +293,7 @@ ArcTo := _ { property sweep; //-rust_type_constructor:sixtyfps::re_exports::PathElement::ArcTo(PathArcTo{{}}) - //-cpp_type:sixtyfps::cbindgen_private::PathArcTo + //-cpp_type:sixtyfps::private_api::PathArcTo //-is_non_item_type } @@ -306,7 +306,7 @@ CubicTo := _ { property y; //-rust_type_constructor:sixtyfps::re_exports::PathElement::CubicTo(PathCubicTo{{}}) - //-cpp_type:sixtyfps::cbindgen_private::PathCubicTo + //-cpp_type:sixtyfps::private_api::PathCubicTo //-is_non_item_type } @@ -317,7 +317,7 @@ QuadraticTo := _ { property y; //-rust_type_constructor:sixtyfps::re_exports::PathElement::QuadraticTo(PathQuadraticTo{{}}) - //-cpp_type:sixtyfps::cbindgen_private::PathQuadraticTo + //-cpp_type:sixtyfps::private_api::PathQuadraticTo //-is_non_item_type } diff --git a/sixtyfps_compiler/generator/cpp.rs b/sixtyfps_compiler/generator/cpp.rs index 2495bbb02..ed726a3cd 100644 --- a/sixtyfps_compiler/generator/cpp.rs +++ b/sixtyfps_compiler/generator/cpp.rs @@ -2731,14 +2731,14 @@ fn compile_path(path: &crate::expression_tree::Path, component: &Rc) }) .unwrap_or_default(); format!( - "sixtyfps::cbindgen_private::PathElement::{}({})", + "sixtyfps::private_api::PathElement::{}({})", element.element_type.native_class.class_name, element_initializer ) }) .collect(); format!( r#"[&](){{ - sixtyfps::cbindgen_private::PathElement elements[{}] = {{ + sixtyfps::private_api::PathElement elements[{}] = {{ {} }}; return sixtyfps::private_api::PathData(&elements[0], std::size(elements)); @@ -2756,10 +2756,10 @@ fn compile_path(path: &crate::expression_tree::Path, component: &Rc) format!( r#"[&](){{ - sixtyfps::cbindgen_private::PathEvent events[{}] = {{ + sixtyfps::private_api::PathEvent events[{}] = {{ {} }}; - sixtyfps::cbindgen_private::Point coordinates[{}] = {{ + sixtyfps::private_api::Point coordinates[{}] = {{ {} }}; return sixtyfps::private_api::PathData(&events[0], std::size(events), &coordinates[0], std::size(coordinates)); diff --git a/sixtyfps_compiler/generator/rust.rs b/sixtyfps_compiler/generator/rust.rs index a9970bb7b..8a319bebc 100644 --- a/sixtyfps_compiler/generator/rust.rs +++ b/sixtyfps_compiler/generator/rust.rs @@ -1939,109 +1939,6 @@ fn box_layout_function( } } } -/* -fn compile_path_events(events: &[crate::expression_tree::PathEvent]) -> TokenStream { - use lyon_path::Event; - - let mut coordinates = Vec::new(); - - let converted_events: Vec = events - .iter() - .map(|event| match event { - Event::Begin { at } => { - coordinates.push(at); - quote!(sixtyfps::re_exports::PathEvent::Begin) - } - Event::Line { from, to } => { - coordinates.push(from); - coordinates.push(to); - quote!(sixtyfps::re_exports::PathEvent::Line) - } - Event::Quadratic { from, ctrl, to } => { - coordinates.push(from); - coordinates.push(ctrl); - coordinates.push(to); - quote!(sixtyfps::re_exports::PathEvent::Quadratic) - } - Event::Cubic { from, ctrl1, ctrl2, to } => { - coordinates.push(from); - coordinates.push(ctrl1); - coordinates.push(ctrl2); - coordinates.push(to); - quote!(sixtyfps::re_exports::PathEvent::Cubic) - } - Event::End { close, .. } => { - if *close { - quote!(sixtyfps::re_exports::PathEvent::EndClosed) - } else { - quote!(sixtyfps::re_exports::PathEvent::EndOpen) - } - } - }) - .collect(); - - let coordinates: Vec = coordinates - .into_iter() - .map(|pt| { - let x = pt.x; - let y = pt.y; - quote!(sixtyfps::re_exports::Point::new(#x, #y)) - }) - .collect(); - - quote!(sixtyfps::re_exports::SharedVector::::from_slice(&[#(#converted_events),*]), - sixtyfps::re_exports::SharedVector::::from_slice(&[#(#coordinates),*])) -} - -fn compile_path(path: &Path, component: &Rc) -> TokenStream { - match path { - Path::Elements(elements) => { - let converted_elements: Vec = elements - .iter() - .map(|element| { - let mut bindings = element - .bindings - .iter() - .map(|(property, expr)| { - let prop_ident = ident(property); - let binding_expr = compile_expression(&expr.borrow(), component); - - quote!(#prop_ident: #binding_expr as _).to_string() - }) - .collect::>(); - - if bindings.len() < element.element_type.properties.len() { - bindings.push("..Default::default()".into()) - } - - let bindings = bindings.join(","); - - let ctor_format_string = element - .element_type - .native_class.rust_type_constructor - .as_ref() - .expect( - "Unexpected error in type registry: path element is lacking rust type name", - ); - - ctor_format_string - .replace("{}", &bindings) - .parse() - .expect("Error parsing rust path element constructor") - }) - .collect(); - - quote!(sixtyfps::re_exports::PathData::Elements( - sixtyfps::re_exports::SharedVector::::from_slice(&[#(#converted_elements),*]) - )) - } - Path::Events(events) => { - let events = compile_path_events(events); - quote!(sixtyfps::re_exports::PathData::Events(#events)) - } - } -} -*/ // In Rust debug builds, accessing the member of the FIELD_OFFSETS ends up copying the // entire FIELD_OFFSETS into a new stack allocation, which with large property // binding initialization functions isn't re-used and with large generated inner diff --git a/sixtyfps_compiler/llr/lower_expression.rs b/sixtyfps_compiler/llr/lower_expression.rs index b7e88984e..e6b560837 100644 --- a/sixtyfps_compiler/llr/lower_expression.rs +++ b/sixtyfps_compiler/llr/lower_expression.rs @@ -866,7 +866,7 @@ fn compile_path( let converted_elements = elements .iter() .map(|element| { - let ty = Type::Struct { + let element_type = Type::Struct { fields: element .element_type .properties @@ -878,14 +878,26 @@ fn compile_path( }; llr_Expression::Struct { - ty, + ty: element_type, values: element - .bindings + .element_type + .properties .iter() - .map(|(property, expr)| { + .map(|(element_field_name, element_property)| { ( - property.clone(), - lower_expression(&expr.borrow().expression, ctx).unwrap(), + element_field_name.clone(), + element.bindings.get(element_field_name).map_or_else( + || { + llr_Expression::default_value_for_type( + &element_property.ty, + ) + .unwrap() + }, + |expr| { + lower_expression(&expr.borrow().expression, ctx) + .unwrap() + }, + ), ) }) .collect(),