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

[macOS] Change view ID to signed #39958

Merged
merged 6 commits into from Mar 31, 2023

Conversation

dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented Feb 28, 2023

This PR makes view ID signed from unsigned int64.

Initially, I made view IDs unsigned because they were opaque anyway. As I'm working deeper into multiview, I found some issues that made me think signed is better:

  • Unsigned integers are worse
    • Sometimes you want negative values to represent special values.
    • Unsigned integers are dangerous (if compared with signed ones by mistake.)
  • Unsigned integers are not needed
    • We're very unlikely to reach that big anyway.
    • Almost all other languages support only signed integers.
    • Also JavaScript only supports up to 51 bits of integer.

Therefore I think it's better to change them to signed int64, especially before these APIs are widely used by developers.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@dkwingsmt dkwingsmt marked this pull request as ready for review February 28, 2023 22:00
@@ -644,7 +644,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
@autoreleasepool {
// Create FVC1.
viewController1 = [[FlutterViewController alloc] initWithProject:project];
EXPECT_EQ(viewController1.id, 0ull);
EXPECT_EQ(viewController1.id, 0ll);
Copy link
Member

Choose a reason for hiding this comment

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

Should this be just 11? Same comment for other occurrences in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First, if this should be 1l, then the tests wouldn't pass. :)

Second, all tests here are for the current single-view uses, which only uses the default view. IDs starting from 1 are only for multiviews.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I'm sorry, those are Ls not 1s. Please ignore this comment, I should check my eye prescription.

Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

Sometimes you want negative values to represent special values.

Can you give an example of such a case? Should we be using a different type to represent view IDs if so?

Unsigned integers are dangerous (if compared with signed ones by mistake.)

One could say the same for signed integers, if compared with unsigned ones by mistake ;-)

All that said, an argument that I really do like in favour of signed integers is that that's what we use for the following other identifiers:

  • external texture
  • platform view
  • semantics node

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

Please define something like typedef int64_t FlutterViewIdentifier or similar rather than using int64_t in the public API.

@dkwingsmt
Copy link
Contributor Author

dkwingsmt commented Mar 1, 2023

@cbracken That's a good idea, but I find it hard to find a place to put it. This type (as well as kFlutterDefaultViewId, which I'll probably put into that header file as well) is used in both public headers (such as FlutterEngine.h) and the leaf classes (such as FlutterView.h), both of which requires minimal includes. The only option I can think of is a new public header. If so, what do you think I should call it? Common.h?

@chinmaygarde
Copy link
Member

Are we making progress on this?

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

LGTM stamp from a Japanese personal seal

@dkwingsmt dkwingsmt merged commit 1212658 into flutter:main Mar 31, 2023
39 checks passed
@dkwingsmt dkwingsmt deleted the change-view-id-to-signed branch March 31, 2023 19:11
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 31, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 31, 2023
zanderso added a commit that referenced this pull request Mar 31, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 31, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 31, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 31, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 31, 2023
dkwingsmt added a commit that referenced this pull request May 3, 2023
This is a reland of #39958, but
only contains the minimal changes that removes all references to viewId
from public interfaces, reverting these changes from
#39576.

Flutter doesn't really support multi-view anyway. These methods
currently only works for view 0. We better remove them until we mark
multi-view stable. It was a mistake that I decided to add them to public
interfaces.

For the reason why #39958 failed,
I'm pretty sure it's the change to
[platform_dispatcher.dart](https://github.com/flutter/engine/pull/39958/files#diff-57d6953e215d0e5dd7260ee60b665c812aa730566ef0b30f7ff1e3d661143585)
that mysteriously and unintentionally appeared in the change list.

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I added new tests to check the change I am making or feature I am
adding, or Hixie said the PR is test-exempt. See [testing the engine]
for instructions on writing and running engine tests.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I signed the [CLA].
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants