Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared State #2858

Merged
merged 161 commits into from Apr 29, 2024
Merged

Shared State #2858

merged 161 commits into from Apr 29, 2024

Conversation

stephencelis
Copy link
Member

This PR introduces all new tools for sharing state in the Composable Architecture.

For more information and for questions and comments, please see this discussion: #2857

@stephencelis stephencelis added the shared state beta Related to our shared state release. label Feb 26, 2024
@mbrandonw mbrandonw merged commit e121b91 into main Apr 29, 2024
6 of 7 checks passed
@mbrandonw mbrandonw deleted the shared-state-beta branch April 29, 2024 00:53
fileExists: { FileManager.default.fileExists(atPath: $0.path) },
fileSystemSource: {
let source = DispatchSource.makeFileSystemObjectSource(
fileDescriptor: open($0.path, O_EVTONLY),
Copy link
Contributor

@Matejkob Matejkob Apr 29, 2024

Choose a reason for hiding this comment

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

Hi there!

Great work on this amazing feature, @stephencelis and @mbrandonw! 😍

I apologize for commenting on an already closed PR, but I believe this is quite important. According to the documentation:

Upon successful completion, the function shall open the file and return a non-negative integer representing the lowest numbered unused file descriptor. Otherwise, -1 shall be returned and errno set to indicate the error. No files shall be created or modified if the function returns -1.1

It appears the open function will return -1 if the system lacks access to the specified path. If a user specifies @Shared(.fileStorage) with an URL that the system cannot access, then calling DispatchSource.makeFileSystemObjectSource with a file descriptor represented by -1 will lead to a crash.

Is this the intended behavior? While I understand the desire to inform developers when they are accessing a file to which they do not have rights, some operating systems implement mechanisms to dynamically enable or disable access to files. Suppose the access is disabled after the application starts; this would lead to the application crashing.

Do you think we could handle this situation?

Footnotes

  1. https://pubs.opengroup.org/onlinepubs/007904875/functions/open.html

Copy link
Member Author

Choose a reason for hiding this comment

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

@Matejkob We'd take a PR that bails out on a negative file descriptor if you're down to submit! Since it's generally a developer-specified URL then failure to access will generally be a programmer error, so a crash is appropriate there, but there is the edge case where the URL could come in from the user, so we shouldn't make the assumption.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure thing, can do. The question is how do you wanna handle such an error?
The createDirectory endpoint can throw an error as well and I can see that you handled it by ignoring it:

try? self.storage.createDirectory(self.url.deletingLastPathComponent(), true)

Do you think it would be appropriate solution here? Or maybe we should emit error down to the user land?

@stephencelis stephencelis restored the shared-state-beta branch April 29, 2024 15:55
cgrindel-self-hosted-renovate bot added a commit to cgrindel/rules_swift_package_manager that referenced this pull request Apr 29, 2024
…ure to from: "1.10.0" (#1052)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
|
[pointfreeco/swift-composable-architecture](https://togithub.com/pointfreeco/swift-composable-architecture)
| minor | `from: "1.9.3"` -> `from: "1.10.0"` |

---

### Release Notes

<details>
<summary>pointfreeco/swift-composable-architecture
(pointfreeco/swift-composable-architecture)</summary>

###
[`v1.10.0`](https://togithub.com/pointfreeco/swift-composable-architecture/releases/tag/1.10.0)

[Compare
Source](https://togithub.com/pointfreeco/swift-composable-architecture/compare/1.9.3...1.10.0)

#### What's Changed

- Added: All new state sharing tools, including the `@Shared` property
wrapper and more
([pointfreeco/swift-composable-architecture#2858).
(Thanks [@&#8203;NFulkerson](https://togithub.com/NFulkerson),
[@&#8203;hallee](https://togithub.com/hallee),
[@&#8203;pyrtsa](https://togithub.com/pyrtsa),
[@&#8203;DandyLyons](https://togithub.com/DandyLyons),
[@&#8203;hiltonc](https://togithub.com/hiltonc),
[@&#8203;lukeredpath](https://togithub.com/lukeredpath),
[@&#8203;andtie](https://togithub.com/andtie),
[@&#8203;AlexKobachiJP](https://togithub.com/AlexKobachiJP),
[@&#8203;ZevEisenberg](https://togithub.com/ZevEisenberg), for their
contributions!)
- Updated: Bumped swift-collections to remove `@unchecked` from
`StackState`'s `Sendable` conformance (thanks
[@&#8203;rhysm94](https://togithub.com/rhysm94),
[pointfreeco/swift-composable-architecture#2997).
- Updated: Bumped swift-custom-dump to avoid a crash and leverage the
latest tools for shared state (thanks
[@&#8203;y-mimura](https://togithub.com/y-mimura),
[pointfreeco/swift-composable-architecture#3008).
- Infrastructure: Update README.md package addition wording to match
latest Xcode (thanks [@&#8203;dafurman](https://togithub.com/dafurman),
[pointfreeco/swift-composable-architecture#2998).
- Infrastructure: Tutorial fixes and updates (thanks
[@&#8203;dafurman](https://togithub.com/dafurman),
[pointfreeco/swift-composable-architecture#3003).

#### New Contributors

- [@&#8203;dafurman](https://togithub.com/dafurman) made their first
contribution in
[pointfreeco/swift-composable-architecture#2998
- [@&#8203;y-mimura](https://togithub.com/y-mimura) made their first
contribution in
[pointfreeco/swift-composable-architecture#3008

**Full Changelog**:
pointfreeco/swift-composable-architecture@1.9.3...1.10.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDkuNCIsInVwZGF0ZWRJblZlciI6IjM2LjEwOS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shared state beta Related to our shared state release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet