Skip to content

fix(patch): resolve overlapping exclusive access errors in library evolution mode#14

Merged
freef4ll merged 1 commit intomainfrom
evolution-library-fixes
Mar 4, 2026
Merged

fix(patch): resolve overlapping exclusive access errors in library evolution mode#14
freef4ll merged 1 commit intomainfrom
evolution-library-fixes

Conversation

@hassila
Copy link
Contributor

@hassila hassila commented Mar 4, 2026

Restructure buffer access patterns to avoid simultaneous inout borrows of sibling stored properties, which the compiler rejects in resilient (library evolution) builds where it cannot prove disjointness.

Description

Include a summary of the change and which issue is fixed.

Fixes #issue-number

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist

  • I have performed a self-review of my own code
  • I have added DocC documentation (/// comments) for any new public APIs
  • I have added tests that prove my fix is effective or that my feature works
  • All tests pass (swift test)
  • If this is a performance-related change, I have included benchmark results (before/after)

… mode

Restructure buffer access patterns to avoid simultaneous inout borrows
of sibling stored properties, which the compiler rejects in resilient
(library evolution) builds where it cannot prove disjointness.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hassila hassila requested a review from freef4ll March 4, 2026 06:48
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves critical compiler errors that occur in Swift's library evolution mode due to strict exclusive access rules. By refactoring how internal buffers are accessed within the fuzzy matching algorithms, it ensures that multiple mutable properties can be safely used simultaneously without triggering runtime or compile-time violations, thereby improving the library's resilience and compatibility with future Swift versions.

Highlights

  • Resolved Overlapping Exclusive Access Errors: Addressed compiler rejections in Swift's resilient (library evolution) builds caused by simultaneous inout borrows of sibling stored properties, which previously led to overlapping exclusive access errors.
  • Introduced Safe Buffer Access Methods: Implemented withEditDistanceBuffers and withSmithWatermanBuffers methods within ScoringBuffer to provide a single exclusive access to self and project its stored properties through a closure, ensuring safe concurrent access to internal buffers.
  • Refactored CandidateStorage Buffer Access: Modified CandidateStorage.withMutableBuffers to use swap operations with local array copies, effectively preventing overlapping exclusive accesses to self when dealing with nested withUnsafeMutableBufferPointer calls.
Changelog
  • Sources/FuzzyMatch/FuzzyMatcher.swift
    • Refactored scoreSmithWatermanImpl call to use the new buffer.withSmithWatermanBuffers method for safe buffer access.
    • Refactored scoreImpl call to use the new buffer.withEditDistanceBuffers method for safe buffer access.
  • Sources/FuzzyMatch/ScoringBuffer.swift
    • Implemented withEditDistanceBuffers method to provide safe, simultaneous inout access to edit distance related buffers.
    • Implemented withSmithWatermanBuffers method to provide safe, simultaneous inout access to Smith-Waterman related buffers.
    • Modified CandidateStorage.withMutableBuffers to use swap for temporary local array copies, preventing overlapping exclusive access violations.
Activity
  • The pull request description indicates that it fixes an issue, but the specific issue number is a placeholder.
  • A checklist is provided in the PR description, outlining tasks like self-review, documentation, and testing, but no actual activity or status updates on these items are available.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.64%. Comparing base (95961d8) to head (99da6be).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #14   +/-   ##
=======================================
  Coverage   98.64%   98.64%           
=======================================
  Files          41       41           
  Lines        9031     9047   +16     
=======================================
+ Hits         8908     8924   +16     
  Misses        123      123           
Files with missing lines Coverage Δ
Sources/FuzzyMatch/FuzzyMatcher.swift 96.39% <100.00%> (+0.01%) ⬆️
Sources/FuzzyMatch/ScoringBuffer.swift 100.00% <100.00%> (ø)
Files with missing lines Coverage Δ
Sources/FuzzyMatch/FuzzyMatcher.swift 96.39% <100.00%> (+0.01%) ⬆️
Sources/FuzzyMatch/ScoringBuffer.swift 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95961d8...99da6be. Read the comment docs.

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

@freef4ll freef4ll merged commit 77668fc into main Mar 4, 2026
11 of 12 checks passed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves an "overlapping exclusive access" compiler error in Swift's library evolution mode by refactoring buffer access patterns. The changes in FuzzyMatcher.swift and ScoringBuffer.swift correctly apply standard Swift patterns to work around simultaneous inout borrows. The implementation is clean and well-documented. I have one suggestion in ScoringBuffer.swift to use a defer statement, which would make the resource cleanup more robust and idiomatic.

Comment on lines +81 to +88
let result = localBytes.withUnsafeMutableBufferPointer { bytesPtr in
localBonus.withUnsafeMutableBufferPointer { bonusPtr in
body(bytesPtr.baseAddress!, bonusPtr.baseAddress!)
}
}
swap(&localBytes, &bytes)
swap(&localBonus, &bonus)
return result

Choose a reason for hiding this comment

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

medium

Using a defer block to swap the arrays back would make this code more robust and idiomatic. While the current implementation is correct because the body closure doesn't throw, defer guarantees that the cleanup logic (swapping back the arrays) is executed right before the function returns. This is especially useful if the function's logic becomes more complex or if the closure's signature is changed to be throwing in the future.

        defer {
            swap(&localBytes, &bytes)
            swap(&localBonus, &bonus)
        }
        return localBytes.withUnsafeMutableBufferPointer { bytesPtr in
            localBonus.withUnsafeMutableBufferPointer { bonusPtr in
                body(bytesPtr.baseAddress!, bonusPtr.baseAddress!)
            }
        }

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

@hassila hassila deleted the evolution-library-fixes branch March 4, 2026 08:07
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