Skip to content

refactor: Remove unused swift-perception dependency, target macOS 15+ only#1

Merged
doozMen merged 1 commit intomainfrom
remove_swift-perception_use_native_things
Dec 13, 2025
Merged

refactor: Remove unused swift-perception dependency, target macOS 15+ only#1
doozMen merged 1 commit intomainfrom
remove_swift-perception_use_native_things

Conversation

@doozMen
Copy link
Owner

@doozMen doozMen commented Dec 12, 2025

  • Remove import Perception from FetchSubscription.swift (was unused)
  • Add explicit import ConcurrencyExtras for LockIsolated
  • Remove swift-perception package dependency from Package.swift
  • Update platforms to macOS 15+ only (drop iOS/tvOS/watchOS)
  • Update Package@swift-6.0.swift similarly

The Perception import was never actually used - the file only uses
LockIsolated (from ConcurrencyExtras) and SharedReader (from Sharing).

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Copy link
Owner Author

doozMen commented Dec 12, 2025

… only

- Remove `import Perception` from FetchSubscription.swift (was unused)
- Add explicit `import ConcurrencyExtras` for LockIsolated
- Remove swift-perception package dependency from Package.swift
- Update platforms to macOS 15+ only (drop iOS/tvOS/watchOS)
- Update Package@swift-6.0.swift similarly

The Perception import was never actually used - the file only uses
LockIsolated (from ConcurrencyExtras) and SharedReader (from Sharing).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@doozMen doozMen force-pushed the remove_swift-perception_use_native_things branch from c4ad36c to 656545a Compare December 13, 2025 19:57
@claude
Copy link

claude bot commented Dec 13, 2025

Pull Request Review

Summary

This PR removes the unused swift-perception dependency and adds the FetchSubscription type. The changes are mostly good, but there's a critical integration issue that needs to be addressed.


🔴 Critical Issues

1. Incomplete Feature Implementation

Location: Sources/SQLiteData/FetchSubscription.swift:1-46

The FetchSubscription type is defined but not integrated with the property wrappers. The documentation in FetchSubscription.swift:13 shows:

.task {
  try? await $reminders.load(Reminder.all).task
}

However, all load() methods in FetchAll.swift, FetchOne.swift, and Fetch.swift currently return Void, not FetchSubscription. This means:

  • The documented API doesn't work
  • Users cannot use .load(...).task
  • The new type is dead code

Required Fix: Update all load() method signatures across the three property wrappers to return FetchSubscription instead of Void.


⚠️ Design & Best Practices

2. Potential Race Condition in Task Management

Location: Sources/SQLiteData/FetchSubscription.swift:36

let task = Task {
  try await withTaskCancellationHandler {
    try await Task.never()
  } onCancel: {
    onCancel()
  }
}
cancellable.withValue { $0 = task }
try await task.cancellableValue

The task is created and stored in cancellable after creation. If cancel() is called between task creation (line 30) and storage (line 36), the cancellation will be missed.

Recommendation: Consider storing the task before or atomically with creation, or document this as expected behavior.

3. Thread-Safety of SharedReader Assignment

Location: Sources/SQLiteData/FetchSubscription.swift:21

onCancel = { sharedReader.projectedValue = SharedReader(value: sharedReader.wrappedValue) }

This captures and mutates sharedReader.projectedValue. Questions:

  • Is SharedReader.projectedValue safe to mutate from arbitrary threads?
  • Should this be dispatched to a specific queue?

Recommendation: Verify thread-safety guarantees with the Sharing library or add documentation about execution context.

4. Platform Restriction Inconsistency

Location: Package.swift:8 and Package@swift-6.0.swift:8

The PR changes platform support to macOS 15+ only, removing iOS, tvOS, and watchOS. This is a breaking change that:

  • May break existing users on other platforms
  • Isn't mentioned in the PR description beyond the bullet point
  • Seems unrelated to removing swift-perception

Questions:

  • Is this intentional or a mistake?
  • If intentional, should this be a separate PR with proper deprecation notice?
  • Does FetchSubscription use macOS 15-specific APIs?

