Skip to content

fix: Use explicit Package.Dependency type to avoid Swift 6.2.3 circular reference bug#11

Merged
doozMen merged 5 commits intomainfrom
fix/swift-623-package-circular-ref
Feb 14, 2026
Merged

fix: Use explicit Package.Dependency type to avoid Swift 6.2.3 circular reference bug#11
doozMen merged 5 commits intomainfrom
fix/swift-623-package-circular-ref

Conversation

@doozMen
Copy link
Owner

@doozMen doozMen commented Jan 4, 2026

Problem

The pattern .package(url:...) inside package.dependencies.append() causes Swift 6.2.3 to confuse the member lookup with the package variable, resulting in a "circular reference" error.

Solution

Use the explicit type Package.Dependency.package(url:...) to avoid this ambiguity.

Testing

  • Verified Package.swift parses correctly with Swift 6.2.3

doozMen and others added 3 commits December 13, 2025 21:03
… 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>
Copilot AI review requested due to automatic review settings January 4, 2026 09:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a Swift 6.2.3 compiler bug where the .package(url:...) pattern inside package.dependencies.append() causes a circular reference error due to ambiguous member lookup. The fix uses explicit type qualification to disambiguate the reference.

  • Uses Package.Dependency.package(url:...) instead of .package(url:...) when appending dependencies
  • Adds explanatory comment documenting the Swift 6.2.3 workaround

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


#if !os(Windows)
// Add the documentation compiler plugin if possible
// NB: Use explicit type to avoid Swift 6.2.3 circular reference bug
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

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

The comment references Swift 6.2.3 as the version with the circular reference bug, but the swift-tools-version at the top of the file is still set to 6.2.1. If this fix is specifically for Swift 6.2.3, consider updating the swift-tools-version to match, or clarify in the comment whether this fix is forward-compatible for users who might upgrade to 6.2.3 while this package remains at 6.2.1.

Suggested change
// NB: Use explicit type to avoid Swift 6.2.3 circular reference bug
// NB: Use explicit type as a forward-compatible workaround for the circular reference
// bug observed when building this package with Swift 6.2.3 toolchains.

Copilot uses AI. Check for mistakes.
Stijn Willems and others added 2 commits January 4, 2026 10:39
Updates dependency to use fix/swift-623-optimizer-crash branch which includes compiler guards to work around the Swift 6.2.3 optimizer crash in SharedChangeTracker deinit.
@claude
Copy link

claude bot commented Jan 4, 2026

Pull Request Review: Swift 6.2.3 Compatibility Fixes

Summary

This PR addresses Swift 6.2.3 compiler compatibility issues through targeted workarounds. The changes are well-documented and appropriately scoped.

Code Quality & Best Practices - APPROVED

Strengths:

  • Clear documentation with detailed comments explaining rationale and tracking issues
  • Minimal scope - surgical changes only affecting code paths that trigger compiler bugs
  • Consistent pattern using compiler version guards across affected files
  • Proper Swift indentation standards maintained
  • Good commit messages following conventional commit style

Key Changes:

  1. Package.swift Lines 109-115: Explicit Package.Dependency.package() syntax workaround with clear comment explaining Swift 6.2.3 circular reference issue

  2. Statement+GRDB.swift Lines 189-211: Comment block explains upstream dependency, references Swift issue tracker, guard pattern matches upstream swift-structured-queries

  3. Table+GRDB.swift Lines 60-82: Fixed CRITICAL BUG - unterminated block comment. Maintains symmetry with Statement+GRDB.swift guards

  4. Package.swift Lines 70-76: Missing dependencies properly added to SQLiteDataTestSupport (InlineSnapshotTesting, StructuredQueriesTestSupport), removed stray package reference, fixed indentation

Potential Issues & Concerns

1. API Availability Impact (Medium Severity)
The find method is disabled on Swift 6.2.3+. Users must use alternative: Self.all.find(primaryKey).fetchOne(db). Consider adding compiler warning directive.

2. Inconsistent Issue Tracking (Low Severity)
Some files reference upstream Swift issue, others reference repo issue. Both valid but consistency would help.

3. Package.resolved Changes (Low Impact)
Origin hash changed as expected. New swift-tagged dependency properly resolved.

Performance Considerations - APPROVED

No performance impact. Compiler guards are compile-time decisions with zero runtime cost.

Security Concerns - APPROVED

No security issues. Changes are defensive, no new attack surface, dependency pins prevent supply chain issues.

Test Coverage - ADEQUATE

Manual verification confirmed. Existing tests cover functionality. Tests for disabled methods skip on affected versions.

Recommendations

  1. Update user-facing docs mentioning Table.find with Swift 6.2.3 compatibility note
  2. Consider CI testing on multiple Swift versions (< 6.2.3 and >= 6.2.3)
  3. Document migration path for when compiler bug is fixed

Final Verdict - APPROVE

Successfully addresses Swift 6.2.3 compatibility while maintaining quality standards, using minimal workarounds, fixing critical bugs, and preserving security/performance.

Critical fixes: Unterminated comment, missing dependencies, malformed dependency reference

Risk level: Low (defensive changes, well-documented temporary workarounds)

Copilot AI review requested due to automatic review settings January 22, 2026 13:27
@doozMen doozMen force-pushed the fix/swift-623-package-circular-ref branch from c8c6224 to 84323a6 Compare January 22, 2026 13:27
@claude
Copy link

claude bot commented Jan 22, 2026

Pull Request Review: Swift 6.2.3 Compiler Workarounds

Summary

This PR addresses Swift 6.2.3 compiler issues through two key changes:

  1. Fixes a circular reference bug in Package.swift using explicit type annotation
  2. Guards find(_:) methods with compiler version checks to work around optimizer crashes

Code Quality & Best Practices ✅

Package.swift Changes

Positive:

  • The explicit Package.Dependency.package(url:...) type annotation is a clean workaround for the Swift 6.2.3 circular reference bug
  • Clear inline documentation explaining the fix with the NB: comment
  • Minimal, surgical change that doesn't affect functionality

Minor Observation:

  • The dependency update from branch: "main" to branch: "fix/swift-623-optimizer-crash" introduces a dependency on a non-standard branch. Consider:
    • Once the upstream fix is stable, create a plan to migrate back to a tagged release or main branch
    • Document this temporary fork dependency in a tracking issue (if not already done)

Statement+GRDB.swift & Table+GRDB.swift Changes

Positive:

  • Appropriate use of #if !compiler(>=6.2.3) to conditionally disable problematic code
  • Excellent documentation with tracking links (https://github.com/swiftlang/swift/issues/82529)
  • Consistent application of the guard across both files
  • The existing commented-out code in Table+GRDB.swift:41-58 shows awareness of upstream issues

Concerns:

  • API Surface Reduction: The find(_:key:) method is completely unavailable for Swift 6.2.3+ users. This is a significant breaking change for anyone using Swift 6.2.3 or later.
    • Impact: Tests in FetchOneTests.swift:172-176 use Record.find(1), which will not compile on Swift 6.2.3+
    • Recommendation: Consider providing an alternative implementation or runtime fallback that doesn't trigger the compiler crash, even if less optimized

Potential Bugs or Issues ⚠️

  1. Test Coverage on Swift 6.2.3+: The guarded methods mean functionality is disabled on newer compilers. Have you:

    • Verified tests pass on Swift 6.2.3+ (where find is unavailable)?
    • Considered conditionally disabling tests that rely on find(_:key:) for Swift 6.2.3+?
  2. Comment Inconsistency:

    • Statement+GRDB.swift:189-191: References "Swift 6.2.3 and 6.3-dev"
    • Table+GRDB.swift:60-62: References "Swift 6.2.3 and 6.3-dev" but links to a different tracking issue (doozMen/sqlite-data/issues/2 vs swiftlang/swift/issues/82529)
    • Recommendation: Use consistent tracking references
  3. Package.resolved Changes: The addition of swift-tagged dependency (0.10.0) appears correct, but ensure this was intentional and not an accidental side effect of the dependency updates.

Performance Considerations ✅

  • No performance impact expected - these are compiler workarounds
  • The conditional compilation ensures no runtime overhead

Security Concerns ✅

  • No security issues identified
  • Dependency on forked branches (doozMen/swift-sharing, doozMen/swift-structured-queries) should be temporary
    • Recommendation: Track upstream progress and plan to migrate back to official releases

Test Coverage 📋

Current State:

  • The PR description mentions "Verified Package.swift parses correctly with Swift 6.2.3"
  • Tests use find(_:) method (e.g., FetchOneTests.swift:172, multiple CloudKit tests)

Recommendations:

  1. Compile Verification: Ensure the test suite compiles on Swift 6.2.3+ where find is guarded out
  2. Conditional Test Exclusion: Consider adding #if !compiler(>=6.2.3) guards around tests that require find(_:key:)
  3. Alternative Test Paths: For guarded functionality, add tests using alternative query methods to maintain coverage

Additional Observations

  1. Migration Path: The changes properly acknowledge these are temporary workarounds. Good practice to include tracking issues.
  2. Documentation: The inline comments are clear and explain the "why" behind the changes.
  3. Code Consistency: The indentation and formatting changes in Package.swift:73-76 improve readability.

Recommendations Summary

Must Address:

  • Verify test suite compiles and runs on Swift 6.2.3+
  • Add conditional compilation guards to tests using find(_:key:) if they fail on Swift 6.2.3+

Should Consider:

  • Unify tracking issue references across files
  • Document migration plan for forked dependencies
  • Consider providing alternative (less optimal) implementation of find that works on Swift 6.2.3+

Nice to Have:

  • Add CI job testing against Swift 6.2.3+ to catch future regressions

Overall Assessment

This is a solid workaround for a challenging compiler issue. The changes are well-documented and minimal. The main concern is ensuring the codebase remains usable on Swift 6.2.3+ despite the guarded methods. Once the test compatibility is verified, this should be safe to merge.

Status: Approve with minor recommendations ✅


Review generated by Claude Code

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// NB: Fork with Swift 6.3 fixes (uses doozMen/swift-perception)
.package(url: "https://github.com/doozMen/swift-sharing", branch: "main"),
// NB: Fork with Swift 6.3 fixes
.package(url: "https://github.com/doozMen/swift-sharing", branch: "fix/swift-623-optimizer-crash"),
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

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

The dependency on the third-party package swift-sharing is pinned to a mutable Git branch (branch: "fix/swift-623-optimizer-crash"), which means future builds will automatically pick up any new commits pushed to that branch. If the doozMen/swift-sharing repository or this branch is ever compromised, an attacker can silently inject malicious code into your build artifacts without any change to this repository. To mitigate this supply-chain risk, pin the dependency to an immutable reference such as a specific tagged version or commit SHA and only update it intentionally after review.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

doozMen commented Jan 22, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@doozMen doozMen force-pushed the fix/swift-623-package-circular-ref branch from d1a5b59 to 24097cc Compare February 14, 2026 16:20
Copilot AI review requested due to automatic review settings February 14, 2026 16:20
Copy link
Owner Author

doozMen commented Feb 14, 2026

Merge activity

  • Feb 14, 4:20 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Feb 14, 4:20 PM UTC: @doozMen merged this pull request with Graphite.

@doozMen doozMen merged commit 1c5920e into main Feb 14, 2026
5 of 10 checks passed
@doozMen doozMen deleted the fix/swift-623-package-circular-ref branch February 14, 2026 16:20
@claude
Copy link

claude bot commented Feb 14, 2026

PR Review: Fix Swift 6.2.3 Circular Reference Bug

Summary

This PR addresses a Swift 6.2.3 compiler bug by using explicit Package.Dependency.package(url:...) syntax in Package.swift and guards compiler-crash-prone code with #if !compiler(>=6.2.3) directives.

Code Quality ✅

Strengths:

Best Practices:

  • Good use of NB (nota bene) comments to explain why the workaround is necessary
  • Proper indentation maintained in guarded code blocks

Potential Issues ⚠️

1. Incomplete Package.swift cleanup (Package.swift:70-84)

The diff shows broken dependency declarations in the test target:

.testTarget(
    name: "SQLiteDataTests",
    dependencies: [
        "SQLiteData",
        "SQLiteDataTestSupport",
        .product(name: "DependenciesTestSupport", package: "swift-dependencies"),
        .product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
        // Line 82: Missing product reference before "package" keyword
        .product(name: "SnapshotTestingCustomDump", package: "swift-snapshot-testing"),
        .product(name: "StructuredQueries", package: "swift-structured-queries"),
    ]
)

There appears to be a removed line at line 82 (package: "swift-tagged") that seems malformed. The current Package.swift should be verified to ensure it compiles correctly.

2. Syntax error in Table+GRDB.swift:58

The diff shows a comment closure changing from #/ to */, which suggests a block comment. However, the opening /* for this comment block is not visible in the context. This could be:

  • Part of the existing commented-out code block starting at line 42
  • A potential syntax issue if the opening /* is missing

Recommendation: Verify that the comment block is properly closed and the file compiles without warnings.

3. Branch name update (Package.swift:34)

The swift-sharing dependency branch changed from "main" to "fix/swift-623-optimizer-crash". This is appropriate for the fix, but:

  • Consider whether this branch will eventually be merged back to main
  • Document the plan for removing this workaround when Swift fixes the issue
  • Add a tracking comment similar to the other workarounds

Performance Considerations ✅

No performance concerns. The changes are:

  • Compile-time only (conditional compilation)
  • The guarded code paths are identical in behavior to the non-guarded versions

Security Concerns ✅

No security issues identified. The changes are:

  • Syntax-level workarounds
  • No changes to logic or data handling
  • Branch reference changes are to trusted repositories (same org)

Test Coverage ⚠️

Observation: The PR description mentions "Verified Package.swift parses correctly with Swift 6.2.3" but doesn't mention:

  • Whether existing tests still pass with Swift 6.2.3
  • Whether the guarded functionality (find(db:key:) methods) has test coverage
  • What happens when this code is compiled with Swift 6.2.3+ (the methods are unavailable)

Recommendations:

  1. Verify all existing tests pass on Swift 6.2.3
  2. Add tests or documentation explaining the impact of losing the find(db:key:) methods on Swift 6.2.3+
  3. Consider adding conditional compilation tests to ensure the guards work correctly

New Dependency: swift-tagged ✅

Package.resolved adds swift-tagged@0.10.0, which was already declared in Package.swift:46. This is expected and correct.

Action Items

Must Fix:

  1. Verify Package.swift compiles correctly - the diff suggests potential syntax issues in the test target dependencies around line 82

Should Address:
2. Verify Table+GRDB.swift:58 comment closure syntax is correct
3. Document the plan for the swift-sharing branch workaround (when to revert to main)

Consider:
4. Add test coverage documentation for the guarded functionality
5. Document the API surface change when compiling with Swift 6.2.3+ (missing find methods)

Conclusion

This is a reasonable workaround for a known Swift compiler bug. The approach is well-documented and follows good practices for conditional compilation. However, there appear to be some potential syntax issues in Package.swift that should be verified before merging.

Recommendation: Request changes to verify Package.swift compiles correctly and address the syntax concerns mentioned above.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +189 to +193
// NB: Swift 6.2.3 and 6.3-dev guard Select.find(_:) in swift-structured-queries due to compiler crashes.
// This extension depends on that method, so it must also be guarded.
// Tracking: https://github.com/swiftlang/swift/issues/82529
#if !compiler(>=6.2.3)
extension SelectStatement where QueryValue == (), From: PrimaryKeyedTable, Joins == () {
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

PR description/title focus on the SwiftPM circular-reference fix, but this file also introduces a new compiler-version guard that removes SelectStatement.find(_:key:) on Swift 6.2.3+. Please update the PR description to mention this behavioral/API availability change (or split it into a separate PR) so reviewers/users understand why the method disappears on newer compilers.

Copilot uses AI. Check for mistakes.
Comment on lines +33 to 35
// NB: Fork with Swift 6.3 fixes
.package(url: "https://github.com/doozMen/swift-sharing", branch: "fix/swift-623-optimizer-crash"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.4"),
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

This PR also changes the swift-sharing dependency to a different branch, but the PR description only mentions the SwiftPM member-lookup/circular-reference fix. Please document why this dependency branch change is required here (or move it to a dedicated PR) to keep the change scoped and traceable.

Copilot uses AI. Check for mistakes.
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.

2 participants