-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Refactor FXIOS-12831 [Swift 6 Migration] MainActor TabManagerMiddleware #29768
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
Refactor FXIOS-12831 [Swift 6 Migration] MainActor TabManagerMiddleware #29768
Conversation
🧹 Tidy commitJust 1 file(s) touched. Thanks for keeping it clean and review-friendly! 💬 Description craftsmanGreat PR description! Reviewers salute you 🫡 ❌ Per-file test coverage gateThe following changed file(s) are below 35.0% coverage:
Client.app: Coverage: 37.2
Generated by 🚫 Danger Swift against 52db608 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup, and thank goodness for finally seeing the correct compiler errors! 👏
firefox-ios/Client/Frontend/Browser/Tabs/Middleware/TabManagerMiddleware.swift
Show resolved
Hide resolved
57ea2c1 to
b80d510
Compare
84f7941 to
a2c6dc6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReadingListsTests fail on my end as well. The tests are known to be passing consistently.
a2c6dc6 to
5b10e38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pulled down to test the crash and it's pretty crazy to me the compiler gives zero warnings on this. I want to test a bit in a brand new Swift 6.2 project and/or playground just to replicate the issue to see if I get anything there.
What do you think changing the group.notify to dispatch to the main thread? That seems the real issue here (the mix of GCD and Concurrency). Then we could put an assert instead of ensureMainThread in the fetchProfileTabInfo completion... because if concurrency was working correctly for us here we shouldn't have to do that. 😭
private func fetchProfileTabInfo(...) {
...
group.notify(queue: dataQueue) // <- main queue instead?
| /// - isPrivate: if the tab should be created in private mode or not | ||
| private func addNewTab(with urlRequest: URLRequest?, isPrivate: Bool, showOverlay: Bool, for uuid: WindowUUID) { | ||
| assert(Thread.isMainThread) | ||
| MainActor.assertIsolated("Expected to be called only on main actor.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to double check that this gets removed at prod compile time, it sounds like it does!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Woohoo the issue in tests has been resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to update here for visibility. After some testing, it seems the only scenario we do NOT get the appropriate build warnings in Xcode is due to the GCD DispatchGroup.notify call. For whatever reason, this call does not require the closure to be marked @Sendable, which in turn would have let us know that the closure might not execute on the main thread (which is what caused the crash @lmarceau saw in the UI tests). If we used instead DispatchQueue.global().async we get the expected warnings to at least tip us off to a runtime crash problem.
I've opened a discussion on the Apple Developer Forums about this last week... haven't heard anything yet.
Anyway, for now I think I'd like to see the dataLoadingCompletion closure marked @Sendable in the fetchProfileTabInfo function definition, and for the notify to dispatch deliberately to the main thread (instead of the background queue). It's a little weird to thread hop for that like we're doing anyway.
Maybe we can also put a main thread assertion in the fetchProfileTabInfo callback implementation and add a comment referring back to this PR for the discussion points. (Also still good to continue to use the ensureMainThread as well as backup 👌 ).
5b10e38 to
52db608
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lmarceau for your iterations on this one! 🚀
9aebabd
into
epic-branch/swift-6-redux-migration
|
Created the task for follow up investigation on notify here |
…re (#29768) * Tab manager middleware * fetchProfileTabInfo completion needs to be called on the main thread * Update following comment
…re (#29768) * Tab manager middleware * fetchProfileTabInfo completion needs to be called on the main thread * Update following comment
…re (#29768) * Tab manager middleware * fetchProfileTabInfo completion needs to be called on the main thread * Update following comment
…re (#29768) * Tab manager middleware * fetchProfileTabInfo completion needs to be called on the main thread * Update following comment
…re (#29768) * Tab manager middleware * fetchProfileTabInfo completion needs to be called on the main thread * Update following comment
…Actor` isolation (#30208) * Refactor FXIOS-12831 [Swift 6 Migration] MainActor TabManagerMiddleware (#29768) * Tab manager middleware * fetchProfileTabInfo completion needs to be called on the main thread * Update following comment * Refactor FXIOS-12831 [Swift 6 Migration] MainActor ToolbarMiddleware (#30014) Toolbar middleware Missing microsurvey to be tested * Ih/fxios 12831 search engine selection middleware 2 (#30026) * Isolate the SearchEngineSelectionMiddleware to the main actor. * Update unit tests. * Tweak mocks so the SearchEnginesManagerTests unit tests pass under the same threading assumptions. * Refactor FXIOS-12831 [Swift 6 Migration] MainActor TopSitesMiddleware & HomepageMiddleware (#30039) Migration for those two middlewares * Refactor FXIOS-12831 [Swift 6 Migration] MainActor SummarizerMiddleware (#30042) Migration * Refactor FXIOS-12831 [Swift 6 Migration] MainActor MainMenuMiddleware (#30013) main menu middleware is now main actor * Refactor FXIOS-12831 [Swift 6 Migration] MainActor TermsOfUseMiddleware & StartAtHomeMiddleware (#30061) Migration * Refactor FXIOS-12831 [Swift 6 Migration] @mainactor MessageCardMiddleware & ShortcutsLibraryMiddleware (#30064) Migration * Refactor FXIOS-12831 [Swift 6 Migration] MainActor MicrosurveyMiddleware & MicrosurveyPromptMiddleware (#30041) * MIgration * Adjust test * Refactor FXIOS-12831 [Swift 6 Migration] MainActor ThemeMiddleware & FakeReduxMiddleware (#30040) Migration * Refactor FXIOS-12831 [Swift 6 Migration] FeltPrivacyMiddleware & BookmarksMiddleware (#30083) Migration * Refactor FXIOS-12831 [Swift 6 Migration] NativeErrorPageMiddleware & TrackingProtectionMiddleware (#30088) * Migration * Native error page VC migration * Fix VC/coordinator not getting deinit * Revert dispatch legacy changes * Refactor FXIOS-12912 [Swift 6] Make Redux States sendable and Reducers @mainactor isolated (#30081) * Make Redux State Sendable and Reducers MainActor isolated * disambiguate passthrough state and default state * Fix tests * PR feedback * Refactor FXIOS-12831 [Swift 6 Migration] RemoteTabsPanelMiddleware & WallpaperMiddleware MainActor (#30117) Migration * Refactor FXIOS-12831 [Swift 6 Migration] PasswordGeneratorMiddleware actor isolation (#30085) * Isolate PasswordGeneratorMiddleware to the main actor. * Add @mainactor annotations to our WebKit JS evaluation wrappers. * Refactor FXIOS-12831 [Swift 6 Migration] MerinoMiddleware actor isolation (#30084) Isolate MerinoMiddleware to the main actor. --------- Co-authored-by: lmarceau <[email protected]> Co-authored-by: Carson Ramsden <[email protected]>

📜 Tickets
Jira ticket
Github issue
💡 Description
Second attempt at this, first one was here.
Now we do get the compiler errors. This is under tab peek (if I remove the
ensureMainThreadwhich was added a week ago or so):And this is another error we didn't catch as well last time around:
cc: @Cramsden @ih-codes
📝 Checklist