Skip to content

[Functions] Address more Swift 6 warnings #14772

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

Merged
merged 1 commit into from
Apr 26, 2025
Merged

[Functions] Address more Swift 6 warnings #14772

merged 1 commit into from
Apr 26, 2025

Conversation

ncooke3
Copy link
Member

@ncooke3 ncooke3 commented Apr 24, 2025

Note: module is not yet 100% Swift 6 compliant.

  1. This was the first error I sought to fix.
Screenshot 2025-04-24 at 6 10 47 PM
  1. I added @MainActor so the compiler enforces that the completion handler can only be called on the main actor. This address the error in step 1.

  2. The new @MainActor attribute needed to bubble up to signature of a function that called the first one.

Screenshot 2025-04-24 at 6 15 55 PM
  1. Next, the compiler enforces the completion is only called on main actor.
Screenshot 2025-04-24 at 6 17 37 PM
  1. That's fixable by wrapping in a main queue dispatch block.
Screenshot 2025-04-24 at 6 19 38 PM
  1. The next appears back in the first function that was changed. The source of the error is that line 487 returns a HTTPSCallableResult which is not Sendable, so sending it could cause data races.
Screenshot 2025-04-24 at 6 20 23 PM
  1. It doesn't seem safe to mark HTTPSCallableResult as Sendable (it would have to be unchecked) because it retains an Any. While our SDK could be audited to verify that it doesn't access the Any reference, there'd be no way to enforce that it isn't accessed unsafely in SDK or client code.
Screenshot 2025-04-24 at 6 22 07 PM
  1. To fix the error, we can specify that the returned HTTPSCallableResult is sending which indicates that it isn't accessed after being returned to the calling context.
Screenshot 2025-04-24 at 6 25 33 PM
  1. The new Task or actor isolated value cannot be sent error in the above screenshot is tricky. The following fixes appear to address it. I think the issue is that we need to indicate that the Any value is only owned in the current context. To do that, we mark responseDataJSON to return a sending Any. Marking FunctionsSerializer as Sendable is the final piece. I'm less sure why it resolves it though? Previously, I added sending to FunctionsSerializer's decodeAPI but that led to errors down a rabbit hole that I ultimately couldn't solve simply.
Screenshot 2025-04-24 at 6 31 16 PM

#no-changelog

Copy link
Contributor

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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

Copy link
Member

@paulb777 paulb777 left a comment

Choose a reason for hiding this comment

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

Thanks for the step-by-step thorough explanation!

Copy link
Contributor

@morganchen12 morganchen12 left a comment

Choose a reason for hiding this comment

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

LGTM

I wonder if we could make HTTPCallableResult a generic instead of Any and then add Sendable conformance for parameterized types that are Sendable.

@ncooke3
Copy link
Member Author

ncooke3 commented Apr 26, 2025

LGTM

I wonder if we could make HTTPCallableResult a generic instead of Any and then add Sendable conformance for parameterized types that are Sendable.

Yes, I like that approach. It would be breaking to add the generic and I am curious how the ObjC API would be affected.

@ncooke3 ncooke3 merged commit 8d1305d into main Apr 26, 2025
39 checks passed
@ncooke3 ncooke3 deleted the nc/functions-swift6 branch April 26, 2025 00:19
@paulb777
Copy link
Member

It looks like this might have broken the Objective-C API. See the nightly failure in https://github.com/firebase/firebase-ios-sdk/actions/runs/14679321280/job/41206125399. @ncooke3 PTAL

Screenshot 2025-04-26 at 7 47 04 AM

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

Successfully merging this pull request may close these issues.

4 participants