Skip to content
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 Semantics in preparation for ARC migration #52729

Merged
merged 4 commits into from May 14, 2024

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented May 11, 2024

Split the too-large Semantics MRC to ARC migration into two PRs: this one, which refactors, and the next which will actually do the migration.

  1. Use properties instead of their backing ivars (except in the usual init, dealloc, getters/setters)
  2. For Foundation collections prefer copy over strong.
  3. Dot notation for properties
  4. Change privateSetParent: to instead use a readwrite property in SemanticsObject ().
  5. Switch the semanticsObject property from weak to retain to get the synthesized property (keeping it as weak is a compilation error in MRC) but I'll swap it back to a weak in the ARC migration PR coming next.
  6. SemanticsObjectTest fails on my machine and passes on CI. Switched the cleaner CGRectEqualToRect (and related) checks to instead assert x, y, width, height so we can see the value when it fails:
((CGSizeEqualToSize( scrollView.contentSize, CGSizeMake((w + scrollExtentMax) * effectivelyScale, h * effectivelyScale))) is true) failed

becomes:

((scrollView.contentSize.height) equal to (h * effectivelyScale)) failed: ("33.3333333333") is not equal to ("33.333336")

Use XCTAssertEqualWithAccuracy now that I can see it's a floating point precision issue.

@jmagman jmagman self-assigned this May 11, 2024
@@ -231,7 +231,7 @@ constexpr float kScrollExtentMaxForInf = 1000;
bridge:(fml::WeakPtr<flutter::AccessibilityBridgeIos>)bridge
NS_DESIGNATED_INITIALIZER;

@property(nonatomic, weak) SemanticsObject* semanticsObject;
@property(nonatomic, assign) SemanticsObject* semanticsObject;
Copy link
Member Author

Choose a reason for hiding this comment

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

Made this assign to get the property synthesis. I'm going to change it back to weak when I do the ARC migration, which allows weak property synthesis. This header isn't public.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh wow i didn't know they have weak support in MRC.

Made this assign to get the property synthesis
So weak in MRC doesn't synthesize the getter/setter/ivar?

/** Should only be called in conjunction with setting child/parent relationship. */
- (void)privateSetParent:(SemanticsObject*)parent;
@property(nonatomic, assign, readwrite) SemanticsObject* parent;
Copy link
Member Author

Choose a reason for hiding this comment

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

Swap privateSetParent: to a readwrite property.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: readwrite is already the default

Copy link
Contributor

Choose a reason for hiding this comment

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

this will change to weak in arc right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I will make it weak in the ARC migration PR.

I was making the readwrite explicit since it's now overriding a readonly in the header:

@property(nonatomic, assign, readonly) SemanticsObject* parent;

}

@end

@implementation SemanticsObjectContainer {
SemanticsObject* _semanticsObject;
Copy link
Member Author

Choose a reason for hiding this comment

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

This backing ivar isn't when I swap from weak to assign. I included it here because when I migrate to ARC this isn't needed since the weak ARC property is auto-synthesized.

@jmagman jmagman changed the title Refactor Semantics in preparation of ARC migration Refactor Semantics in preparation for ARC migration May 11, 2024
@jmagman jmagman marked this pull request as ready for review May 13, 2024 20:47
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

I love to see all this modernization! LGTM!

Just some extremely optional comments.

[_children release];
[_childrenInHitTestOrder release];

_parent = nil;
_container.get().semanticsObject = nil;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to make sure I'm reading the other code correctly: this is safe to remove because semantics object was changed to weak at some point, right, and thus we don't need to explicitly clear it any more?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's how I read it too, I don't think weak property would need to be set to nil in MRC?

I see this comment where it was introduced:
https://github.com/flutter/engine/pull/7244/files#r259211775

But I don't see why it would be needed...

}
[_children removeAllObjects];
[_childrenInHitTestOrder removeAllObjects];
[_children release];
[_childrenInHitTestOrder release];

_parent = nil;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this here for the same reason as the awful _inDealloc workaround? In theory it shouldn't be necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

The _inDealloc workaround was done in #27786, which didn't include setting _parent to nil.

Setting _parent to nil was done in #4602 and I think it was for this guard:

if ([self parent] == nil) {
// This can happen when we have released the accessibility tree but iOS is
// still holding onto our objects. iOS can take some time before it
// realizes that the tree has changed.
return nil;
}

I don't like this but it seems like iOS is, or at least was, digging around the accessibilityContainer type methods during -[super dealloc] which was causing crashes. I'd rather not touch that for this refactor.

}

return self;
}

- (void)dealloc {
for (SemanticsObject* child in _children) {
[child privateSetParent:nil];
child.parent = nil;
}
[_children removeAllObjects];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this too? Hopefully we don't have code that is relying on the contents of an array that came from a since-deallocated object changing out from under it...

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll remove it in the ARC migration.

@@ -231,7 +231,7 @@ constexpr float kScrollExtentMaxForInf = 1000;
bridge:(fml::WeakPtr<flutter::AccessibilityBridgeIos>)bridge
NS_DESIGNATED_INITIALIZER;

@property(nonatomic, weak) SemanticsObject* semanticsObject;
@property(nonatomic, assign) SemanticsObject* semanticsObject;
Copy link
Contributor

Choose a reason for hiding this comment

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

oh wow i didn't know they have weak support in MRC.

Made this assign to get the property synthesis
So weak in MRC doesn't synthesize the getter/setter/ivar?

/** Should only be called in conjunction with setting child/parent relationship. */
- (void)privateSetParent:(SemanticsObject*)parent;
@property(nonatomic, assign, readwrite) SemanticsObject* parent;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: readwrite is already the default

/** Should only be called in conjunction with setting child/parent relationship. */
- (void)privateSetParent:(SemanticsObject*)parent;
@property(nonatomic, assign, readwrite) SemanticsObject* parent;
Copy link
Contributor

Choose a reason for hiding this comment

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

this will change to weak in arc right?

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label May 14, 2024
@auto-submit auto-submit bot merged commit 86c55dd into flutter:main May 14, 2024
29 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 14, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 14, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 14, 2024
…148338)

flutter/engine@7bf8657...08b44d9

2024-05-14 [email protected] [Impeller] migrated one test over from aiks to dl (flutter/engine#52786)
2024-05-14 [email protected] [Impeller] Create framebuffer blend vertices based on the snapshot's texture size instead of coverage (flutter/engine#52790)
2024-05-14 [email protected] Refactor Semantics in preparation for ARC migration (flutter/engine#52729)
2024-05-14 [email protected] Rolls in buildroot with stack protection flag (flutter/engine#52774)

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
@jmagman jmagman deleted the semantics-refactor branch May 15, 2024 03:48
auto-submit bot pushed a commit that referenced this pull request May 15, 2024
On top of the `SemanticsObject` refactor #52729 migrate `SemanticsObject` and `FlutterSemanticsScrollView` to ARC.

Part of flutter/flutter#137801.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-ios
Projects
None yet
3 participants