Skip to content

Commit

Permalink
Use *const () to represent CompactLength and add implementation f…
Browse files Browse the repository at this point in the history
…or 32 bit platforms (#789)

* Use *const() to represent CompactLength and add implementation for 32 bit platforms

Signed-off-by: Nico Burns <[email protected]>

* Add strict_provenance feature

* Add strict_provenance feature to benchmarks

* Fix serde impls for CompactLength

Signed-off-by: Nico Burns <[email protected]>

---------

Signed-off-by: Nico Burns <[email protected]>
  • Loading branch information
nicoburns authored Feb 20, 2025
1 parent 9da7a72 commit 8d2a036
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 99 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ grid = ["alloc", "dep:grid"]
content_size = []
## Causes algorithms to stores detailed information of the nodes in TaffyTree, with only CSS Grid supporting this.
detailed_layout_info = []
## Use strict provenance APIs for pointer manipulation. Using this feature requires Rust 1.84 or higher.
strict_provenance = []

#! ### Taffy Tree

Expand Down
1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ yoga = ["dep:yoga", "dep:slotmap", "dep:ordered-float"]
yoga-super-deep = ["yoga"]
taffy03 = ["dep:taffy_03"]
content_size = ["taffy/content_size"]
strict_provenance = ["taffy/strict_provenance"]
small = []
large = []

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_tree_owned_partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl taffy::LayoutPartialTree for Node {
self.node_from_id_mut(node_id).layout = *layout
}

fn resolve_calc_value(&self, _val: u64, _basis: f32) -> f32 {
fn resolve_calc_value(&self, _val: *const (), _basis: f32) -> f32 {
0.0
}

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_tree_owned_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl LayoutPartialTree for StatelessLayoutTree {
unsafe { node_from_id_mut(node_id).unrounded_layout = *layout };
}

fn resolve_calc_value(&self, _val: u64, _basis: f32) -> f32 {
fn resolve_calc_value(&self, _val: *const (), _basis: f32) -> f32 {
0.0
}

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_tree_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl taffy::LayoutPartialTree for Tree {
self.node_from_id_mut(node_id).unrounded_layout = *layout;
}

fn resolve_calc_value(&self, _val: u64, _basis: f32) -> f32 {
fn resolve_calc_value(&self, _val: *const (), _basis: f32) -> f32 {
0.0
}

Expand Down
4 changes: 2 additions & 2 deletions src/compute/grid/explicit_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) fn compute_explicit_grid_size_in_axis(
style: &impl GridContainerStyle,
template: &[TrackSizingFunction],
inner_container_size: Size<Option<f32>>,
resolve_calc_value: impl Fn(u64, f32) -> f32,
resolve_calc_value: impl Fn(*const (), f32) -> f32,
axis: AbsoluteAxis,
) -> u16 {
// If template contains no tracks, then there are trivially zero explicit tracks
Expand Down Expand Up @@ -106,7 +106,7 @@ pub(crate) fn compute_explicit_grid_size_in_axis(
fn track_definite_value(
sizing_function: &NonRepeatedTrackSizingFunction,
parent_size: Option<f32>,
calc_resolver: impl Fn(u64, f32) -> f32,
calc_resolver: impl Fn(*const (), f32) -> f32,
) -> f32 {
let max_size = sizing_function.max.definite_value(parent_size, &calc_resolver);
let min_size = sizing_function.min.definite_value(parent_size, &calc_resolver);
Expand Down
2 changes: 1 addition & 1 deletion src/compute/grid/track_sizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ where

/// Simple pass-through function to `LayoutPartialTreeExt::calc`
#[inline(always)]
fn calc(&self, val: u64, basis: f32) -> f32 {
fn calc(&self, val: *const (), basis: f32) -> f32 {
self.tree.calc(val, basis)
}

Expand Down
4 changes: 2 additions & 2 deletions src/compute/grid/types/grid_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl GridItem {
axis: AbstractAxis,
axis_tracks: &[GridTrack],
axis_parent_size: Option<f32>,
resolve_calc_value: &dyn Fn(u64, f32) -> f32,
resolve_calc_value: &dyn Fn(*const (), f32) -> f32,
) -> Option<f32> {
let spanned_tracks = &axis_tracks[self.track_range_excluding_lines(axis)];
let tracks_all_fixed = spanned_tracks.iter().all(|track| {
Expand All @@ -215,7 +215,7 @@ impl GridItem {
axis: AbstractAxis,
axis_tracks: &[GridTrack],
axis_parent_size: Option<f32>,
resolve_calc_value: &dyn Fn(u64, f32) -> f32,
resolve_calc_value: &dyn Fn(*const (), f32) -> f32,
) -> Option<f32> {
let spanned_tracks = &axis_tracks[self.track_range_excluding_lines(axis)];
let tracks_all_fixed = spanned_tracks.iter().all(|track| {
Expand Down
2 changes: 1 addition & 1 deletion src/compute/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use core::unreachable;
pub fn compute_leaf_layout<MeasureFunction>(
inputs: LayoutInput,
style: &impl CoreStyle,
resolve_calc_value: impl Fn(u64, f32) -> f32,
resolve_calc_value: impl Fn(*const (), f32) -> f32,
measure_function: MeasureFunction,
) -> LayoutOutput
where
Expand Down
Loading

0 comments on commit 8d2a036

Please sign in to comment.