✅ Code Quality & Style

5. Good: Proper Import Hygiene

The removal of unused import Perception and explicit addition of import ConcurrencyExtras follows Swift best practices for minimal imports.

6. Good: Sendable Conformance

FetchSubscription properly declares Sendable conformance, which is essential for Swift 6 concurrency safety.

7. Good: Documentation

The doc comments are clear and include usage examples, matching the style of other files in the codebase.


🧪 Test Coverage

8. Missing: No Tests for FetchSubscription

Location: Tests/SQLiteDataTests/

There are no tests for the new FetchSubscription type. Recommended test cases:

  • Basic subscription lifecycle (create, await task, cancel)
  • Cancellation via Task cancellation
  • Manual cancellation via .cancel()
  • Multiple concurrent subscriptions
  • Subscription cleanup behavior

🔒 Security & Performance

9. Performance: Efficient Use of LockIsolated

The use of LockIsolated for the cancellable task is appropriate and matches patterns elsewhere in the codebase (as seen in CloudKit/SyncEngine.swift and other files).

10. No Security Concerns

No security issues identified in this change.


📋 Recommendations Summary

Must Fix Before Merge:

  1. ✅ Integrate FetchSubscription with load() methods in all three property wrappers
  2. ⚠️ Clarify/reconsider the macOS 15+ only platform restriction

Should Address:
3. Add tests for FetchSubscription
4. Document or fix the potential race condition in task management
5. Verify thread-safety of the onCancel closure

Nice to Have:
6. Add inline examples showing the complete integration once load() returns FetchSubscription


Verdict

Status: ❌ Needs Work

While the dependency cleanup is good, the FetchSubscription feature is incomplete. The type cannot be used as documented without updating the property wrapper APIs. This should be completed before merging to avoid shipping half-implemented functionality.

@doozMen doozMen merged commit 341b624 into main Dec 13, 2025
4 of 7 checks passed
doozMen added a commit that referenced this pull request Jan 3, 2026
… only (#1)

- Remove `import Perception` from FetchSubscription.swift (was unused)
- Add explicit `import ConcurrencyExtras` for LockIsolated
- Remove swift-perception package dependency from Package.swift
- Update platforms to macOS 15+ only (drop iOS/tvOS/watchOS)
- Update Package@swift-6.0.swift similarly

The Perception import was never actually used - the file only uses
LockIsolated (from ConcurrencyExtras) and SharedReader (from Sharing).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
doozMen added a commit that referenced this pull request Jan 22, 2026
… only (#1)

- Remove `import Perception` from FetchSubscription.swift (was unused)
- Add explicit `import ConcurrencyExtras` for LockIsolated
- Remove swift-perception package dependency from Package.swift
- Update platforms to macOS 15+ only (drop iOS/tvOS/watchOS)
- Update Package@swift-6.0.swift similarly

The Perception import was never actually used - the file only uses
LockIsolated (from ConcurrencyExtras) and SharedReader (from Sharing).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
doozMen added a commit that referenced this pull request Feb 14, 2026
… only (#1)

- Remove `import Perception` from FetchSubscription.swift (was unused)
- Add explicit `import ConcurrencyExtras` for LockIsolated
- Remove swift-perception package dependency from Package.swift
- Update platforms to macOS 15+ only (drop iOS/tvOS/watchOS)
- Update Package@swift-6.0.swift similarly

The Perception import was never actually used - the file only uses
LockIsolated (from ConcurrencyExtras) and SharedReader (from Sharing).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
doozMen added a commit that referenced this pull request Feb 14, 2026
… only (#1)

- Remove `import Perception` from FetchSubscription.swift (was unused)
- Add explicit `import ConcurrencyExtras` for LockIsolated
- Remove swift-perception package dependency from Package.swift
- Update platforms to macOS 15+ only (drop iOS/tvOS/watchOS)
- Update Package@swift-6.0.swift similarly

The Perception import was never actually used - the file only uses
LockIsolated (from ConcurrencyExtras) and SharedReader (from Sharing).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant