-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Migrate FlutterCallbackCache and FlutterKeyboardManager to ARC #51983
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
@@ -89,7 +76,7 @@ - (void)handlePress:(nonnull FlutterUIPressProxy*)press | |||
// encounter. | |||
NSAssert([_primaryResponders count] >= 0, @"At least one primary responder must be added."); | |||
|
|||
__block auto weakSelf = [self getWeakNSObject]; | |||
__block __weak __typeof(self) weakSelf = self; |
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.
Removed the WeakNSObjectFactory
in favor of __weak
where it's used before the block. I can swap __typeof(self)
to FlutterKeyboardManager*
I don't really have a preference.
ed4e0e3
to
a1a9cde
Compare
de33c74
to
a0a0ebf
Compare
@@ -168,7 +168,7 @@ - (void)testResize { | |||
[binaryMessenger stopMocking]; | |||
} | |||
|
|||
- (bool)testSetWarnsOnOverflow { | |||
- (void)testSetWarnsOnOverflow { |
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.
Unrelated, but noticed this wasn't running because the signature wasn't void.
shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm
Outdated
Show resolved
Hide resolved
} // namespace | ||
|
||
// These tests were designed to run on iOS 13.4 or later. | ||
API_AVAILABLE(ios(13.4)) |
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.
Putting the availability on the class FlutterKeyboardManagerTest
means it won't need to be checked in setUp or decorated on the methods.
@property(nonatomic, assign) BOOL didCallNotifyLowMemory; | ||
@end | ||
|
||
@interface FlutterEngine () |
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.
Dead code.
using namespace flutter::testing; | ||
|
||
/// Sometimes we have to use a custom mock to avoid retain cycles in ocmock. | ||
@interface FlutterEnginePartialMock : FlutterEngine |
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.
Dead code.
[super tearDown]; | ||
} | ||
|
||
- (id)checkKeyDownEvent:(UIKeyboardHIDUsage)keyCode API_AVAILABLE(ios(13.4)) { |
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.
Dead code.
@interface FlutterKeyboardManagerTest : XCTestCase | ||
@property(nonatomic, strong) id mockEngine; |
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.
Moved this into a local in the one remaining spot the engine is mocked.
|
||
// Verify that the nextResponder returned from mockOwnerWithPressesBeginOnlyNext() | ||
// throws exception when pressesEnded is called. | ||
- (bool)testNextResponderShouldThrowOnPressesEnded API_AVAILABLE(ios(13.4)) { |
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.
This wasn't actually running because the return type wasn't void.
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.
Maybe we need a custom CI check on this? It seems like anything in Test.{m,mm}
that starts - (anything but void)test
is probably wrong.
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.
Filed flutter/flutter#146671
shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm
Outdated
Show resolved
Hide resolved
46815b3
to
0c8d245
Compare
// It will be destroyed and invalidate its weak pointers | ||
// before any other members are destroyed. | ||
_weakFactory.reset(); | ||
|
||
[_primaryResponders removeAllObjects]; | ||
[_secondaryResponders removeAllObjects]; |
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.
Why would we need to remove everything from private properties in dealloc? Is there some way we are vending outside references to these arrays?
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.
Let me check.
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 don't think it would be necessary, this is the only place -addPrimaryResponder
and -addSecondaryResponder
are called:
engine/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Lines 823 to 831 in 76a270f
[self.keyboardManager addPrimaryResponder:[[[FlutterEmbedderKeyResponder alloc] | |
initWithSendEvent:sendEvent] autorelease]]; | |
FlutterChannelKeyResponder* responder = [[[FlutterChannelKeyResponder alloc] | |
initWithChannel:self.engine.keyEventChannel] autorelease]; | |
[self.keyboardManager addPrimaryResponder:responder]; | |
FlutterTextInputPlugin* textInputPlugin = self.engine.textInputPlugin; | |
if (textInputPlugin != nil) { | |
[self.keyboardManager addSecondaryResponder:textInputPlugin]; | |
} |
I'll remove.
FlutterUIPressProxy* press; | ||
FlutterAsyncKeyCallback callback; | ||
__unsafe_unretained FlutterUIPressProxy* press; | ||
__unsafe_unretained FlutterAsyncKeyCallback callback; |
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.
This seems scary. Why are we passing unsafe unretained pointers to an async block? It seems like this code was probably just wrong before?
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 think it's needed for ARC NSInvocation calls, that's the only place I've regularly seen __unsafe_unretained
used
https://developer.apple.com/documentation/foundation/nsinvocation/1437830-getargument#discussion
__unsafe_unretained id tempObject = nil;
[myInvocation getArgument: &tempObject atIndex: 2];
self.myObject = tempObject;
NSLog(@"Argument 0 was: %@", self.myObject); // prints "A string"
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.
Given that the next thing we do is pass the arguments into an async block, I think we are missing a critical intermediate step:
You can then copy this into another form of storage, like a strongly-held property.
I know this is pre-existing, but it seems like a very likely source of flaky test crashing, so we should fix it while we are here. We can rename these something like pressUnsafe
and callbackUnsafe
and then do
FlutterUIPressProxy* press = pressUnsafe;
FlutterAsyncKeyCallback callback = callbackUnsafe;
That way we won't be trying to run an async block with pointers into memory owned by an invocation that's almost certainly out of scope. I'm pretty surprised that the current code is ever working.
|
||
// Verify that the nextResponder returned from mockOwnerWithPressesBeginOnlyNext() | ||
// throws exception when pressesEnded is called. | ||
- (bool)testNextResponderShouldThrowOnPressesEnded API_AVAILABLE(ios(13.4)) { |
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.
Maybe we need a custom CI check on this? It seems like anything in Test.{m,mm}
that starts - (anything but void)test
is probably wrong.
f79c459
to
92daaec
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.
LGTM. Thanks for the fixes!
auto label is removed for flutter/engine/51983, due to Pull request flutter/engine/51983 is not in a mergeable state. |
92daaec
to
25bfa11
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.
Nice! Also nice catch on the dead code. Wonder how much else we have floating around :/
…146776) flutter/engine@84238c4...07ae93c 2024-04-15 [email protected] Roll Dart SDK from ac31be3c8546 to 3c2376cb9850 (1 revision) (flutter/engine#52095) 2024-04-15 [email protected] Migrate FlutterCallbackCache and FlutterKeyboardManager to ARC (flutter/engine#51983) 2024-04-15 [email protected] Roll buildroot and set ios_use_simulator variable used by Skia GN scripts (flutter/engine#52101) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…lutter#146776) flutter/engine@84238c4...07ae93c 2024-04-15 [email protected] Roll Dart SDK from ac31be3c8546 to 3c2376cb9850 (1 revision) (flutter/engine#52095) 2024-04-15 [email protected] Migrate FlutterCallbackCache and FlutterKeyboardManager to ARC (flutter/engine#51983) 2024-04-15 [email protected] Roll buildroot and set ios_use_simulator variable used by Skia GN scripts (flutter/engine#52101) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Smart pointers support ARC as of #47612, and the unit tests were migrated in #48162.
Migrate
FlutterCallbackCache
andFlutterKeyboardManager
from MRC to ARC. These files do not themselves import any MRC files, making them leaf nodes in the dependency graph of MRC files.Doing a few at a time to make the dependency graph manageable, and to easily revert if this causes retain cycles or other memory management issues.
Part of flutter/flutter#137801.