Skip to content

fix(runtime): port yoga backend to taffy 0.13 - #8503

Merged
proggeramlug merged 3 commits into
PerryTS:mainfrom
proggeramlug:fix/8438-taffy-013
Aug 21, 2026
Merged

fix(runtime): port yoga backend to taffy 0.13#8503
proggeramlug merged 3 commits into
PerryTS:mainfrom
proggeramlug:fix/8438-taffy-013

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Ports the Perry TUI and Yoga layout backends from taffy 0.7 to 0.13 without an unsafe Send assertion. Yoga nodes now live in a per-thread registry, matching the single-threaded UI runtime and taffy 0.13 storage model.

Changes

  • update taffy and its lockfile entry to 0.13
  • migrate TUI and Yoga alignment values to the new associated constants
  • preserve Yoga’s existing unsafe overflow-alignment semantics explicitly
  • move Yoga nodes and the GC scanner-registration latch to thread-local storage so every JS worker registers and scans its own callback roots
  • add focused alignment and thread-isolation regression tests

Related issue

Closes #8438

Test plan

  • cargo check --locked -p perry-runtime

  • cargo test -p perry-runtime --lib yoga::tests -- --test-threads=1

  • cargo test -p perry-runtime --lib tui::layout::tests -- --test-threads=1

  • cargo fmt --all -- --check

  • git diff --check

  • ./scripts/pre-tag-check.sh --quick

  • cargo build --release clean

  • cargo test --workspace --exclude perry-ui-ios --exclude perry-ui-tvos --exclude perry-ui-watchos --exclude perry-ui-gtk4 --exclude perry-ui-android --exclude perry-ui-windows passes

  • (if user-facing) Added or updated a test under test-files/ or a #[test] in the affected crate

  • (if CLI / stdlib / runtime API changed) Docs are not required; no public API changed

  • (if touching a platform UI backend) Built -p perry-ui-<backend> locally on that platform

Checklist

  • I have NOT bumped the workspace version or edited CLAUDE.md / CHANGELOG.md (maintainer handles these at merge)
  • My commits follow the loose feat: / fix: / docs: / chore: prefix convention used in the log
  • I have read CONTRIBUTING.md and agree to the Code of Conduct

Summary by CodeRabbit

  • Bug Fixes

    • Updated layout handling to the latest Taffy version while preserving existing alignment behavior.
    • Improved reliability of Yoga-based layouts across worker threads.
    • Added safeguards for alignment and overflow behavior.
  • Documentation

    • Added changelog notes covering the layout backend updates.

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d0bb4a1-a4c6-4b48-a7e7-cde901821d98

📥 Commits

Reviewing files that changed from the base of the PR and between 50245d7 and 523861a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • changelog.d/8503-taffy-013.md
  • crates/perry-runtime/Cargo.toml
  • crates/perry-runtime/src/tui/layout.rs
  • crates/perry-runtime/src/yoga.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The runtime upgrades Taffy from 0.7 to 0.13, updates alignment constants, and moves Yoga node and GC scanner state from process-wide storage to thread-local storage. Tests cover alignment safety and per-thread registry isolation.

Changes

Taffy and Yoga runtime update

Layer / File(s) Summary
Taffy 0.13 alignment update
crates/perry-runtime/Cargo.toml, crates/perry-runtime/src/tui/layout.rs, crates/perry-runtime/src/yoga.rs, changelog.d/8503-taffy-013.md
The runtime upgrades Taffy to 0.13 and uses its uppercase alignment constants. The changelog records the migration and preserved unsafe overflow alignment.
Thread-local Yoga registry and validation
crates/perry-runtime/src/yoga.rs
Yoga node storage and GC registration now use per-thread state. Tests verify alignment safety and independent thread-local registries.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to 52386

This localized runtime dependency migration preserves the intended thread-isolated behavior and includes focused regression coverage; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant YogaWorkerThread
  participant YogaNodeRegistry
  participant GCScanner
  participant MeasureCallbacks
  YogaWorkerThread->>YogaNodeRegistry: call with_nodes
  YogaNodeRegistry->>GCScanner: register root scanner once per thread
  GCScanner->>YogaNodeRegistry: scan current thread's nodes
  YogaNodeRegistry->>MeasureCallbacks: scan stored measure callbacks
Loading

Suggested reviewers: thehypnoo

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 2 files. (2 skipped: 2 unsupported.) Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the runtime Yoga backend port to taffy 0.13, which is the primary change.
Description check ✅ Passed The description includes the required summary, changes, issue reference, test plan, and checklist with clear implementation details.
Linked Issues check ✅ Passed The changes satisfy all coding requirements in issue #8438, including alignment constants, explicit safety, thread-local storage, and GC root handling.
Out of Scope Changes check ✅ Passed The reviewed changes are limited to the taffy upgrade, Yoga and TUI migration, tests, and related changelog documentation.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

Audited and merging.

This is more than a dependency bump — it also closes a latent multi-thread GC rooting hole, and the PR description undersells that half.

MUTABLE_ROOT_SCANNERS is thread-local (crates/perry-runtime/src/gc/roots.rs:105), but on main GC_SCANNER_REGISTERED is a global Mutex<bool>. So the first thread to touch yoga registers yoga_root_scanner into its own thread-local registry and flips the global latch — and every later thread sees the latch already true and registers nothing. That thread's collector then never scans yoga's stored JS measure callbacks, so a callback set by a second worker between setMeasureFunc and calculateLayout is invisible to the collector that would reclaim it.

Moving both the registry and the latch to perry_thread_local! is the correct fix, and the reasoning in the code comment is right about why the latch has to follow the registry. YOGA_NEXT_ID correctly stays a global Mutex, so handle ids remain unique across the per-thread registries and a stale id cannot alias a live node on another thread.

The port itself is mechanical — associated constants for the alignment enums, grid dropped from the lockfile. Good call pinning AlignmentSafety::Unsafe on every mapped alignment with an explicit assertion rather than inheriting whatever taffy 0.13 defaults to; that is the kind of behavior an enum-shape migration silently flips.

Validation on this branch:

check result
gc_runtime_root_holders gate OK — 633 holders, 96 scanner-reached, 140 registered scanners
yoga:: tests (incl. yoga_registry_and_gc_registration_are_per_thread) 2 passed
tui::layout tests 6 passed
perry-runtime --lib, RUST_TEST_THREADS=1 2608 passed, 4 ignored

One consequence worth a line in the changelog: a yoga node created on one thread is no longer visible from another. That is consistent with the single-threaded UI runtime the handle design assumes, and the new isolation test pins it — but it is a real behavioral narrowing, not just an internal refactor.

@proggeramlug
proggeramlug merged commit 9aee500 into PerryTS:main Aug 21, 2026
19 of 20 checks passed
@proggeramlug
proggeramlug deleted the fix/8438-taffy-013 branch August 21, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deps: port perry-runtime yoga backend to taffy 0.13 (alignment enums restructured; Style is no longer Send)

1 participant