Skip to content

Add LazyState#906

Open
Kyle-Ye wants to merge 1 commit into
mainfrom
feature/lazy_state
Open

Add LazyState#906
Kyle-Ye wants to merge 1 commit into
mainfrom
feature/lazy_state

Conversation

@Kyle-Ye

@Kyle-Ye Kyle-Ye commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

  • Add LazyState as a private SPI property wrapper with lazy initial storage, wrapped value access, projected bindings, and dynamic property installation.
  • Reuse stored location state plumbing through package-scoped access needed by the OpenSwiftUI target.
  • Include unavailable Sendable conformances for the wrapper and storage.

Testing

  • swift build --target OpenSwiftUI

@github-actions github-actions Bot added area: data-flow State, binding, environment, preference, observation, or property data flow. type: feature New API, behavior, platform support, or user-facing capability. labels Jun 10, 2026
@Kyle-Ye Kyle-Ye marked this pull request as ready for review June 10, 2026 19:12
@augmentcode

augmentcode Bot commented Jun 10, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR introduces a new private-SPI @LazyState property wrapper that defers computing its initial value until the state is actually installed in the dynamic property system.

Changes:

  • Added LazyState (OpenSwiftUI target) with thunk-based storage, wrapped value access, and projected Binding support.
  • Implemented LazyState._makeProperty and a matching LazyStatePropertyBox to integrate with _DynamicPropertyBuffer and state signaling.
  • Reused existing StoredLocation plumbing to back LazyState once installed, updating the wrapper’s storage from thunk to concrete value.
  • Adjusted StoredLocation/StoredLocationBase access control (e.g., updateValue, invalidate(), initializer) to package so OpenSwiftUI can use it across targets in the same SwiftPM package.
  • Switched OpenAttributeGraphShims import in StoredLocation.swift to package import to align with package-scoped usage.
  • Added unavailable Sendable conformances for LazyState and its internal storage to match intended concurrency semantics.

Technical Notes: The wrapper mirrors State update semantics (including GraphHost.isUpdating read tracking) while allowing the initial value closure to be skipped on repeated view re-initializations.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

public var projectedValue: Binding<Value> {
let value = getValue(forReading: false)
guard let _location else {
Log.runtimeIssues("Accessing State's value outside of being installed on a View. This will result in a constant Binding of the initial value and will not update.")

@augmentcode augmentcode Bot Jun 10, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Log.runtimeIssues message here still says "Accessing State's value" even though this is LazyState; that can be confusing when diagnosing runtime warnings.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.24%. Comparing base (2ef0b16) to head (b956bd0).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
Sources/OpenSwiftUI/Data/State/LazyState.swift 0.00% 67 Missing ⚠️
...es/OpenSwiftUICore/Data/State/StoredLocation.swift 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #906      +/-   ##
==========================================
- Coverage   26.71%   26.24%   -0.47%     
==========================================
  Files         697      711      +14     
  Lines       48916    49787     +871     
==========================================
+ Hits        13068    13069       +1     
- Misses      35848    36718     +870     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: data-flow State, binding, environment, preference, observation, or property data flow. type: feature New API, behavior, platform support, or user-facing capability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant